private void RegularMethodExecution(Isolated <PluginRuntimeHandler> appDomain, PluginExecutionDto pluginExecutionDto, IDev2MethodInfo dev2MethodInfo, int i, int update, IDSFDataObject dataObject)
        {
            var start = DateTime.Now;

            pluginExecutionDto.ObjectString = ObjectResult;
            string          objString;
            IDev2MethodInfo result = PluginServiceExecutionFactory.InvokePlugin(appDomain, pluginExecutionDto, dev2MethodInfo, out objString);

            pluginExecutionDto.ObjectString = objString;
            ObjectResult = objString;
            var pluginAction = MethodsToRun[i];

            pluginAction.MethodResult   = result.MethodResult;
            pluginAction.HasError       = result.HasError;
            pluginAction.ErrorMessage   = result.ErrorMessage;
            dev2MethodInfo.HasError     = result.HasError;
            dev2MethodInfo.ErrorMessage = result.ErrorMessage;
            if (result.HasError)
            {
                DispatchDebugStateForMethod(pluginAction, dataObject, update, false, start);
                return;
            }
            AssignMethodResult(pluginAction, update, dataObject, start);
            if (!string.IsNullOrEmpty(ObjectName) && !pluginExecutionDto.IsStatic)
            {
                var jToken = JToken.Parse(ObjectResult) as JContainer ?? ObjectResult.DeserializeToObject();
                dataObject.Environment.AddToJsonObjects(ObjectName, jToken);
            }
        }
Exemple #2
0
        public IDev2MethodInfo Run(IDev2MethodInfo dev2MethodInfo, PluginExecutionDto dto, out string objectString)
        {
            try
            {
                var args            = dto.Args;
                var tryLoadAssembly = _assemblyLoader.TryLoadAssembly(args.AssemblyLocation, args.AssemblyName, out Assembly loadedAssembly);
                if (!tryLoadAssembly)
                {
                    throw new Exception(args.AssemblyName + "Not found");
                }

                ExecutePlugin(dto, args, loadedAssembly, dev2MethodInfo);
                objectString = dto.ObjectString;
                return(dev2MethodInfo);
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    dev2MethodInfo.HasError     = true;
                    dev2MethodInfo.ErrorMessage = e.InnerException.Message;
                    Dev2Logger.Error(e, GlobalConstants.WarewolfError);
                    objectString = dto.ObjectString;
                    return(dev2MethodInfo);
                }
                dev2MethodInfo.HasError     = true;
                dev2MethodInfo.ErrorMessage = e.Message;
                Dev2Logger.Error(e, GlobalConstants.WarewolfError);
                throw;
            }
        }
        private void DispatchDebugState(IDSFDataObject dataObject, IDev2MethodInfo dev2MethodInfo, int index, IServiceTestOutput serviceTestOutput)
        {
            var start = DateTime.Now;

            if (dev2MethodInfo.IsObject)
            {
                var jContainer = JToken.Parse(serviceTestOutput.Value) as JContainer
                                 ?? serviceTestOutput.Value.DeserializeToObject();
                if (!string.IsNullOrEmpty(serviceTestOutput.Variable))
                {
                    dataObject.Environment.AddToJsonObjects(serviceTestOutput.Variable, jContainer);
                }
            }
            else
            {
                dataObject.Environment.Assign(serviceTestOutput.Variable, serviceTestOutput.Value, 0);
            }
            dev2MethodInfo.MethodResult      = serviceTestOutput.Value;
            MethodsToRun[index].MethodResult = serviceTestOutput.Value;
            DispatchDebugStateForMethod(MethodsToRun[index], dataObject, 0, true, start);
        }
 void MockMethodExecution(IDSFDataObject dataObject, IServiceTestStep serviceTestStep, IDev2MethodInfo dev2MethodInfo, int index)
 {
     if (serviceTestStep.StepOutputs != null)
     {
         foreach (var serviceTestOutput in serviceTestStep.StepOutputs)
         {
             DispatchDebugState(dataObject, dev2MethodInfo, index, serviceTestOutput);
         }
     }
 }
 private void MethodExecution(int update, IDSFDataObject dataObject, PluginExecutionDto pluginExecutionDto, Isolated <PluginRuntimeHandler> appDomain, int index, IDev2MethodInfo dev2MethodInfo, IServiceTestStep serviceTestStep)
 {
     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);
     }
 }
        public static IDev2MethodInfo InvokePlugin(Isolated <PluginRuntimeHandler> appDomain, PluginExecutionDto dto, IDev2MethodInfo dev2MethodInfo, out string objString)
        {
            var invokePlugin = appDomain.Value.Run(dev2MethodInfo, dto, out string objectString);

            objString = objectString;
            return(invokePlugin);
        }
Exemple #7
0
        void ExecuteSingleMethod(Type type, object instance, Func <MethodInfo, object, List <object>, Type, object> invokeMethodsAction, Assembly loadedAssembly, IDev2MethodInfo dev2MethodInfo)
        {
            if (dev2MethodInfo.Parameters != null)
            {
                var typeList       = BuildTypeList(dev2MethodInfo.Parameters, loadedAssembly);
                var valuedTypeList = new List <object>();

                foreach (var methodParameter in dev2MethodInfo.Parameters)
                {
                    var valuesForParameters = SetupValuesForParameters(methodParameter.Value, methodParameter.TypeName, methodParameter.EmptyToNull, loadedAssembly);
                    if (valuesForParameters != null)
                    {
                        var item = valuesForParameters.FirstOrDefault();
                        valuedTypeList.Add(item);
                    }
                }

                MethodInfo methodToRun;
                if (typeList.Count == 0)
                {
                    try
                    {
                        methodToRun = type.GetMethod(dev2MethodInfo.Method);
                    }
                    catch (Exception)
                    {
                        methodToRun = type.GetMethods().SingleOrDefault(info => info.Name.Equals(dev2MethodInfo.Method) && !info.GetParameters().Any());
                    }
                }
                else
                {
                    methodToRun = type.GetMethod(dev2MethodInfo.Method, typeList.ToArray());
                }

                var methodsActionResult = invokeMethodsAction?.Invoke(methodToRun, instance, valuedTypeList, type);
                var knownBinder         = new KnownTypesBinder();
                knownBinder.KnownTypes.Add(type);
                knownBinder.KnownTypes.Add(methodsActionResult?.GetType());
                dev2MethodInfo.MethodResult = methodsActionResult.SerializeToJsonString(knownBinder);
            }
        }
Exemple #8
0
        void ExecutePlugin(PluginExecutionDto objectToRun, PluginInvokeArgs setupInfo, Assembly loadedAssembly, IDev2MethodInfo dev2MethodInfo)
        {
            VerifyArgument.IsNotNull("objectToRun", objectToRun);
            VerifyArgument.IsNotNull("loadedAssembly", loadedAssembly);
            VerifyArgument.IsNotNull("setupInfo", setupInfo);
            var type        = loadedAssembly.GetType(setupInfo.Fullname);
            var knownBinder = new KnownTypesBinder();

            loadedAssembly.ExportedTypes.ForEach(t => knownBinder.KnownTypes.Add(t));
            if (objectToRun.IsStatic)
            {
                ExecuteSingleMethod(type, null, InvokeMethodsAction, loadedAssembly, dev2MethodInfo);
                return;
            }
            var instance = objectToRun.ObjectString.DeserializeToObject(type, knownBinder);

            ExecuteSingleMethod(type, instance, InvokeMethodsAction, loadedAssembly, dev2MethodInfo);
            objectToRun.ObjectString = instance.SerializeToJsonString(knownBinder);//
        }