Example #1
0
        private List <PluginWrapper> UpdateSinglePlugin(
            PluginUpdateSettings plugin,
            PluginSourceDownloader pluginSourceDownloader,
            PluginFilter pluginFilter,
            PluginCompiler pluginCompiler,
            PluginLoader pluginLoader
            )
        {
            pluginSourceDownloader.Update(plugin);
            var sourcePluginDirectory   = new DirectoryInfo(Path.Combine(SourcePluginsDirectory, plugin.Name?.Value));
            var compiledPluginDirectory = new DirectoryInfo(Path.Combine(CompiledPluginsDirectory, plugin.Name?.Value));

            if (!pluginFilter.ShouldCompilePlugin(sourcePluginDirectory, compiledPluginDirectory))
            {
                return(null);
            }

            var dependencyTasks  = PluginCopyFiles.CopyDependencies(sourcePluginDirectory, compiledPluginDirectory);
            var settingsTasks    = PluginCopyFiles.CopySettings(sourcePluginDirectory, compiledPluginDirectory);
            var staticFilesTasks = PluginCopyFiles.CopyStaticFiles(sourcePluginDirectory, compiledPluginDirectory);

            Task.WaitAll(dependencyTasks?.ToArray());
            var assembly = pluginCompiler.CompilePlugin(sourcePluginDirectory, compiledPluginDirectory.FullName);

            Task.WaitAll(settingsTasks?.ToArray());
            Task.WaitAll(staticFilesTasks?.ToArray());
            var pluginWrapper = pluginLoader.Load(compiledPluginDirectory, assembly);

            return(pluginWrapper);
        }
Example #2
0
        private List <PluginWrapper> UpdateSinglePlugin(
            SinglePluginUpdateSettings plugin,
            PluginSourceDownloader pluginSourceDownloader,
            PluginFilter pluginFilter,
            IPluginCompiler pluginCompiler,
            string rootDirectory,
            PluginLoader pluginLoader
            )
        {
            pluginSourceDownloader.Update(plugin);
            var sourcePluginDirectory   = new DirectoryInfo(Path.Combine(SourcePluginsDirectory, plugin.Name?.Value));
            var compiledPluginDirectory = new DirectoryInfo(Path.Combine(CompiledPluginsDirectory, plugin.Name?.Value));

            if (!pluginFilter.ShouldCompilePlugin(sourcePluginDirectory, compiledPluginDirectory))
            {
                return(null);
            }

            var dependencyTasks  = PluginCopyFiles.CopyDependencies(sourcePluginDirectory, compiledPluginDirectory);
            var settingsTasks    = PluginCopyFiles.CopySettings(sourcePluginDirectory, compiledPluginDirectory);
            var staticFilesTasks = PluginCopyFiles.CopyStaticFiles(sourcePluginDirectory, compiledPluginDirectory);

            /*var txtJsonFilesTask = PluginCopyFiles.CopyTxtAndJsonFromRoot(sourcePluginDirectory, compiledPluginDirectory);*/

            if (dependencyTasks != null)
            {
                Task.WaitAll(dependencyTasks.ToArray());
            }

            var csProjFiles = sourcePluginDirectory
                              .GetFiles("*.csproj", SearchOption.AllDirectories)
                              .Where(f => f.Extension == ".csproj");

            foreach (var csProjFile in csProjFiles)
            {
                pluginCompiler.CompilePlugin(
                    csProjFile,
                    compiledPluginDirectory.FullName,
                    new DirectoryInfo(rootDirectory)
                    );
            }


            if (settingsTasks != null)
            {
                Task.WaitAll(settingsTasks.ToArray());
            }
            if (staticFilesTasks != null)
            {
                Task.WaitAll(staticFilesTasks.ToArray());
            }
            /*txtJsonFilesTask.Wait();*/
            var pluginWrapper = pluginLoader.Load(compiledPluginDirectory);

            return(pluginWrapper);
        }
