/// <summary>
        ///     Makes a DELETE call to the Api service
        /// </summary>
        /// <param name="client">the LiveConnectClient object this method is attached to.</param>
        /// <param name="path">relative path to the resource being deleted.</param>
        public static Task <LiveOperationResult> Delete(this LiveConnectClient client, string path)
        {
            client.DeleteCompleted += OnOperationCompleted;
            var tcs = new TaskCompletionSource <LiveOperationResult>();

            client.DeleteAsync(path, new OperationState <LiveOperationResult>(tcs, client, ApiMethod.Delete));

            return(tcs.Task);
        }
Exemplo n.º 2
0
            public async Task<Boolean> RenameLiveFolder(String OldName, String NewName)
            {

                try
                {
                    LiveConnectClient uploadClient = new LiveConnectClient(meClient.Session);
                    LiveOperationResult result = await uploadClient.GetAsync("/me/skydrive/files");
        
                    dynamic files = result.Result;
                    List<object> data = (List<object>)files.data;
                    foreach (dynamic item in data)
                    {
                     
                        if (item.name == OldName)
                        {

                            try
                            {

                                LoadProfile(NewName);
                                
                                await uploadClient.CopyAsync(OldName, NewName);
                                await uploadClient.DeleteAsync(OldName);
                                
                                return true;
                            }
                            catch (NullReferenceException)
                            {
                                return false;
                            }
                            catch (FileNotFoundException)
                            {
                                return false;
                            }
                            catch (ArgumentOutOfRangeException)
                            {
                                return false;
                            }
                        }
                    }
                }
                catch (NullReferenceException)
                {
                }
                catch (LiveConnectException)
                {
                }

                return false;
            }
