예제 #1
0
        public async static Task<List<SkyDriveEntity>> GetFolderContents(LiveConnectSession session, string folderId)
        {
            try
            {
                LiveConnectClient client = new LiveConnectClient(session);
                LiveOperationResult result = await client.GetAsync(folderId + "/files");

                //clear entries in data
                data.Clear();

                List<object> container = (List<object>)result.Result["data"];
                foreach (var item in container)
                {
                    SkyDriveEntity entity = new SkyDriveEntity();

                    IDictionary<string, object> dictItem = (IDictionary<string, object>)item;
                    string type = dictItem["type"].ToString();
                    entity.IsFolder = type == "folder" || type == "album" ? true : false;
                    entity.ID = dictItem["id"].ToString();
                    entity.Name = dictItem["name"].ToString();
                    data.Add(entity);
                }
                return null;
            }
            catch
            {
                return null;
            }
        }
        private async void InitializePage()
        {
            try
            {
                this.authClient = new LiveAuthClient();
                LiveLoginResult loginResult = await this.authClient.InitializeAsync(scopes);
                if (loginResult.Status == LiveConnectSessionStatus.Connected)
                {
                    if (this.authClient.CanLogout)
                    {
                        this.btnLogin.Content = "Sign Out";
                    }
                    else
                    {
                        this.btnLogin.Visibility = Visibility.Collapsed;
                    }

                    this.liveClient = new LiveConnectClient(loginResult.Session);
                    this.GetMe();
                }
            }
            catch (LiveAuthException authExp)
            {
                this.tbResponse.Text = authExp.ToString();
            }
        }
예제 #3
0
        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var liveIdClient = new LiveAuthClient();
            Task<LiveLoginResult> tskLoginResult = liveIdClient.LoginAsync(new string[] { "wl.signin" });
            tskLoginResult.Wait();

            switch (tskLoginResult.Result.Status)
            {
                case LiveConnectSessionStatus.Connected:

                    try
                    {
                        LiveConnectClient client = new LiveConnectClient(tskLoginResult.Result.Session);
                        LiveOperationResult liveOperationResult = await client.GetAsync("me");

                        dynamic operationResult = liveOperationResult.Result;
                        string name = string.Format("Hello {0} ", operationResult.first_name);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(string.Format("ERRO, {0}", ex.Message), ex);
                    }

                    break;
                case LiveConnectSessionStatus.NotConnected:
                    int j = 10;
                    break;
                default:
                    int z = 10;
                    break;
            }
        }
예제 #4
0
        private void OnSessionChanged(object sender, Microsoft.Live.Controls.LiveConnectSessionChangedEventArgs e)
        {
            if (e.Error == null)
            {
                if (e.Status == LiveConnectSessionStatus.Connected)
                {

                    this.liveClient = new LiveConnectClient(e.Session);

                    this.GetMe();

                    /*var client = new LiveConnectClient(e.Session);
                    client.GetCompleted += (o, args) =>
                    {
                        if (args.Error == null)
                        {
                            MessageBox.Show(Convert.ToString(args.Result["name"]));
                        }
                    };
                    client.GetAsync("me"); */

                }
                else
                {
                    this.liveClient = null; 

                }
            }

        }
