public TfProjectCollection(string uri, ITfsConnectionFactory connectionFactory, ILogger logger) { _uri = uri; _connectionFactory = connectionFactory; _logger = logger; _projects = new ConcurrentDictionary <Guid, ITfProject>(); ProjectRetrievalStatus = RetrievalStatus.Unstarted; }
public async Task RetrieveProjects() { if (ProjectRetrievalStatus == RetrievalStatus.Suceeded) { return; } ProjectRetrievalStatus = RetrievalStatus.Ongoing; _logger.Info($"{nameof(TfProjectCollection)}: triggering one-time retrieval of projects from {_uri}..."); var exceptions = new List <Exception>(); try { var connection = _connectionFactory.Create(_uri); var currentProjectReferences = await connection.GetProjects(); foreach (var projectReference in currentProjectReferences) { _projects[projectReference.Id] = projectReference; } ProjectRetrievalStatus = RetrievalStatus.Suceeded; _logger.Info($"{nameof(TfProjectCollection)}: projects successfully retrieved; project count is {Projects.Count()}."); } catch (AggregateException ae) { exceptions.AddRange(ae.Flatten().InnerExceptions); ProjectRetrievalStatus = RetrievalStatus.FailedReasonUnknown; } catch (Exception e) { exceptions.Add(e); ProjectRetrievalStatus = RetrievalStatus.FailedReasonUnknown; } if (exceptions.Any(ExceptionClassifiers.IsConnectivityException)) { ProjectRetrievalStatus = RetrievalStatus.FailedDueToConnection; _logger.Info($"{nameof(TfProjectCollection)}: retrieving projects failed because the server cannot be contacted."); } else if (exceptions.Any(ExceptionClassifiers.IsAuthorisationException)) { ProjectRetrievalStatus = RetrievalStatus.FailedDueToAuth; _logger.Info($"{nameof(TfProjectCollection)}: retrieving projects failed because of an authentication or authorisation error."); } else if (exceptions.Any()) { _logger.Error($"{nameof(TfProjectCollection)}: retrieving projects failed due to one or more unrecognised exceptions. The first:", exceptions[0]); } OnProjectRetrievalCompleted(this, EventArgs.Empty); }