public AgentConfigurationService(IAgentSettings agentSettings, IAgentConfigurationDownloader configurationDownloader) { if (agentSettings == null) throw new ArgumentNullException("agentSettings"); if (configurationDownloader == null) throw new ArgumentNullException("configurationDownloader"); _configurationDownloader = configurationDownloader; TimedTask = new TimedSingleExecutionTask(agentSettings.ConfigurationSyncIntervalMs, DownloadConfiguration, true); }
public static StringBuilder ExecuteInlinePowerShellScript(string scriptText, IAgentSettings agentSettings) { var serviceCommands = new Command(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Scripts/PS/Services.ps1")); // create Powershell runspace Runspace runspace = RunspaceFactory.CreateRunspace(); // open it runspace.Open(); var pipeline = runspace.CreatePipeline(); pipeline.Commands.Add(serviceCommands); // add the custom script pipeline.Commands.AddScript(scriptText); // add an extra command to transform the script output objects into nicely formatted strings // remove this line to get the actual objects that the script returns. For example, the script // "Get-Process" returns a collection of System.Diagnostics.Process instances. pipeline.Commands.Add("Out-String"); var results = pipeline.Invoke(); runspace.Close(); // convert the script result into a single string var stringBuilder = new StringBuilder(); foreach (var obj in results) { stringBuilder.AppendLine(obj.ToString()); } return stringBuilder; }
public Agent(AppSecret secret, INotificationConsumer consumer, ITokenStore store, IAgentSettings agentSettings) { this.Secret = secret; this.Consumer = consumer; this.Store = store; _agentSettings = agentSettings; _retryWaitSeconds = agentSettings.InitialRetryWaitSeconds; }
public Worker(ILogger <Worker> logger, IAgentSettings settings, IHostApplicationLifetime appLifetime, ILapsAgent lapsWorker, ILocalSam sam) { this.logger = logger; this.settings = settings; this.appLifetime = appLifetime; this.lapsAgent = lapsWorker; this.sam = sam; }
public PackageDownloadingService(IAgentSettings agentSettings, IRetrievePackageQuery allPackagesQuery, ILocalPackageCache agentCache, IAgentConfigurationManager agentConfigurationManager) { _settings = agentSettings; AllPackagesQuery = allPackagesQuery; AgentCache = agentCache; _agentConfigurationManager = agentConfigurationManager; TimedTask = new TimedSingleExecutionTask(agentSettings.PackageSyncIntervalMs, FetchPackages); }
public DeploymentService(IEnumerable<IDeploymentHook> hooks, ILocalPackageCache packageCache, IInstalledPackageArchive installedPackageArchive, IAgentSettings agentSettings) { _hooks = hooks; _packageCache = packageCache; _installedPackageArchive = installedPackageArchive; _agentSettings = agentSettings; }
public HomeModule() { _agentSettings = Container().GetType<IAgentSettings>(); Get["/"] = x => View["index.cshtml"]; Get["/sitrep"] = x => { var _log = Container().GetType<ILogger>(); _log.Debug(string.Format("{0} asked for status", Request.UserHostAddress)); var cache = Container().GetType<ILocalPackageCache>(); var runningTasks = Container().GetType<RunningInstallationTaskList>(); var installCache = Container().GetType<IInstalledPackageArchive>(); var model = new AgentStatusViewModel { Packages = cache.AvailablePackages.Select(name => new LocalPackageInformation() { PackageId = name, InstalledVersion = installCache.GetCurrentInstalledVersion(name) != null ? installCache.GetCurrentInstalledVersion(name).Version.ToString() : "", LatestAvailableVersion = cache.GetLatestVersion(name) != null ? cache.GetLatestVersion(name).Version.ToString() : "", AvailableVersions = cache.AvailablePackageVersions(name).ToList(), CurrentTask = runningTasks.Where(t => t.PackageId == name) .Select(t => new InstallTaskViewModel() { Messages = t.ProgressReports.Select(pr => pr.Message).ToArray(), Status = Enum.GetName(typeof(TaskStatus), t.Task.Status), PackageId = t.PackageId, Version = t.Version, LastMessage = t.ProgressReports.Count > 0 ? t.ProgressReports.LastOrDefault().Message : "" }).FirstOrDefault() }).ToArray(), CurrentTasks = runningTasks.Select(t => new InstallTaskViewModel() { Messages = t.ProgressReports.Select(pr => pr.Message).ToArray(), Status = Enum.GetName(typeof(TaskStatus), t.Task.Status), PackageId = t.PackageId, Version = t.Version, LastMessage = t.ProgressReports.Count > 0 ? t.ProgressReports.LastOrDefault().Message : "" }).ToList(), AvailableVersions = cache.AllCachedPackages().Select(p => p.Version.ToString()).Distinct().OrderByDescending(s => s), Environment = _agentSettings.DeploymentEnvironment, }; return this.ViewOrJson("sitrep.cshtml", model); }; }
public AppOfflineDeploymentHook(IFileSystem fileSystem, IAgentSettings agentSettings) : base(agentSettings, fileSystem) { _fileSystem = fileSystem; }
private static LogListViewModel LoadServerLogList(IFileSystem fileSystem, IAgentSettings agentSettings) { var logDirectoryPath = GetLogDirectory(agentSettings); var fileList = fileSystem.Directory.GetFiles(logDirectoryPath, "*.log", SearchOption.TopDirectoryOnly); return new LogListViewModel(fileList.Select(f => LoadLogViewModel(f, fileSystem, agentSettings, false))){Group="server"}; }
protected DeploymentHookBase(IAgentSettings agentSettings, IFileSystem fileSystem) { AgentSettings = agentSettings; FileSystem = fileSystem; }
public PowershellDeploymentHook(IAgentSettings agentSettings, IFileSystem fileSystem) : base(agentSettings, fileSystem) { _fileSystem = fileSystem; }
public ConfigTransformationDeploymentHook(IFileSystem fileSystem, IAgentSettings agentSettings) : base(agentSettings, fileSystem) { }
private Configuration WatchForChanges(Configuration configuration) { // watch for changes string agentConfigFilePath = Path.Combine(AgentSettings.AgentProgramDataPath, "agent.config"); var configurationWatcher = new FileSystemWatcher(Path.GetDirectoryName(agentConfigFilePath), Path.GetFileName(agentConfigFilePath)); configurationWatcher.Changed += (sender, args) => { configurationWatcher.EnableRaisingEvents = false; try { _log.Info("Configuration change detected - reloading"); configuration = LocateOrCreateAgentConfiguration(_fileSystem); _settings = LoadSettings(configuration.AppSettings.Settings); } finally { configurationWatcher.EnableRaisingEvents = true; } }; configurationWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size; configurationWatcher.EnableRaisingEvents = true; return configuration; }
public static PackageListViewModel Convert(ILocalPackageCache cache, RunningInstallationTaskList runningTasks, IInstalledPackageArchive installPackageArchive, CompletedInstallationTaskList completedTasks, IAgentSettings agentSettings, IPackagesList allPackagesList) { var model = new PackageListViewModel(); var packagesById = allPackagesList.GetWatched().GroupBy(p => p.Id); foreach (var package in packagesById) { var packageInfo = new LocalPackageInformation { PackageId = package.Key }; var latestVersion = package.OrderByDescending(p=>p.Version).FirstOrDefault(); if (latestVersion != null) packageInfo.LatestAvailableVersion = latestVersion.Version.ToString(); var installedPackage = installPackageArchive.GetCurrentInstalledVersion(package.Key); packageInfo.InstalledVersion = installedPackage == null ? "0.0.0.0" : installedPackage.Version.ToString(); /*packageInfo.LastInstallationTask = completedTasks .Where(t => t.PackageId == package.Key).OrderByDescending(t => t.LogFileName) .FirstOrDefault();*/ packageInfo.CurrentTask = runningTasks.Count > 0 ? runningTasks .Where(t => t.PackageId == package.Key) .Select(t => { var lastOrDefault = t.ProgressReports.LastOrDefault(); return lastOrDefault != null ? new InstallTaskViewModel { Messages = t.ProgressReports.Select(pr => pr.Message).ToArray(), Status = Enum.GetName(typeof(TaskStatus), t.Task.Status), PackageId = t.PackageId, Version = t.Version, LastMessage = t.ProgressReports.Count > 0 ? lastOrDefault.Message : "" } : null; }).FirstOrDefault() : null; packageInfo.AvailableVersions = package.OrderByDescending(x => x.Version).Select(x => x.Version.ToString()).ToList(); if (latestVersion != null) { packageInfo.Tags = latestVersion.Tags.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (var tag in packageInfo.Tags) { if (!model.Tags.Any(t => t.Equals(tag.ToLower()))) { model.Tags.Add(tag.ToLower()); } } } else { packageInfo.Tags = new string[0]; } model.Packages.Add(packageInfo); } model.CurrentTasks = runningTasks .Select(t => { var progressReport = t.ProgressReports.LastOrDefault(); return progressReport != null ? new InstallTaskViewModel { Messages = t.ProgressReports.Select(pr => pr.Message).ToArray(), Status = Enum.GetName(typeof (TaskStatus), t.Task.Status), PackageId = t.PackageId, Version = t.Version, LastMessage = t.ProgressReports.Count > 0 ? progressReport.Message : "" } : null; }).ToList(); model.AvailableVersions = allPackagesList.Select(p => p.Version.ToString()).Distinct().OrderByDescending(s => s); model.NugetRepository = agentSettings.NuGetRepository; return model; }
private static LogListViewModel GetLogList(IFileSystem fileSystem, IAgentSettings agentSettings, string packageId) { var viewModel = new LogListViewModel {Group = packageId}; var packageLogPath = Path.Combine(GetLogDirectory(agentSettings), packageId); if (fileSystem.Directory.Exists(packageLogPath)) { var logFiles = fileSystem.Directory.GetFiles(packageLogPath, "*.log", SearchOption.TopDirectoryOnly); if (logFiles != null) { viewModel.Logs.AddRange(logFiles.Select(f => { var fileInfo1 = fileSystem.FileInfo.FromFileName(f); return new LogViewModel { LogFilePath = fileInfo1.FullName, LogFileName = fileInfo1.Name, Group = packageId, DateModified = fileInfo1.LastWriteTime, DateCreated = fileInfo1.CreationTime }; }) .OrderByDescending(f=>f.DateModified)); } } return viewModel; }
public IisMsDeployDeploymentHook(IAgentSettings agentSettings, IFileSystem fileSystem) : base(agentSettings, fileSystem) { }
public ServiceDeploymentHook(IFileSystem fileSystem, IAgentSettings agentSettings) : base(agentSettings, fileSystem) { _serviceInstallationPath = Path.Combine(agentSettings.BaseInstallationPath, "services"); }
private static LogViewModel LoadLogViewModel(string logFilename, IFileSystem fileSystem, IAgentSettings agentSettings, bool includeContents, string subFolder=null) { string logDirectory = ""; if (string.IsNullOrWhiteSpace(subFolder)) { logDirectory = GetLogDirectory(agentSettings); } else { logDirectory = Path.Combine(GetLogDirectory(agentSettings), subFolder); } var logFilePath = Path.Combine(logDirectory, logFilename); if (!fileSystem.File.Exists(logFilePath)) { throw new ArgumentOutOfRangeException("filename"); } var fileInfo = fileSystem.FileInfo.FromFileName(logFilename); var viewModel = new LogViewModel() { LogFileName = fileInfo.Name, Group = subFolder ?? "server", DateCreated = fileSystem.File.GetCreationTime(logFilePath), DateModified = fileSystem.File.GetLastWriteTime(logFilePath) }; if (includeContents) { using (var stream = new FileStream(logFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var reader = new StreamReader(stream)) { viewModel.LogContents = reader.ReadToEnd(); } } return viewModel; }
private static List<string> GetPackageLogDirectories(IFileSystem fileSystem, IAgentSettings agentSettings) { var logDirectory = GetLogDirectory(agentSettings); return !fileSystem.Directory.Exists(logDirectory) ? new List<string>() : fileSystem.Directory.GetDirectories(logDirectory).Select(Path.GetFileName).ToList(); }
public void UnloadSettings() { _settings = null; }
private static LogViewModel GetLog(IFileSystem fileSystem, IAgentSettings agentSettings, string packageId, string filename) { return LoadLogViewModel(filename, fileSystem, agentSettings, true, packageId); }
private static string GetLogDirectory(IAgentSettings agentSettings) { return agentSettings.LogsDirectory.MapVirtualPath(); }
public NuGetPackageCache(IFileSystem fileSystem, IAgentSettings agentSettings) : this(fileSystem, agentSettings.CacheDirectory) { }
public InstalledPackageArchive(IAgentSettings agentSettings, IFileSystem fileSystem, ILocalPackageCache packageCache) { _agentSettings = agentSettings; _fileSystem = fileSystem; _packageCache = packageCache; }