예제 #5
0
        private  async void loginButton_Click(object sender, RoutedEventArgs e)//登录
        {
            try
            {
                msgText.Text = "亲:正在登录";
                var authClient = new LiveAuthClient();

                LiveLoginResult result = await authClient.LoginAsync(new string[] { "wl.signin", "wl.skydrive" });

                if (result.Status == LiveConnectSessionStatus.Connected)
                {

                    var connectClient = new LiveConnectClient(result.Session);
                    var meResult = await connectClient.GetAsync("me");
                    msgText.Text = "亲爱的:" + meResult.Result["name"].ToString() + "  您已成功登录OneDrive!";
                }
                updateButton.Visibility = Visibility.Visible;
                uploadButton.Visibility = Visibility.Visible;
                downButton.Visibility = Visibility.Visible;


            }
            catch (LiveAuthException ex)
            {
                msgText.Text = ex.Message;
            }
            catch (LiveConnectException ex)
            {
                msgText.Text = ex.Message;
            }
        }
 private async void liveSignIn_SessionChanged(object sender, Microsoft.Live.Controls.LiveConnectSessionChangedEventArgs e)
 {
     if (e.Status == LiveConnectSessionStatus.Connected)
     {
         liveClient = new LiveConnectClient(e.Session);
         LiveOperationResult operationResult = await liveClient.GetAsync("me");
         try
         {
             dynamic meResult = operationResult.Result;
             if (meResult.first_name != null && meResult.last_name != null)
             {
                 infoTextBlock.Text = "Hello " + meResult.first_name + " " + meResult.last_name + "!";
             }
             else
             {
                 infoTextBlock.Text = "Hello, signed-in user!";
             }
         }
         catch (LiveConnectException exception)
         {
             this.infoTextBlock.Text = "Error calling API: " + exception.Message;
         }
     }
     else
     {
         infoTextBlock.Text = "Not signed in.";
     }
 }
예제 #7
0
        private  async void uploadButton_Click(object sender, RoutedEventArgs e)//上传
        {
            try
            {
                msgText.Text = "亲:正在上传";
                var authClient = new LiveAuthClient();
                var authResult = await authClient.LoginAsync(new string[] { "wl.skydrive", "wl.skydrive_update" });
                if (authResult.Session != null)
                {
                    var liveConnectClient = new LiveConnectClient(authResult.Session);
                    StorageFolder localFolder = ApplicationData.Current.LocalFolder;
                    StorageFile file = await localFolder.GetFileAsync(App.WordBookFileName);
                    String fileText = await FileIO.ReadTextAsync(file);

                    LiveUploadOperation uploadOperation = await liveConnectClient.CreateBackgroundUploadAsync(
                        "me/skydrive", file.Name, file, OverwriteOption.Overwrite);
                    LiveOperationResult uploadResult = await uploadOperation.StartAsync();

                    if (uploadResult.Result != null)
                    {
                        msgText.Text = "恭喜:您已成功同步生词至OneDrive!";
                    }

                }
            }
            catch (LiveAuthException ex)
            {
                msgText.Text = ex.Message;
            }
            catch (LiveConnectException ex)
            {
                msgText.Text = ex.Message;
            }

        }
