Esempio n. 1
0
        public object Run(ComPluginInvokeArgs setupInfo)
        {
            var methodToRun = ExecuteComPlugin(setupInfo, out object pluginResult);
            var formater    = setupInfo.OutputFormatter;

            if (formater != null)
            {
                pluginResult = AdjustPluginResult(pluginResult);
                return(formater.Format(pluginResult).ToString());
            }
            return(pluginResult);
        }
Esempio n. 2
0
        public IOutputDescription Test(ComPluginInvokeArgs setupInfo, out string serializedResult)
        {
            try
            {
                serializedResult = null;

                var methodToRun = ExecuteComPlugin(setupInfo, out object pluginResult);

                // do formating here to avoid object serialization issues ;)
                var dataBrowser     = DataBrowserFactory.CreateDataBrowser();
                var dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape();

                if (pluginResult != null)
                {
                    if (pluginResult is KeyValuePair <bool, string> )
                    {
                        var pluginKeyValuePair = (KeyValuePair <bool, string>)pluginResult;
                        serializedResult = "Exception: " + pluginKeyValuePair.Value;
                    }
                    else
                    {
                        serializedResult = pluginResult.ToString();
                    }
                    pluginResult = AdjustPluginResult(pluginResult);
                    var tmpData = dataBrowser.Map(pluginResult);
                    dataSourceShape.Paths.AddRange(tmpData);
                }

                var result = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);
                result.DataSourceShapes.Add(dataSourceShape);
                return(result);
            }
            catch (COMException e)
            {
                Dev2Logger.Error("IOutputDescription Test(PluginInvokeArgs setupInfo)", e, GlobalConstants.WarewolfError);
                throw;
            }
            catch (Exception e)
            {
                if (e.InnerException is COMException)
                {
                    throw e.InnerException;
                }

                Dev2Logger.Error("IOutputDescription Test(PluginInvokeArgs setupInfo)", e, GlobalConstants.WarewolfError);
                serializedResult = null;
                return(null);
            }
        }
Esempio n. 3
0
        public IOutputDescription TestPlugin(ComPluginService pluginService)
        {
            var args = new ComPluginInvokeArgs
            {
                Is32Bit    = ((ComPluginSource)pluginService.Source).Is32Bit,
                ClsId      = ((ComPluginSource)pluginService.Source).ClsId,
                Method     = pluginService.Method.Name,
                Fullname   = pluginService.Namespace,
                Parameters = pluginService.Method.Parameters
            };

            var pluginResult = ComPluginServiceExecutionFactory.TestComPlugin(args, out string serializedResult);

            pluginService.SerializedResult = serializedResult;
            return(pluginResult);
        }
Esempio n. 4
0
        static IEnumerable <object> TryBuildValuedTypeParams(ComPluginInvokeArgs setupInfo)
        {
            var valuedTypeList = new object[setupInfo.Parameters.Count];

            for (int index = 0; index < setupInfo.Parameters.Count; index++)
            {
                var methodParameter = setupInfo.Parameters[index];
                try
                {
                    BuildValuedTypeParams(ref valuedTypeList, index, methodParameter);
                }
                catch (Exception)
                {
                    TryBuildValuedTypeParamsAgain(ref valuedTypeList, index, methodParameter);
                }
            }
            return(valuedTypeList);
        }
Esempio n. 5
0
        private static IEnumerable <object> BuildValuedTypeParams(ComPluginInvokeArgs setupInfo)
        {
            var valuedTypeList = new object[setupInfo.Parameters.Count];

            for (int index = 0; index < setupInfo.Parameters.Count; index++)
            {
                var methodParameter = setupInfo.Parameters[index];
                try
                {
                    var anonymousType = JsonConvert.DeserializeObject(methodParameter.Value, Type.GetType(methodParameter.TypeName));
                    if (anonymousType != null)
                    {
                        valuedTypeList[index] = anonymousType;
                    }
                }
                catch (Exception)
                {
                    var argType = Type.GetType(methodParameter.TypeName);
                    try
                    {
                        if (argType != null)
                        {
                            var provider    = TypeDescriptor.GetConverter(argType);
                            var convertFrom = provider.ConvertFrom(methodParameter.Value);
                            valuedTypeList[index] = convertFrom;
                        }
                    }
                    catch (Exception)
                    {
                        try
                        {
                            var typeConverter = TypeDescriptor.GetConverter(methodParameter.Value);
                            var convertFrom   = typeConverter.ConvertFrom(methodParameter.Value);
                            valuedTypeList[index] = convertFrom;
                        }
                        catch (Exception k)
                        {
                            Dev2Logger.Error($"Failed to convert {argType?.FullName}", k);
                        }
                    }
                }
            }
            return(valuedTypeList);
        }
Esempio n. 6
0
        MethodInfo ExecuteComPlugin(ComPluginInvokeArgs setupInfo, out object pluginResult)
        {
            if (!string.IsNullOrEmpty(setupInfo.ClsId))
            {
                if (setupInfo.Is32Bit)
                {
                    var strings = setupInfo.Parameters.Select(parameter => new ParameterInfoTO {
                        Name = parameter.Name, DefaultValue = parameter.Value, TypeName = parameter.TypeName
                    }).ToArray();
                    pluginResult = IpcClient.GetIPCExecutor(_clientStreamWrapper).Invoke(setupInfo.ClsId.ToGuid(), setupInfo.Method, Execute.ExecuteSpecifiedMethod, strings);
                    return(null);
                }
                var typeList       = BuildTypeList(setupInfo.Parameters);
                var valuedTypeList = TryBuildValuedTypeParams(setupInfo);
                var type           = GetType(setupInfo.ClsId, setupInfo.Is32Bit);
                var methodToRun    = type.GetMethod(setupInfo.Method, typeList.ToArray()) ??
                                     type.GetMethod(setupInfo.Method);
                if (methodToRun == null && typeList.Count == 0)
                {
                    methodToRun = type.GetMethod(setupInfo.Method);
                }
                var instance = Activator.CreateInstance(type);

                if (methodToRun != null)
                {
                    if (methodToRun.ReturnType == typeof(void))
                    {
                        methodToRun.Invoke(instance,
                                           BindingFlags.InvokeMethod | BindingFlags.IgnoreCase | BindingFlags.Public, null,
                                           valuedTypeList.ToArray(), CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        pluginResult = methodToRun.Invoke(instance,
                                                          BindingFlags.InvokeMethod | BindingFlags.IgnoreCase | BindingFlags.Public, null,
                                                          valuedTypeList.ToArray(), CultureInfo.InvariantCulture);
                        return(methodToRun);
                    }
                }
            }
            pluginResult = null;
            return(null);
        }
Esempio n. 7
0
        public static object InvokeComPlugin(ComPluginInvokeArgs args)
        {
            var runtime = CreateInvokeAppDomain();

            return(runtime.Run(args));
        }
Esempio n. 8
0
        public static IOutputDescription TestComPlugin(ComPluginInvokeArgs args, out string serializedResult)
        {
            var runtime = CreateInvokeAppDomain();

            return(runtime.Test(args, out serializedResult));
        }