示例#1
0
        IEnumerable <ICommandOutput> AddNew(RemoteRepositories repositories)
        {
            var repositoryInput = Href ?? Name;
            var repository      = Factories.Select(x => x.FromUserInput(repositoryInput, _credentials)).NotNull().FirstOrDefault();

            if (repository == null)
            {
                yield return(new UnknownEndpointType(repositoryInput));

                yield break;
            }
            List <RemoteRepositoryEndpoint> publishTokens;

            if (Publish != null)
            {
                var publishRepository = Factories.Select(x => x.FromUserInput(Publish, _credentials)).NotNull().FirstOrDefault();
                if (publishRepository == null)
                {
                    // TODO: add tests to check that
                    yield return(new UnknownEndpointType(Publish));

                    yield break;
                }
                publishTokens = new List <RemoteRepositoryEndpoint>
                {
                    new RemoteRepositoryEndpoint
                    {
                        Token    = publishRepository.Token,
                        Username = Username,
                        Password = Password
                    }
                };
            }
            else
            {
                var supportPublishing = repository.Feature <ISupportPublishing>();
                publishTokens = (supportPublishing != null)
                                    ? new List <RemoteRepositoryEndpoint>
                {
                    new RemoteRepositoryEndpoint {
                        Token = repository.Token, Username = Username, Password = Password
                    }
                }
                                    : new List <RemoteRepositoryEndpoint>();
            }

            int position = GetNewRemotePriority(repositories);

            repositories[Name] = new RemoteRepository
            {
                FetchRepository = new RemoteRepositoryEndpoint {
                    Token = repository.Token, Username = Username, Password = Password
                },
                PublishRepositories = publishTokens,
                Name     = Name,
                Priority = position
            };
            ConfigurationManager.Save(repositories);
            yield return(new RemoteAdded(Name));
        }
示例#2
0
        IEnumerable <ICommandOutput> Append(RemoteRepositories repositories)
        {
            var existingReg = repositories[Name];
            var publishRepo = Factories.Select(x => x.FromUserInput(Publish, _credentials)).NotNull().FirstOrDefault();

            if (publishRepo == null)
            {
                yield return(new UnknownEndpointType(Publish));

                yield break;
            }
            if (publishRepo.Feature <ISupportPublishing>() == null)
            {
                yield return(new RemoteEndpointReadOnly(Publish));

                yield break;
            }
            existingReg.PublishRepositories.Add(new RemoteRepositoryEndpoint
            {
                Token    = publishRepo.Token,
                Username = Username,
                Password = Password
            });

            ConfigurationManager.Save(repositories);
            yield return(new RemotePublishEndpointAdded(Name, Publish));
        }
示例#3
0
 int GetNewRemotePosition(RemoteRepositories repositories)
 {
     if (_priority.HasValue)
     {
         return(_priority.Value);
     }
     return(repositories.Count > 0 ? repositories.Values.Max(r => r.Priority) + 1 : 1);
 }
示例#4
0
 IEnumerable <ICommandOutput> NameExists()
 {
     _remotes = ConfigurationManager.Load <RemoteRepositories>();
     if (!_remotes.ContainsKey(Name))
     {
         yield return(new UnknownRemoteName(Name));
     }
 }
示例#5
0
 IEnumerable <IPackageRepository> GetAmbient(string input, RemoteRepositories remotes)
 {
     if (input != null && remotes.ContainsKey(input) == false)
     {
         var ambient = FromInput(input);
         if (ambient != null)
         {
             yield return(ambient);
         }
     }
 }
示例#6
0
        static IEnumerable <RemoteRepository> GetRepositoriesOrdered(string input, RemoteRepositories remoteRepositories)
        {
            var remotes = remoteRepositories;
            IEnumerable <RemoteRepository> entries = remotes.Select(x => x.Value).OrderBy(x => x.Priority);

            if (input != null && remotes.ContainsKey(input))
            {
                entries = new[] { remotes[input] }.Concat(entries.Where(_ => _ != remotes[input]));
            }
            return(entries);
        }
示例#7
0
        void HandlePrioritySetting(RemoteRepositories repositories, RemoteRepository remote)
        {
            if (!Priority.HasValue || remote.Priority == Priority)
            {
                return;
            }

            MoveRepositoriesToHigherPriority(Priority.Value, repositories);

            remote.Priority = Priority.Value;
        }