예제 #8
0
파일: Auth.cs 프로젝트: NickHeiner/chivalry
 private async Task<LiveConnectClient> ensureConnection()
 {
     if (connection != null)
     {
         return connection;
     }
     // Initialize access to the Live Connect SDK.
     LiveAuthClient LCAuth = new LiveAuthClient("https://chivalry.azure-mobile.net/");
     LiveLoginResult LCLoginResult = await LCAuth.InitializeAsync();
     // Sign in to the user's Microsoft account with the required scope.
     //    
     //  This call will display the Microsoft account sign-in screen if the user 
     //  is not already signed in to their Microsoft account through Windows 8.
     // 
     //  This call will also display the consent dialog, if the user has 
     //  has not already given consent to this app to access the data described 
     //  by the scope.
     // 
     LiveLoginResult loginResult = await LCAuth.LoginAsync(new string[] { "wl.basic", "wl.emails" });
     if (loginResult.Status == LiveConnectSessionStatus.Connected)
     {
         // Create a client session to get the profile data.
         connection = new LiveConnectClient(LCAuth.Session);
         mobileServiceUser = await App.MobileService.LoginAsync(loginResult.Session.AuthenticationToken);
         return connection;
     }
     if (LoginFailed != null)
     {
         LoginFailed(this, null);
     }
     return null;
 }
        private void SignInButtonSessionChanged(object sender, LiveConnectSessionChangedEventArgs e)
        {
            if (e.Session != null)
            {
                _session = e.Session;
                var client = new LiveConnectClient(_session);
                EventHandler<LiveOperationCompletedEventArgs> handler = null;
                handler = (s, even) =>
                              {
                                  client.GetCompleted -= handler;
                                  var resultDict = (Dictionary<string, object>)even.Result;

                                  var items = (List<object>)resultDict["data"];
                                  // Перебираем все объекты в папке, отбиаем только тип folder
                                  foreach (var item in
                                      items.Cast<Dictionary<string, object>>().Where(item => item["type"].ToString() == "folder"))
                                  {
                                      _files.Add(new FileModel() { Name = item["name"].ToString() });
                                  }
                                  lbFileList.ItemsSource = _files;
                              };
                client.GetCompleted += handler;
                //Путь к корню вашего skydrive
                client.GetAsync("me/skydrive/files");

            }
        }
        private async void InitializePage()
        {
            try
            {
                this.authClient = new LiveAuthClient();
                LiveLoginResult loginResult = await this.authClient.InitializeAsync(scopes);
                if (loginResult.Status == LiveConnectSessionStatus.Connected)
                {
                    if (this.authClient.CanLogout)
                    {
                        this.btnLogin.Content = "Sign Out";
                    }
                    else
                    {
                        this.btnLogin.Visibility = Visibility.Collapsed;
                    }

                    this.liveClient = new LiveConnectClient(loginResult.Session);
                }
            }
            catch (LiveAuthException)
            {
                // TODO: Display the exception
            }
        }
        private async Task<dynamic> GetUserLogged() 
        {
            var liveIdClient = new LiveAuthClient();
            Task<LiveLoginResult> tskLoginResult = liveIdClient.LoginAsync(new string[] { "wl.signin" });
            tskLoginResult.Wait();

            switch (tskLoginResult.Result.Status)
            {
                case LiveConnectSessionStatus.Connected:
                    try
                    {
                        LiveConnectClient client = new LiveConnectClient(tskLoginResult.Result.Session);
                        LiveOperationResult liveOperationResult = await client.GetAsync("me");

                        dynamic operationResult = liveOperationResult.Result;
                        return operationResult;
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(string.Format("ERRO, {0}", ex.Message), ex);
                    }
                case LiveConnectSessionStatus.NotConnected:
                    break;
            }

            return null;
        }
 private async void btnSignin_SessionChanged_2(object sender, LiveConnectSessionChangedEventArgs e)
 {
     currentLoginType = "Microsoft";
     if (TextValidation())
     {
         lblMsg.Text = "";
         App.liveAuthClient = new LiveAuthClient(redirectURL);
         LiveLoginResult liveLoginResult = await App.liveAuthClient.LoginAsync(new string[] { "wl.signin", "wl.basic" });
         if (liveLoginResult.Session != null && liveLoginResult.Status == LiveConnectSessionStatus.Connected)
         {
             client = new LiveConnectClient(liveLoginResult.Session);
             LiveOperationResult operationResult = await client.GetAsync("me");
             dynamic pic = await client.GetAsync("me/picture");
             try
             {
                 MobileServiceUser user = await App.MobileService.LoginAsync(client.Session.AuthenticationToken);
                 if (!String.IsNullOrEmpty(user.UserId))
                 {
                     dynamic meResult = operationResult.Result;
                     if (meResult.first_name != null && meResult.last_name != null)
                         //initiliazed user LiveUserInfo properties
                         SetUserDetails(user.UserId, meResult.name, meResult.first_name, meResult.last_name, pic.Result.location);
                     else
                         infoTextBlock.Text = "Welcome, Guest!";
                 }
             }
             catch (LiveConnectException exception)
             {
                 this.infoTextBlock.Text = "Error calling API: " +
                     exception.Message;
             }
         }
     }
 }
예제 #13
0
        private async Task <bool> DownloadFile(string fileID, string whereToSave)
        {
            bool   fileDownloadResult = false;
            string skydriveFileId     = fileID;

            try
            {
                LiveConnectClient client = new Microsoft.Live.LiveConnectClient(authClient.Session);

                //create a target file with the correct name and extension
                StorageFile downloadedFile = await storageFolder.CreateFileAsync(whereToSave, CreationCollisionOption.ReplaceExisting);

                //pass in the file id (path) and the StorageFile you created and it's filled with the downloaded files data
                await client.BackgroundDownloadAsync(skydriveFileId + "/content", downloadedFile);

                fileDownloadResult = true;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message.ToString());
                fileDownloadResult = false;
            }

            return(fileDownloadResult);
        }
