Exemple #1
0
        public InstalledApplication CommitInstallation(string applicationName)
        {
            lock (_syncRoot)
            {
                InstalledApplication newApp = _pendingInstallations[applicationName];
                foreach (InstalledFile file in newApp.Files)
                {
                    Stream stream;
                    if (_openedFiles.TryGetValue(file.Id, out stream))
                    {
                        stream.Dispose();
                        _openedFiles.Remove(file.Id);
                    }
                }

                _pendingInstallations.Remove(applicationName);
                _installedApplications[applicationName] = newApp;

                Log.DebugFormat("Installation of '{0}' finished", newApp.Name);

                StartAllApplicationInstances(newApp.Name);

                return(newApp);
            }
        }
Exemple #2
0
        private InstalledFile CreateAndAddFileDescription(InstalledApplication app, Environment.SpecialFolder folder, string fileName, long fileSize)
        {
            var existing =
                app.Files.FirstOrDefault(
                    x => string.Equals(fileName, x.Filename, StringComparison.InvariantCultureIgnoreCase) && x.Folder == folder);
            long id;

            if (existing != null)
            {
                app.Files.Remove(existing);
                id = existing.Id;
            }
            else
            {
                id = Interlocked.Increment(ref _nextFileId);
            }

            var file = new InstalledFile
            {
                Id         = id,
                FileLength = fileSize,
                Filename   = fileName,
                Folder     = folder
            };

            app.Files.Add(file);
            return(file);
        }
Exemple #3
0
        public void DeleteFile(string applicationName, Environment.SpecialFolder folder, string fileName)
        {
            Log.DebugFormat("Deleting file '{0}'", fileName);

            InstalledApplication app = _installedApplications[applicationName];
            string path = Resolve(app, folder, fileName);

            File.Delete(path);
        }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
        /// <inheritdoc />
        public void UninstallApplication(InstalledApplication application)
        {
            if (application == null)
            {
                throw new ArgumentNullException(nameof(application));
            }

            _internalWatchdog.RemoveApplication(application.Descriptor.Name);
        }
Exemple #6
0
        public InstalledApplication Commit()
        {
            _commitTokenSource.Cancel();
            _task.Wait();

            ThrowIfNecessary();

            // No exception was thrown - let's try to end the installation
            // on the remote system - if that work's then we're done
            InstalledApplication ret = _watchdog.CommitInstallation(_descriptor.Name);

            _success = true;
            return(ret);
        }
Exemple #7
0
        public void WriteFile(string applicationName, Environment.SpecialFolder folder, string fileName, byte[] content)
        {
            Log.DebugFormat("Creating file '{0}': {1} bytes", fileName, content.Length);

            InstalledApplication app = _pendingInstallations[applicationName];
            string path = Resolve(app, folder, fileName);

            if (File.Exists(path))
            {
                File.Delete(path);
            }
            File.WriteAllBytes(path, content);

            CreateAndAddFileDescription(app, folder, fileName, content.Length);
        }
Exemple #8
0
        private Process StartNewProcress(string instanceName)
        {
            lock (_syncRoot)
            {
                ApplicationInstanceDescription instance = _registeredApplicationInstances[instanceName];
                InstalledFile        executable         = instance.Executable;
                InstalledApplication application        = _installedApplications[instance.ApplicationName];

                var process = new Process
                {
                    StartInfo = new ProcessStartInfo
                    {
                        FileName = Resolve(application, executable.Folder, executable.Filename),
                    },
                    EnableRaisingEvents = true
                };

                return(process);
            }
        }
Exemple #9
0
        public long CreateFile(string applicationName, Environment.SpecialFolder folder, string fileName, long fileSize)
        {
            Log.DebugFormat("Creating file '{0}': {1} bytes", fileName, fileSize);

            InstalledApplication app = _pendingInstallations[applicationName];
            string fname             = Resolve(app, folder, fileName);

            var file = CreateAndAddFileDescription(app, folder, fileName, fileSize);

            CreateFolder(fname);
            if (File.Exists(fname))
            {
                File.Delete(fname);
            }

            var fs = new FileStream(fname, FileMode.Create, FileAccess.Write, FileShare.None);

            fs.SetLength(fileSize);
            lock (_syncRoot)
            {
                _openedFiles.Add(file.Id, fs);
            }
            return(file.Id);
        }
Exemple #10
0
 public static string Resolve(InstalledApplication app, Environment.SpecialFolder folder, string relativeFileName)
 {
     return(Resolve(app.Name, folder, relativeFileName));
 }