public Process Run() { Process.StartInfo.RedirectStandardOutput = true; Process.OutputDataReceived += (sender, e) => output.Display(e.Data); Process.Start(); Process.BeginOutputReadLine(); Process.WaitForExit(); var oldProcess = Process; Process = new Process(); return(oldProcess); }
public async Task Run() { var settings = appContext.Settings; var terms = appContext.Terms; output.Display(terms.DatabaseTaskStart); settings.Name = settings.Name ?? throw new ArgumentNullException(nameof(settings.Name)); settings.DatabaseName = settings.DatabaseName ?? throw new ArgumentNullException(nameof(settings.DatabaseName)); if (appContext.Mvc) { await database .From($"{settings.DatabaseName}.dbo.CMS_Site") .Where("SiteName", "=", settings.Name) .Update(new { SitePresentationURL = $"https://{settings.AppDomain}" }); } }
public async Task Run() { var settings = appContext.Settings; var terms = appContext.Terms; output.Display(terms.InstallTaskStart); settings.Name = settings.Name ?? throw new ArgumentNullException(nameof(settings.Name)); settings.Path = settings.Path ?? throw new ArgumentNullException(nameof(settings.Path)); settings.DatabaseName ??= settings.Name; settings.DatabaseName = await EnsureValidDatabaseName(settings.DatabaseName); var boilerplateTempPath = string.Empty; if (appContext.Boilerplate) { settings.BoilerplateUri = settings.BoilerplateUri.Replace("v{}", $"v{appContext.Version}"); var boilerplateDownloadPath = await cache.GetString(settings.BoilerplateUri); if (boilerplateDownloadPath == null || !File.Exists(boilerplateDownloadPath)) { boilerplateDownloadPath = Path.GetTempFileName(); await DownloadFile(httpClient, settings.BoilerplateUri, boilerplateDownloadPath, output, terms.DownloadingBoilerplate); await cache.SetString(settings.BoilerplateUri, boilerplateDownloadPath); output.Display(terms.DownloadComplete); } else { output.Display(terms.SkippingDownload); } boilerplateTempPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); ZipFile.ExtractToDirectory(boilerplateDownloadPath, boilerplateTempPath, true); var packagesConfigContent = await File.ReadAllTextAsync(Path.Combine(boilerplateTempPath, "packages.config")); var kenticoLibrariesMatch = new Regex("(?<=Kentico\\.Libraries).*?version=\"(.*?)\"").Match(packagesConfigContent); if (!kenticoLibrariesMatch.Success) { throw new Exception("Boilerplate does not reference Kentico.Libraries!"); } settings.Version = new KenticoVersion(kenticoLibrariesMatch.Groups[1].Value); } if (settings.Version == null) { output.Display(terms.VersionNotSpecified); output.Display(terms.UsingLatestVersion); settings.Version = new KenticoVersion(12); } if (settings.Version.Hotfix < 0) { output.Display(terms.HotfixNotSpecified); output.Display(terms.GettingLatestHotfix); settings.Version.Hotfix = await GetLatestHotfix(settings.Version.Major); } if (settings.Version.Major == 12 && settings.Version.Hotfix < 29) { settings.Version.Hotfix = 29; } using var iisManager = new ServerManager(); if (appContext.Mvc) { settings.AppDomain ??= GetNextUnboundIpAddress(iisManager, settings.Version); } settings.AdminDomain ??= GetNextUnboundIpAddress(iisManager, settings.Version, settings.AppDomain); var versionUri = settings.InstallerUri; var installDownloadPath = await cache.GetString(versionUri); if (installDownloadPath == null || !File.Exists(installDownloadPath)) { installDownloadPath = Path.GetTempFileName(); await DownloadFile(httpClient, versionUri, installDownloadPath, output, string.Format(terms.DownloadingInstaller, settings.Version.Major)); await cache.SetString(versionUri, installDownloadPath); output.Display(terms.DownloadComplete); } else { output.Display(terms.SkippingDownload); } SetPermissions(settings.Path, WellKnownSidType.NetworkServiceSid, FileSystemRights.Modify); if (appContext.Source) { output.Display(terms.BeginSourceInstallOutput); var sourceInstallProcess = process .FromPath(installDownloadPath) .InDirectory(Path.GetDirectoryName(installDownloadPath)) .WithArguments($"-o\"{settings.AppPath}\" -p\"{settings.SourcePassword}\" -y") .Run(); if (sourceInstallProcess.ExitCode > 0) { throw new Exception("Source install process failed!"); } return; } var installXmlPath = Path.GetTempFileName(); var installLogPath = Path.GetTempFileName(); var setupPath = settings.SetupPath; await WriteInstallXml(installXmlPath, installLogPath, setupPath); output.Display(terms.BeginInstallOutput); var installProcess = process .FromPath(installDownloadPath) .InDirectory(Path.GetDirectoryName(installDownloadPath)) .WithArguments($"{Path.GetFileName(installXmlPath)}") .Run(); if (installProcess.ExitCode == 1) { if (DateTime.Now - installProcess.StartTime < TimeSpan.FromSeconds(10)) { output.Display(terms.BeginUninstallOutput); var uninstallProcess = process .FromPath(installDownloadPath) .WithArguments("-u") .Run(); if (uninstallProcess.ExitCode == 1) { throw new Exception("Uninstall process failed!"); } Directory.Delete(setupPath, true); installProcess = process .FromPath(installDownloadPath) .InDirectory(Path.GetDirectoryName(installDownloadPath)) .WithArguments($"{Path.GetFileName(installXmlPath)}") .Run(); } else { throw new Exception("Install process failed!"); } } if (installProcess.ExitCode == 1) { throw new Exception("Install after uninstall process failed!"); } if (appContext.Boilerplate) { Directory.Move(boilerplateTempPath, settings.AppPath); File.Move(Path.Combine(settings.AppPath, settings.BoilerplateSln), settings.BoilerplateSlnPath); var boilerplateSlnContent = await File.ReadAllTextAsync(settings.BoilerplateSlnPath); if (string.IsNullOrWhiteSpace(boilerplateSlnContent)) { throw new Exception("Boilerplate SLN is empty!"); } var newBoilerplateSlnContent = new StringBuilder(boilerplateSlnContent); newBoilerplateSlnContent.Replace("{{settings.Name}}", settings.Name); await File.WriteAllTextAsync(settings.BoilerplateSlnPath, newBoilerplateSlnContent.ToString()); } }
public async Task Run() { var terms = appContext.Terms; var settings = appContext.Settings; output.Display(terms.CreateKenticoAppVersion + appContext.Version); if (settings.Help ?? false) { output.Display(terms.Help); var rows = typeof(Settings) .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Select(property => { var typeRequiredDescription = (typeof(Terms).GetProperty($"Help{property.Name}")?.GetValue(terms) as string)?.Split('|'); var type = string.Empty; var required = string.Empty; var description = string.Empty; switch (typeRequiredDescription?.Length) { case 1: description = typeRequiredDescription[0]; break; case 2: type = typeRequiredDescription[0]; description = typeRequiredDescription[1]; break; case 3: type = typeRequiredDescription[0]; required = typeRequiredDescription[1]; description = typeRequiredDescription[2]; break; } return(new HelpRow { Name = $"--{property.Name[0].ToString().ToLower()}{property.Name.Substring(1)}", Aliases = property.GetCustomAttribute <AliasesAttribute>()?.Aliases.Aggregate((a, b) => $"{a}, {b}"), Type = type, Required = required, Description = description }); }); output.DisplayTable(rows); return; } output.Display(terms.Setup); settings.Name = settings.Name ?? throw new ArgumentNullException(nameof(settings.Name)); settings.Path ??= Path.Combine(@"C:\inetpub\wwwroot\", settings.Name ?? throw new ArgumentNullException(nameof(settings.Name))); settings.Path = EnsureValidAppPath(settings.Path); var installTask = tasks.InstallTask(); var iisSiteTask = tasks.IisTask(); var databaseTask = tasks.DatabaseTask(); var hotfixTask = tasks.HotfixTask(); if (settings.AppTemplate == "Boilerplate") { appContext.Boilerplate = true; appContext.Mvc = true; } else if (!string.IsNullOrWhiteSpace(settings.AppTemplate)) { appContext.Template = true; if (settings.AppTemplate.EndsWith("Mvc")) { appContext.Mvc = true; } } if (settings.Source ?? false) { settings.SourcePassword = settings.SourcePassword ?? throw new ArgumentNullException( nameof(settings.SourcePassword), $"Must be set if '{nameof(settings.Source)}' is 'true'." ); appContext.Source = true; await installTask.Run(); await iisSiteTask.Run(); output.Display(terms.InstallComplete); output.Display(string.Format(terms.SolutionPath, settings.Path)); output.Display(string.Format(terms.AdminPath, settings.AdminDomain)); output.Display(string.Format(terms.SourceHotfixStep, settings.HotfixUri)); output.Display(terms.AdditionalSourceSteps); return; } await installTask.Run(); if (settings.Version?.Hotfix > 0) { await tasks.HotfixTask().Run(); } await iisSiteTask.Run(); await databaseTask.Run(); output.Display(terms.InstallComplete); output.Display(string.Format(terms.SolutionPath, settings.Path)); output.Display(string.Format(terms.AdminPath, settings.AdminDomain)); if (appContext.Mvc) { output.Display(string.Format(terms.AppPath, settings.AppDomain)); } }
public async Task Run() { var settings = appContext.Settings; var terms = appContext.Terms; output.Display(terms.IisTaskStart); using var iisManager = new ServerManager(); settings.Name = settings.Name ?? throw new ArgumentNullException(nameof(settings.Name)); settings.Version = settings.Version ?? throw new ArgumentNullException(nameof(settings.Version)); var store = new X509Store(StoreName.My, StoreLocation.LocalMachine); store.Open(OpenFlags.ReadWrite | OpenFlags.OpenExistingOnly); X509Certificate2 certificate; X509Certificate2Collection?filteredCertificates = null; var certificateThumbprint = await cache.GetString(CertificateCacheKey); if (certificateThumbprint != null) { filteredCertificates = store.Certificates.Find(X509FindType.FindByThumbprint, certificateThumbprint, false); } if (filteredCertificates?.Count > 0) { output.Display(terms.SkippingCreatingCertificate); certificate = filteredCertificates[0]; } else { certificate = GetSelfSignedCertificate(terms.CertificateName); store.Add(certificate); await cache.SetString(CertificateCacheKey, certificate.Thumbprint); output.Display(terms.CreatedNewCertificate); } store.Close(); var adminSuffix = "_Admin"; var siteName = EnsureValidSiteName(iisManager.Sites, settings.Name, adminSuffix); var adminSite = iisManager.Sites.Add( siteName + adminSuffix, settings.AdminDomain + ":443:", settings.AdminPath, certificate.GetCertHash(), store.Name, SslFlags.None ); var appPool = iisManager.ApplicationPools.Add(EnsureValidAppPoolName(iisManager.ApplicationPools, siteName)); appPool.Cpu.Action = ProcessorAction.KillW3wp; appPool.ProcessModel.IdentityType = ProcessModelIdentityType.NetworkService; adminSite.ApplicationDefaults.ApplicationPoolName = appPool.Name; if (appContext.Mvc) { settings.AppDomain = settings.AppDomain ?? throw new ArgumentNullException( nameof(settings.AppDomain), $"Must be set if '{settings.AppTemplate}' is an MVC template." ); var appSite = iisManager.Sites.Add( siteName, settings.AppDomain + ":443:", settings.AppPath, certificate.GetCertHash(), store.Name, SslFlags.None ); appSite.ApplicationDefaults.ApplicationPoolName = appPool.Name; } iisManager.CommitChanges(); }
public async Task Run() { var settings = appContext.Settings; var terms = appContext.Terms; output.Display(terms.HotfixTaskStart); settings.Version ??= settings.Version ?? throw new ArgumentNullException(nameof(settings.Version)); var hotfixUri = settings.HotfixUri; var hotfixDownloadPath = await cache.GetString(hotfixUri + HotfixDownloadCacheKeySuffix); if (hotfixDownloadPath == null || !File.Exists(hotfixDownloadPath)) { hotfixDownloadPath = Path.GetTempFileName(); await DownloadFile(httpClient, hotfixUri, hotfixDownloadPath, output, string.Format(terms.DownloadingHotfix, settings.Version)); await cache.SetString(hotfixUri + HotfixDownloadCacheKeySuffix, hotfixDownloadPath); output.Display(terms.DownloadComplete); } else { output.Display(terms.SkippingDownload); } var hotfixUnpackPath = await cache.GetString(hotfixUri + HotfixUnpackCacheKeySuffix); if (hotfixUnpackPath == null || !File.Exists(hotfixUnpackPath)) { hotfixUnpackPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); Directory.CreateDirectory(hotfixUnpackPath); await cache.SetString(hotfixUri + HotfixUnpackCacheKeySuffix, hotfixUnpackPath); } var hotfixPath = Path.Combine(hotfixUnpackPath, "Hotfix.exe"); if (!File.Exists(hotfixPath)) { output.Display(terms.UnpackingHotfix); var hotfixUnpackProcess = process .FromPath(hotfixDownloadPath) .InDirectory(Path.GetDirectoryName(hotfixUnpackPath)) .WithArguments($"/verysilent /dir=\"{hotfixUnpackPath}\"") .Run(); if (hotfixUnpackProcess.ExitCode > 0) { throw new Exception("Hotfix unpack process failed!"); } } else { output.Display(terms.SkippingUnpackingHotfix); } output.Display(terms.BeginHotfixOutput); var hotfixProcess = process .FromPath(hotfixPath) .InDirectory(Path.GetDirectoryName(hotfixPath)) .WithArguments($"/silentpath=\"{settings.Path}\"") .Run(); if (hotfixProcess.ExitCode > 0) { throw new Exception("Hotfix unpack process failed!"); } output.Display(terms.RebuildingSolution); var nugetServicePath = Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !, "NuGetCLI", "nuget.exe" ); process .FromPath(nugetServicePath) .WithArguments($"restore {settings.BoilerplateSlnPath}") .Run(); var buildServicePath = Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !, "App.Infrastructure.Services.BuildService", "BuildService.exe" ); var buildService = process .FromPath(buildServicePath) .WithArguments(settings.BoilerplateSlnPath) .Run(); if (buildService.ExitCode != 0) { throw new Exception("Build process failed!"); } // Restore CI // Run CI }