예제 #14
0
        private void UploadFile (string name)
            {
            try
                {
                using (var storage = IsolatedStorageFile.GetUserStoreForApplication ())
                    {
                    var fileStream = storage.OpenFile (name + ".wav", FileMode.Open);
                    var uploadClient = new LiveConnectClient (Utilities.SkyDriveSession);
                    uploadClient.UploadCompleted += UploadClient_UploadCompleted;
                    uploadClient.UploadAsync ("me/skydrive", name + ".wav", fileStream, OverwriteOption.Rename);
                    _progressIndicatror = new ProgressIndicator
                    {
                        IsVisible = true,
                        IsIndeterminate = true,
                        Text = "Uploading file..."
                    };

                    SystemTray.SetProgressIndicator (this, _progressIndicatror);
                    }
                }
            catch (Exception)
                {
                ShowError ();
                NavigationService.GoBack ();
                }
            }
        /// <summary>
        /// Tests logging into MobileService with Live SDK token. App needs to be assosciated with a WindowsStoreApp
        /// </summary>
        private async Task TestLiveSDKLogin()
        {
            try
            {
                LiveAuthClient liveAuthClient = new LiveAuthClient(GetClient().MobileAppUri.ToString());
                LiveLoginResult result = await liveAuthClient.InitializeAsync(new string[] { "wl.basic", "wl.offline_access", "wl.signin" });
                if (result.Status != LiveConnectSessionStatus.Connected)
                {
                    result = await liveAuthClient.LoginAsync(new string[] { "wl.basic", "wl.offline_access", "wl.signin" });
                }
                if (result.Status == LiveConnectSessionStatus.Connected)
                {
                    LiveConnectSession session = result.Session;
                    LiveConnectClient client = new LiveConnectClient(result.Session);
                    LiveOperationResult meResult = await client.GetAsync("me");
                    MobileServiceUser loginResult = await GetClient().LoginWithMicrosoftAccountAsync(result.Session.AuthenticationToken);

                    Log(string.Format("{0} is now logged into MobileService with userId - {1}", meResult.Result["first_name"], loginResult.UserId));
                }
            }
            catch (Exception exception)
            {
                Log(string.Format("ExceptionType: {0} Message: {1} StackTrace: {2}",
                                                exception.GetType().ToString(),
                                                exception.Message,
                                                exception.StackTrace));
                Assert.Fail("Log in with Live SDK failed");
            }
        }
예제 #16
0
 void clientDataFetch_GetCompleted(object sender, LiveOperationCompletedEventArgs e)
 {
     if (e.Error == null)
     {
         List<object> data = (List<object>)e.Result["data"];
         string file_id = "";
         foreach (IDictionary<string, object> content in data)
         {
             if ((string)content["name"] == "BillDB.sdf")
                 file_id = (string)content["id"];
         }
         if (file_id == "")
             MessageBox.Show("No database file found.");
         else
         {
             MessageBox.Show("DB id: " + file_id + ";");
             try
             {
                 LiveConnectClient liveClient = new LiveConnectClient(session);
                 liveClient.GetCompleted += new EventHandler<LiveOperationCompletedEventArgs>(shareLink_completed);
                 liveClient.GetAsync(file_id + "/shared_edit_link");
             }
             catch (LiveConnectException exception)
             {
                 MessageBox.Show("Error getting shared edit link: " + exception.Message);
             }
         }
     }
 }
예제 #17
0
 public async Task<ActionResult> Index()
 {
     // récupération du statut de la connection de l'utilisateur
     var loginResult = await AuthClient.InitializeWebSessionAsync(this.HttpContext);
     // si l'utilisateur est connecté
     if (loginResult != null && loginResult.Status == LiveConnectSessionStatus.Connected)
     {
         // Récupération et affichage des informations de l'utilisateur
         var userData = new UserDataModel();
         LiveConnectClient client = new LiveConnectClient(this.AuthClient.Session);
         LiveOperationResult meResult = await client.GetAsync("me");
         if (meResult != null)
         {
             dynamic meInfo = meResult.Result;
             userData.LastName = meInfo.last_name;
             userData.FirstName = meInfo.first_name;
         }
         return View("LoggedIn", userData);
     }
     else
     {
         // l'utilisateur n'est pas connecté, génération de l'URL de connection
         var options = new Dictionary<string, string>();
         options["state"] = REDIRECT_URL;
         string loginUrl = this.AuthClient.GetLoginUrl(new string[] { "wl.signin" }, REDIRECT_URL, options);
         ViewBag.loginUrl = loginUrl;
         return View("LoggedOut");
     }
 }
        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;
            }

        }