Example #3
0
        public PluginUpdater(
            PluginsUpdateSettings pluginUpdateSettings,
            string rootDirectory,
            string compiledPluginsDirectory,
            string sourcePluginsDirectory,
            PluginLoader pluginLoader)
        {
            PluginsUpdateSettings    = pluginUpdateSettings ?? throw new ArgumentNullException(nameof(pluginUpdateSettings));
            RootDirectory            = rootDirectory ?? throw new ArgumentNullException(nameof(rootDirectory));
            CompiledPluginsDirectory = compiledPluginsDirectory ?? throw new ArgumentNullException(nameof(compiledPluginsDirectory));
            SourcePluginsDirectory   = sourcePluginsDirectory ?? throw new ArgumentNullException(nameof(sourcePluginsDirectory));

            PluginFilter           = new PluginFilter();
            PluginSourceDownloader = new PluginSourceDownloader(SourcePluginsDirectory, pluginUpdateSettings);
            PluginLoader           = pluginLoader;
        }
Example #4
0
        private List <PluginWrapper> UpdateSinglePlugin(
            SinglePluginUpdateSettings plugin,
            PluginSourceDownloader pluginSourceDownloader,
            PluginFilter pluginFilter,
            IPluginCompiler pluginCompiler,
            string rootDirectory,
            PluginLoader pluginLoader
            )
        {
            var sourcePluginDirectory   = new DirectoryInfo(Path.Combine(SourcePluginsDirectory, plugin.Name?.Value));
            var compiledPluginDirectory = new DirectoryInfo(Path.Combine(CompiledPluginsDirectory, plugin.Name?.Value));

            try
            {
                pluginSourceDownloader.Update(plugin);

                if (!pluginFilter.ShouldCompilePlugin(sourcePluginDirectory, compiledPluginDirectory))
                {
                    return(null);
                }

                var dependencyTasks         = PluginCopyFiles.CopyDependencies(sourcePluginDirectory, compiledPluginDirectory);
                var settingsTasks           = PluginCopyFiles.CopySettings(sourcePluginDirectory, compiledPluginDirectory);
                var staticFilesTasks        = PluginCopyFiles.CopyStaticFiles(sourcePluginDirectory, compiledPluginDirectory);
                var txtJsonFilesTask        = PluginCopyFiles.CopyTxtAndJsonFromRoot(sourcePluginDirectory, compiledPluginDirectory);
                var txtJsonDefaultFilesTask = PluginCopyFiles.CopyTxtAndJsonDefaultFiles(sourcePluginDirectory, compiledPluginDirectory);

                if (dependencyTasks != null)
                {
                    Task.WaitAll(dependencyTasks.ToArray());
                }

                var csProjFiles = sourcePluginDirectory
                                  .GetFiles("*.csproj", SearchOption.AllDirectories)
                                  .Where(f => f.Extension == ".csproj");
                foreach (var csProjFile in csProjFiles)
                {
                    pluginCompiler.CompilePlugin(
                        csProjFile,
                        compiledPluginDirectory.FullName,
                        new DirectoryInfo(rootDirectory)
                        );
                }

                var remainingTasks = new List <Task>();
                remainingTasks.AddRange(settingsTasks);
                remainingTasks.AddRange(staticFilesTasks);
                remainingTasks.AddRange(txtJsonFilesTask);
                remainingTasks.AddRange(txtJsonDefaultFilesTask);

                if (remainingTasks != null)
                {
                    Task.WaitAll(remainingTasks.ToArray());
                }
            }
            catch (Exception e)
            {
                DebugWindow.LogError($"PluginUpdater -> UpdateSinglePlugin \"{plugin.Name?.Value}\" failed.");
                DebugWindow.LogError($"PluginUpdater -> {e}");
            }

            var pluginWrapper = pluginLoader.Load(compiledPluginDirectory);

            return(pluginWrapper);
        }