public IOutputDescription Test(PluginInvokeArgs setupInfo)
        {
            Assembly loadedAssembly;

            _assemblyLocation = setupInfo.AssemblyLocation;
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            if(!TryLoadAssembly(setupInfo.AssemblyLocation, setupInfo.AssemblyName, out loadedAssembly))
            {
                return null;
            }
            var parameters = BuildParameterList(setupInfo.Parameters);
            var typeList = BuildTypeList(setupInfo.Parameters);

            var type = loadedAssembly.GetType(setupInfo.Fullname);
            var methodToRun = type.GetMethod(setupInfo.Method, typeList);
            var instance = Activator.CreateInstance(type);
            var pluginResult = methodToRun.Invoke(instance, parameters);
            AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
            // do formating here to avoid object serialization issues ;)
            var dataBrowser = DataBrowserFactory.CreateDataBrowser();
            var dataSourceShape = DataSourceShapeFactory.CreateDataSourceShape();

            if(pluginResult != null)
            {
                pluginResult = AdjustPluginResult(pluginResult, methodToRun);

                var tmpData = dataBrowser.Map(pluginResult);
                dataSourceShape.Paths.AddRange(tmpData);
            }

            var result = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);
            result.DataSourceShapes.Add(dataSourceShape);
            return result;
        }
        /// <summary>
        /// Runs the specified setup information.
        /// </summary>
        /// <param name="setupInfo">The setup information.</param>
        /// <returns></returns>
        public object Run(PluginInvokeArgs setupInfo)
        {
            Assembly loadedAssembly;
            _assemblyLocation = setupInfo.AssemblyLocation;
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            if(!TryLoadAssembly(setupInfo.AssemblyLocation, setupInfo.AssemblyName, out loadedAssembly))
            {
                return null;
            }
            var parameters = BuildParameterList(setupInfo.Parameters);
            var typeList = BuildTypeList(setupInfo.Parameters);

            var type = loadedAssembly.GetType(setupInfo.Fullname);
            var methodToRun = type.GetMethod(setupInfo.Method, typeList);
            var instance = Activator.CreateInstance(type);
            var pluginResult = methodToRun.Invoke(instance, parameters);
            AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
            // do formating here to avoid object serialization issues ;)
            var formater = setupInfo.OutputFormatter;
            if(formater != null)
            {
                pluginResult = AdjustPluginResult(pluginResult, methodToRun);

                return formater.Format(pluginResult).ToString();
            }

            return pluginResult;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Tests the plugin.
        /// </summary>
        /// <param name="pluginService">The plugin service.</param>
        /// <returns></returns>
        public IOutputDescription TestPlugin(PluginService pluginService)
        {
            PluginInvokeArgs args = new PluginInvokeArgs
                                    {
                                        AssemblyLocation = ((PluginSource)pluginService.Source).AssemblyLocation,
                                        AssemblyName = ((PluginSource)pluginService.Source).AssemblyName,
                                        Method = pluginService.Method.Name,
                                        Fullname = pluginService.Namespace,
                                        Parameters = pluginService.Method.Parameters
                                    };

            var pluginResult = PluginServiceExecutionFactory.TestPlugin(args);

            return pluginResult;
        }
        public static IOutputDescription TestPlugin(PluginInvokeArgs args)
        {
            AppDomain childDomain = null;

            try
            {
                var runtime = CreateInvokeAppDomain(out childDomain);

                // start the runtime.  call will marshal into the child runtime app domain
                return(runtime.Test(args));
            }
            finally
            {
                if (childDomain != null)
                {
                    AppDomain.Unload(childDomain);
                }
            }
        }
        public static object InvokePlugin(PluginInvokeArgs args)
        {
            AppDomain childDomain = null;

            try
            {
                var runtime = CreateInvokeAppDomain(out childDomain);

                // start the runtime.  call will marshal into the child runtime app domain
                return runtime.Run(args);
            }
            finally
            {
                if(childDomain != null)
                {
                    AppDomain.Unload(childDomain);
                }
            }
        }
        public static IOutputDescription TestPlugin(PluginInvokeArgs args)
        {
            AppDomain childDomain = null;

            try
            {
                var runtime = CreateInvokeAppDomain(out childDomain);

                // start the runtime.  call will marshal into the child runtime app domain
                return runtime.Test(args);
            }
            finally
            {
                if(childDomain != null)
                {
                    AppDomain.Unload(childDomain);
                }
            }
        }
Exemplo n.º 7
0
        public static object InvokePlugin(PluginInvokeArgs args)
        {
            AppDomain childDomain = null;

            try
            {
                var runtime = CreateInvokeAppDomain(out childDomain);

                // start the runtime.  call will marshal into the child runtime app domain
                return(runtime.Run(args));
            }
            finally
            {
                if (childDomain != null)
                {
                    AppDomain.Unload(childDomain);
                }
            }
        }
Exemplo n.º 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);//
        }
        /// <summary>
        /// Runs the specified setup information.
        /// </summary>
        /// <param name="setupInfo">The setup information.</param>
        /// <returns></returns>
        public object Run(PluginInvokeArgs setupInfo)
        {
            _assemblyLocation = setupInfo.AssemblyLocation;
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            if (!_assemblyLoader.TryLoadAssembly(setupInfo.AssemblyLocation, setupInfo.AssemblyName, out Assembly loadedAssembly))
            {
                return(null);
            }
            var methodToRun = TryExecutePlugin(setupInfo, loadedAssembly, out object pluginResult);

            AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
            var formater = setupInfo.OutputFormatter;

            if (formater != null)
            {
                pluginResult = AdjustPluginResult(pluginResult, methodToRun);
                return(formater.Format(pluginResult).ToString());
            }
            pluginResult = JsonConvert.SerializeObject(pluginResult);
            return(pluginResult);
        }