예제 #19
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (this.NavigationContext.QueryString.ContainsKey("path"))
            {
                this.folderPath = NavigationContext.QueryString["path"];
            }
            if (this.NavigationContext.QueryString.ContainsKey("id"))
            {
                this.fileID = NavigationContext.QueryString["id"];
            }
            if (this.NavigationContext.QueryString.ContainsKey("filename"))
            {
                this.filename = this.NavigationContext.QueryString["filename"];
                this.filenameInput.Text = this.filename;
            }

            if (this.fileID != null)
            { // try to get file contents

                this.progressIndicator = new ProgressIndicator();
                this.progressIndicator.IsIndeterminate = true;
                this.progressIndicator.IsVisible = true;
                this.progressIndicator.Text = "Looking for rain...";
                SystemTray.SetProgressIndicator(this, this.progressIndicator);

                LiveConnectClient client = new LiveConnectClient(App.Current.LiveSession);
                client.DownloadCompleted += new EventHandler<LiveDownloadCompletedEventArgs>(OnFileDownloadComplete);
                client.DownloadAsync(this.fileID+"/content");
            }
            else
            {
                this.contentInput.IsEnabled = true;
                this.filenameInput.Focus(); // doesn't work as it is here, maybe because page isn't actually loaded yet?
            }
        }
예제 #20
0
        /// <summary>
        /// DownloadPictures downs picutre link from sky dirve
        /// </summary>
        /// <param name="albumItem"></param>
        private async void DownloadPictures(SkydriveAlbum albumItem)
        {
            LiveConnectClient folderListClient = new LiveConnectClient(App.Session);
            LiveOperationResult result = await folderListClient.GetAsync(albumItem.ID + "/files");
            FolderListClient_GetCompleted(result, albumItem);

        }
예제 #21
0
        async void skydriveList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SkyDriveListItem item = this.skydriveList.SelectedItem as SkyDriveListItem;
            if (item == null)
                return;

            try
            {
                LiveConnectClient client = new LiveConnectClient(this.session);
                if (item.Type == SkyDriveItemType.Folder)
                {
                    if (this.session != null)
                    {
                        this.skydriveList.ItemsSource = null;
                        this.currentFolderBox.Text = item.Name;
                        LiveOperationResult result = await client.GetAsync(item.SkyDriveID + "/files");
                        this.client_GetCompleted(result);
                    }
                }
                else if (item.Type == SkyDriveItemType.Savestate || item.Type == SkyDriveItemType.SRAM)
                {
                    if (item.Type == SkyDriveItemType.Savestate)
                    {
                        string slot = item.Name.Substring(item.Name.Length - 5, 1);
                        int parsedSlot = 0;
                        if (!int.TryParse(slot, out parsedSlot))
                        {
                            MessageBox.Show(AppResources.ImportSavestateInvalidFormat, AppResources.ErrorCaption, MessageBoxButton.OK);
                            return;
                        }
                    }
                    // Download
                    if (!item.Downloading)
                    {
                        try
                        {
                            item.Downloading = true;
                            await this.DownloadFile(item, client);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(String.Format(AppResources.DownloadErrorText, item.Name, ex.Message), AppResources.ErrorCaption, MessageBoxButton.OK);
                        }
                    }
                    else
                    {
                        MessageBox.Show(AppResources.AlreadyDownloadingText, AppResources.ErrorCaption, MessageBoxButton.OK);
                    }
                }
                this.statusLabel.Height = 0;
            }
            catch (LiveConnectException)
            {
                this.statusLabel.Height = this.labelHeight;
                this.statusLabel.Text = AppResources.SkyDriveInternetLost;
            }
        }