示例#8
0
 IEnumerable <ICommandOutput> RemoteExists()
 {
     _remotes = ConfigurationManager.Load <RemoteRepositories>();
     if (_remotes.ContainsKey(Name) == false)
     {
         yield return(new UnknownRemoteName(Name));
     }
     else
     {
         _targetRemote = _remotes[Name];
     }
 }
示例#9
0
        IEnumerable<ICommandOutput> AddNew(RemoteRepositories repositories)
        {
            var repositoryInput = Href ?? Name;
            var repository = Factories.Select(x => x.FromUserInput(repositoryInput, _credentials)).NotNull().FirstOrDefault();
            if (repository == null)
            {
                yield return new UnknownEndpointType(repositoryInput);
                yield break;
            }
            List<RemoteRepositoryEndpoint> publishTokens;
            if (Publish != null)
            {
                var publishRepository = Factories.Select(x => x.FromUserInput(Publish,_credentials)).NotNull().FirstOrDefault();
                if (publishRepository == null)
                {
                    // TODO: add tests to check that
                    yield return new UnknownEndpointType(Publish);
                    yield break;
                }
                publishTokens = new List<RemoteRepositoryEndpoint>
                {
                    new RemoteRepositoryEndpoint
                    {
                        Token = publishRepository.Token,
                        Username = Username,
                        Password = Password
                    }
                };
            }
            else
            {
                var supportPublishing = repository.Feature<ISupportPublishing>();
                publishTokens = (supportPublishing != null)
                                    ? new List<RemoteRepositoryEndpoint>
                                    {
                                        new RemoteRepositoryEndpoint { Token = repository.Token, Username = Username, Password = Password }
                                    }
                                    : new List<RemoteRepositoryEndpoint>();
            }

            int position = GetNewRemotePriority(repositories);

            repositories[Name] = new RemoteRepository
            {
                FetchRepository = new RemoteRepositoryEndpoint { Token = repository.Token, Username = Username, Password = Password },
                PublishRepositories = publishTokens,
                Name = Name,
                Priority = position
            };
            ConfigurationManager.Save(repositories);
            yield return new RemoteAdded(Name);
        }
        protected int MoveRepositoriesToHigherPriority(int val, RemoteRepositories repositories)
        {
            int reorderFrom = val;
            int reorderTo = reorderFrom;
// ReSharper disable AccessToModifiedClosure
            while (repositories.Any(_ => _.Value.Priority == reorderTo))
// ReSharper restore AccessToModifiedClosure
                reorderTo++;

            foreach (var repo in repositories.Where(_ => _.Value.Priority >= reorderFrom && _.Value.Priority < reorderTo))
                repo.Value.Priority = repo.Value.Priority + 1;
            return val;
        }
示例#11
0
 int GetNewRemotePosition(RemoteRepositories repositories)
 {
     if (_position.HasValue)
     {
         return _position.Value;
     }
     else if (repositories.Count > 0)
     {
         return repositories.Values.Max(r => r.Priority) + 1;
     }
     else
     {
         return 1;
     }
 }
示例#12
0
        void HandlePrioritySetting(RemoteRepositories repositories, RemoteRepository remote)
        {
            if (!_position.HasValue || remote.Priority == _position)
            {
                return;
            }

            var prioHasIncreased = remote.Priority > _position;

            var otherRepositories = repositories.Values.Except(remote.ToEnumerable());

            var vars = prioHasIncreased
                                        ? new
            {
                RelevantRepositories = otherRepositories.OrderBy(r => r.Priority).ToList(),
                SkipCondition        = new Func <RemoteRepository, bool>(r => r.Priority < _position),
                PriorityMutator      = new Func <int, int>(i => i + 1)
            }
                                        : new
            {
                RelevantRepositories = otherRepositories.OrderByDescending(r => r.Priority).ToList(),
                SkipCondition        = new Func <RemoteRepository, bool>(r => r.Priority > _position),
                PriorityMutator      = new Func <int, int>(i => i - 1)
            };

            if (!vars.RelevantRepositories.Any(r => r.Priority == _position))
            {
                return;
            }

            var lastPriority = (int)_position;

            foreach (var repository in vars.RelevantRepositories.SkipWhile(vars.SkipCondition))
            {
                if (repository.Priority == lastPriority)
                {
                    repository.Priority = (lastPriority = vars.PriorityMutator(lastPriority));
                }
                else
                {
                    break;
                }
            }

            remote.Priority = _position.Value;
        }
