Esempio n. 1
0
        private void InvokeEditorToEditPayload()
        {
            try
            {
                ConfigActioin action = this.GetSelectedAction();
                if (action == null ||
                    string.Equals("get", action.HttpMethod, StringComparison.OrdinalIgnoreCase) ||
                    string.Equals("delete", action.HttpMethod, StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }

                string payload = action.Payload;
                foreach (var item in ConfigSettingFactory.ConfigSettings.DefaultValues)
                {
                    payload = payload.Replace("{" + item.Key + "}", item.Value.ToString());
                }
                // Also update the parameters from the UI
                SetParameterValues(payload);
                File.WriteAllText(_tmpPayloadFile, string.IsNullOrWhiteSpace(payload) ? "" : payload);
                Process.Start(ConfigSettingFactory.ConfigSettings.Editor, _tmpPayloadFile);
                Logger.InfoLn("Editing payload in {0} (Ctrl + W)", _tmpPayloadFile);
            }
            catch (Exception ex)
            {
                Logger.ErrorLn("Editor: '{0}'", ConfigSettingFactory.ConfigSettings.Editor);
                Logger.ErrorLn("Payload file: '{0}'", _tmpPayloadFile);
                Logger.ErrorLn("{0} {1}", ex.Message, ex.StackTrace);
            }
        }
Esempio n. 2
0
        private void ExecuteEditPayloadCommand(object sender, ExecutedRoutedEventArgs e)
        {
            ConfigActioin action = this.GetSelectedAction();

            if (string.Equals("get", action.HttpMethod, StringComparison.OrdinalIgnoreCase) ||
                string.Equals("delete", action.HttpMethod, StringComparison.OrdinalIgnoreCase))
            {
                Logger.WarnLn("{0} request doesn`t require any payload", action.HttpMethod);
                return;
            }

            this.InvokeEditorToEditPayload();
        }
Esempio n. 3
0
        private void UpdateCmdText()
        {
            ConfigActioin action = this.GetSelectedAction();

            if (action == null)
            {
                return;
            }

            string cmd = action.Template;

            cmd = SetParameterValues(cmd);

            this.CmdText.Text = cmd;
        }
Esempio n. 4
0
        private void ActionCB_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ConfigActioin action = this.GetSelectedAction();

            this.PopulateParamsUI(action);
            this.UpdateCmdText();

            if (ConfigSettingFactory.ConfigSettings.AutoPromptEditor)
            {
                this.InvokeEditorToEditPayload();
            }
            else
            {
                Logger.WarnLn("Ctrl + W to edit payload.");
            }
        }
Esempio n. 5
0
        private async Task RunArmRequest()
        {
            try
            {
                if (!this._authHelper.IsCacheValid())
                {
                    Logger.WarnLn("Login session corrputed");
                    this._authHelper.ClearTokenCache();
                    this.CheckIsLogin();
                    await this._authHelper.AcquireTokens();

                    this.PopulateTenant();
                }
                else
                {
                    this.ExecuteBtn.IsEnabled = false;
                    string        path           = this.CmdText.Text;
                    string        subscriptionId = this.SubscriptionCB.SelectedValue as string;
                    ConfigActioin action         = this.GetSelectedAction();
                    Uri           uri            = AuthUtils.EnsureAbsoluteUri(path, this._authHelper);
                    var           cacheInfo      = await this._authHelper.GetToken(subscriptionId);

                    var         handler = new HttpLoggingHandler(new HttpClientHandler(), ConfigSettingFactory.ConfigSettings.Verbose);
                    HttpContent payload = null;
                    if (!string.Equals("get", action.HttpMethod, StringComparison.OrdinalIgnoreCase) &&
                        !string.Equals("delete", action.HttpMethod, StringComparison.OrdinalIgnoreCase))
                    {
                        payload = new StringContent(File.ReadAllText(_tmpPayloadFile), Encoding.UTF8, Constants.JsonContentType);
                    }

                    await AuthUtils.HttpInvoke(uri, cacheInfo, action.HttpMethod, handler, payload);
                }
            }
            catch (Exception ex)
            {
                Logger.ErrorLn("{0} {1}", ex.Message, ex.StackTrace);
            }
            finally
            {
                this.ExecuteBtn.IsEnabled = true;
            }
        }
Esempio n. 6
0
        private void PopulateParamsUI(ConfigActioin action)
        {
            this.ParamLV.Items.Clear();
            double textboxWidth = this.ParamLV.Width * 0.7;

            if (action == null || action.Params == null || action.Params.Length == 0)
            {
                return;
            }

            for (int i = 0; i < action.Params.Length; i++)
            {
                ActionParam param = action.Params[i];

                StackPanel sp = new StackPanel();
                sp.Orientation = Orientation.Vertical;

                Label label = new Label();
                label.Content = param.Name + (param.Required ? "*" : string.Empty);

                TextBox textbox = new TextBox();
                textbox.Name = param.PlaceHolder;
                if (ConfigSettingFactory.ConfigSettings.DefaultValues.ContainsKey(param.PlaceHolder))
                {
                    textbox.Text = ConfigSettingFactory.ConfigSettings.DefaultValues[param.PlaceHolder].ToString();
                }
                textbox.Width  = textboxWidth;
                textbox.KeyUp += new KeyEventHandler((object sender, KeyEventArgs e) =>
                {
                    this.UpdateCmdText();
                });

                sp.Children.Add(label);
                sp.Children.Add(textbox);

                this.ParamLV.Items.Add(sp);
            }
        }