예제 #22
0
 /// <summary>
 /// GetAlubmData gets all the album
 /// </summary>
 private async void GetAlubmData()
 {
     ImageCounter = 0;
     // show progressbar.
     string progMsgDownAlbum = SkyPhoto.Resources.Resources.progMsgDownAlbum;
     ShowProgressBar(progMsgDownAlbum);
     LiveConnectClient clientFolder = new LiveConnectClient(App.Session);
     LiveOperationResult result = await clientFolder.GetAsync("/me/albums");
     GetAlubmData_Completed(result);
 }
예제 #23
0
        /// <summary>
        /// Lädt informationen wie Namen über den Windows Live User.
        /// </summary>
        /// <param name="userId">id des Users.</param>
        /// <returns>Der neu erstellte User.</returns>
        internal async static Task<Person> GetNewUserData(string userId, string notificationChannel, int score, DateTime accountCreatedDate)
        {
            LiveConnectClient client = new LiveConnectClient(session);

            var data = (await client.GetAsync("me")).Result;

            return new Person(0, userId, (string)data["id"], (string)data["last_name"], (string)data["first_name"],
                    notificationChannel, System.Globalization.CultureInfo.CurrentCulture.ToString(), score, App.VersionNumber, accountCreatedDate);

        }
예제 #24
0
        /// <summary>
        ///     Prompts a OneDrive login prompt to the user.
        /// </summary>
        public async Task Login()
        {
            var result = await new LiveAuthClient()
                .LoginAsync(new List<string> {"wl.basic", "wl.skydrive", "wl.skydrive_update", "wl.offline_access"});

            if (result.Status == LiveConnectSessionStatus.Connected)
            {
                liveClient = new LiveConnectClient(result.Session);
            }
        }
예제 #25
0
        public void GetProfileData()
        {
            LiveConnectClient clientGetMe = new LiveConnectClient(App.Session);
            clientGetMe.GetCompleted += new EventHandler<LiveOperationCompletedEventArgs>(clientGetMe_GetCompleted);
            clientGetMe.GetAsync("me");

            LiveConnectClient clientGetPicture = new LiveConnectClient(App.Session);
            clientGetPicture.GetCompleted += new EventHandler<LiveOperationCompletedEventArgs>(clientGetPicture_GetCompleted);
            clientGetPicture.GetAsync("me/picture");
        }
예제 #26
0
 /// <summary>
 /// GetAlubmData gets all the album
 /// </summary>
 private void GetAlubmData()
 {
     ImageCounter = 0;
     // show progressbar.
     string progMsgDownAlbum = SkyPhoto.Resources.Resources.progMsgDownAlbum;
     ShowProgressBar(progMsgDownAlbum);
     LiveConnectClient clientFolder = new LiveConnectClient(App.Session);
     clientFolder.GetCompleted += new EventHandler<LiveOperationCompletedEventArgs>(GetAlubmData_Completed);
     clientFolder.GetAsync("/me/albums");
 }
예제 #27
0
        private async void LoadProfile()
        {
            LiveConnectClient client = new LiveConnectClient(App.Session);
            LiveOperationResult liveOpResult = await client.Get("me");
            dynamic dynResult = liveOpResult.Result;
            this.txtUserName.Text = dynResult.name;

            liveOpResult = await client.Get("me/picture");
            dynResult = liveOpResult.Result;
            this.imgProfile.Source = new BitmapImage(new Uri(dynResult.location)); 
        }
예제 #28
0
 public async Task Activate()
 {
     var session = _cache.SkydriveSession;
     if (session == null)
     {
         var authClient = new LiveAuthClient(ApiKeys.SkyDriveClientId);
         var x = await authClient.InitializeAsync();
         session = x.Session;
     }
     _liveClient = new LiveConnectClient(session);
 }