示例#13
0
        protected int MoveRepositoriesToHigherPriority(int val, RemoteRepositories repositories)
        {
            int reorderFrom = val;
            int reorderTo   = reorderFrom;

// ReSharper disable AccessToModifiedClosure
            while (repositories.Any(_ => _.Value.Priority == reorderTo))
            {
// ReSharper restore AccessToModifiedClosure
                reorderTo++;
            }

            foreach (var repo in repositories.Where(_ => _.Value.Priority >= reorderFrom && _.Value.Priority < reorderTo))
            {
                repo.Value.Priority = repo.Value.Priority + 1;
            }
            return(val);
        }
示例#14
0
        protected openwrap_context()
        {
            // TODO: Review if we should use the Service registry?
            RemoteRepositories = new List <IPackageRepository>();
            ConfiguredRemotes  = new RemoteRepositories();
            ServiceLocator.Clear();
            var currentDirectory = System.Environment.CurrentDirectory;

            FileSystem  = given_file_system(currentDirectory);
            Environment = new InMemoryEnvironment(
                FileSystem.GetDirectory(currentDirectory),
                FileSystem.GetDirectory(DefaultInstallationPaths.ConfigurationDirectory));
            //Environment.DescriptorFile.MustExist();
            ServiceLocator.RegisterService <IFileSystem>(FileSystem);
            ServiceLocator.RegisterService <IEnvironment>(Environment);
            ServiceLocator.RegisterService <IPackageResolver>(new StrategyResolver());
            ServiceLocator.TryRegisterService <IPackageDeployer>(() => new DefaultPackageDeployer());
            ServiceLocator.TryRegisterService <IPackageExporter>(() => new DefaultPackageExporter(new IExportProvider[] {
                new DefaultAssemblyExporter(),
                new CecilCommandExporter()
            }));
            ServiceLocator.RegisterService <ICommandRepository>(Commands);

            ServiceLocator.TryRegisterService <IPackageManager>(PackageManagerFactory());

            ServiceLocator.RegisterService <IConfigurationManager>(new DefaultConfigurationManager(Environment.ConfigurationDirectory));


            Factory           = new MemoryRepositoryFactory();
            Factory.FromToken = token => RemoteRepositories.FirstOrDefault(repo => repo.Token == token);
            RemoteFactories   = new List <IRemoteRepositoryFactory> {
                Factory
            };

            ServiceLocator.TryRegisterService <IEnumerable <IRemoteRepositoryFactory> >(() => RemoteFactories);

            ConfigurationManager = ServiceLocator.GetService <IConfigurationManager>();
            ConfigurationManager.Save(ConfiguredRemotes);

            ServiceLocator.RegisterService <IRemoteManager>(new DefaultRemoteManager(ConfigurationManager, ServiceLocator.GetService <IEnumerable <IRemoteRepositoryFactory> >()));
        }
示例#15
0
        void HandlePrioritySetting(RemoteRepositories repositories, RemoteRepository remote)
        {
            if (!_position.HasValue || remote.Priority == _position)
                return;

            var prioHasIncreased = remote.Priority > _position;

            var otherRepositories = repositories.Values.Except(remote.ToEnumerable());

            var vars = prioHasIncreased
                                        ? new
                                        {
                                            RelevantRepositories = otherRepositories.OrderBy(r => r.Priority).ToList(),
                                            SkipCondition = new Func<RemoteRepository, bool>(r => r.Priority < _position),
                                            PriorityMutator = new Func<int, int>(i => i + 1)
                                        }
                                        : new
                                        {
                                            RelevantRepositories = otherRepositories.OrderByDescending(r => r.Priority).ToList(),
                                            SkipCondition = new Func<RemoteRepository, bool>(r => r.Priority > _position),
                                            PriorityMutator = new Func<int, int>(i => i - 1)
                                        };

            if (!vars.RelevantRepositories.Any(r => r.Priority == _position))
                return;

            var lastPriority = (int)_position;

            foreach (var repository in vars.RelevantRepositories.SkipWhile(vars.SkipCondition))
            {
                if (repository.Priority == lastPriority)
                    repository.Priority = (lastPriority = vars.PriorityMutator(lastPriority));
                else
                    break;
            }

            remote.Priority = _position.Value;
        }
