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

            client.MoveAsync(path, destination, new OperationState <LiveOperationResult>(tcs, client, ApiMethod.Move));

            return(tcs.Task);
        }
示例#2
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);
            }
        }