예제 #1
0
        public override void Run()
        {
            if (!(Owner is ISelectableEditor))
            {
                return;
            }

            try
            {
                XmlEditor editor = Owner as XmlEditor;
                if (editor == null)
                {
                    return;
                }

                _xpath       = editor.SingleDirectionData.SelectedXPath.XPath;
                _elementName = ExtractElementName(editor.SingleDirectionData.SelectedText);
                _value       = ExtractElementValue(editor.SingleDirectionData.SelectedText);

                var selectableEditor = Owner as ISelectableEditor;
                if (selectableEditor.Selected == null)
                {
                    return;
                }

                var stepService = ServiceManager.Instance.GetService <IStepService>();
                if (stepService == null)
                {
                    return;
                }

                var currentStep = stepService.CurrentStep;

                var parserStatus = stepService.GetParserStatus(currentStep.FunctionCall.Location.FilePath);
                if (parserStatus == false)
                {
                    MessageService.ShowMessage("Cannot add step");
                    return;
                }

                var functionCall = new FunctionCall();
                var signature    = new FunctionCallSignature {
                    Name = this.Name
                };


                FillParameters(signature);

                functionCall.Signature = signature;
                functionCall.Location  = new FunctionCallLocation(currentStep.FunctionCall.Location.FilePath, null, null);

                IStepModel stepModel = stepService.GenerateStep(functionCall);
                stepModel.ShowArguments(asyncResult =>
                {
                    var result = (ShowArgumentsResult)asyncResult.AsyncState;
                    if (result.IsModified)
                    {
                        //set the last parameter to False, so it will not move cursor to the newly added step
                        stepService.AddStep(ref stepModel, currentStep,
                                            Relative, false);

                        stepService.CurrentStep = currentStep;
                    }
                });
            }
            catch (Exception ex)
            {
                Log.VuGen.Error(string.Format("Error occurred when adding the {2} step. (Type: '{0}', Exception: '{1}')", Owner.GetType(), ex, Name));
            }
        }
예제 #2
0
        public override void Run()
        {
            if (!(Owner is ISelectableEditor))
            {
                return;
            }

            try
            {
                XmlEditor editor = Owner as XmlEditor;
                if (editor == null)
                {
                    return;
                }

                _xpath       = editor.SingleDirectionData.SelectedXPath.XPath;
                _elementName = ExtractElementName(editor.SingleDirectionData.SelectedText);
                _value       = ExtractElementValue(editor.SingleDirectionData.SelectedText);

                var selectableEditor = Owner as ISelectableEditor;
                if (selectableEditor.Selected == null)
                {
                    return;
                }

                var stepService = ServiceManager.Instance.GetService <IStepService>();
                if (stepService == null)
                {
                    return;
                }

                var currentStep = stepService.CurrentStep;

                var parserStatus = stepService.GetParserStatus(currentStep.FunctionCall.Location.FilePath);
                if (parserStatus == false)
                {
                    MessageService.ShowMessage("Cannot add step");
                    return;
                }

                var functionCall = new FunctionCall();
                var signature    = new FunctionCallSignature {
                    Name = this.Name
                };

                string currentParameterName = GetCurrentStepResponseParameter();
                if (!string.IsNullOrEmpty(currentParameterName))
                {
                    signature.Parameters.Add(new FunctionCallParameter(String.Format("XML={0}", currentParameterName),
                                                                       ParameterType.ArgtypeString));
                }

                FillParameters(signature);

                functionCall.Signature = signature;
                functionCall.Location  = new FunctionCallLocation(currentStep.FunctionCall.Location.FilePath, null, null);


                IStepModel stepModel = stepService.GenerateStep(functionCall);
                stepModel.ShowArguments(asyncResult =>
                {
                    var result = (ShowArgumentsResult)asyncResult.AsyncState;
                    if (result.IsModified)
                    {
                        //set the last parameter to False, so it will not move cursor to the newly added step
                        stepService.AddStep(ref stepModel, currentStep,
                                            Relative, false);

                        if (string.IsNullOrEmpty(currentParameterName))
                        {
                            FunctionCallParameter userParameter = stepModel.FunctionCall.Signature.Parameters.Find(p =>
                            {
                                return(p.Value.StartsWith("XML=", StringComparison.InvariantCultureIgnoreCase));
                            });
                            if (userParameter != null)
                            {
                                SetCurrentStepResponseParameter(stepModel.ScriptItem.Script as IVuGenScript, userParameter.Value.Remove(0, 4));
                            }
                        }

                        stepService.CurrentStep = currentStep;
                    }
                });
            }
            catch (Exception ex)
            {
                Log.VuGen.Error(string.Format("Error occurred when adding the {2} step. (Type: '{0}', Exception: '{1}')", Owner.GetType(), ex, Name));
            }
        }