public ApplicationInstaller(IInternalWatchdog watchdog, ApplicationDescriptor descriptor, Installation installation = Installation.FailOnUpgrade) { if (watchdog == null) { throw new ArgumentNullException(nameof(watchdog)); } if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } if (descriptor.Name == null) { throw new ArgumentNullException("descriptor.Name"); } _blockBuffer = new byte[BlockSize]; _descriptor = descriptor; _installation = installation; _watchdog = watchdog; _pendingFiles = new ConcurrentBag <File>(); _cancellationTokenSource = new CancellationTokenSource(); _commitTokenSource = new CancellationTokenSource(); _task = Task.Factory.StartNew(InstallApplication); _watchdog.StartInstallation(descriptor, installation); }
public void StartInstallation(ApplicationDescriptor description, Installation installation) { lock (_syncRoot) { Log.DebugFormat("Starting installation of '{0}': {1}", description.Name, installation); // If there's another pending installation with the same folder then we'll bail early... InstalledApplication pending = _pendingInstallations.Values.FirstOrDefault(x => x.Descriptor.Name == description.Name); if (pending != null) { throw new InstallationFailedException( string.Format( "There already is a pending installation for the same application - this installation must be completed or aborted in order for a new installation to be allowed")); } // Let's find out if we're replacing an existing installation... InstalledApplication existingApp; _installedApplications.TryGetValue(description.Name, out existingApp); InstalledApplication newApp; if (existingApp != null) { switch (installation) { case Installation.FailOnUpgrade: throw new InstallationFailedException( string.Format("There already is an installation of the same application present")); case Installation.CleanInstall: StopAllApplicationInstances(existingApp.Name); RemoveApplication(existingApp.Name); newApp = new InstalledApplication(description); break; case Installation.ColdUpdate: StopAllApplicationInstances(existingApp.Name); newApp = new InstalledApplication(description); newApp.Files.AddRange(existingApp.Files); break; case Installation.HotUpdate: newApp = new InstalledApplication(description); newApp.Files.AddRange(existingApp.Files); break; default: throw new InvalidEnumArgumentException(nameof(installation), (int)installation, typeof(Installation)); } } else { newApp = new InstalledApplication(description); } _pendingInstallations.Add(newApp.Name, newApp); } }
/// <summary> /// Creates a new (empty) installed application from the given description. /// </summary> /// <param name="description"></param> /// <exception cref="ArgumentNullException">When <paramref name="description"/> is null</exception> /// <exception cref="ArgumentNullException">When description.Name is null</exception> public InstalledApplication(ApplicationDescriptor description) { if (description == null) { throw new ArgumentNullException(nameof(description)); } // ReSharper disable NotResolvedInText if (description.Name == null) { throw new ArgumentNullException("description.Name"); } // ReSharper restore NotResolvedInText Descriptor = description; Files = new List <InstalledFile>(); }
/// <inheritdoc /> public IApplicationInstaller StartInstallation(ApplicationDescriptor description, Installation installation = Installation.FailOnUpgrade) { return(new ApplicationInstaller(_internalWatchdog, description, installation)); }