示例#16
0
 public void the_package_is_published()
 {
     package_is_in_repository(RemoteRepositories.First(x => x.Name == "mordor"), "sauron", new Version("1.0.0.123"));
 }
示例#17
0
 int GetNewRemotePriority(RemoteRepositories repositories)
 {
     return Priority.HasValue
                ? MoveRepositoriesToHigherPriority(Priority.Value, repositories)
                : (repositories.Count > 0 ? repositories.Values.Max(r => r.Priority) + 1 : 1);
 }
示例#18
0
        IEnumerable<ICommandOutput> Append(RemoteRepositories repositories)
        {
            var existingReg = repositories[Name];
            var publishRepo = Factories.Select(x => x.FromUserInput(Publish, _credentials)).NotNull().FirstOrDefault();
            if (publishRepo == null)
            {
                yield return new UnknownEndpointType(Publish);
                yield break;
            }
            if (publishRepo.Feature<ISupportPublishing>() == null)
            {
                yield return new RemoteEndpointReadOnly(Publish);
                yield break;
            }
            existingReg.PublishRepositories.Add(new RemoteRepositoryEndpoint
            {
                Token = publishRepo.Token,
                Username = Username,
                Password = Password
            });

            ConfigurationManager.Save(repositories);
            yield return new RemotePublishEndpointAdded(Name, Publish);
        }
示例#19
0
 protected void given_remote_configuration(RemoteRepositories remoteRepositories)
 {
     Services.ServiceLocator.GetService <IConfigurationManager>()
     .Save(Configurations.Addresses.RemoteRepositories, remoteRepositories);
 }
示例#20
0
 IEnumerable<ICommandOutput> NameExists()
 {
     _remotes = ConfigurationManager.Load<RemoteRepositories>();
     if (!_remotes.ContainsKey(Name))
         yield return new UnknownRemoteName(Name);
 }
示例#21
0
 protected void given_configuration(RemoteRepositories remoteRepositories)
 {
     ConfigurationManager.Save(remoteRepositories);
 }
示例#22
0
 public static void SaveRemoteRepositories(this IConfigurationManager configurationManager, RemoteRepositories repositories)
 {
     configurationManager.Save(Addresses.RemoteRepositories, repositories);
 }
示例#23
0
 int GetNewRemotePriority(RemoteRepositories repositories)
 {
     return(Priority.HasValue
                ? MoveRepositoriesToHigherPriority(Priority.Value, repositories)
                : (repositories.Count > 0 ? repositories.Values.Max(r => r.Priority) + 1 : 1));
 }
示例#24
0
 protected void given_remote_config(RemoteRepositories remoteRepositories)
 {
     ServiceLocator.GetService <IConfigurationManager>().Save(ConfiguredRemotes = remoteRepositories);
     ReloadRepositories();
 }
示例#25
0
        void HandlePrioritySetting(RemoteRepositories repositories, RemoteRepository remote)
        {
            if (!Priority.HasValue || remote.Priority == Priority)
                return;

            MoveRepositoriesToHigherPriority(Priority.Value, repositories);

            remote.Priority = Priority.Value;
        }
示例#26
0
 IEnumerable<ICommandOutput> RemoteExists()
 {
     _remotes = ConfigurationManager.Load<RemoteRepositories>();
     if (_remotes.ContainsKey(Name) == false)
         yield return new UnknownRemoteName(Name);
     else
         _targetRemote = _remotes[Name];
 }
示例#27
0
 public void the_package_is_published()
 {
     package_is_in_repository(RemoteRepositories.First(x => x.Name == "mordor"), "sauron", "1.0.0+123".ToSemVer());
 }
示例#28
0
 protected void given_configuration(RemoteRepositories remoteRepositories)
 {
     ConfigurationManager.Save(remoteRepositories);
 }
示例#29
0
 protected void ReloadRepositories()
 {
     ConfiguredRemotes = ConfigurationManager.Load <RemoteRepositories>();
 }
示例#30
0
 int GetNewRemotePosition(RemoteRepositories repositories)
 {
     if (_priority.HasValue)
         return _priority.Value;
     return repositories.Count > 0 ? repositories.Values.Max(r => r.Priority) + 1 : 1;
 }