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)); }
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)); }
int GetNewRemotePosition(RemoteRepositories repositories) { if (_priority.HasValue) { return(_priority.Value); } return(repositories.Count > 0 ? repositories.Values.Max(r => r.Priority) + 1 : 1); }
IEnumerable <ICommandOutput> NameExists() { _remotes = ConfigurationManager.Load <RemoteRepositories>(); if (!_remotes.ContainsKey(Name)) { yield return(new UnknownRemoteName(Name)); } }
IEnumerable <IPackageRepository> GetAmbient(string input, RemoteRepositories remotes) { if (input != null && remotes.ContainsKey(input) == false) { var ambient = FromInput(input); if (ambient != null) { yield return(ambient); } } }
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); }
void HandlePrioritySetting(RemoteRepositories repositories, RemoteRepository remote) { if (!Priority.HasValue || remote.Priority == Priority) { return; } MoveRepositoriesToHigherPriority(Priority.Value, repositories); remote.Priority = Priority.Value; }
IEnumerable <ICommandOutput> RemoteExists() { _remotes = ConfigurationManager.Load <RemoteRepositories>(); if (_remotes.ContainsKey(Name) == false) { yield return(new UnknownRemoteName(Name)); } else { _targetRemote = _remotes[Name]; } }
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; }
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; } }
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; }
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); }
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> >())); }
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; }
public void the_package_is_published() { package_is_in_repository(RemoteRepositories.First(x => x.Name == "mordor"), "sauron", new Version("1.0.0.123")); }
int GetNewRemotePriority(RemoteRepositories repositories) { return Priority.HasValue ? MoveRepositoriesToHigherPriority(Priority.Value, repositories) : (repositories.Count > 0 ? repositories.Values.Max(r => r.Priority) + 1 : 1); }
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); }
protected void given_remote_configuration(RemoteRepositories remoteRepositories) { Services.ServiceLocator.GetService <IConfigurationManager>() .Save(Configurations.Addresses.RemoteRepositories, remoteRepositories); }
IEnumerable<ICommandOutput> NameExists() { _remotes = ConfigurationManager.Load<RemoteRepositories>(); if (!_remotes.ContainsKey(Name)) yield return new UnknownRemoteName(Name); }
protected void given_configuration(RemoteRepositories remoteRepositories) { ConfigurationManager.Save(remoteRepositories); }
public static void SaveRemoteRepositories(this IConfigurationManager configurationManager, RemoteRepositories repositories) { configurationManager.Save(Addresses.RemoteRepositories, repositories); }
int GetNewRemotePriority(RemoteRepositories repositories) { return(Priority.HasValue ? MoveRepositoriesToHigherPriority(Priority.Value, repositories) : (repositories.Count > 0 ? repositories.Values.Max(r => r.Priority) + 1 : 1)); }
protected void given_remote_config(RemoteRepositories remoteRepositories) { ServiceLocator.GetService <IConfigurationManager>().Save(ConfiguredRemotes = remoteRepositories); ReloadRepositories(); }
void HandlePrioritySetting(RemoteRepositories repositories, RemoteRepository remote) { if (!Priority.HasValue || remote.Priority == Priority) return; MoveRepositoriesToHigherPriority(Priority.Value, repositories); remote.Priority = Priority.Value; }
IEnumerable<ICommandOutput> RemoteExists() { _remotes = ConfigurationManager.Load<RemoteRepositories>(); if (_remotes.ContainsKey(Name) == false) yield return new UnknownRemoteName(Name); else _targetRemote = _remotes[Name]; }
public void the_package_is_published() { package_is_in_repository(RemoteRepositories.First(x => x.Name == "mordor"), "sauron", "1.0.0+123".ToSemVer()); }
protected void ReloadRepositories() { ConfiguredRemotes = ConfigurationManager.Load <RemoteRepositories>(); }
int GetNewRemotePosition(RemoteRepositories repositories) { if (_priority.HasValue) return _priority.Value; return repositories.Count > 0 ? repositories.Values.Max(r => r.Priority) + 1 : 1; }