public bool UninstallExtension(string id) { string installationDirectory = GetInstallationDirectory(id); SiteExtensionInfo info = GetLocalExtension(id, checkLatest: false); if (info == null || !FileSystemHelpers.DirectoryExists(info.LocalPath)) { throw new DirectoryNotFoundException(installationDirectory); } var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string uninstallScript = Path.Combine(installationDirectory, _uninstallScriptName); if (FileSystemHelpers.FileExists(uninstallScript)) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(uninstallScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } OperationManager.Attempt(() => CleanupSiteExtensionJobs(id)); OperationManager.Attempt(() => FileSystemHelpers.DeleteFileSafe(GetNuGetPackageFile(info.Id, info.Version))); OperationManager.Attempt(() => FileSystemHelpers.DeleteDirectorySafe(installationDirectory)); return(GetLocalExtension(id, checkLatest: false) == null); }
public ProductCreateResponse Create(ProductCreateRequest request) { var factory = new ExternalCommandFactory(); var command = factory.Create <ProductCreateCommand>(); return(command.Execute(request)); }
public ExternalResponse Create(CustomerCreateRequest request) { var factory = new ExternalCommandFactory(); var command = factory.Create <CustomerCreateCommand>(); return(command.Execute(request)); }
public bool UninstallExtension(string id) { string installationDirectory = GetInstallationDirectory(id); if (!FileSystemHelpers.DirectoryExists(installationDirectory)) { throw new DirectoryNotFoundException(installationDirectory); } OperationManager.Attempt(() => { var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string uninstallScript = Path.Combine(installationDirectory, _uninstallScriptName); if (FileSystemHelpers.FileExists(uninstallScript)) { Executable exe = externalCommandFactory.BuildCommandExecutable(uninstallScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); } FileSystemHelpers.DeleteDirectorySafe(installationDirectory); }); return(!FileSystemHelpers.DirectoryExists(installationDirectory)); }
public PartnerAuthenticateResponse Authenticate(PartnerAuthenticateRequest request) { var factory = new ExternalCommandFactory(); var command = factory.Create <PartnerAuthenticateCommand>(); return(command.Execute(request)); }
public async Task <bool> UninstallExtension(string id) { ITracer tracer = _traceFactory.GetTracer(); string installationDirectory = GetInstallationDirectory(id); SiteExtensionInfo info = await GetLocalExtension(id, checkLatest : false); if (info == null || !FileSystemHelpers.DirectoryExists(info.LocalPath)) { tracer.TraceError("Site extension {0} not found.", id); throw new DirectoryNotFoundException(installationDirectory); } if (IsInstalledToWebRoot(id)) { // special handling for package that install in wwwroot instead of under site extension folder tracer.Trace("Clear all content in wwwroot"); OperationManager.Attempt(() => FileSystemHelpers.DeleteDirectoryContentsSafe(_environment.WebRootPath)); } else { // default action for site extension uninstall // only site extension has below infomation var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string uninstallScript = Path.Combine(installationDirectory, _uninstallScriptName); if (FileSystemHelpers.FileExists(uninstallScript)) { using (tracer.Step("Execute uninstall.cmd")) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(uninstallScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } } using (tracer.Step("Remove site extension job")) { OperationManager.Attempt(() => CleanupSiteExtensionJobs(id)); } } using (tracer.Step("Delete site extension package, directory and arm settings")) { OperationManager.Attempt(() => FileSystemHelpers.DeleteFileSafe(GetNuGetPackageFile(info.Id, info.Version))); OperationManager.Attempt(() => FileSystemHelpers.DeleteDirectorySafe(installationDirectory)); SiteExtensionStatus armSettings = new SiteExtensionStatus(_environment.SiteExtensionSettingsPath, id, tracer); await armSettings.RemoveStatus(); } return(await GetLocalExtension(id, checkLatest : false) == null); }
/// <summary> /// <para>1. Download package</para> /// <para>2. Generate xdt file if not exist</para> /// <para>3. Deploy site extension job</para> /// <para>4. Execute install.cmd if exist</para> /// </summary> private async Task <UIPackageMetadata> InstallExtension(UIPackageMetadata package, string installationDirectory, string feedUrl) { ITracer tracer = _traceFactory.GetTracer(); try { if (FileSystemHelpers.DirectoryExists(installationDirectory)) { FileSystemHelpers.DeleteDirectorySafe(installationDirectory); } SourceRepository remoteRepo = GetRemoteRepository(feedUrl); // Copy content folder // Copy nupkg file for package list/lookup FileSystemHelpers.CreateDirectory(installationDirectory); // package path from local repo string packageLocalFilePath = GetNuGetPackageFile(package.Identity.Id, package.Identity.Version.ToString()); using (tracer.Step("Download site extension: {0}", package.Identity)) { await remoteRepo.DownloadPackageToFolder(package.Identity, installationDirectory, pathToLocalCopyOfNudpk : packageLocalFilePath); } // If there is no xdt file, generate default. using (tracer.Step("Check if applicationhost.xdt file existed.")) { GenerateApplicationHostXdt(installationDirectory, '/' + package.Identity.Id, isPreInstalled: false, tracer: tracer); } using (tracer.Step("Trigger site extension job")) { OperationManager.Attempt(() => DeploySiteExtensionJobs(package.Identity.Id)); } var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string installScript = Path.Combine(installationDirectory, _installScriptName); if (FileSystemHelpers.FileExists(installScript)) { using (tracer.Step("Execute install.cmd")) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(installScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } } } catch (Exception ex) { tracer.TraceError(ex); FileSystemHelpers.DeleteDirectorySafe(installationDirectory); throw; } return(await _localRepository.GetLatestPackageById(package.Identity.Id)); }
public static void Chmod(string permission, string filePath, IEnvironment environment, IDeploymentSettingsManager deploymentSettingManager, ILogger logger) { var folder = Path.GetDirectoryName(filePath); var exeFactory = new ExternalCommandFactory(environment, deploymentSettingManager, null); Executable exe = exeFactory.BuildCommandExecutable("/bin/chmod", folder, deploymentSettingManager.GetCommandIdleTimeout(), logger); exe.Execute("{0} \"{1}\"", permission, filePath); }
public CommandExecutor(string repositoryPath, IEnvironment environment, IDeploymentSettingsManager settings, ITracer tracer) { _rootDirectory = repositoryPath; _environment = environment; _externalCommandFactory = new ExternalCommandFactory(environment, settings, repositoryPath); _settings = settings; _tracer = tracer; }
private IPackage InstallExtension(IPackage package, string installationDirectory) { try { if (FileSystemHelpers.DirectoryExists(installationDirectory)) { FileSystemHelpers.DeleteDirectorySafe(installationDirectory); } foreach (IPackageFile file in package.GetContentFiles()) { // It is necessary to place applicationHost.xdt under site extension root. string contentFilePath = file.Path.Substring("content/".Length); string fullPath = Path.Combine(installationDirectory, contentFilePath); FileSystemHelpers.CreateDirectory(Path.GetDirectoryName(fullPath)); using (Stream writeStream = FileSystemHelpers.OpenWrite(fullPath), readStream = file.GetStream()) { OperationManager.Attempt(() => readStream.CopyTo(writeStream)); } } // If there is no xdt file, generate default. GenerateApplicationHostXdt(installationDirectory, '/' + package.Id, isPreInstalled: false); OperationManager.Attempt(() => DeploySiteExtensionJobs(package.Id)); var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string installScript = Path.Combine(installationDirectory, _installScriptName); if (FileSystemHelpers.FileExists(installScript)) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(installScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } // Copy nupkg file for package list/lookup FileSystemHelpers.CreateDirectory(installationDirectory); string packageFilePath = GetNuGetPackageFile(package.Id, package.Version.ToString()); using ( Stream readStream = package.GetStream(), writeStream = FileSystemHelpers.OpenWrite(packageFilePath)) { OperationManager.Attempt(() => readStream.CopyTo(writeStream)); } } catch (Exception ex) { ITracer tracer = _traceFactory.GetTracer(); tracer.TraceError(ex); FileSystemHelpers.DeleteDirectorySafe(installationDirectory); throw; } return(_localRepository.FindPackage(package.Id)); }
protected BaseJobRunner(string jobName, string jobsTypePath, IEnvironment environment, IDeploymentSettingsManager settings, ITraceFactory traceFactory, IAnalytics analytics) { TraceFactory = traceFactory; Environment = environment; Settings = settings; JobName = jobName; _analytics = analytics; JobBinariesPath = Path.Combine(Environment.JobsBinariesPath, jobsTypePath, jobName); JobTempPath = Path.Combine(Environment.TempPath, Constants.JobsPath, jobsTypePath, jobName); JobDataPath = Path.Combine(Environment.DataPath, Constants.JobsPath, jobsTypePath, jobName); _externalCommandFactory = new ExternalCommandFactory(Environment, Settings, Environment.RepositoryPath); }
public async Task <bool> UninstallExtension(string id) { ITracer tracer = _traceFactory.GetTracer(); string installationDirectory = GetInstallationDirectory(id); SiteExtensionInfo info = await GetLocalExtension(id, checkLatest : false); if (info == null || !FileSystemHelpers.DirectoryExists(info.LocalPath)) { tracer.TraceError("Site extension {0} not found.", id); throw new DirectoryNotFoundException(installationDirectory); } var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string uninstallScript = Path.Combine(installationDirectory, _uninstallScriptName); if (FileSystemHelpers.FileExists(uninstallScript)) { using (tracer.Step("Execute uninstall.cmd")) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(uninstallScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } } using (tracer.Step("Remove site extension job")) { OperationManager.Attempt(() => CleanupSiteExtensionJobs(id)); } using (tracer.Step("Delete site extension package and directory")) { OperationManager.Attempt(() => FileSystemHelpers.DeleteFileSafe(GetNuGetPackageFile(info.Id, info.Version))); OperationManager.Attempt(() => FileSystemHelpers.DeleteDirectorySafe(installationDirectory)); } return(await GetLocalExtension(id, checkLatest : false) == null); }
private static string PackageArtifactFromFolder(IEnvironment environment, IDeploymentSettingsManager settings, DeploymentContext context, string srcDirectory, string artifactDirectory, string artifactFilename) { context.Logger.Log("Writing the artifacts to a squashfs file"); string file = Path.Combine(artifactDirectory, artifactFilename); ExternalCommandFactory commandFactory = new ExternalCommandFactory(environment, settings, context.RepositoryPath); Executable exe = commandFactory.BuildExternalCommandExecutable(srcDirectory, artifactDirectory, context.Logger); try { exe.ExecuteWithProgressWriter(context.Logger, context.Tracer, $"mksquashfs . {file} -noappend"); } catch (Exception) { context.GlobalLogger.LogError(); throw; } int numOfArtifacts = OryxBuildConstants.FunctionAppBuildSettings.ConsumptionBuildMaxFiles; DeploymentHelper.PurgeBuildArtifactsIfNecessary(artifactDirectory, BuildArtifactType.Squashfs, context.Tracer, numOfArtifacts); return(file); }
/// <summary> /// Package every files and sub directories from a source folder /// </summary> /// <param name="context">The deployment context in current scope</param> /// <param name="srcDirectory">The source directory to be packed</param> /// <param name="artifactDirectory">The destination directory to eject the build artifact</param> /// <param name="artifactFilename">The filename of the build artifact</param> /// <param name="artifactType">The method for packing the artifact</param> /// <param name="numBuildArtifacts">The number of temporary artifacts should be hold in the destination directory</param> /// <returns></returns> private string PackageArtifactFromFolder(DeploymentContext context, string srcDirectory, string artifactDirectory, string artifactFilename, BuildArtifactType artifactType, int numBuildArtifacts = 0) { context.Logger.Log($"Writing the artifacts to {artifactType.ToString()} file at {artifactDirectory}"); string file = Path.Combine(artifactDirectory, artifactFilename); var exe = ExternalCommandFactory.BuildExternalCommandExecutable(srcDirectory, artifactDirectory, context.Logger); try { switch (artifactType) { case BuildArtifactType.Zip: exe.ExecuteWithProgressWriter(context.Logger, context.Tracer, $"zip -r -0 -q {file} ."); break; case BuildArtifactType.Squashfs: exe.ExecuteWithProgressWriter(context.Logger, context.Tracer, $"mksquashfs . {file} -noappend"); break; default: throw new ArgumentException($"Received unknown file extension {artifactType.ToString()}"); } } catch (Exception) { context.GlobalLogger.LogError(); throw; } // Just to be sure that we don't keep adding build artifacts here if (numBuildArtifacts > 0) { DeploymentHelper.PurgeBuildArtifactsIfNecessary(artifactDirectory, artifactType, context.Tracer, numBuildArtifacts); } return(file); }
/// <summary> /// <para>1. Download package</para> /// <para>2. Generate xdt file if not exist</para> /// <para>3. Deploy site extension job</para> /// <para>4. Execute install.cmd if exist</para> /// </summary> private async Task <UIPackageMetadata> InstallExtension(UIPackageMetadata package, string installationDirectory, SourceRepository remoteRepo, SiteExtensionInfo.SiteExtensionType type, ITracer tracer, string installationArgs) { try { EnsureInstallationEnviroment(installationDirectory, tracer); string packageLocalFilePath = GetNuGetPackageFile(package.Identity.Id, package.Identity.Version.ToNormalizedString()); bool packageExisted = FileSystemHelpers.DirectoryExists(installationDirectory); using (tracer.Step("Download site extension: {0}", package.Identity)) { string extractPath = installationDirectory; if (SiteExtensionInfo.SiteExtensionType.WebRoot == type) { extractPath = _environment.WebRootPath; FileSystemHelpers.EnsureDirectory(extractPath); } // Copy/update content folder // Copy/update nupkg file for package list/lookup if (packageExisted) { await remoteRepo.UpdateLocalPackage(_localRepository, package.Identity, extractPath, packageLocalFilePath, tracer); } else { FileSystemHelpers.EnsureDirectory(installationDirectory); await remoteRepo.DownloadPackageToFolder(package.Identity, extractPath, packageLocalFilePath); } if (SiteExtensionInfo.SiteExtensionType.WebRoot == type) { // if install to WebRoot, check if there is any xdt or scmXdt file come with package // if there is, move it to site extension folder string xdtFile = Path.Combine(extractPath, Constants.ApplicationHostXdtFileName); string scmXdtFile = Path.Combine(extractPath, Constants.ScmApplicationHostXdtFileName); bool findXdts = false; if (FileSystemHelpers.FileExists(xdtFile)) { tracer.Trace("Use xdt file from package."); string newXdtFile = Path.Combine(installationDirectory, Constants.ApplicationHostXdtFileName); tracer.Trace("Moving {0} to {1}", xdtFile, newXdtFile); FileSystemHelpers.MoveFile(xdtFile, newXdtFile); findXdts = true; } // if the siteextension applies to both main site and the scm site if (FileSystemHelpers.FileExists(scmXdtFile)) { tracer.Trace("Use scmXdt file from package."); string newScmXdtFile = Path.Combine(installationDirectory, Constants.ScmApplicationHostXdtFileName); tracer.Trace("Moving {0} to {1}", scmXdtFile, newScmXdtFile); FileSystemHelpers.MoveFile(scmXdtFile, newScmXdtFile); findXdts = true; } if (!findXdts) { tracer.Trace("No xdt file come with package."); } } } // ignore below action if we install packge to wwwroot if (SiteExtensionInfo.SiteExtensionType.WebRoot != type) { using (tracer.Step("Check if applicationHost.xdt or scmApplicationHost.xdt file existed.")) { GenerateDefaultScmApplicationHostXdt(installationDirectory, '/' + package.Identity.Id, tracer: tracer); } using (tracer.Step("Trigger site extension job")) { OperationManager.Attempt(() => DeploySiteExtensionJobs(package.Identity.Id)); } var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string installScript = Path.Combine(installationDirectory, _installScriptName); if (FileSystemHelpers.FileExists(installScript)) { using (tracer.Step("Execute install.cmd")) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(installScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), installationArgs ?? String.Empty); }); } } } } catch (Exception ex) { tracer.TraceError(ex); FileSystemHelpers.DeleteDirectorySafe(installationDirectory); throw; } return(await _localRepository.GetLatestPackageByIdFromSrcRepo(package.Identity.Id)); }
protected virtual IProcess CreateProcess(string connectionId, string shell) { var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, _environment.RootPath); var exe = externalCommandFactory.BuildExternalCommandExecutable(_environment.RootPath, _environment.WebRootPath, NullLogger.Instance); var startInfo = new ProcessStartInfo() { UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true, RedirectStandardInput = true, RedirectStandardOutput = true, WorkingDirectory = _environment.RootPath }; if (shell.Equals("powershell", StringComparison.OrdinalIgnoreCase)) { startInfo.FileName = System.Environment.ExpandEnvironmentVariables(@"%windir%\System32\WindowsPowerShell\v1.0\powershell.exe"); startInfo.Arguments = "-File -"; } else { startInfo.FileName = System.Environment.ExpandEnvironmentVariables(@"%windir%\System32\cmd.exe"); startInfo.Arguments = "/Q"; } foreach (var environmentVariable in exe.EnvironmentVariables) { startInfo.EnvironmentVariables[environmentVariable.Key] = environmentVariable.Value; } // add '>' to distinguish PROMPT from other output startInfo.EnvironmentVariables["PROMPT"] = "$P$G"; // dir cmd would list folders then files alpabetically // consistent with FileBrowser ui. startInfo.EnvironmentVariables["DIRCMD"] = "/OG /ON"; var process = new Process { StartInfo = startInfo, EnableRaisingEvents = true }; process.Exited += delegate { SafeInvoke(() => { ProcessInfo temp; _processes.TryRemove(connectionId, out temp); Connection.Send(connectionId, new { Output = "\r\nprocess [" + process.Id + "] terminated! Press ENTER to start a new cmd process.\r\n", RunningProcessesCount = _processes.Count }).Wait(); }); }; process.Start(); EnsureIdleTimer(); HookProcessStreamsToConnection(process, connectionId); return(new ProcessWrapper(process)); }
/// <summary> /// <para>1. Download package</para> /// <para>2. Generate xdt file if not exist</para> /// <para>3. Deploy site extension job</para> /// <para>4. Execute install.cmd if exist</para> /// </summary> private async Task <UIPackageMetadata> InstallExtension(UIPackageMetadata package, string installationDirectory, string feedUrl, SiteExtensionInfo.SiteExtensionType type, ITracer tracer) { try { if (FileSystemHelpers.DirectoryExists(installationDirectory)) { FileSystemHelpers.DeleteDirectorySafe(installationDirectory); } SourceRepository remoteRepo = GetRemoteRepository(feedUrl); // Copy content folder // Copy nupkg file for package list/lookup FileSystemHelpers.CreateDirectory(installationDirectory); // package path from local repo string packageLocalFilePath = GetNuGetPackageFile(package.Identity.Id, package.Identity.Version.ToString()); using (tracer.Step("Download site extension: {0}", package.Identity)) { string extractPath = installationDirectory; if (SiteExtensionInfo.SiteExtensionType.WebRoot == type) { extractPath = _environment.WebRootPath; FileSystemHelpers.EnsureDirectory(extractPath); } await remoteRepo.DownloadPackageToFolder(package.Identity, extractPath, pathToLocalCopyOfNudpk : packageLocalFilePath); if (SiteExtensionInfo.SiteExtensionType.WebRoot == type) { // if install to WebRoot, check if there is any xdt file come with package // if there is one, move it to site extension folder string xdtFile = Path.Combine(extractPath, Constants.ApplicationHostXdtFileName); if (File.Exists(xdtFile)) { tracer.Trace("Use xdt file from package."); string newXdtFile = Path.Combine(installationDirectory, Constants.ApplicationHostXdtFileName); tracer.Trace("Moving {0} to {1}", xdtFile, newXdtFile); FileSystemHelpers.MoveFile(xdtFile, newXdtFile); } else { tracer.Trace("No xdt file come with package."); } } } // ignore below action if we install packge to wwwroot if (SiteExtensionInfo.SiteExtensionType.WebRoot != type) { // If there is no xdt file, generate default. using (tracer.Step("Check if applicationhost.xdt file existed.")) { GenerateApplicationHostXdt(installationDirectory, '/' + package.Identity.Id, isPreInstalled: false, tracer: tracer); } using (tracer.Step("Trigger site extension job")) { OperationManager.Attempt(() => DeploySiteExtensionJobs(package.Identity.Id)); } var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string installScript = Path.Combine(installationDirectory, _installScriptName); if (FileSystemHelpers.FileExists(installScript)) { using (tracer.Step("Execute install.cmd")) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(installScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } } } } catch (Exception ex) { tracer.TraceError(ex); FileSystemHelpers.DeleteDirectorySafe(installationDirectory); throw; } return(await _localRepository.GetLatestPackageById(package.Identity.Id)); }