예제 #29
0
 private void downloadButton_Click(object sender, RoutedEventArgs e)
 {
     if (session == null)
     {
         MessageBox.Show("You must sign in first.");
     }
     else
     {
         LiveConnectClient client = new LiveConnectClient(session);
         client.DownloadCompleted += new EventHandler<LiveDownloadCompletedEventArgs>(OnDownloadCompleted);
         client.DownloadAsync("file.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!131/picture?type=thumbnail");
     }
 }
        private void btnSignIn_OnSessionChanged(object sender, LiveConnectSessionChangedEventArgs e)
        {
            if (e.Status == LiveConnectSessionStatus.Connected)
            {
                btnSave.Visibility = App.ProfilesManager.Items.Count != 0 ? Visibility.Visible : Visibility.Collapsed;
                btnRestore.Visibility = Visibility.Visible;

                client = new LiveConnectClient(e.Session);
                client.UploadCompleted += client_UploadCompleted;
                client.GetCompleted += client_GetCompleted;
                client.DownloadCompleted += client_DownloadCompleted;
            }
        }
예제 #31
0
        private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
        {
            this.Loaded -= this.OnLoaded;

            if (MainPage.Session == null)
            {
                this.NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            }
            else
            {
                this.liveClient = new LiveConnectClient(MainPage.Session);
                this.ButtonPlay.IsEnabled = true;
            }
        }
예제 #32
0
        private async void SkydriveDownload_Click(object sender, RoutedEventArgs e)
        {
            string id = string.Empty;

            try
            {
                LiveConnectClient   client   = new Microsoft.Live.LiveConnectClient(authClient.Session);
                LiveOperationResult opResult = await client.GetAsync("me/skydrive/files");

                dynamic result = opResult.Result;

                List <object> items = opResult.Result["data"] as List <object>;

                foreach (object item in items)
                {
                    IDictionary <string, object> file = item as IDictionary <string, object>;

                    if (file["name"].ToString() == theFileToGet)
                    {
                        id = file["id"].ToString();
                        tblUserName.Text = file["id"].ToString();
                        //file found
                        //terminate loop
                        break;
                    }
                }

                if (id != "")
                {
                    bool downloadOperationResult = await DownloadFile(id, theFileToGet);

                    if (!downloadOperationResult)
                    {
                        tblUserName.Text = "File Downloading Failed";
                    }
                    else
                    {
                        tblUserName.Text = "File Downloading Successful";
                        var file = await storageFolder.GetFileAsync(theFileToGet);

                        string text = await Windows.Storage.FileIO.ReadTextAsync(file);

                        try
                        {
                            GlobalV.tempLevel = Convert.ToInt32(text);
                        }
                        catch (OverflowException of)
                        {
                        }
                        catch (FormatException fx)
                        {
                        }
                    }
                }//end if (id != "")
                else
                {
                    tblUserName.Text = "file did not downloaded continue play";
                }
            }
            catch (Exception ex)
            {
                MessageDialog dlg = new MessageDialog("File did not downloaded from skydrive. please continue play");
                dlg.ShowAsync();
            }
        }//end download method
예제 #33
0
 static LiveConnectClient()
 {
     LiveConnectClient.AttachActiveTransfers();
 }
 /// <summary>
 ///     Download a file into a stream.
 /// </summary>
 /// <param name="client">the LiveConnectClient object this method is attached to.</param>
 /// <param name="path">relative or absolute uri to the file to be downloaded.</param>
 public static Task <Stream> Download(this LiveConnectClient client, string path)
 {
     return(Download(client, path, null));
 }
 /// <summary>
 ///     Upload a file to the server.
 /// </summary>
 /// <param name="client">the LiveConnectClient object this method is attached to.</param>
 /// <param name="path">relative or absolute uri to the location where the file should be uploaded to.</param>
 /// <param name="fileName">name for the uploaded file.</param>
 /// <param name="inputStream">Stream that contains the file content.</param>
 /// <param name="progress">a delegate that is called to report the upload progress.</param>
 public static Task <LiveOperationResult> Upload(this LiveConnectClient client, string path, string fileName, Stream inputStream, bool overwriteExisting)
 {
     return(Upload(client, path, fileName, inputStream, false, null));
 }
 /// <summary>
 ///     Constructor for creating a new OperationState object.
 /// </summary>
 public OperationState(TaskCompletionSource <TResult> tcs, LiveConnectClient client, ApiMethod method)
 {
     this.Tcs        = tcs;
     this.LiveClient = client;
     this.Method     = method;
 }