コード例 #1
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);
        }
コード例 #2
0
 public IEnumerable <ExecutorStepConfiguration> Prepare(UpdatePreparationWorkspaceInformation workspaceInformation)
 {
     yield return(new ExchangeFilesStepConfiguration()
     {
         DestinationDirectory = _applicationReplaceDirectory,
         SourceDirectory = workspaceInformation.ArtifactsDirectory.FullName
     });
 }
コード例 #3
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();
            }
        }
コード例 #4
0
        public override void Download(UpdatePreparationWorkspaceInformation workspace)
        {
            var file = new FileInfo(_fileVersionDownloadSource.FilePath);

            if (_fileVersionDownloadSource.IsZipFile)
            {
                using (var stream = file.OpenRead())
                {
                    var archive = new ZipArchive(stream);
                    archive.ExtractToDirectory(workspace.ArtifactsDirectory.FullName);
                }
            }
            else
            {
                file.CopyTo(Path.Combine(workspace.ArtifactsDirectory.FullName, file.Name));
            }
        }
コード例 #5
0
        public override void Download(UpdatePreparationWorkspaceInformation workspace)
        {
            var request  = WebRequest.CreateHttp(_downloadSource.Url);
            var response = request.GetResponse();
            var content  = response.GetResponseStream();

            if (_downloadSource.IsZipFile)
            {
                var archive = new ZipArchive(content);
                archive.ExtractToDirectory(workspace.ArtifactsDirectory.FullName);
            }
            else
            {
                var destFile = Path.Combine(workspace.ArtifactsDirectory.FullName, _downloadSource.FileName);
                using (var stream = File.OpenWrite(destFile))
                {
                    content.CopyTo(stream);
                }
            }
        }
コード例 #6
0
 public override void Download(UpdatePreparationWorkspaceInformation workspace)
 {
 }
コード例 #7
0
 public abstract void Download(UpdatePreparationWorkspaceInformation workspace);