Exemple #1
0
        static void RestartingApplication(ExecutorConfiguration configuration)
        {
            _logger.LogInformation("Restarting parent application: Path: '{0}' Arguments: '{1}'", configuration.Application.Path, configuration.Application.RestartArguments);
            var startInfo = new ProcessStartInfo(configuration.Application.Path, configuration.Application.RestartArguments);

            Process.Start(startInfo);
        }
Exemple #2
0
        static bool WaitClosingOfParentProcess(ExecutorConfiguration configuration)
        {
            var parentProcess = Process.GetProcessById(configuration.Application.CallingProcessId);

            if (parentProcess == null)
            {
                _logger.LogDebug("Parent process with id '{0}' not found. Continue", configuration.Application.CallingProcessId);
                return(true);
            }

            _logger.LogDebug("Parent process found.");
            var waitCounter = 0;

            while (!parentProcess.HasExited)
            {
                if (waitCounter > 30)
                {
                    _logger.LogError("Waiting on closing of parent process reached timeout");
                    return(false);
                }

                _logger.LogTrace("Parent process with id '{1}' still running. Waiting. Count {0}", waitCounter, parentProcess.Id);
                Thread.Sleep(1000);
                waitCounter++;
            }

            _logger.LogDebug("Parent process closed");
            return(true);
        }
Exemple #3
0
        private void CopyAndStartExecutor(UpdatePreparationWorkspaceInformation workspace,
                                          ExecutorConfiguration config)
        {
            var executorDirectory = Path.Combine(workspace.WorkingDirectory.FullName, "Executor");
            var executorFile      = new FileInfo(Path.Combine(executorDirectory, "AutoUpdate.Executor.exe"));

            using (var executorStream = GetExecutorStream())
            {
                var archive = new ZipArchive(executorStream);
                archive.ExtractToDirectory(executorDirectory);
            }

            executorFile.Refresh();
            if (!executorFile.Exists)
            {
                throw new InvalidOperationException("Preparation of executor helper was not successfull");
            }

            var serializer       = new ConfigurationSerializer();
            var serializedConfig = serializer.Serialize(config);

            var configFile = new FileInfo(Path.Combine(executorDirectory, ExecutorConfiguration.DEFAULT_FILENAME));

            using (var configFileStream = configFile.OpenWrite())
                using (var configFileWriter = new StreamWriter(configFileStream))
                {
                    configFileWriter.Write(serializedConfig);
                }

            var startInfo = new ProcessStartInfo(executorFile.FullName, configFile.FullName);

            startInfo.WorkingDirectory = executorDirectory;
            startInfo.UseShellExecute  = false;
            var result = Process.Start(startInfo);
        }
 public string Serialize(ExecutorConfiguration configuration)
 {
     using (var writer = new StringWriter())
     {
         _serializer.Serialize(writer, configuration);
         return(writer.GetStringBuilder().ToString());
     }
 }
Exemple #5
0
        internal void UpdateVersion(UpdateVersionHandle handle)
        {
            if (!handle.HasNewVersion)
            {
                return;
            }

            _logger.LogTrace("Starting update to version [{0}]. Waiting other operation finished", handle.NewVersion);
            _semaphore.Wait();
            _logger.LogTrace("Lock accuired. Starting update");

            try
            {
                _logger.LogInformation("Update to version [{0}] started", handle.NewVersion);

                var updateFolder = new DirectoryInfo(Path.Combine(Path.GetTempPath(), "AutoUpdate.Net", Guid.NewGuid().ToString()));
                _logger.LogDebug("Creating working folder '{0}'", updateFolder.FullName);
                updateFolder.Create();

                var artifactsFolder = new DirectoryInfo(Path.Combine(updateFolder.FullName, "Artifacts"));
                _logger.LogDebug("Creating artifacts folder '{0}'", artifactsFolder.FullName);
                artifactsFolder.Create();

                var workspace             = new UpdatePreparationWorkspaceInformation(handle.NewVersion, updateFolder, artifactsFolder);
                var executorConfiguration = new ExecutorConfiguration();

                var downloader = handle.NewVersion.Source.Accept(new DownloaderFactory());
                downloader.Download(workspace);

                executorConfiguration.Steps = _prepareSteps.SelectMany(x => x.Prepare(workspace))
                                              .ToArray();

                var curProcess = Process.GetCurrentProcess();
                executorConfiguration.Application.Path             = curProcess.MainModule.FileName;
                executorConfiguration.Application.RestartArguments = Environment.CommandLine;
                executorConfiguration.Application.CallingProcessId = Process.GetCurrentProcess().Id;

                _logger.LogDebug("Copy update executor application to working folder");
                CopyAndStartExecutor(workspace, executorConfiguration);

                _logger.LogDebug("Executor started. Closing current application");
                _applicationCloser.CloseApplication();
            }
            finally
            {
                _logger.LogTrace("Releasing lock. Updating");
                _semaphore.Release();
            }
        }
Exemple #6
0
 public void Create(out IExecutorConfiguration @object) => @object = new ExecutorConfiguration();