private async Task <object> GetStatusAppService(InstallDirectoryItem appInstallation, int?timeoutSeconds) { string error = null; var processInfo = new ProcessInfo { State = "Error while getting process information." }; var imageUrl = GetImageUrl(appInstallation); try { processInfo = await _appService.GetProcessInfo(appInstallation, timeoutSeconds); } catch (AggregateException e) { error = (e.InnerExceptions.Count == 1) ? e.InnerExceptions[0].Message : e.Message; } catch (Exception e) { return(new AppStatus(appInstallation, imageUrl, new ProcessInfo(), e.Message)); } return(new AppStatus(appInstallation, imageUrl, processInfo, error)); }
private static Task ExecuteWorkerService(string commandVerb, InstallDirectoryItem appInstallation, int?timeoutSeconds = null, string startOptions = null) { var workerServiceFile = Path.Combine(appInstallation.Directory.FullName, WorkerServiceFile); var workerServiceArguments = BuildServiceCommand(commandVerb, appInstallation, timeoutSeconds, startOptions); return(MonoHelper.ExecuteProcessAsync(workerServiceFile, workerServiceArguments)); }
private static string GetImageUrl(InstallDirectoryItem appInstallation) { var packagesDirectoryName = AppSettings.GetValue("PackagesRepository"); if (!string.IsNullOrEmpty(packagesDirectoryName)) { var packageFullName = $"{appInstallation.PackageId}.{appInstallation.PackageVersion}"; var packageDirectory = Path.Combine(packagesDirectoryName, packageFullName); var packageDirectoryInfo = new DirectoryInfo(packageDirectory); if (packageDirectoryInfo.Exists) { var nuspecFilePath = Path.Combine(packageDirectoryInfo.FullName, $"{appInstallation.PackageId}.nuspec"); using (var stream = new FileStream(nuspecFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { var nuspec = XDocument.Load(stream); var ns = nuspec.Root?.Name.Namespace; return(nuspec.Root?.Element(ns + "metadata")?.Element(ns + "iconUrl")?.Value); } } } return(string.Empty); }
public AppStatus(InstallDirectoryItem appInstallation, string iconUrl, ProcessInfo processInfo, string error) { Id = appInstallation.PackageId; Version = appInstallation.PackageVersion; Instance = appInstallation.Instance; FullName = $"{appInstallation.PackageId}.{appInstallation.PackageVersion}@{appInstallation.Instance}".TrimEnd('@'); IconUrl = iconUrl; ProcessInfo = processInfo; Error = error; }
private static string BuildServiceCommand(string commandVerb, InstallDirectoryItem appInstallation, int?timeoutSeconds, string startOptions) { var command = new StringBuilder(commandVerb); AddCommandOption(command, "packageId", appInstallation.PackageId); AddCommandOption(command, "packageVersion", appInstallation.PackageVersion); AddCommandOption(command, "packageInstance", appInstallation.Instance); AddCommandOption(command, "packageDirectory", appInstallation.Directory.FullName); AddCommandOption(command, "packageTimeout", timeoutSeconds); if (startOptions != null) { AddCommandOption(command, "startOptions", startOptions); } return(command.ToString()); }
/// <summary> /// Возвращает статус процесса, соответствующего установленному приложению. /// </summary> /// <param name="appInstallation">Сведения об установке приложения.</param> public static Task <ProcessInfo> GetProcessInfo(InstallDirectoryItem appInstallation) { ProcessInfo processInfo; var process = Process.GetProcessesByName("Infinni.NodeWorker") .FirstOrDefault(p => Directory.GetParent(p.MainModule.FileName).Name == appInstallation.Directory.Name); if (process != null) { var versionInfo = process.MainModule.FileVersionInfo; processInfo = new ProcessInfo { Id = process.Id, State = "Running", ModuleName = process.MainModule.ModuleName, FileVersion = versionInfo.FileVersion, ProductVersion = versionInfo.ProductVersion, Language = versionInfo.Language, IsPreRelease = versionInfo.IsPreRelease, IsDebug = versionInfo.IsDebug, ProductName = versionInfo.ProductName, CompanyName = versionInfo.CompanyName, LegalCopyright = versionInfo.LegalCopyright }; } else { processInfo = new ProcessInfo { State = "Stopped" }; } return(Task.FromResult(processInfo)); }
public Task <ProcessInfo> GetProcessInfo(InstallDirectoryItem appInstallation, int?timeoutSeconds = null) { return(ProcessHelper.GetProcessInfo(appInstallation)); }
public Task Stop(InstallDirectoryItem appInstallation, int?timeoutSeconds = null) { return(ExecuteWorkerService(WorkerServiceStopVerb, appInstallation, timeoutSeconds)); }
public Task Start(InstallDirectoryItem appInstallation, int?timeoutSeconds = null) { return(ExecuteWorkerService(WorkerServiceStartVerb, appInstallation, timeoutSeconds, StartStartOptionVerb)); }
public Task Uninstall(InstallDirectoryItem appInstallation) { return(ExecuteWorkerService(WorkerServiceUninstallVerb, appInstallation)); }