Пример #1
0
        public void Main(string[] args)
        {
            var pluginName    = args.FirstOrDefault();
            var pluginVersion = args.Skip(1).FirstOrDefault();

            // Install command plugin from nuget feeds
            var pluginInstall = new PluginInstall
            {
                PackageId      = pluginName,
                PackageVersion = pluginVersion
            };
            //pluginInstall.Execute();

            var sw = Stopwatch.StartNew();
            // Load plugin from installed assemblies
            var pluginExecute = new PluginExecute
            {
                PackageId = pluginName
            };

            pluginExecute.Execute();
            sw.Stop();
            Console.WriteLine($"Elapsed: {sw.ElapsedMilliseconds}ms");
            Console.ReadLine();
        }
Пример #2
0
        public Parser Create(
            EnvironmentInit environmentInit = null,
            NewFile newFile                     = null,
            PluginInstall pluginInstall         = null,
            PluginUninstall pluginUninstall     = null,
            PluginList pluginList               = null,
            SetUsername setEnvironmentSetting   = null,
            TemplateInstall templateInstall     = null,
            TemplateUninstall templateUninstall = null)
        {
            // if environmentInit hasn't been provided (for testing) then assign the Command Handler
            environmentInit ??= EnvironmentInitHandler.ExecuteAsync;
            newFile ??= NewFileHandler.ExecuteAsync;
            pluginInstall ??= PluginInstallHandler.ExecuteAsync;
            pluginUninstall ??= PluginUninstallHandler.ExecuteAsync;
            pluginList ??= PluginListHandler.ExecuteAsync;
            setEnvironmentSetting ??= SetEnvironmentSettingHandler.ExecuteAsync;
            templateInstall ??= TemplatePackageInstallerHandler.ExecuteAsync;
            templateUninstall ??= TemplatePackageUninstallerHandler.ExecuteAsync;

            // Set up intrinsic commands that will always be available.
            RootCommand rootCommand = Root();

            rootCommand.AddCommand(Environment());
            rootCommand.AddCommand(NewFile());
            rootCommand.AddCommand(Plugins());
            rootCommand.AddCommand(Templates());

            var commandBuilder = new CommandLineBuilder(rootCommand);

            try
            {
                foreach (Command command in this.commandPluginHost.Discover(this.appEnvironment.PluginPaths))
                {
                    commandBuilder.AddCommand(command);
                }
            }
            catch (DirectoryNotFoundException)
            {
                // If this is the first run, initialize the environment and default plugins
                Console.WriteLine("Error Detected: vellum environment uninitialized.");
                Parser parser = commandBuilder.UseDefaults().Build();

                int result = parser.Invoke("environment init");

                if (result == ReturnCodes.Ok)
                {
                    // Now the environment has been re-initialized, try to discover the plugins again.
                    foreach (Command command in this.commandPluginHost.Discover(this.appEnvironment.PluginPaths))
                    {
                        commandBuilder.AddCommand(command);
                    }
                }
            }

            return(commandBuilder.UseDefaults().Build());
Пример #3
0
        public ActionResult InstallPlugin(string AssemblyName)
        {
            IPluginDetails details = _pluginServices.GetPluginDetailsFromAssembly(Path.Combine(Server.MapPath("~/Plugins"), AssemblyName + ".dll"));

            TempData["PluginDetails"] = details;

            PluginInstall results = new PluginInstall {
                Configs = "", SQL = ""
            };

            if (!string.IsNullOrWhiteSpace(details.InstallDetails.GetSQL))
            {
                try
                {
                    SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["cleanConnectionString"].ConnectionString);
                    SqlCommand    cmd    = sqlCon.CreateCommand();
                    cmd.CommandText = details.InstallDetails.GetSQL;
                    sqlCon.Open();
                    cmd.ExecuteNonQuery();
                    sqlCon.Close();
                }
                catch (Exception ex)
                {
                    results.SQL = ex.Message;
                }
            }

            var configs = details.InstallDetails.GetConfigs();

            if (configs != null && configs.Count > 01)
            {
                try
                {
                    foreach (var config in configs)
                    {
                        _pluginConfigRepository.Add(new PluginConfig()
                        {
                            Name        = config.Name,
                            Note        = config.Note,
                            Options     = config.Options,
                            Type        = config.Type,
                            Value       = config.Value,
                            PluginGroup = details.Name
                        });
                    }
                }
                catch (Exception ex)
                {
                    results.Configs = ex.Message;
                }
            }

            if (results.Configs == "" && results.SQL == "")
            {
                _pluginRepository.Add(new Plugin
                {
                    Name         = details.Name,
                    Description  = details.Description,
                    Installed    = true,
                    AssemblyName = AssemblyName
                });

                SetSuccess("Plugin successfully installed");
                return(RedirectToAction("PluginInstalled", new { AssemblyName = AssemblyName }));
            }
            else
            {
                SetError("An error occurred while installing the plugin");
                TempData["InstallResults"] = results;
                return(RedirectToAction("Install", new { AssemblyName = AssemblyName }));
            }
        }