Exemple #1
0
        private async void SendRequest()
        {
            try
            {
                if (autoClearToolStripButton.Checked)
                {
                    this.traceColoredTextBox.Text = string.Empty;
                }

                Subscription sub         = this.SelectedSubscription;
                string       tenantToken = await _client.GetAuthSecret(sub != null?sub.TenantId : null);

                string path = pathToolStripTextBox.Text;
                string body = excludeBodyToolStripButton.Checked ? string.Empty : this.bodyColoredTextBox.Text;


                bool valid = true;
                IEnumerable <string> parametersInPath = FindMissingParameters(path).Distinct();
                if (parametersInPath.Count() > 0)
                {
                    valid = false;

                    Trace.WriteLine("PATH: The following parameters require a value:");

                    foreach (string parameter in parametersInPath)
                    {
                        Trace.WriteLine("    " + parameter);
                    }

                    Trace.WriteLine(string.Empty);
                }

                IEnumerable <string> parametersInBody = FindMissingParameters(body).Distinct();
                if (parametersInBody.Count() > 0)
                {
                    valid = false;

                    Trace.WriteLine("BODY: The following parameters require a value:");
                    foreach (string parameter in parametersInBody)
                    {
                        Trace.WriteLine("    " + parameter);
                    }

                    Trace.WriteLine(string.Empty);
                }

                if (!valid)
                {
                    return;
                }

                Trace.WriteLine("REQUEST: " + verbToolStripComboBox.SelectedItem.ToString() + " " + pathToolStripTextBox.Text);
                Trace.WriteLine("SECRET: " + tenantToken);

                string response = await _client.CallAzureResourceManager(
                    method : verbToolStripComboBox.SelectedItem.ToString(),
                    path : path,
                    token : tenantToken,
                    body : body,
                    parameters : null,
                    apiVersion : null);

                if (string.IsNullOrWhiteSpace(response))
                {
                    Trace.WriteLine("The request has completed successfully!");
                }
                else
                {
                    Trace.WriteLine("RESPONSE:");
                    Trace.WriteLine(JsonHelper.FormatJson(response));
                }

                Trace.WriteLine(string.Empty);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Empty);
                Trace.WriteLine("ERROR:");
                Trace.WriteLine(JsonHelper.FormatJson(ex.Message));
                Trace.WriteLine(string.Empty);
            }
        }
Exemple #2
0
        private async void SendRequest()
        {
            if (this.IsBusy)
            {
                return;
            }

            // Update the UI
            this.IsBusy = true;

            Guid newRequestGuid = Guid.NewGuid();

            try
            {
                if (autoClearToolStripButton.Checked)
                {
                    this.traceColoredTextBox.Text = string.Empty;
                }

                Subscription sub         = this.SelectedSubscription;
                string       tenantToken = await _client.GetAuthSecret(sub != null?sub.TenantId : null);

                string path = pathToolStripTextBox.Text;
                string body = excludeBodyToolStripButton.Checked ? string.Empty : this.bodyColoredTextBox.Text;


                bool valid = true;
                IEnumerable <string> parametersInPath = FindMissingParameters(path).Distinct();
                if (parametersInPath.Count() > 0)
                {
                    valid = false;

                    Trace.WriteLine("PATH: The following parameters require a value:");

                    foreach (string parameter in parametersInPath)
                    {
                        Trace.WriteLine("    " + parameter);
                    }

                    Trace.WriteLine(string.Empty);
                }

                IEnumerable <string> parametersInBody = FindMissingParameters(body).Distinct();
                if (parametersInBody.Count() > 0)
                {
                    valid = false;

                    Trace.WriteLine("BODY: The following parameters require a value:");
                    foreach (string parameter in parametersInBody)
                    {
                        Trace.WriteLine("    " + parameter);
                    }

                    Trace.WriteLine(string.Empty);
                }

                if (!valid)
                {
                    return;
                }

                Trace.WriteLine("REQUEST: " + verbToolStripComboBox.SelectedItem.ToString() + " " + pathToolStripTextBox.Text);
                Trace.WriteLine("SECRET: " + (this.hideTokensToolStripButton.Checked ? "●●●●●●" : tenantToken));
                Trace.WriteLine(string.Empty);

                Request newRequestToLog = new Request()
                {
                    Body = body,
                    Path = path,
                    Verb = verbToolStripComboBox.SelectedItem.ToString(),
                    Id   = newRequestGuid
                };

                this.AddRequest(newRequestToLog);

                string responseToLog = string.Empty;

                _client.HttpHeadersProcessor = new HttpHeadersProcessor();

                string response = await _client.CallAzureResourceManager(
                    method : verbToolStripComboBox.SelectedItem.ToString(),
                    path : path,
                    token : tenantToken,
                    body : body,
                    parameters : null,
                    apiVersion : null);

                Trace.WriteLine("REQUEST HEADERS: ");
                Trace.WriteLine(_client.HttpHeadersProcessor.GetFormattedRequestHeaders());

                StringBuilder responseToLogBuilder = new StringBuilder();
                responseToLogBuilder.AppendLine("RESPONSE HEADERS: ");
                responseToLogBuilder.AppendLine(_client.HttpHeadersProcessor.GetFormattedResponseHeaders());
                responseToLogBuilder.AppendLine("RESPONSE: ");

                if (string.IsNullOrWhiteSpace(response))
                {
                    responseToLogBuilder.AppendLine("The request has completed successfully!");
                }
                else
                {
                    responseToLogBuilder.AppendLine(JsonHelper.FormatJson(response));
                }

                responseToLog = responseToLogBuilder.ToString();
                Trace.WriteLine(responseToLog);

                UpdateRequestResponse(newRequestGuid, responseToLog);

                Trace.WriteLine(string.Empty);
            }
            catch (Exception ex)
            {
                string        responseToLog        = string.Empty;
                StringBuilder responseToLogBuilder = new StringBuilder();


                responseToLogBuilder.AppendLine(string.Empty);
                responseToLogBuilder.AppendLine("ERROR:");
                responseToLogBuilder.AppendLine(JsonHelper.FormatJson(ex.Message));
                responseToLogBuilder.AppendLine(string.Empty);
                responseToLog = responseToLogBuilder.ToString();

                Trace.WriteLine(responseToLog);

                UpdateRequestResponse(newRequestGuid, responseToLog);
            }
            finally
            {
                // Remove http header processor from the client instance
                _client.HttpHeadersProcessor = null;

                // Update the UI
                this.IsBusy = false;
            }
        }