public ExecutionResult Install(InstallDto installOptions)
        {
            var logger = new StringLogger();
            try
            {
                var packageInfo = new PackageInfo();

                packageInfo.Configuration = installOptions.Configuration;
                packageInfo.InstallationDirectory = installOptions.Directory;
                packageInfo.Name = installOptions.Application;
                packageInfo.Version = installOptions.Version;
                var PackageInstaller = new PackageInstaller();
                PackageInstaller.Logger = logger;

                PackageInstaller.Install(packageInfo, new string[] { installOptions.Repository }, installOptions.AdditionalParameters, installOptions.InstallScript, installOptions.ConfigurationFile, installOptions.ConfigurationTransform);

                return new ExecutionResult()
                {
                    Success = true,
                    Log = logger.Logs
                };
            }
            catch (Exception e)
            {
                logger.Log(e.InnerException != null ? e.InnerException.Message : e.Message, true);
                return new ExecutionResult()
                {
                    Success = false,
                    Exception = e.InnerException != null ? e.InnerException.Message : e.Message,
                    Log = logger.Logs
                };
            }
        }
            public void ShouldLogErrorIfExitCode()
            {
                var logger = new StringLogger();
                var parameters = new Dictionary<string, string>();

                PowershellHelpers.ExecuteScript(".", "throw \"test\"", logger, parameters);

                logger.Logs.Count.Should().Be.EqualTo(1);
                logger.Logs.ElementAt(0).Error.Should().Be.True();
            }
            public void ShouldRunScript()
            {
                var logger = new StringLogger();
                var parameters = new Dictionary<string, string>();
                parameters.Add("username", "paolo");
                parameters.Add("password", "240686pn");
                PowershellHelpers.Execute(@"C:\\Users\Paolo\Downloads", "Install.ps1","test", logger, parameters);

                logger.Logs.Count.Should().Be.EqualTo(1);
                logger.Logs.ElementAt(0).Error.Should().Be.True();
            }
 public ExecutionResult ExecuteScript(RemoteScriptDto options)
 {
     var logger = new StringLogger();
     try
     {
         PowershellHelpers.ExecuteScript(options.Folder, options.Script, logger, new Dictionary<string, string>());
     }
     catch (Exception e)
     {
         return new ExecutionResult()
         {
             Exception = e.InnerException == null ? e.Message : e.InnerException.Message,
             Success = false,
             Log = logger.Logs
         };
     }
     return new ExecutionResult()
     {
         Success = true,
         Log = logger.Logs
     };
 }
 public ExecutionResult DatabaseDeploy(DatabaseDeployDto options)
 {
     var logger = new StringLogger();
     try
     {
         var stream = PackageHelpers.DownloadDacpac(options.PackageName, options.Version, options.Repository);
         DacpacHelpers.ApplyDacpac(stream, options.ConnectionString, options.DataBase, logger);
     }
     catch (Exception e)
     {
         return new ExecutionResult()
         {
             Exception = e.InnerException == null ? e.Message : e.InnerException.Message,
             Success = false,
             Log = logger.Logs
         };
     }
     return new ExecutionResult()
     {
         Success = true,
         Log = logger.Logs
     };
 }
Exemple #6
0
        private static void LocalScriptTask(int id, int deploymentId, string version, string config)
        {
            using (var dc = new ReadContext())
            {
                var unit = dc.LocalScriptTasks.Single(x => x.Id == id);
                var cwd = Environment.CurrentDirectory;
                var logger = new StringLogger();
                using (var session = Store.OpenSession())
                {

                    session.Save(new DataAccess.Write.LogEntry()
                    {
                        DeploymentId = deploymentId,
                        Error = false,
                        TaskName = unit.Name,
                        Text = "Executing local script " + unit.Name,
                        TimeStamp = DateTime.UtcNow
                    });

                    session.Flush();
                }

                PowershellHelpers.ExecuteScript(cwd, unit.Script, logger, new Dictionary<string, string>());

                using (var session = Store.OpenSession())
                {

                    session.Save(new DataAccess.Write.LogEntry()
                    {
                        DeploymentId = deploymentId,
                        Error = false,
                        TaskName = unit.Name,
                        Text = String.Join("\r\n", logger.Logs.Select(x => x.Text)),
                        TimeStamp = DateTime.UtcNow
                    });

                    session.Flush();
                }
            }
        }
        public ExecutionResult Update(InstallDto installOptions)
        {
            var logger = new StringLogger();
            try
            {
                var files = Directory.GetFiles(installOptions.Directory, "*.nupkg");

                if (files.Count() == 0 )
                {
                    logger.Log("No package to uninstall found, proceeding with a normal install.");
                }

                if (files.Count() >= 1)
                {
                    var filename = PackageHelpers.ExtractPackageName(files.First()).Trim();
                    var packageInfo = new PackageInfo()
                    {
                        Name = filename.Substring(filename.LastIndexOf("\\") + 1),
                        Version = PackageHelpers.ExtractPackageVersion(files.First()).Trim(),
                        InstallationDirectory = installOptions.Directory,
                        Configuration = installOptions.Configuration
                    };
                    var packageRemover = new PackageRemover();
                    packageRemover.Logger = logger;

                    var additionalParams = installOptions.AdditionalParameters;
                    packageRemover.Remove(packageInfo, new string[] { installOptions.Directory }, additionalParams, installOptions.UninstallScript);
                }

                var packageInfo2 = new PackageInfo()
                {
                    Configuration = installOptions.Configuration,
                    InstallationDirectory = installOptions.Directory,
                    Name = installOptions.Application,
                    Version = installOptions.Version
                };

                var PackageInstaller = new PackageInstaller();
                PackageInstaller.Logger = logger;
                PackageInstaller.Install(packageInfo2, new string[] { installOptions.Repository }, installOptions.AdditionalParameters, installOptions.InstallScript, installOptions.ConfigurationFile, installOptions.ConfigurationTransform);
                return new ExecutionResult()
                {
                    Success = true,
                    Log = logger.Logs
                };
            }
            catch (Exception e)
            {
                logger.Log(e.InnerException != null ? e.InnerException.Message : e.Message, true);

                return new ExecutionResult()
                {
                    Success = false,
                    Exception = e.InnerException != null ? e.InnerException.Message : e.Message,
                    Log = logger.Logs
                };
            }
        }
        public ExecutionResult Uninstall(UninstallDto uninstallOptions)
        {
            var logger = new StringLogger();
            try
            {
                var packageInfo = new PackageInfo();
                packageInfo.Name = uninstallOptions.Application;
                packageInfo.Version = uninstallOptions.Version;
                var packageRemover = new PackageRemover();
                packageRemover.Logger = logger;
                packageRemover.Remove(packageInfo, new string[] { uninstallOptions.Directory }, uninstallOptions.AdditionalParameters, uninstallOptions.UninstallScript);

                return new ExecutionResult()
                {
                    Success = true,
                    Log = logger.Logs
                };
            }
            catch (Exception e)
            {
                logger.Log(e.InnerException != null ? e.InnerException.Message : e.Message, true);
                return new ExecutionResult()
                {
                    Success = false,
                    Exception = e.InnerException != null ? e.InnerException.Message : e.Message,
                    Log = logger.Logs
                };
            }
        }