void ExecuteService(int update, out ErrorResultTO errors, IPluginConstructor constructor, INamespaceItem namespaceItem, IDSFDataObject dataObject)
        {
            _childStatesToDispatch = new List <IDebugState>();
            errors = new ErrorResultTO();
            PluginExecutionDto pluginExecutionDto;

            if (Constructor.IsExistingObject)
            {
                var existingObj        = DataListUtil.AddBracketsToValueIfNotExist(Constructor.ConstructorName);
                var warewolfEvalResult = dataObject.Environment.EvalForJson(existingObj);
                var existingObject     = ExecutionEnvironment.WarewolfEvalResultToString(warewolfEvalResult);
                pluginExecutionDto = new PluginExecutionDto(existingObject);
                ObjectResult       = pluginExecutionDto.ObjectString;
            }
            else
            {
                pluginExecutionDto = new PluginExecutionDto(string.Empty);
            }
            constructor.Inputs = new List <IConstructorParameter>();
            foreach (var parameter in ConstructorInputs)
            {
                var resultToString = GetEvaluatedResult(dataObject, parameter.Value, parameter.EmptyIsNull, update);
                constructor.Inputs.Add(new ConstructorParameter()
                {
                    TypeName    = parameter.TypeName,
                    Name        = parameter.Name,
                    Value       = resultToString,
                    EmptyToNull = parameter.EmptyIsNull,
                    IsRequired  = parameter.RequiredField
                });
            }

            var args = BuidlPluginInvokeArgs(update, constructor, namespaceItem, dataObject);

            pluginExecutionDto.Args = args;
            try
            {
                TryExecuteService(update, dataObject, pluginExecutionDto, args);
            }
            catch (Exception e)
            {
                errors.AddError(e.Message.Contains("Cannot convert given JSON to target type") ? ErrorResource.JSONIncompatibleConversionError + Environment.NewLine + e.Message : e.Message);
            }
        }
        PluginInvokeArgs BuidlPluginInvokeArgs(int update, IPluginConstructor constructor, INamespaceItem namespaceItem, IDSFDataObject dataObject)
        {
            var pluginSource = ResourceCatalog.GetResource <PluginSource>(GlobalConstants.ServerWorkspaceID, SourceId);

            return(new PluginInvokeArgs
            {
                AssemblyLocation = pluginSource.AssemblyLocation,
                AssemblyName = Namespace.AssemblyName,
                Fullname = namespaceItem.FullName,
                PluginConstructor = constructor,
                MethodsToRun = MethodsToRun?.Select(action =>
                {
                    if (action != null)
                    {
                        return new Dev2MethodInfo
                        {
                            Method = action.Method,
                            ID = action.ID,
                            Parameters = action.Inputs?.Select(p => new MethodParameter
                            {
                                Name = p.Name,
                                Value = GetEvaluatedResult(dataObject, p.Value, p.EmptyIsNull, update),
                                TypeName = p.TypeName,
                                EmptyToNull = p.EmptyIsNull,
                                IsRequired = p.RequiredField
                            } as IMethodParameter).ToList() ?? new List <IMethodParameter>(),
                            IsObject = action.IsObject,
                            MethodResult = action.MethodResult,
                            OutputVariable = action.OutputVariable,
                            IsVoid = action.IsVoid
                        } as IDev2MethodInfo;
                    }
                    return new Dev2MethodInfo();
                }).Where(info => !string.IsNullOrEmpty(info.Method)).ToList() ?? new List <IDev2MethodInfo>()
            });
        }
        private void ExecuteService(int update, out ErrorResultTO errors, IPluginConstructor constructor, INamespaceItem namespaceItem, IDSFDataObject dataObject)
        {
            _childStatesToDispatch = new List <IDebugState>();
            errors = new ErrorResultTO();
            PluginExecutionDto pluginExecutionDto;

            if (Constructor.IsExistingObject)
            {
                var existingObj        = DataListUtil.AddBracketsToValueIfNotExist(Constructor.ConstructorName);
                var warewolfEvalResult = dataObject.Environment.EvalForJson(existingObj);
                var existingObject     = ExecutionEnvironment.WarewolfEvalResultToString(warewolfEvalResult);
                pluginExecutionDto = new PluginExecutionDto(existingObject);
                ObjectResult       = pluginExecutionDto.ObjectString;
            }
            else
            {
                pluginExecutionDto = new PluginExecutionDto(string.Empty);
            }
            constructor.Inputs = new List <IConstructorParameter>();
            foreach (var parameter in ConstructorInputs)
            {
                var resultToString = GetEvaluatedResult(dataObject, parameter.Value, parameter.EmptyIsNull, update);
                constructor.Inputs.Add(new ConstructorParameter()
                {
                    TypeName    = parameter.TypeName,
                    Name        = parameter.Name,
                    Value       = resultToString,
                    EmptyToNull = parameter.EmptyIsNull,
                    IsRequired  = parameter.RequiredField
                });
            }

            var args = BuidlPluginInvokeArgs(update, constructor, namespaceItem, dataObject);

            pluginExecutionDto.Args = args;
            try
            {
                using (var appDomain = PluginServiceExecutionFactory.CreateAppDomain())
                {
                    if (dataObject.IsServiceTestExecution)
                    {
                        var serviceTestStep = dataObject.ServiceTest?.TestSteps?.Flatten(step => step.Children)?.FirstOrDefault(step => step.UniqueId == pluginExecutionDto.Args.PluginConstructor.ID);
                        if (serviceTestStep != null && serviceTestStep.Type == StepType.Mock)
                        {
                            var start = DateTime.Now;
                            MockConstructorExecution(dataObject, serviceTestStep, ref pluginExecutionDto);
                            DebugStateForConstructorInputsOutputs(dataObject, update, true, start);
                        }
                        else
                        {
                            var start = DateTime.Now;
                            RegularConstructorExecution(dataObject, appDomain, ref pluginExecutionDto);
                            DebugStateForConstructorInputsOutputs(dataObject, update, false, start);
                        }
                    }
                    else
                    {
                        var start = DateTime.Now;
                        RegularConstructorExecution(dataObject, appDomain, ref pluginExecutionDto);
                        DebugStateForConstructorInputsOutputs(dataObject, update, false, start);
                    }

                    var index = 0;
                    foreach (var dev2MethodInfo in args.MethodsToRun)
                    {
                        if (dataObject.IsServiceTestExecution)
                        {
                            var serviceTestStep = dataObject.ServiceTest?.TestSteps?.Flatten(step => step.Children)?.FirstOrDefault(step => step.UniqueId == dev2MethodInfo.ID);
                            if (serviceTestStep != null)
                            {
                                if (serviceTestStep.Type == StepType.Mock)
                                {
                                    MockMethodExecution(dataObject, serviceTestStep, dev2MethodInfo, index);
                                }
                                else
                                {
                                    RegularMethodExecution(appDomain, pluginExecutionDto, dev2MethodInfo, index, update, dataObject);
                                }
                            }
                            else
                            {
                                RegularMethodExecution(appDomain, pluginExecutionDto, dev2MethodInfo, index, update, dataObject);
                            }
                        }
                        else
                        {
                            RegularMethodExecution(appDomain, pluginExecutionDto, dev2MethodInfo, index, update, dataObject);
                        }
                        if (dev2MethodInfo.HasError)
                        {
                            break;
                        }
                        index++;
                    }
                }
            }
            catch (Exception e)
            {
                if (e.Message.Contains("Cannot convert given JSON to target type"))
                {
                    errors.AddError(ErrorResource.JSONIncompatibleConversionError + Environment.NewLine + e.Message);
                }
                else
                {
                    errors.AddError(e.Message);
                }
            }
        }