示例#1
0
        public static DownloadablesHost FetchDownloadables(this DownloadablesHost host, bool force = false)
        {
            if (!force && host.Downloadables.Any())
            {
                return(host);
            }

            host.Downloadables.Clear();

            var githubTags = GithubApiManager
                             .GetTags(host.AuthorName, host.RepositoryName).ToArray();

            var tags = githubTags
                       .Select(_ => new Downloadable()
            {
                AuthorName     = host.AuthorName,
                RepositoryName = host.RepositoryName,
                CommitSha      = _.CommitSha,
                Name           = _.Name,
                Type           = DownloadableType.Tag,
                AssociatedDate = DateTime.Now
            }).ToArray();

            var branches = GithubApiManager
                           .GetBranches(host.AuthorName, host.RepositoryName)
                           .Select(_ => new Downloadable
            {
                AuthorName     = host.AuthorName,
                RepositoryName = host.RepositoryName,
                CommitSha      = _.CommitSha,
                Name           = _.Name,
                Type           = DownloadableType.Branch,
                AssociatedDate = DateTime.Now
            }).ToArray();

            var releases = GithubApiManager
                           .GetReleases(host.AuthorName, host.RepositoryName)
                           .OrderByDescending(_ => _.Date)
                           .Select(_ =>
            {
                var tag = tags.FirstOrDefault(t => t.Name == _.TagName);
                return(new Downloadable
                {
                    AuthorName = host.AuthorName,
                    RepositoryName = host.RepositoryName,
                    CommitSha = tag.CommitSha,
                    Name = tag.Name,
                    Type = DownloadableType.Release,
                    AssociatedDate = _.Date
                });
            }).ToArray();

            host.Downloadables.AddRange(releases);
            host.Downloadables.AddRange(tags);
            host.Downloadables.AddRange(branches);

            return(host);
        }
示例#2
0
文件: Core.cs 项目: Siniana/Universum
        public void ListDownloadables(string[] args)
        {
            var shc = GithubSchemeDecoder.DecodeShort(args[1]);

            var host = new DownloadablesHost()
            {
                AuthorName     = shc.Owner,
                RepositoryName = shc.Name
            };

            host.FetchDownloadables();

            foreach (var downloadable in host.Downloadables)
            {
                Terminal.Log(downloadable.ToString());
            }
        }
示例#3
0
文件: Core.cs 项目: Siniana/Universum
        public void Install(string[] args)
        {
            GithubRepositoryEntry dec = GithubSchemeDecoder.Decode(args[1]);

            Terminal.Log(string.Format("Will install {0} from {1} at {2}", dec.Name, dec.Owner, dec.Tag));

            var downloadableHost = new DownloadablesHost()
            {
                AuthorName     = dec.Owner,
                RepositoryName = dec.Name
            };

            Terminal.Log("Fetching downloadables...");

            downloadableHost.FetchDownloadables();

            Terminal.Log(string.Format("{0}/{1} contains {2} downloadable entries...", dec.Owner, dec.Name, downloadableHost.Downloadables.Count));


            Downloadable d = downloadableHost.Downloadables.FirstOrDefault();

            if (!string.IsNullOrEmpty(dec.Tag))
            {
                d = downloadableHost.Downloadables.FirstOrDefault(_ => _.Name == dec.Tag);
            }

            if (d == null)
            {
                throw new Exception("Downloadable Entry not found");
            }

            Terminal.Log(string.Format("Installing {0}/{1} @ {2} # {3}...", d.AuthorName, d.RepositoryName, d.Name, d.CommitSha));


            KoinoniaApplication.Instance.InstallNode(d);
        }
示例#4
0
 public bool IsInstallOf(DownloadablesHost host)
 {
     return(host.AuthorName == AuthorName && host.RepositoryName == RepositoryName);
 }
示例#5
0
        private void AnalyzePackage(InstallPlanEntry entry)
        {
            _logger.Log("Checking dependencies in " + entry);

            if (entry.ConfigData.Dependencies.Any())
            {
                foreach (var dependency in entry.ConfigData.Dependencies)
                {
                    _logger.Log("   Processing " + dependency.Key + " @ " + dependency.Value);

                    var depData = GithubSchemeDecoder.DecodeShort(dependency.Key);

                    // See if this package is already planned to be installed
                    var depEntry = PlanInstall.FirstOrDefault(_ => depData.Owner == _.AuthorName && depData.Name == _.RepositoryName);

                    if (depEntry != null)
                    {
                        continue;                   //Already been processed
                    }
                    // See if we got this package registered
                    var host = _hostsRegistry.DownloadablesHosts.FirstOrDefault(_ => depData.Owner == _.AuthorName && depData.Name == _.RepositoryName);

                    // If not, create it locally
                    if (host == null)
                    {
                        host = new DownloadablesHost()
                        {
                            AuthorName = depData.Owner, RepositoryName = depData.Name,
                        };
                    }

                    if (_installsRegistry.Installs.Where(i => i.IsInstallOf(host)).Any())
                    {
                        _logger.Log(dependency.Key + " is already installed.");
                        continue;
                    }

                    host.FetchDownloadables();

                    var downloadable = host.Downloadables.FirstOrDefault();

                    //TODO: need version here

                    if (!string.IsNullOrEmpty(dependency.Value))
                    {
                        downloadable = host.Downloadables.FirstOrDefault(_ => _.Name == dependency.Value);
                    }

                    if (downloadable == null)
                    {
                        throw new Exception("No Downloadables found for " + host);
                    }

                    var newEntry = Add(downloadable);

                    AnalyzePackage(newEntry);
                }
            }
            else
            {
                _logger.Log("   Seeing no dependencies for " + entry);
            }
        }
示例#6
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);
        }
示例#7
0
 public static DownloadablesHost FetchInstall(this DownloadablesHost host, bool force = false)
 {
     return(host);
 }