private void Install(DeploymentTaskContext context) { PackageDetails packageDetails = context.PackageDetails; string packageId = packageDetails.PackageId; _skipList = context.KeepOnUpdate; _destination = (string)context.Folders.DeployFolder; var repository = PackageRepositoryFactory.Default.CreateRepository(packageDetails.FeedUri); var manager = new PackageManager(repository, _destination); _buildLog.WriteLine("Install '{0}' from '{1}' to '{2}'.", packageId, packageDetails.FeedUri, _destination); manager.PackageInstalled += (sender, args) => MoveFilesToDestination(args, context); var version = GetVersion(context.Parameters); _buildLog.WriteLine($"Package version to install: {version ?? "latest"}"); if (packageDetails.Version == null) { manager.InstallPackage(packageId); } else { manager.InstallPackage(packageId, new SemanticVersion(version)); } }
public override void Execute(DeploymentTaskContext context) { var startService = false; ServiceControllerStatus status; if (context.TryGetValue(DeploymentTaskContext.ServiceStatus, out status)) { startService = status == ServiceControllerStatus.Running || status == ServiceControllerStatus.StartPending; } bool forceStart; if (context.TryGetValue(DeploymentTaskContext.ForceStartService, out forceStart)) { startService = startService || forceStart; } if (startService) { context.BuildLog.WriteLine("Starting service {0}", ServiceName); Execute(sc => { sc.Start(); sc.WaitForStatus(ServiceControllerStatus.StartPending); }); } else { context.BuildLog.WriteLine("Service {0} was not started before update. Start skipped.", ServiceName); } }
public void Execute(DeploymentTaskContext context) { var backupFolder = context.Folders.BackupFolder; dynamic restoreFrom = Folder.Combine((string)backupFolder, (string)context.Parameters.RestoreFrom); FullPath deployFolder = context.Folders.DeployFolder; context.BuildLog.WriteLine("Restore from {0} to {1}", restoreFrom, deployFolder); Folder.Copy(restoreFrom, (string)deployFolder); }
public void Execute(DeploymentTaskContext context) { var buildLog = context.BuildLog; if (!_baseFolderInfo.Exists) { buildLog.WriteLine("Directory '{0}' does not exists. Clear binaries skipped", _baseFolderInfo.FullName); return; } Delete(buildLog); }
public void Execute(DeploymentTaskContext context) { _instance = context.InstanceName; var exePath = Folder.Combine((string)context.Folders.DeployFolder, context.ServiceFileName); context.BuildLog.WriteLine("Executing '{0} {1}'", exePath, CommandLineArguments); var result = ProcessStarter.ExecuteWithParams(exePath, CommandLineArguments); context.BuildLog.WriteLine("Exe output:"); context.BuildLog.WriteLine(result.StdOut); context.BuildLog.WriteLine("Exe error:"); context.BuildLog.WriteLine(result.StdError); }
public void Execute(DeploymentTaskContext context) { _context = context; var exePath = Folder.Combine(_serviceFolder, _hostFileName); context.BuildLog.WriteLine("Executing '{0} {1}'", exePath, CommandLineArguments); var result = ProcessStarter.ExecuteWithParams(exePath, CommandLineArguments); context.BuildLog.WriteLine("Exe output:"); context.BuildLog.WriteLine(result.StdOut); context.BuildLog.WriteLine("Exe error:"); context.BuildLog.WriteLine(result.StdError); }
public void Execute(DeploymentTaskContext context) { _buildLog = context.BuildLog; // TODO: create base operation class and move all the necessary folder creation there Folder.EnsureExists(_backupFolder); if (IsNothingToBackup()) { _buildLog.WriteLine("Empty service folder for {0}. Nothing to backup", _serviceName); return; } Backup(); }
public void Execute(DeploymentTaskContext context) { foreach (string specialFolder in context.Folders.ToArray()) { if (Folder.Exists(specialFolder)) { context.BuildLog.WriteLine($"Folder '{specialFolder}' exists"); continue; } Folder.EnsureExists(specialFolder); context.BuildLog.WriteLine($"Folder {specialFolder}' was created"); } }
public void Execute(DeploymentTaskContext context) { dynamic hostConfig = new ExpandoObject(); foreach (var folder in context.GetValue <SpecialFolder[]>(DeploymentTaskContext.Folders)) { ((IDictionary <string, object>)hostConfig)[folder.Purpose] = folder.FullPath; } var hostConfigString = JsonConvert.SerializeObject(hostConfig, Formatting.Indented); context.BuildLog.WriteLine("Generated host config"); context.BuildLog.WriteLine(hostConfigString); WriteConfig(context.BuildLog, hostConfigString); }
private void MoveFilesToDestination(PackageOperationEventArgs e, DeploymentTaskContext context) { var installPath = e.InstallPath; _buildLog.WriteLine("Installed '{0}.{1}' to '{2}'.", e.Package.Id, e.Package.Version, installPath); foreach (var file in e.Package.GetFiles()) { MoveFileToDestination(installPath, file); } _buildLog.WriteLine("Delete '{0}'", installPath); Folder.EnsureDeleted(installPath); context.InstalledPackageVersion = e.Package.Version.Version; }
public void Execute(DeploymentTaskContext context) { _skippedFolders = new List <DirectoryInfo>(); _keepOnUpdate = context.KeepOnUpdate; _deployFolderInfo = new DirectoryInfo((string)context.Folders.DeployFolder); var buildLog = context.BuildLog; if (!_deployFolderInfo.Exists) { buildLog.WriteLine("Directory '{0}' does not exists. Clear binaries skipped", _deployFolderInfo.FullName); return; } Delete(buildLog); }
public void Execute(DeploymentTaskContext context) { _buildLog = context.BuildLog; ; var backupFolder = context.Folders.BackupFolder; Folder.EnsureExists((string)backupFolder); if (IsNothingToBackup(context.Folders.DeployFolder)) { _buildLog.WriteLine("Nothing to backup"); return; } Backup(context.Folders.DeployFolder, context.Folders.BackupFolder); }
public void Execute(DeploymentTaskContext context) { var actual = context.Folders; var folderName = (string)context.Parameters.FolderName; var folderValue = (FullPath)(string)context.Parameters.FolderValue; var errors = ValidateFolders(actual, folderName, folderValue); if (errors.Count > 0) { var message = "Could not move folders. Reasons: " + Environment.NewLine + string.Join(Environment.NewLine, errors); throw new InvalidOperationException(message); } MoveFolders(actual, folderName, folderValue, context); }
public void Execute(DeploymentTaskContext context) { var folders = context.GetValue <SpecialFolder[]>(DeploymentTaskContext.Folders); foreach (var specialFolder in folders) { if (Folder.Exists(specialFolder.FullPath)) { context.BuildLog.WriteLine($"Folder '{specialFolder.Purpose}'-'{specialFolder.FullPath}' exists"); continue; } Folder.EnsureExists(specialFolder.FullPath); context.BuildLog.WriteLine($"Folder '{specialFolder.Purpose}'-'{specialFolder.FullPath}' was created"); } }
public void Execute(DeploymentTaskContext context) { foreach (var folder in context.Folders.ToArray()) { try { context.BuildLog.Write("Delete folder {0} ", folder); Folder.EnsureDeleted(folder); context.BuildLog.WriteLine("succeed."); } catch { context.BuildLog.WriteLine("failed."); throw; } } }
public void Execute(DeploymentTaskContext context) { string[] folders = context.Parameters.LogFolders; int timeToLive = context.Parameters.PurgeLogOlderThen; if (timeToLive <= 0) { context.BuildLog.WriteLine("Purge Logs Older than is set to {0}. Skipped.", timeToLive); return; } var lastDateToLive = Clock.UtcNow.AddDays(-timeToLive).Date; foreach (var folder in folders) { RemoveOldFiles(folder, lastDateToLive, context.BuildLog); } }
public override void Execute(DeploymentTaskContext context) { var exePath = new FileInfo(Path.Combine(_serviceFolder, _hostFileName)); if (!exePath.Exists && SkipIfNotFound) { context.BuildLog.WriteLine("Service executable '{0}' not found. Uninstall skipped", exePath.FullName); return; } if (!IsServiceExists() && SkipIfNotFound) { context.BuildLog.WriteLine("Service '{0}' are not installed. Uninstall skipped", exePath.FullName); return; } var exeParams = string.Format("uninstall -instance:{0}", _instance); context.BuildLog.WriteLine("Executing '{0} {1}'", exePath, exeParams); ExecutionResult result = null; string handledResult = null; try { result = ProcessStarter.ExecuteWithParams(exePath.FullName, exeParams); } catch (Win32Exception ex) { if (!SkipIfNotFound) { throw; } TryHandle(ex, out handledResult); } context.BuildLog.WriteLine("Exe output:"); context.BuildLog.WriteLine(result); context.BuildLog.WriteLine("Exe error:"); context.BuildLog.WriteLine(handledResult ?? result?.StdError); }
public void Execute(DeploymentTaskContext context) { if (string.IsNullOrWhiteSpace(context.Config)) { context.BuildLog.WriteLine("Service config is not provided or empty. Operation Skipped."); return; } context.BuildLog.WriteLine("Found service config:"); context.BuildLog.WriteLine(context.Config); var configFolder = context.Folders.Configs; var configPath = Path.Combine((string)configFolder, "config.json"); context.BuildLog.WriteLine("Write service config to '{0}'", configPath); File.WriteAllText(configPath, context.Config); context.BuildLog.WriteLine("Config was successfully written"); }
public void Execute(DeploymentTaskContext context) { Context = context; ServiceName = context.ServiceName; ServiceController[] candidates = ServiceController.GetServices(); Logger.Debug("Looking for service '{0}'", ServiceName); foreach (ServiceController candidate in candidates) { var found = candidate.ServiceName.Equals(ServiceName, StringComparison.Ordinal); Logger.Debug("Checking '{0}' is {1}", candidate.ServiceName, found); if (found) { Logger.Debug("Service found"); _controller = candidate; break; } } ExecuteInternal(context); }
public void Execute(DeploymentTaskContext context) { if (!Folder.Exists((string)context.Folders.DeployFolder)) { context.BuildLog.WriteLine($"Directory '{context.Folders.DeployFolder}' does not exist. Host config will not be deployed."); return; } dynamic hostConfig = new ExpandoObject(); hostConfig.Configs = (string)context.Folders.Configs; hostConfig.Logs = (string)context.Folders.Logs; hostConfig.Data = (string)context.Folders.Data; var hostConfigString = JsonConvert.SerializeObject(hostConfig, Formatting.Indented); context.BuildLog.WriteLine("Generated host config"); context.BuildLog.WriteLine(hostConfigString); WriteConfig(context.BuildLog, context.Folders.DeployFolder, hostConfigString); }
protected override void ExecuteInternal(DeploymentTaskContext context) { var startService = context.ServiceStatus == ServiceControllerStatus.Running || context.ServiceStatus == ServiceControllerStatus.StartPending || ForceStartService(context.Parameters); if (startService) { context.BuildLog.WriteLine("Starting service {0}", ServiceName); Execute( sc => { sc.Start(); sc.WaitForStatus(ServiceControllerStatus.StartPending); }); } else { context.BuildLog.WriteLine("Service {0} was not started before update. Start skipped.", ServiceName); } }
protected override void ExecuteInternal(DeploymentTaskContext context) { var exePath = new FileInfo(Path.Combine((string)context.Folders.DeployFolder, context.ServiceFileName)); if (!exePath.Exists) { context.BuildLog.WriteLine("Service executable '{0}' not found. Uninstall skipped", exePath.FullName); return; } if (!IsServiceExists()) { context.BuildLog.WriteLine("Service '{0}' are not installed. Uninstall skipped", exePath.FullName); return; } var exeParams = $"uninstall -instance:{context.InstanceName}"; context.BuildLog.WriteLine("Executing '{0} {1}'", exePath, exeParams); ExecutionResult result = null; string handledResult = null; try { result = ProcessStarter.ExecuteWithParams(exePath.FullName, exeParams); } catch (Win32Exception ex) { TryHandle(ex, out handledResult); } context.BuildLog.WriteLine("Exe output:"); context.BuildLog.WriteLine(result); context.BuildLog.WriteLine("Exe error:"); context.BuildLog.WriteLine(handledResult ?? result?.StdError); }
public void Execute(DeploymentTaskContext context) { string config; if (!context.TryGetValue <string>(DeploymentTaskContext.Config, out config) || string.IsNullOrWhiteSpace(config)) { context.BuildLog.WriteLine("Service config is not provided or empty. Operation Skipped."); return; } context.BuildLog.WriteLine("Found service config:"); context.BuildLog.WriteLine(config); var configFolder = context .GetValue <SpecialFolder[]>(DeploymentTaskContext.Folders) .Single(x => x.Purpose == SpecialFolderDictionary.Configs); var configPath = Path.Combine(configFolder.FullPath, "config.json"); context.BuildLog.WriteLine("Write service config to '{0}'", configPath); File.WriteAllText(configPath, config); context.BuildLog.WriteLine("Config was successfully written"); }
private void MoveFolders(ServiceFolders actual, string folderName, FullPath path, DeploymentTaskContext context) { var cloned = actual.Clone(); var source = (string)actual[folderName]; var destination = path; var haveSameRoot = Path.GetPathRoot(source) == Path.GetPathRoot((string)destination); if (haveSameRoot) { MoveSimple(context.BuildLog, source, destination); } else { CopyAndDelete(context.BuildLog, source, destination); } cloned[folderName] = destination; context.NewFolders = cloned; }
public void Execute(DeploymentTaskContext context) { context.BuildLog.WriteLine("Restore from {0} to {1}", _backupFolder, _serviceFolder); Folder.Copy(_backupFolder, _serviceFolder); }
public void Execute(DeploymentTaskContext context) { _buildLog = context.BuildLog; Install(context); }
protected override void ExecuteInternal(DeploymentTaskContext context) { Execute(StopServiceAction); }
public void Execute(DeploymentTaskContext context) { context.BuildLog.WriteLine("Delete folder {0}", (string)context.Folders.DeployFolder); Folder.EnsureDeleted((string)context.Folders.DeployFolder); }
public abstract void Execute(DeploymentTaskContext context);
public void Execute(DeploymentTaskContext context) { context .Mediator .Send(new DeploymentDeletedEvent(context.DeploymentId)).Wait(); }