がりらぼ

WindowsRuntimeの応援ブログ

C#で組み合わせ(ry

[csharp]</pre>

using ContinentOfAlpaca.Model;

using ContinentOfAlpaca.SharedData;

using GalaSoft.MvvmLight;

using GalaSoft.MvvmLight.Command;

using LinqToTwitter;

using System;

using System.Collections.Generic;

using System.Diagnostics;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Windows.UI.Core;

using Windows.UI.Popups;

namespace ContinentOfAlpaca.ViewModel

{

public class AuthenticationViewModel : ViewModelBase

{

public PinAuthorizer Authorizer { get; set; }

public CoreDispatcher Dispatcher { get; set; }

public AuthenticationViewModel(CoreDispatcher dispatcher)

{

this.Dispatcher = dispatcher;

AuthInitCommand = new RelayCommand(() =>

{

Authorizer = new PinAuthorizer()

{

Credentials = new InMemoryCredentials()

{

ConsumerKey = ConstantData.ConsumerKey,

ConsumerSecret = ConstantData.ConsumerSecret

},

UseCompression = true,

};

});

BeginAuthCommand = new RelayCommand(() =>

{

Authorizer.BeginAuthorize(q =>

{

});

});

PinAuthCommand = new RelayCommand<string>(pin =>

{

Authorizer.CompleteAuthorize(pin, q=>

{

TwitterContext context = new TwitterContext(new PinAuthorizer()

{

Credentials = Authorizer.Credentials

});

var verify=context.Account.Where(p => p.Type == AccountType.VerifyCredentials).Select(p => p).SingleOrDefault();

Dispatcher.RunAsync(CoreDispatcherPriority.Normal,()=>{

SharedInstance.savedInstance.AccountList.Add(new UserAccount()

{

AccessToken = Authorizer.Credentials.AccessToken,

TokenSecret = Authorizer.Credentials.OAuthToken,

ScreenName = q.State.ScreenName,

Name = verify.User.Name,

ProfileImageUrl = verify.User.ProfileImageUrl,

Id = q.State.ID

});

});

});

});

}

public RelayCommand AuthInitCommand { get; set; }

public RelayCommand<string> PinAuthCommand { get; set; }

public RelayCommand BeginAuthCommand { get; set; }

}

}

<pre>

[/csharp]