Language: C#
Windows Live SDK for Windows 8
public class LiveId { // used by Live ID public LiveId(IDictionary<string, object> result) : this(result, null) { } public LiveId(IDictionary<string, object> result, Uri image) { Id = result.ContainsKey("id") ? result["id"] as string : string.Empty; NameFull = result.ContainsKey("name") ? result["name"] as string : string.Empty; NameFirst = result.ContainsKey("first_name") ? result["first_name"] as string : string.Empty; NameLast = result.ContainsKey("last_name") ? result["last_name"] as string : string.Empty; Gender = result.ContainsKey("gender") ? result["gender"] as string : string.Empty; Locale = result.ContainsKey("locale") ? result["locale"] as string : string.Empty; Uri _Uri; if (Uri.TryCreate(result.ContainsKey("link") ? result["link"] as string : string.Empty, UriKind.Absolute, out _Uri)) Link = _Uri; DateTime _Date; if (DateTime.TryParse(result.ContainsKey("updated_time") ? result["updated_time"] as string : string.Empty, out _Date)) UpdatedTime = _Date; var _Emails = result.ContainsKey("emails") ? result["emails"] as IDictionary<string, object> : new Dictionary<string, object>(); EmailPreferred = _Emails.ContainsKey("preferred") ? _Emails["preferred"] as string : string.Empty; EmailAccount = _Emails.ContainsKey("account") ? _Emails["account"] as string : string.Empty; if (image != null) { PhotoLocation = image; var _PhotoBitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage(image); PhotoBitmap = _PhotoBitmap; } } public string Id { get; set; } public string NameFull { get; set; } public string NameFirst { get; set; } public string NameLast { get; set; } public Uri Link { get; set; } public string Gender { get; set; } public string Locale { get; set; } public DateTime UpdatedTime { get; set; } public string EmailAccount { get; set; } public string EmailPreferred { get; set; } public Uri PhotoLocation { get; set; } public Windows.UI.Xaml.Media.Imaging.BitmapImage PhotoBitmap { get; set; } } protected async override void OnNavigatedTo(NavigationEventArgs e) { var _Result = await LoginAsync(false); if (!_Result.HasValue) { // TODO: error occurred } else if (_Result.Value) { // TODO: login success } else { // TODO: login failed } } public async Task<bool?> LoginAsync(bool logout) { try { var _Client = new Microsoft.Live.LiveAuthClient() { Theme = Microsoft.Live.ThemeType.Light }; if (logout && _Client.CanLogout) _Client.Logout(); Login.LoginResult = await _Client.LoginAsync(new string[] { "wl.signin", "wl.basic", "wl.emails" }); if (Login.LoginResult.Status != Microsoft.Live.LiveConnectSessionStatus.Connected) return false; Login.Client = new Microsoft.Live.LiveConnectClient(Login.LoginResult.Session); var _MeResult = (await Login.Client.GetAsync("me")).Result; dynamic _PhotoResult = (await Login.Client.GetAsync("me/picture")).Result; var _PhotoLocation = new Uri(_PhotoResult.location, UriKind.Absolute); Login.User = new Models.LiveId(_MeResult, _PhotoLocation); return true; } catch (Exception) { System.Diagnostics.Debugger.Break(); return null; } } public static Microsoft.Live.LiveLoginResult LoginResult { get; private set; } public static Microsoft.Live.LiveConnectClient Client { get; private set; } public static Models.LiveId User { get; private set; }
Tags:
Report Abuse
Subscribe
Discuss
News
About
New Snippet
Recent Snippets
My Snippets
Favorites
Web Code
Search
Copy
Line#