예제 #1
0
        /// <summary>
        ///     Activates the input output panel.
        /// </summary>
        void ActivateInputOutputPanel()
        {
            var scenario         = scope.Get(SelectedScenario);
            var methodDefinition = scope.Get(SelectedMethodDefinition);

            EnableAllTopButtons();
            buttonActivateInputOutputPanel.IsPressed = true;

            var responseTextView = new JsonTextEditor();

            void updateResponseOutputText()
            {
                Dispatcher.InvokeAsync(() =>
                {
                    var output = scope.TryGetScenarioExecuteResponse(scenario)?.InvokeOutput;
                    if (output == null)
                    {
                        responseTextView.Text = null;
                        return;
                    }

                    if (!IsSuccess(output))
                    {
                        responseTextView.Text = "ERROR: " + output.Error;
                        return;
                    }

                    responseTextView.Text = output.ExecutionResponseAsJson;
                });
            }

            var inputEditors = ParameterPanelIntegration.Create(scenario.MethodParameters, methodDefinition).ToArray();

            EnableAllTopButtons();
            buttonActivateInputOutputPanel.IsPressed = true;

            var content = NewColumnSplittedGrid(NewGroupBox(NewBoldTextBlock("Method Parameters"), NewStackPanel(inputEditors)),
                                                NewGroupBox(NewBoldTextBlock("Response"), responseTextView));


            responseTextView.Loaded   += (s, e) => scope.SubscribeEvent(OnScenarioExecuteResponseUpdated, updateResponseOutputText);
            responseTextView.Unloaded += (s, e) => scope.UnSubscribeEvent(OnScenarioExecuteResponseUpdated, updateResponseOutputText);

            CurrentContent = content;

            updateResponseOutputText();
        }
        /// <summary>
        ///     Creates the specified definition.
        /// </summary>
        static GroupBox Create(ParameterDefinition definition, InvocationMethodParameterInfo parameterInfo)
        {
            var isNullableDateTime = definition.ParameterType.FullName == "System.Nullable`1<System.DateTime>";
            var isDateTime         = definition.ParameterType.FullName == "System.DateTime";

            var getLabel = Fun(() =>
            {
                if (isNullableDateTime)
                {
                    return("DateTime? [Sample: 23/02/2020 19:48:59]");
                }

                if (isDateTime)
                {
                    return("DateTime [Sample: 23/02/2020 19:48:59]");
                }

                return(definition.ParameterType.Name);
            });

            var defaultValueIsZero = Fun((TypeReference t) =>
            {
                var types = new[]
                {
                    // numbers
                    typeof(byte),
                    typeof(short),
                    typeof(int),
                    typeof(long),

                    // unsigned numbers
                    typeof(ushort),
                    typeof(uint),
                    typeof(ulong),
                };

                return(types.Any(x => x.FullName == t.FullName));
            });

            var createEditor = Fun(() =>
            {
                if (CanPresentSimpleTextBox(definition.ParameterType.FullName))
                {
                    if (defaultValueIsZero(definition.ParameterType) && string.IsNullOrWhiteSpace(parameterInfo.Value + string.Empty))
                    {
                        parameterInfo.Value = 0.ToString();
                    }

                    var editor = new TextBox
                    {
                        TextWrapping  = TextWrapping.Wrap,
                        AcceptsReturn = true,
                        VerticalScrollBarVisibility = ScrollBarVisibility.Auto
                    };
                    Bind(editor, TextBox.TextProperty, parameterInfo, nameof(parameterInfo.Value));
                    return((UIElement)editor);
                }

                if (definition.ParameterType.FullName == typeof(ObjectHelper).FullName)
                {
                    parameterInfo.Value = null;

                    var editor = new TextBox
                    {
                        IsEnabled = false,
                        Text      = "objectHelper"
                    };
                    return((UIElement)editor);
                }

                // complex items should be as json input
                {
                    if (string.IsNullOrWhiteSpace(parameterInfo.Value))
                    {
                        parameterInfo.Value = GetDefaultJsonForClass(definition.ParameterType.FullName) ?? string.Empty;
                    }

                    var editor = new JsonTextEditor
                    {
                        Text = parameterInfo.Value + string.Empty
                    };

                    editor.TextChanged += (s, e) => { parameterInfo.Value = editor.Text; };

                    return((UIElement)editor);
                }
            });

            return(NewGroupBox(NewTextBlock($"{definition.Name} : {getLabel()}", FontWeights.Light), createEditor()));
        }