/// <summary>
        ///     Makes a PUT 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 to be updated.</param>
        /// <param name="body">properties of the updated resource in json.</param>
        public static Task <LiveOperationResult> Put(this LiveConnectClient client, string path, string body)
        {
            client.PutCompleted += OnOperationCompleted;
            var tcs = new TaskCompletionSource <LiveOperationResult>();

            client.PutAsync(path, body, new OperationState <LiveOperationResult>(tcs, client, ApiMethod.Put));

            return(tcs.Task);
        }
Esempio n. 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);
            }
        }
        void ButtonOK_Click(object sender, RoutedEventArgs e)
        {
            //Is 'new list name' TextBox.Text Empty?
            if (editNameDlg.DialogData.Text.Trim() != String.Empty)
            {
                Dictionary<string, object> fileData = new Dictionary<string, object>();
                fileData.Add("name", editNameDlg.DialogData.Text.Trim() + ".txt");

                editNameDlg.Deactivate();

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

                LiveConnectClient client = new LiveConnectClient(this.LiveSession);
                client.PutCompleted += new EventHandler<LiveOperationCompletedEventArgs>(client_PutCompleted);
                client.PutAsync(this.renameFileId, fileData);
            }
        }