コード例 #1
0
 public void CopyFile(InstallDirectoryItem appInstallation, PackageFile appFile, string appLibPath)
 {
     var installPath = appInstallation.Directory.FullName;
     var installFiles = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
     var destinationPath = Path.Combine(installPath, appLibPath, appFile.InstallPath);
     CopyFileWithOverwrite(appFile.SourcePath, destinationPath, installFiles);
 }
コード例 #2
0
        public void CopyFiles(InstallDirectoryItem appInstallation, PackageContent appPackage, string appLibPath)
        {
            if (!appInstallation.Directory.Exists)
            {
                appInstallation.Directory.Create();
            }

            var installPath  = appInstallation.Directory.FullName;
            var installFiles = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            // Копирование файлов из каталога 'lib'
            foreach (var libFile in appPackage.Lib)
            {
                var destinationPath = Path.Combine(installPath, appLibPath, libFile.InstallPath);
                CopyFileWithOverwrite(libFile.SourcePath, destinationPath, installFiles);
            }

            // Копирование файлов из каталога 'content'
            foreach (var contentFile in appPackage.Content)
            {
                var destinationPath = Path.Combine(installPath, "content", contentFile.InstallPath);
                CopyFileWithOverwrite(contentFile.SourcePath, destinationPath, installFiles);
            }


            // Копирование файлов из каталога 'plugin'
            foreach (var contentFile in appPackage.Plugin)
            {
                var destinationPath = Path.Combine(installPath, "platform", contentFile.InstallPath);
                CopyFileWithOverwrite(contentFile.SourcePath, destinationPath, installFiles);
            }
        }
コード例 #3
0
        public void CopyFile(InstallDirectoryItem appInstallation, PackageFile appFile, string appLibPath)
        {
            var installPath     = appInstallation.Directory.FullName;
            var installFiles    = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            var destinationPath = Path.Combine(installPath, appLibPath, appFile.InstallPath);

            CopyFileWithOverwrite(appFile.SourcePath, destinationPath, installFiles);
        }
コード例 #4
0
 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;
 }
コード例 #5
0
        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();
        }
コード例 #6
0
        public IEnumerable <InstallDirectoryItem> GetItems()
        {
            if (!Directory.Exists(_rootInstallPath))
            {
                yield break;
            }

            var directories = Directory.EnumerateDirectories(_rootInstallPath);

            foreach (var path in directories)
            {
                var installDir = InstallDirectoryItem.Parse(path);

                if (installDir != null)
                {
                    yield return(installDir);
                }
            }
        }
コード例 #7
0
        public void Delete(InstallDirectoryItem appInstallation)
        {
            // Есть вероятность, что при удалении каталога установки его файлы
            // еще используются, поскольку служба останавливается асинхронно.
            // Пока более интеллектуального способа не найдено, производится
            // несколько попыток удаления каталога с интервалом в 1 секунду.

            Exception exception = null;

            // Максимальный таймаут равен 2 минуты (24 попытки по 5 секунд каждая)
            const int attempts = 24;
            const int timeout = 5000;

            for (var i = 0; i < attempts; i++)
            {
                if (exception != null)
                {
                    Thread.Sleep(timeout);
                }

                try
                {
                    if (appInstallation.Directory.Exists)
                    {
                        appInstallation.Directory.Delete(true);
                    }

                    return;
                }
                catch (Exception e)
                {
                    exception = e;

                    _log.InfoFormat(Resources.AttemptToDeletePackageDirectoryHasCompletedWithError, i + 1, appInstallation, e.Message);
                }
            }

            if (exception != null)
            {
                throw new InvalidOperationException(string.Format(Resources.CannotDeletePackageDirectory, appInstallation), exception);
            }
        }
コード例 #8
0
        public void Delete(InstallDirectoryItem appInstallation)
        {
            // Есть вероятность, что при удалении каталога установки его файлы
            // еще используются, поскольку служба останавливается асинхронно.
            // Пока более интеллектуального способа не найдено, производится
            // несколько попыток удаления каталога с интервалом в 1 секунду.

            Exception exception = null;

            // Максимальный таймаут равен 2 минуты (24 попытки по 5 секунд каждая)
            const int attempts = 24;
            const int timeout  = 5000;

            for (var i = 0; i < attempts; i++)
            {
                if (exception != null)
                {
                    Thread.Sleep(timeout);
                }

                try
                {
                    if (appInstallation.Directory.Exists)
                    {
                        appInstallation.Directory.Delete(true);
                    }

                    return;
                }
                catch (Exception e)
                {
                    exception = e;

                    _log.InfoFormat(Resources.AttemptToDeletePackageDirectoryHasCompletedWithError, i + 1, appInstallation, e.Message);
                }
            }

            if (exception != null)
            {
                throw new InvalidOperationException(string.Format(Resources.CannotDeletePackageDirectory, appInstallation), exception);
            }
        }
コード例 #9
0
        /// <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);
        }
コード例 #10
0
        public void CopyFiles(InstallDirectoryItem appInstallation, PackageContent appPackage, string appLibPath)
        {
            if (!appInstallation.Directory.Exists)
            {
                appInstallation.Directory.Create();
            }

            var installPath = appInstallation.Directory.FullName;
            var installFiles = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

            // Копирование файлов из каталога 'lib'
            foreach (var libFile in appPackage.Lib)
            {
                var destinationPath = Path.Combine(installPath, appLibPath, libFile.InstallPath);
                CopyFileWithOverwrite(libFile.SourcePath, destinationPath, installFiles);
            }

            // Копирование файлов из каталога 'content'
            foreach (var contentFile in appPackage.Content)
            {
                var destinationPath = Path.Combine(installPath, "content", contentFile.InstallPath);
                CopyFileWithOverwrite(contentFile.SourcePath, destinationPath, installFiles);
            }


            // Копирование файлов из каталога 'plugin'
            foreach (var contentFile in appPackage.Plugin)
            {
                var destinationPath = Path.Combine(installPath, "platform", contentFile.InstallPath);
                CopyFileWithOverwrite(contentFile.SourcePath, destinationPath, installFiles);
            }
        }
コード例 #11
0
 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);
 }
コード例 #12
0
 public Task<ProcessInfo> GetProcessInfo(InstallDirectoryItem appInstallation, int? timeoutSeconds = null)
 {
     return ProcessHelper.GetProcessInfo(appInstallation);
 }
コード例 #13
0
 public Task Stop(InstallDirectoryItem appInstallation, int? timeoutSeconds = null)
 {
     return ExecuteWorkerService(WorkerServiceStopVerb, appInstallation, timeoutSeconds);
 }
コード例 #14
0
 public Task Start(InstallDirectoryItem appInstallation, int? timeoutSeconds = null)
 {
     return ExecuteWorkerService(WorkerServiceStartVerb, appInstallation, timeoutSeconds, StartStartOptionVerb);
 }
コード例 #15
0
 public Task Uninstall(InstallDirectoryItem appInstallation)
 {
     return ExecuteWorkerService(WorkerServiceUninstallVerb, appInstallation);
 }