private bool AutoRefreshIsNotAvailable(int projectID) { var utcNow = DateTime.UtcNow; if (LastRefresh.HasValue) { const double canRefreshAfterHours = 1.0; TimeSpan lastRefreshDifference = utcNow.Subtract(LastRefresh.Value); if (lastRefreshDifference.TotalHours < canRefreshAfterHours) { _logger.Debug($"Refresh executed {lastRefreshDifference.TotalMinutes:0} minutes ago."); return(true); } } if (LastProjectRefresh.ContainsKey(projectID)) { const double canRefreshAfterHours = 24.0; TimeSpan lastRefreshDifference = utcNow.Subtract(LastProjectRefresh[projectID]); if (lastRefreshDifference.TotalHours < canRefreshAfterHours) { _logger.Debug($"Project {projectID} refresh executed {lastRefreshDifference.TotalMinutes:0} minutes ago."); return(true); } } return(false); }
public IReadOnlyCollection <ProteinChange> Refresh(IProgress <ProgressInfo> progress) { _logger.Info("Downloading new project data from Stanford..."); var proteins = _projectSummaryService.GetProteins(progress); IReadOnlyCollection <ProteinChange> changes = null; if (proteins != null) { var collection = new ProteinCollection(_collection); changes = collection.Update(proteins); Interlocked.Exchange(ref _collection, collection); foreach (var info in changes.Where(info => info.Action != ProteinChangeAction.None)) { _logger.Info(info.ToString()); } } var now = DateTime.UtcNow; foreach (var key in LastProjectRefresh.Keys.ToList()) { if (_collection.Contains(key)) { LastProjectRefresh.Remove(key); } else { LastProjectRefresh[key] = now; } } LastRefresh = now; Write(); return(changes); }