Exemplo n.º 10
0
        static object TryBuildInstance(PluginInvokeArgs setupInfo, Type type, List <object> constructorArgs, Assembly loadedAssembly)
        {
            var instance = new object();

            if (setupInfo.PluginConstructor?.Inputs != null && (setupInfo.PluginConstructor == null || setupInfo.PluginConstructor.Inputs.Any()))
            {
                try
                {
                    instance = BuildInstance(setupInfo, type, constructorArgs, loadedAssembly, instance);
                }
                catch (Exception)
                {
                    instance = Activator.CreateInstance(type, constructorArgs);
                }
            }
            else
            {
                instance = Activator.CreateInstance(type);
            }
            return(instance);
        }
        public IOutputDescription Test(PluginInvokeArgs setupInfo, out string jsonResult)
        {
            try
            {
                Assembly loadedAssembly;
                jsonResult        = null;
                _assemblyLocation = setupInfo.AssemblyLocation;
                AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
                if (!_assemblyLoader.TryLoadAssembly(setupInfo.AssemblyLocation, setupInfo.AssemblyName, out loadedAssembly))
                {
                    return(null);
                }
                object pluginResult;
                var    methodToRun = ExecutePlugin(setupInfo, loadedAssembly, out pluginResult);

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

                if (pluginResult != null)
                {
                    jsonResult   = JsonConvert.SerializeObject(pluginResult);
                    pluginResult = AdjustPluginResult(pluginResult, methodToRun);
                    var tmpData = dataBrowser.Map(pluginResult);
                    dataSourceShape.Paths.AddRange(tmpData);
                }

                var result = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);
                result.DataSourceShapes.Add(dataSourceShape);
                return(result);
            }
            catch (Exception e)
            {
                Dev2Logger.Error("IOutputDescription Test(PluginInvokeArgs setupInfo)", e);
                jsonResult = null;
                return(null);
            }
        }
Exemplo n.º 12
0
        public IOutputDescription Test(PluginInvokeArgs setupInfo)
        {
            Assembly loadedAssembly;

            _assemblyLocation = setupInfo.AssemblyLocation;
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            if (!TryLoadAssembly(setupInfo.AssemblyLocation, setupInfo.AssemblyName, out loadedAssembly))
            {
                return(null);
            }
            var parameters = BuildParameterList(setupInfo.Parameters);
            var typeList   = BuildTypeList(setupInfo.Parameters);

            var type         = loadedAssembly.GetType(setupInfo.Fullname);
            var methodToRun  = type.GetMethod(setupInfo.Method, typeList);
            var instance     = Activator.CreateInstance(type);
            var pluginResult = methodToRun.Invoke(instance, parameters);

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

            if (pluginResult != null)
            {
                pluginResult = AdjustPluginResult(pluginResult, methodToRun);

                var tmpData = dataBrowser.Map(pluginResult);
                dataSourceShape.Paths.AddRange(tmpData);
            }

            var result = OutputDescriptionFactory.CreateOutputDescription(OutputFormats.ShapedXML);

            result.DataSourceShapes.Add(dataSourceShape);
            return(result);
        }
        public void PluginRuntimeHandler_Run_WhenNullParameters_ExpectException()
        {
            //------------Setup for test--------------------------
            var svc = CreatePluginService();
            var source = CreatePluginSource();
            var pluginRuntimeHandler = new PluginRuntimeHandler();
            PluginInvokeArgs args = new PluginInvokeArgs { AssemblyLocation = source.AssemblyLocation, AssemblyName = "Foo", Fullname = svc.Namespace, Method = svc.Method.Name, Parameters = null };

            //------------Execute Test---------------------------
            pluginRuntimeHandler.Run(args);
        }
        public void PluginRuntimeHandler_Run_WhenValidLocation_ExpectResult()
        {
            //------------Setup for test--------------------------
            var svc = CreatePluginService();
            var source = CreatePluginSource();
            var pluginRuntimeHandler = new PluginRuntimeHandler();
            PluginInvokeArgs args = new PluginInvokeArgs { AssemblyLocation = source.AssemblyLocation, AssemblyName = "Foo", Fullname = svc.Namespace, Method = svc.Method.Name, Parameters = svc.Method.Parameters };

            //------------Execute Test---------------------------
            var result = pluginRuntimeHandler.Run(args);
            var castResult = result as DummyClassForPluginTest;

            //------------Assert Results-------------------------
            if(castResult != null)
            {
                StringAssert.Contains(castResult.Name, "test data");
            }
            else
            {
                Assert.Fail("Failed Conversion for Assert");
            }
        }
        public void PluginRuntimeHandler_InvokePlugin_WhenValidDll_ExpectValidResults()
        {
            //------------Setup for test--------------------------
            var source = CreatePluginSource();
            var svc = CreatePluginService();
                     
            

            //------------Execute Test---------------------------
            using (Isolated<PluginRuntimeHandler> isolated = new Isolated<PluginRuntimeHandler>())
            {
                PluginInvokeArgs args = new PluginInvokeArgs { AssemblyLocation = source.AssemblyLocation, AssemblyName = "Foo", Fullname = svc.Namespace, Method = svc.Method.Name, Parameters = svc.Method.Parameters };
                var result = PluginServiceExecutionFactory.InvokePlugin(args);
                var castResult = result as DummyClassForPluginTest;
                //------------Assert Results-------------------------
                if (castResult != null)
                {
                    StringAssert.Contains(castResult.Name, "test data");
                }
                else
                {
                    Assert.Fail("Failed Conversion for Assert");
                }
            }  
            
        }