Ejemplo n.º 1
0
 protected override void ExecuteTask(CancellationToken token)
 {
     if (token.IsCancellationRequested)
     {
         return;
     }
     _mutex = UpdaterUtilities.CheckAndSetGlobalMutex(MutexName);
 }
Ejemplo n.º 2
0
        public void Run(CancellationToken token = default)
        {
            Schedule();
            var installsOrUninstalls = _installsOrUninstalls?.OfType <ComponentInstallTask>() ?? Enumerable.Empty <ComponentInstallTask>();

            using var mutex = UpdaterUtilities.CheckAndSetGlobalMutex();
            try
            {
                try
                {
                    _linkedCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token);
                    _downloads.Run(_linkedCancellationTokenSource.Token);
                    _installs.Run(_linkedCancellationTokenSource.Token);

                    try
                    {
                        _downloads.Wait();
                    }
                    catch (Exception)
                    {
                    }
                }
                finally
                {
                    if (_linkedCancellationTokenSource != null)
                    {
                        _linkedCancellationTokenSource.Dispose();
                        _linkedCancellationTokenSource = null;
                    }

                    Logger.Trace("Completed update operation");
                }

                if (RequiredProcessElevation)
                {
                    throw new ElevationRequireException(_elevationRequests);
                }

                if (IsCancelled)
                {
                    throw new OperationCanceledException(token);
                }
                token.ThrowIfCancellationRequested();

                var failedDownloads = _componentsToDownload.Where(p =>
                                                                  p.Error != null && !p.Error.IsExceptionType <OperationCanceledException>());

                var failedInstalls = installsOrUninstalls
                                     .Where(installTask => !installTask.Result.IsSuccess()).ToList();

                if (failedDownloads.Any() || failedInstalls.Any())
                {
                    throw new ComponentFailedException(
                              "Update failed because one or more downloads or installs had an error.");
                }

                var requiresRestart = LockedFilesWatcher.Instance.LockedFiles.Any();
                if (requiresRestart)
                {
                    Logger.Info("The operation finished. A restart is pedning.");
                }
            }
            finally
            {
                mutex.ReleaseMutex();
                _installMutexTask?.Dispose();
            }
        }