public IEnumerable <IMirror> GetBySourceRepository(ISvcRepository repository) { // TODO: read document async and directly convert to model for a better performance var result = new List <IMirror>(); var objectId = this.GenerateIdObject(repository.Id); var filter = Builders <BsonDocument> .Filter.Eq("SourceRepositoryId", objectId); var document = this.collection.Find(filter); if (document != null && document.Count() > 0) { using (var cursor = document.ToCursor()) { while (cursor.MoveNext()) { using (var enumerator = cursor.Current.GetEnumerator()) { while (enumerator.MoveNext()) { var doc = enumerator.Current; var dto = BsonSerializer.Deserialize <MirrorDto>(doc); var model = this.ConvertToModel(dto); result.Add(model); } } } } } return(result); }
public Svn(ISynchronization sync, ISvcRepository repository, string repoPath, string ownerName, string ownerPassword, ISyncLogger syncLogger) { this.sync = sync; this.repository = repository; this.repoPath = repoPath; this.username = ownerName; this.ownerPassword = ownerPassword; this.syncLogger = syncLogger; }
public Git(ISynchronization sync, ISvcRepository repository, string repoPath, string userName, string password, string refspec, ISyncLogger syncLogger) { this.credentials = new UsernamePasswordCredentials { Username = userName, Password = password }; this.sync = sync; this.repository = repository; this.repoPath = repoPath; this.userName = userName; this.refspec = refspec; this.syncLogger = syncLogger; if (Repository.IsValid(repoPath)) { this.repo = new Repository(repoPath); } }
public static SvcRepositoryDto ToDto(this ISvcRepository repo) { var dto = new SvcRepositoryDto { CheckoutUser = repo.CheckoutUser.ToDto(), PushUser = repo.PushUser.ToDto(), Id = repo.Id, Type = repo.Type, Name = repo.Name, Uri = repo.Uri, DefaultCommitMessagePrefix = repo.DefaultCommitMessagePrefix, MappedCheckoutCredentials = repo.MappedCheckoutCredentials?.ToDto() }; return(dto); }
private Svn CreateSvnSvc(ISvcRepository repo) { string repoPath = WorkspacePathProvider.SvnRepositoryPath(this.sync); var user = this.retriever.GetUser(repo.CheckoutUser.Id); string login = user.RepositoryCredentials.FirstOrDefault(c => c.RepositoryType == repo.Type)?.Login; if (login == null) { throw new InvalidOperationException($"User {repo.CheckoutUser.Name} does not have {repo.Type} credentials."); } string password = this.retriever.GetPassword(repo.CheckoutUser.Id, repo.Type); var svn = new Svn(this.sync, repo, repoPath, login, password, this.syncLogger); return(svn); }
private Git CreateGitSvc(ISvcRepository repo, string refspec) { string repoPath = WorkspacePathProvider.GitRepositoryPath(this.sync); var user = this.retriever.GetUser(repo.CheckoutUser.Id); string login = user.RepositoryCredentials.FirstOrDefault(c => c.RepositoryType == repo.Type)?.Login; if (login == null) { this.syncLogger.Log(this.sync, $"User {repo.CheckoutUser.Name} does not have {repo.Type} credentials. Trying with anonymous authentication."); } string password = login == null ? null : this.retriever.GetPassword(repo.CheckoutUser.Id, repo.Type); var git = new Git(this.sync, repo, repoPath, login, password, refspec, this.syncLogger); return(git); }
public ISvc Create(ISvcRepository repo) { switch (repo.Type) { case SvcRepositoryType.git: { if (string.IsNullOrWhiteSpace(this.sync.Mirror.TargetRepositoryRefSpec)) { throw new InvalidOperationException($"Mirror '{this.sync.Mirror.Name}' (Id '{this.sync.Mirror.Id}') does not have valid 'TargetRepositoryRefSpec'. This information is required to clone the repository. Please update this mirror."); } return(this.CreateGitSvc(repo, this.sync.Mirror.TargetRepositoryRefSpec)); } case SvcRepositoryType.svn: return(this.CreateSvnSvc(repo)); default: throw new NotSupportedException($"Repository type {repo.Type} is not supported."); } }
public IEnumerable <IMirror> GetBySourceRepository(ISvcRepository repository) { return(this.query.GetBySourceRepository(repository)); }