Example #1
0
        public override IPluginResponse Execute()
        {
            var pluginResponse = CreatePluginResponse();

            if (PluginResponses.All(response => response.GeneratedNoData))
            {
                Log.WarnFormat("No plugins associated with this run generated any data; skipping execution of this plugin.");
                pluginResponse.GeneratedNoData = true;
            }
            else
            {
                try
                {
                    var dependencyManager = new WorkbookDependencyManager(PluginResponses, WorkbookDirectory, WorkbookConfigFilename);
                    workbookNames = dependencyManager.GetValidWorkbooks();
                }
                catch (Exception ex)
                {
                    string errorMessage = String.Format("Failed to generate custom workbooks: {0}", ex.Message);
                    Log.Error(errorMessage);
                    pluginResponse.SetExecutionOutcome(false, errorMessage);
                }
            }

            return(pluginResponse);
        }
Example #2
0
        private void ExecuteInMemoryAssembly(HostedPlugin plugin, string input)
        {
            var context = new CollectibleAssemblyContext();

            using (var ms = new MemoryStream())
            {
                var compilation = CSharpCompilation.Create(plugin.Name, new[] { CSharpSyntaxTree.ParseText(plugin.Code) },
                                                           new[]
                {
                    MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location),
                    MetadataReference.CreateFromFile(typeof(Console).GetTypeInfo().Assembly.Location),
                    MetadataReference.CreateFromFile(SystemRuntime.Location),
                },
                                                           new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));

                var cr = compilation.Emit(ms);
                ms.Seek(0, SeekOrigin.Begin);
                var assembly = context.LoadFromStream(ms);

                var type          = assembly.GetType("Plugin");
                var executeMethod = type.GetMethod("Execute");

                var instance = Activator.CreateInstance(type);

                var dic = PluginResponses.GetOrCreate(plugin.Name);

                dic.Add(executeMethod.Invoke(instance, new object[] { input }).ToString());
            }

            context.Unload();
        }
Example #3
0
        private void ExecuteAssembly(HostedPlugin plugin, string input)
        {
            var context      = new CollectibleAssemblyContext();
            var assemblyPath = Path.Combine(plugin.FilePath);

            using (var fs = new FileStream(assemblyPath, FileMode.Open, FileAccess.Read))
            {
                var assembly = context.LoadFromStream(fs);

                var type          = assembly.GetType("PluginSystem.Plugin");
                var executeMethod = type.GetMethod("Execute");

                var instance = Activator.CreateInstance(type);

                var dic = PluginResponses.GetOrCreate(plugin.Name);

                dic.Add(executeMethod.Invoke(instance, new object[] { input }).ToString());
            }

            context.Unload();
        }
Example #4
0
 public void RegisterPluginResponse(IPluginResponse pluginResponse)
 {
     PluginResponses.Add(pluginResponse);
 }