private void RequestRepository(TransferRepository repository, Reporter reporter) { var repozipFile = RepoEnv.TempFiles.CreateFile(); UpdateLock.EnterUpgradeableReadLock(); try { Log.Info("Incomming Transfer Request for Repository {Name}", repository.RepoName); reporter.Send(RepositoryMessages.GetRepo); var data = _repos.AsQueryable().FirstOrDefault(r => r.RepoName == repository.RepoName); if (data == null) { reporter.Compled(OperationResult.Failure(RepoErrorCodes.DatabaseNoRepoFound)); return; } var commitInfo = _gitHubClient.Repository.Commit.GetSha1(data.RepoId, "HEAD").Result; var repozip = repozipFile.Stream; if (!(commitInfo != data.LastUpdate && UpdateRepository(data, reporter, repository, commitInfo, repozip))) { reporter.Send(RepositoryMessages.GetRepositoryFromDatabase); Log.Info("Downloading Repository {Name} From Server", repository.RepoName); repozip.SetLength(0); _bucket.DownloadToStream(ObjectId.Parse(data.FileName), repozip); } //_reporter = reporter; //repozip.Seek(0, SeekOrigin.Begin); //Timers.StartSingleTimer(_reporter, new TransferFailed(string.Empty, FailReason.Timeout, data.RepoName), TimeSpan.FromMinutes(10)); var request = DataTransferRequest.FromStream(repository.OperationId, repozip, repository.Manager ?? throw new ArgumentNullException("FileManager"), commitInfo); request.SendCompletionBack = true; _dataTransfer.Request(request); _currentTransfers[request.OperationId] = repozipFile; reporter.Compled(OperationResult.Success(new FileTransactionId(request.OperationId))); } finally { UpdateLock.ExitUpgradeableReadLock(); } }
private void RegisterRepository(RegisterRepository repository, Reporter reporter) { UpdateLock.EnterUpgradeableReadLock(); try { Log.Info("Incomming Registration Request for Repository {Name}", repository.RepoName); reporter.Send(RepositoryMessages.GetRepo); var data = _repos.AsQueryable().FirstOrDefault(e => e.RepoName == repository.RepoName); if (data != null) { Log.Info("Repository {Name} is Registrated", repository.RepoName); if (repository.IgnoreDuplicate) { reporter.Compled(OperationResult.Success()); return; } reporter.Compled(OperationResult.Failure(RepoErrorCodes.DuplicateRepository)); return; } if (!repository.RepoName.Contains('/')) { Log.Info("Repository {Name} Name is Invalid", repository.RepoName); reporter.Compled(OperationResult.Failure(RepoErrorCodes.InvalidRepoName)); return; } var nameSplit = repository.RepoName.Split('/'); var repoInfo = _gitHubClient.Repository.Get(nameSplit[0], nameSplit[1]).Result; if (repoInfo == null) { Log.Info("Repository {Name} Name not found on Github", repository.RepoName); reporter.Compled(OperationResult.Failure(RepoErrorCodes.GithubNoRepoFound)); return; } Log.Info("Savin new Repository {Name} on Database", repository.RepoName); data = new RepositoryEntry { RepoName = repository.RepoName, SourceUrl = repoInfo.CloneUrl, RepoId = repoInfo.Id }; UpdateLock.EnterWriteLock(); try { _repos.InsertOne(data); } finally { UpdateLock.ExitWriteLock(); } reporter.Compled(OperationResult.Success()); } finally { UpdateLock.ExitUpgradeableReadLock(); } }