Exemplo n.º 3
0
        private async void RunButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Validate parameters
                string path = pathTextBox.Text;
                string destination = destinationTextBox.Text;
                string requestBody = requestBodyTextBox.Text;
                var scope = (authScopesComboBox.SelectedValue as ComboBoxItem).Content as string;
                var method = (methodsComboBox.SelectedValue as ComboBoxItem).Content as string;

                // acquire auth permissions
                var authClient = new LiveAuthClient();
                var authResult = await authClient.LoginAsync(new string[] { scope });
                if (authResult.Session == null)
                {
                    throw new InvalidOperationException("You need to login and give permission to the app.");
                }

                var liveConnectClient = new LiveConnectClient(authResult.Session);
                LiveOperationResult operationResult = null;
                switch (method)
                {
                    case "GET":
                        operationResult = await liveConnectClient.GetAsync(path);
                        break;
                    case "POST":
                        operationResult = await liveConnectClient.PostAsync(path, requestBody);
                        break;
                    case "PUT":
                        operationResult = await liveConnectClient.PutAsync(path, requestBody);
                        break;
                    case "DELETE":
                        operationResult = await liveConnectClient.DeleteAsync(path);
                        break;
                    case "COPY":
                        operationResult = await liveConnectClient.CopyAsync(path, destination);
                        break;
                    case "MOVE":
                        operationResult = await liveConnectClient.MoveAsync(path, destination);
                        break;
                }

                if (operationResult != null)
                {
                    Log("Operation succeeded: \r\n" + operationResult.RawResult);
                }
            }
            catch (Exception ex)
            {
                Log("Got error: " + ex.Message);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// ContextMenu delete button tergar MenuDelte_Click and delete the picture from sky drive
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void MenuDelte_Click(object sender, RoutedEventArgs e)
        {
            var Menu = sender as MenuItem;
            SkydrivePhoto selectedFile = Menu.DataContext as SkydrivePhoto;

            string msgDelPic = SkyPhoto.Resources.Resources.msgDelPic;
            string msgDelPicTitel = SkyPhoto.Resources.Resources.msgDelPicTitle;
            MessageBoxResult m = MessageBox.Show(msgDelPic + selectedFile.Title + "?", msgDelPicTitel, MessageBoxButton.OKCancel);
            if (m == MessageBoxResult.OK)
            {
                LiveConnectClient client = new LiveConnectClient(App.Session);
                LiveOperationResult result = await client.DeleteAsync(selectedFile.ID);
                DeleteFile_Completed(selectedFile, result);

            }
            else
            {
                return;
            }
        }
Exemplo n.º 5
0
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            // Tag contains the bound ID of the associated ListBoxItem
            string itemID = ((MenuItem)sender).Tag.ToString();

            if (itemID != null)
            {

                this.progressIndicator = new ProgressIndicator();
                ProgressIndicatorHelper.showProgressIndicator("Deleting...", this, this.progressIndicator);

                LiveConnectClient client = new LiveConnectClient(App.Current.LiveSession);
                client.DeleteCompleted +=
                    new EventHandler<LiveOperationCompletedEventArgs>(DeleteFileOrFolder_Completed);

                // for now, only allow deletes of non-folders
                if (itemID.Contains("folder") == false)
                {
                    client.DeleteAsync(itemID);
                }
                else
                {
                    MessageBox.Show("I can't let you delete a folder, sorry!");
                    ProgressIndicatorHelper.hideProgressIndicator(this.progressIndicator);
                }

            }
        }
        //Finish uploading the file to SkyDrive storage
        void uploadClient_UploadCompleted(object sender, LiveOperationCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                MessageBox.Show("'"+ fileName + "' have been successfully saved to the SkyDrive", "All Done!", MessageBoxButton.OK);
                SystemTray.ProgressIndicator.IsVisible = false;
                //Maring 'invisible' UI upload file section
                ((FrameworkElement)ContentPanel.Children[1]).Height = 0;
                //Update SkyDrive data list
                this.DownloadSkyDriveDataList();
            }
            else
            {
                if (e.Error.Message == "The resource could not be created. The resource '"
                    + fileName + ".txt" + "' already exists.")
                {
                    if (MessageBox.Show("File with this name is already exist in SkyDrive data storage\nDo you want to rewrite existing file?",
                        "Information", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                    {
                        //If 'Rewrite existing file?' message box result == OK -> delete existing file
                        //and upload new
                        //At first it's needed to get existing file ID
                        if (this.SkyDriveFilesCollection != null)
                        {
                            SkyDriveFileInfo fi = this.SkyDriveFilesCollection.Where(f => f.Name ==
                                this.fileName).FirstOrDefault();

                            //Set SystemTray.ProgressIndicator
                            ProgressIndicator prog = new ProgressIndicator();
                            prog.IsIndeterminate = true;
                            prog.IsVisible = true;
                            prog.Text = "File uploading...";
                            SystemTray.SetProgressIndicator(this, prog);

                            LiveConnectClient client = new LiveConnectClient(LiveSession);
                            client.DeleteCompleted += new EventHandler<LiveOperationCompletedEventArgs>(client_DeleteExistingCompleted);
                            client.DeleteAsync(fi.FileID);
                        }
                    }
                    else
                    {
                        //If 'Rewrite existing file?' message box result == Cancel -> stop uploading file.
                        //In this case user will be able to rename existing
                        SystemTray.ProgressIndicator.IsVisible = false;
                    }
                }
                else
                {
                    MessageBox.Show("There is an error occur during file uploading: " + e.Error.Message, "Warning", MessageBoxButton.OK);
                    SystemTray.ProgressIndicator.IsVisible = false;
                }
            }
        }
        private void DeleteMenu_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to delete this file?", "Delete", MessageBoxButton.OKCancel)
                == MessageBoxResult.OK)
            {
                MenuItem menu = sender as MenuItem;
                SkyDriveFileInfo info = menu.DataContext as SkyDriveFileInfo;

                //Set SystemTray.ProgressIndicator
                ProgressIndicator prog = new ProgressIndicator();
                prog.IsIndeterminate = true;
                prog.IsVisible = true;
                prog.Text = "File deleting...";
                SystemTray.SetProgressIndicator(this, prog);

                LiveConnectClient client = new LiveConnectClient(this.LiveSession);
                client.DeleteCompleted += new EventHandler<LiveOperationCompletedEventArgs>(client_DeleteCompleted);
                client.DeleteAsync(info.FileID);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// ContextMenu delete button tergar MenuDelte_Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuDelte_Click(object sender, RoutedEventArgs e)
        {
            var Menu = sender as MenuItem;
            SkydriveAlbum selectedAlbum = Menu.DataContext as SkydriveAlbum;
            string msgDel = SkyPhoto.Resources.Resources.msgDelAlbum;
            string msgDelAlbumTitel = SkyPhoto.Resources.Resources.msgDelAlbumTitel;

            MessageBoxResult m = MessageBox.Show(msgDel + selectedAlbum.Title + "?", msgDelAlbumTitel, MessageBoxButton.OKCancel);
            if (m == MessageBoxResult.OK)
            {
                LiveConnectClient client = new LiveConnectClient(App.Session);
                client.DeleteCompleted +=
                    new EventHandler<LiveOperationCompletedEventArgs>(DeleteFolder_Completed);
                client.DeleteAsync(selectedAlbum.ID, selectedAlbum);

            }
            else
            {
                return;
            }
        }