Ejemplo n.º 1
0
 void OnGetCompleted(LiveOperationResult e)
 {
     if (e.Result.ContainsKey("first_name") ||
         e.Result.ContainsKey("last_name"))
     {
         if (e.Result.ContainsKey("first_name"))
         {
             if (e.Result["first_name"] != null)
             {
                 FirstName = e.Result["first_name"].ToString();
             }
         }
         if (e.Result.ContainsKey("last_name"))
         {
             if (e.Result["last_name"] != null)
             {
                 LastName = e.Result["last_name"].ToString();
             }
         }
         String Welcome = SkyPhoto.Resources.Resources.Welcome;
         ProfileName.Text = Welcome + " " + FirstName + " " + LastName;
         gotoAlbum.Visibility = Visibility.Visible;
         GetProfilePicture();
         NavigationService.Navigate(new Uri("/AlbumPage.xaml", UriKind.Relative));
     }
 }
        public async Task Authenticate(LiveConnectSessionChangedEventArgs e)
        {
            if (e.Status == LiveConnectSessionStatus.Connected)
            {
                CurrentLoginStatus = "Connected to Microsoft Services";
                liveConnectClient = new LiveConnectClient(e.Session);
                microsoftAccountLoggedInUser = await liveConnectClient.GetAsync("me");

                CurrentLoginStatus = "Getting Microsoft Account Details";
                mobileServiceLoggedInUser =
                    await App.MobileService.LoginWithMicrosoftAccountAsync(e.Session.AuthenticationToken);

                CurrentLoginStatus = string.Format("Welcome {0}!", microsoftAccountLoggedInUser.Result["name"]);
                userName = microsoftAccountLoggedInUser.Result["name"].ToString();

                await Task.Delay(2000); // non-blocking Thread.Sleep for 2000ms (2 seconds)

                CurrentlyLoggedIn = true;
                CurrentLoginStatus = string.Empty;
                // this will then flip the bit that shows the different UI for logged in

                await UpdateUserOnRemoteService(); // and update on the remote service
                await UpdateLeaderBoard(); // do first pass on leaderboard update
            }
            else
            {
                CurrentLoginStatus = "Y U NO LOGIN?";
                CurrentlyLoggedIn = false;
            }

        }
