/// <summary>
        ///     Copy a file to another location.
        /// </summary>
        /// <param name="client">the LiveConnectClient object this method is attached to.</param>
        /// <param name="path">relative path to the file resource to be copied.</param>
        /// <param name="destination">relative path to the folder resource where the file should be copied to.</param>
        public static Task <LiveOperationResult> Copy(this LiveConnectClient client, string path, string destination)
        {
            client.CopyCompleted += OnOperationCompleted;
            var tcs = new TaskCompletionSource <LiveOperationResult>();

            client.CopyAsync(path, destination, new OperationState <LiveOperationResult>(tcs, client, ApiMethod.Copy));

            return(tcs.Task);
        }
Пример #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;
            }
Пример #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);
            }
        }