Ejemplo n.º 1
0
        public void Run(ResolvedPackage root)
        {
            var runWaitersRepository = new RunWaitersRepository();

            RegisterRunWaiters(runWaitersRepository, root);
            runWaitersRepository.RunAllNonLocked().GetAwaiter().GetResult();
        }
Ejemplo n.º 2
0
        private void RegisterRunWaiters(RunWaitersRepository runWaitersRepository, ResolvedPackage package)
        {
            void RunAction(ResolvedPackage t)
            {
                Thread.Sleep(100);
                Console.WriteLine($"{t.PackageMeta.PackageInfo.Name} {t.PackageMeta.PackageInfo.Version} was started");
                runWaitersRepository.NotifyRunAsync(t).GetAwaiter().GetResult();
            }

            if (!package.ResolvedDependencies.Any())
            {
                runWaitersRepository.AddEmptyRunWaiter(package, RunAction);
            }

            foreach (var dependency in package.ResolvedDependencies)
            {
                runWaitersRepository.AddRunWaiter(
                    package,
                    dependency,
                    RunAction);
                RegisterRunWaiters(runWaitersRepository, dependency);
            }
        }
Ejemplo n.º 3
0
        private static ResolvedPackage ResolveInner(
            PackageMeta package,
            PackageRepository localRepository,
            PackageRepository repository,
            IDictionary <string, List <ResolvedPackage> > resolved)
        {
            var resolvedPackage = new ResolvedPackage(package);

            if (resolved.TryGetValue(package.PackageInfo.Name, out var alreadyResolved))
            {
                alreadyResolved.Add(resolvedPackage);
            }
            else
            {
                resolved[package.PackageInfo.Name] = new List <ResolvedPackage> {
                    resolvedPackage
                };
            }

            foreach (var packageInfoDependency in package.PackageInfo.Dependencies)
            {
                var(lower, upper) = packageInfoDependency.Version.ToRange();

                if (resolved.TryGetValue(packageInfoDependency.Name, out var packages))
                {
                    var suitableResolvedPackage = packages.FirstOrDefault(x =>
                                                                          lower <= x.PackageMeta.PackageInfo.Version &&
                                                                          x.PackageMeta.PackageInfo.Version <= upper);
                    if (suitableResolvedPackage != null)
                    {
                        resolvedPackage.ResolvedDependencies.Add(suitableResolvedPackage);
                        continue;
                    }
                }

                var suitableLocalPackages = localRepository.FindPackages(packageInfoDependency.Name, lower, upper);
                if (suitableLocalPackages.Any())
                {
                    var newResolvedPackage = ResolveInner(
                        suitableLocalPackages.First(),
                        localRepository,
                        repository,
                        resolved);
                    resolvedPackage.ResolvedDependencies.Add(newResolvedPackage);
                    continue;
                }

                var suitableRepositoryPackages = repository.FindPackages(packageInfoDependency.Name, lower, upper);
                if (suitableRepositoryPackages.Any())
                {
                    var newResolvedPackage = ResolveInner(
                        suitableRepositoryPackages.First(),
                        localRepository,
                        repository,
                        resolved);
                    resolvedPackage.ResolvedDependencies.Add(newResolvedPackage);
                    continue;
                }

                throw new InvalidOperationException($"Dependency {packageInfoDependency.Name} of package {package.PackageInfo.Name} can't be found");
            }

            return(resolvedPackage);
        }