Ejemplo n.º 3
0
        private IEnumerable<ICloudItem> TryLoadItems(LiveOperationResult operationResult)
        {
            dynamic result = operationResult.Result;

            if (result.data == null) return new List<SkyDriveItem>();            

            dynamic items = result.data;
            return LoadItems(items);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// LiveConnectClient event handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void GetAlubmData_Completed(LiveOperationResult e)
        {
            List<object> data = (List<object>)e.Result["data"];
            if (ImageCounter == 0)
            {
                ImageCounter = data.Count;
            }

            foreach (IDictionary<string, object> album in data)
            {
                SkydriveAlbum albumItem = new SkydriveAlbum();
                albumItem.Title = (string)album["name"];
                albumItem.Description = (string)album["description"];
                albumItem.ID = (string)album["id"];
                Albums.Add(albumItem);
                GetAlbumPicture(albumItem);
            }
        }
        /// <summary>
        ///     Event handler called when an operation (except for download) is completed.
        /// </summary>
        /// <param name="sender">The object that fires the event.</param>
        /// <param name="e">The event arg containing the result of the operation.</param>
        private static void OnOperationCompleted(object sender, LiveOperationCompletedEventArgs e)
        {
            var state = e.UserState as OperationState <LiveOperationResult>;

            if (state != null)
            {
                UnSubscribe(state.LiveClient, state.Method);

                var tcs = state.Tcs;
                if (e.Error != null)
                {
                    tcs.TrySetException(e.Error);
                }
                else
                {
                    LiveOperationResult result = new LiveOperationResult(e.Result, e.RawResult);
                    tcs.TrySetResult(result);
                }
            }
        }
Ejemplo n.º 6
0
        private static void ValidateContacts(LiveOperationResult result)
        {
            Assert.IsNotNull(result, "ValidateContacts failed.  result is null.");
            Assert.IsNotNull(result.Result, "ValidateContacts failed.  result.Result is null.");
            var data = result.Result["data"] as IList;
            Assert.IsNotNull(data, "ValidateContacts failed.  'data' is null.");
            Assert.AreEqual(data.Count, 3, "ValidateContacts failed.  'data' count is incorrect.");

            foreach (object value in data)
            {
                var contactProperties = value as IDictionary<string, object>;
                ValidateContactProperties(contactProperties);
            }
        }
Ejemplo n.º 7
0
 private static void ValidateMe(LiveOperationResult result)
 {
     Assert.IsNotNull(result, "ValidateMe failed.  result is null.");
     Assert.IsNotNull(result.Result, "ValidateMe failed.  result.Result is null.");
     Assert.IsTrue(!string.IsNullOrEmpty(result.RawResult), "ValidateMe failed.  result.RawResult is null or empty.");
     Assert.IsTrue(!string.IsNullOrEmpty(result.Result["id"] as string), "ValidateMe failed.  'id' is null or empty.");
     Assert.IsTrue(!string.IsNullOrEmpty(result.Result["first_name"] as string), "ValidateMe failed.  'first_name' is null or empty.");
     Assert.IsTrue(!string.IsNullOrEmpty(result.Result["last_name"] as string), "ValidateMe failed.  'last_name' is null or empty.");
 }
Ejemplo n.º 8
0
        void client_GetCompleted(LiveOperationResult e)
        {
            if (e != null)
            {
                List<object> list = e.Result["data"] as List<object>;

                if (list == null)
                {
                    return;
                }
                List<SkyDriveListItem> listItems = new List<SkyDriveListItem>();
                foreach (var item in list)
                {
                    
                    IDictionary<string, object> dict = item as IDictionary<string, object>;
                    if (dict == null)
                    {
                        continue;
                    }

                    if (this.skydriveStack.Count == 1)
                    {
                        this.skydriveStack.Last()[0].SkyDriveID = dict["parent_id"].ToString();
                    }

                    String name = dict["name"].ToString();
                    SkyDriveItemType type;
                    if (dict["type"].Equals("folder") || dict["type"].Equals("album"))
                    {
                        type = SkyDriveItemType.Folder;
                    }
                    else
                    {
                        type = SkyDriveItemType.File;
                        int dotIndex = -1;
                        if ((dotIndex = name.LastIndexOf('.')) != -1)
                        {
                            String substrName = name.Substring(dotIndex).ToLower();
#if GBC
                            if (substrName.Equals(".gb") || substrName.Equals(".gbc"))
#else
                            if (substrName.Equals(".gba"))
#endif
                            {
                                type = SkyDriveItemType.ROM;
                            }
                        }
                    }

                    if (type == SkyDriveItemType.File)
                    {
                        continue;
                    }

                    SkyDriveListItem listItem = new SkyDriveListItem()
                    {
                        Name = dict["name"].ToString(),
                        SkyDriveID = dict["id"].ToString(),
                        Type = type,
                        ParentID = dict["parent_id"].ToString()
                    };
                    if (type == SkyDriveItemType.Folder)
                    {
                        int count = 0;
                        int.TryParse(dict["count"].ToString(), out count);
                        listItem.FolderChildrenCount = count;
                    }

                    listItems.Add(listItem);
                }
                this.skydriveStack.Add(listItems);
                this.skydriveList.ItemsSource = listItems;
            }
            else
            {
                MessageBox.Show(String.Format(AppResources.SkyDriveGeneralError, "Api Error"), AppResources.ErrorCaption, MessageBoxButton.OK);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// folderListClient event handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void FolderListClient_GetCompleted(LiveOperationResult e, SkydriveAlbum album)
        {
            album.Photos.Clear();
            List<object> data = (List<object>)e.Result["data"];
            NumberOfImages = data.Count;

            if (NumberOfImages == 0)
            {
                HideProgressBar();
                return;
            }

            foreach (IDictionary<string, object> photo in data)
            {
                var item = new SkydrivePhoto();
                item.Title = (string)photo["name"];
                item.Subtitle = (string)photo["name"];
                item.PhotoUrl = (string)photo["source"];
                item.Description = (string)photo["description"];
                item.ID = (string)photo["id"];

                if (album != null)
                {
                    album.Photos.Add(item);
                }
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// LiveConnectClient event handler
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void DeleteFile_Completed(SkydrivePhoto selectedFile, LiveOperationResult e)
 {
     if (e.Result != null)
     {
         App.CurrentAlbum.Photos.Remove(selectedFile);
     }
     else
     {
         string downFaild = SkyPhoto.Resources.Resources.downFaild;
         MessageBox.Show(downFaild);
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// LiveConnectClient event handler
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void DeleteFolder_Completed(SkydriveAlbum selectedAlbum, LiveOperationResult e)
 {
     if (e.Result != null)
     {
         Albums.Remove(selectedAlbum);
     }
     else
     {
         string msgDelFailed = SkyPhoto.Resources.Resources.msgDelFailed;
         MessageBox.Show(msgDelFailed);
     }
 }
        public async Task Authenticate()
        {
            // For Microsoft ID to work in Windows 8, you need to associate the Windows 8 app
            // with a Windows 8 Store app (ie: create an app in the Store/reserve a name)
            // you do not need to publish the app to test

            var liveIdClient = new LiveAuthClient("https://headstails.azure-mobile.net/");

            while (App.liveConnectSession == null)
            {
                // Force a logout to make it easier to test with multiple Microsoft Accounts
                if (liveIdClient.CanLogout)
                    liveIdClient.Logout();

                CurrentLoginStatus = "Connecting to Microsoft Services";

                // as per: http://stackoverflow.com/questions/17938828/obtaining-the-users-email-address-from-the-live-sdk

                var result = await liveIdClient.LoginAsync(new[] { "wl.emails" });
                if (result.Status == LiveConnectSessionStatus.Connected)
                {
                    CurrentLoginStatus = "Connected to Microsoft Services";
                    App.liveConnectSession = result.Session;
                    var client = new LiveConnectClient(result.Session);
                    microsoftAccountLoggedInUser = await client.GetAsync("me");

                    CurrentLoginStatus = "Getting Microsoft Account Details";
                    mobileServiceLoggedInUser = await App.MobileService.LoginWithMicrosoftAccountAsync(result.Session.AuthenticationToken);
                    
                    var remoteLeaderBoard = App.MobileService.GetTable<Leaderboard>();
                    remoteLeaderBoard = App.MobileService.GetTable<Leaderboard>();

                    CurrentLoginStatus = string.Format("Welcome {0}!", microsoftAccountLoggedInUser.Result["name"]);
                    userName = microsoftAccountLoggedInUser.Result["name"].ToString();

                    await Task.Delay(2000); // non-blocking Thread.Sleep for 2000ms (2 seconds)

                    CurrentlyLoggedIn = true; // this will then flip the bit that shows the different UI for logged in
                }
                else
                {
                    CurrentLoginStatus = "Y U NO LOGIN?";
                    CurrentlyLoggedIn = false;
                }
            }
        }
        private void LiveConnector_UploadCompleted(LiveOperationResult e)
        {
            System.Action action = null;

            if (null == null)
            {
                if (action == null)
                {
                    action = delegate
                    {
                        this.datatransferingStep.Success();
                        this.actionEndingStep.Start();
                        this.actionEndingStep.Success();
                    };
                }
                this.StatusUpdatingCallBack(action);
                string msg = string.Empty;
                if (BackupAndRestoreDataSyncingMode)
                {
                    msg = this.DataContextSyncingDataHandler.DataSynchronizationDataArg.GetMessage();
                }
                this.StatusUpdatingCallBack(delegate
                {
                    this.OnReportingStatus(new ReportStatusHandlerEventArgs("UploadDataToSkyDriveSuccessMessage", msg));
                });
            }
            else
            {
                this.StatusUpdatingCallBack(new System.Action(this.datatransferingStep.Failed));
                //UNDONE:
                //this.OnReportingStatus(new ReportStatusHandlerEventArgs("UploadDataToSkyDriveFailedMessage", e.Error.Message));
                //AppUpdater.AddErrorLog("Error when Uploading DataToSkyDrive", e.Error.ToString(), new string[0]);
            }
            this.OnSyncingFinished(System.EventArgs.Empty);
        }
 private void getUserPicture_Callback(LiveOperationResult e, MemoryStream userState)
 {
     if (null == null)
     {
         if (userState != null)
         {
             new BitmapImage().SetSource(userState);
         }
         else
         {
             this.OnLiveConnectorSyncingObjectFailed(new LiveConnectorSyncHandlerEventArgs(LiveConnectorSyncObject.UserPicture, null, "Could not find user's picture"));
         }
     }
     else
     {
         //this.OnLiveConnectorSyncingObjectFailed(new LiveConnectorSyncHandlerEventArgs(LiveConnectorSyncObject.UserPicture, e.Error, "Could not find user's picture"));
     }
     this.getUserName();
 }
 private void getUserName_Callback(LiveOperationResult e)
 {
     if (null == null)
     {
         System.Collections.Generic.IDictionary<String, Object> result = e.Result;
         this.UserName = result["name"].ToString();
     }
     else
     {
         this.OnLiveConnectorSyncingObjectFailed(new LiveConnectorSyncHandlerEventArgs(LiveConnectorSyncObject.UserName, null, "Could not find user's Name"));
     }
 }
Ejemplo n.º 16
0
        private static void ValidateFiles(LiveOperationResult result)
        {
            Assert.IsNotNull(result, "ValidateFiles failed.  result is null.");
            Assert.IsNotNull(result.Result, "ValidateFiles failed.  result.Result is null.");
            var data = result.Result["data"] as IList;
            Assert.IsNotNull(data, "ValidateFiles failed.  'data' is null.");
            Assert.AreEqual(data.Count, 6, "ValidateFiles failed.  'data' count is incorrect.");

            foreach (object value in data)
            {
                var fileProperties = value as IDictionary<string, object>;
                Assert.IsTrue(!string.IsNullOrEmpty(fileProperties["id"] as string), "ValidateFiles failed.  'id' is null or empty.");

                string type = fileProperties["type"] as string;
                Assert.IsTrue(!string.IsNullOrEmpty(type), "ValidateFiles failed.  'type' is null or empty.");

                if (string.CompareOrdinal(type, "folder") == 0 || string.CompareOrdinal(type, "album") == 0)
                {
                    Assert.IsTrue(!string.IsNullOrEmpty(fileProperties["name"] as string), "ValidateFiles failed.  'name' is null or empty.");
                    Assert.IsTrue(!string.IsNullOrEmpty(fileProperties["upload_location"] as string), "ValidateFiles failed.  'upload_location' is null or empty.");
                }
                else
                {
                    ValidateFileProperties(fileProperties);
                }
            }
        }
        private async Task UpdateSession(LiveConnectClient client, LiveOperationResult result)
        {
            var session = this.DataContext as Session;
            
            LiveOperationResult operationResult = await client.GetAsync(result.Result["id"] + "/content?download=true");
            dynamic value = operationResult.Result;

            session.DeckSource = value.location.ToString();
        }
Ejemplo n.º 18
0
        private static void ValidateFile(LiveOperationResult result)
        {
            Assert.IsNotNull(result, "ValidateFiles failed.  result is null.");
            Assert.IsNotNull(result.Result, "ValidateFiles failed.  result.Result is null.");

            ValidateFileProperties(result.Result);
        }
Ejemplo n.º 19
0
 void CreateFolder_Completed(LiveOperationResult result)
 {
     if (result != null)
     {
         // succesful.
         Dispatcher.BeginInvoke(() =>
         {
             Albums.Clear();
             GetAlubmData();
         }
         );
     }
     else
     {
         string newAlbumFaild = SkyPhoto.Resources.Resources.newAlbumFaild;
         MessageBox.Show(newAlbumFaild);
     }
 }
Ejemplo n.º 20
0
 /// <summary>
 /// LiveOperationCompletedEventArgs event handler GetPicture_GetCompleted
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void GetPicture_GetCompleted(LiveOperationResult e)
 {
     ProfilePic.Source = new BitmapImage(new Uri((string)e.Result["location"], UriKind.RelativeOrAbsolute));   
 }
Ejemplo n.º 21
0
 /// <summary>
 /// uploadClient event handler
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void ISFile_UploadCompleted(LiveOperationResult args)
 {
     HideProgressBar();
     string progMsgDownAlumPic = SkyPhoto.Resources.Resources.progMsgDownAlumPic;
     ShowProgressBar(progMsgDownAlumPic);
     ImageCounter = 0;
     DownloadPictures(App.CurrentAlbum);
 }
        private static bool CheckIfFolderExists(ref string eventBuddyFolderId, LiveOperationResult foldersResult)
        {
            var folders = (List<object>)foldersResult.Result["data"];
            var isFound = false;
            var iterator = 0;

            while (!isFound && iterator < folders.Count())
            {
                dynamic folder = folders[iterator];

                if (folder.name == "EventBuddy")
                {
                    isFound = true;

                    eventBuddyFolderId = folder.id;
                }

                iterator++;
            }

            return isFound;
        }
Ejemplo n.º 23
0
        /// <summary>
        /// LiveConnectClient event handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void albumPictureClient_GetCompleted(LiveOperationResult e, SkydriveAlbum album)
        {
            if (e != null)
            {
                album.AlbumPicture = (string)e.Result["location"];
            }
            else
            {
                album.AlbumPicture = "/icons/empty_album.png";
            }
            // hide progressbar.
            ImageCounter--;

            if (ImageCounter == 0)
            {
                HideProgressBar();
            }
        }