예제 #1
0
        public bool Update(Install install)
        {
            var host = new DownloadablesHost()
            {
                AuthorName     = install.AuthorName,
                RepositoryName = install.RepositoryName
            };

            host.FetchDownloadables();

            Downloadable update = null;

            switch (install.Type)
            {
            case DownloadableType.Branch:
                var newsetCommit = host.Downloadables.FirstOrDefault(s => s.Type == DownloadableType.Branch && s.Name == install.Name);
                if (newsetCommit == null)
                {
                    _logger.LogProblem("No commits found for branch " + install.Name);
                    return(false);
                }
                if (newsetCommit.CommitSha != install.CommitSha)
                {
                    update = newsetCommit;
                }
                else
                {
                    _logger.Log("Nothing to update");
                }
                break;

            case DownloadableType.Tag:
                _logger.LogProblem("Updating Tags is not supported. Install release instead.");
                return(false);

            case DownloadableType.Release:
                var release = host.Downloadables.FirstOrDefault(s => s.Type == DownloadableType.Release && s.AssociatedDate > install.AssociatedDate);
                if (release == null)
                {
                    _logger.Log("Nothing to update");
                    return(false);
                }
                else
                {
                    update = release;
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            if (update == null)
            {
                return(false);
            }
            _logger.Log("Will replace " + install.AssociatedDate + " with " + update.AssociatedDate);

            var uninstall = new Uninstallation(_hostsRegistry, _installsRegistry, _githubApi, _logger);

            uninstall.Uninstall(install);

            var installation = new Installation(_hostsRegistry, _installsRegistry, _githubApi, _logger);

            installation.Install(update);

            return(true);
        }