private void ProcessNewlyChanges(DateTime?lastSyncDate) { var lastSyncronizationDate = LastSyncDates.FirstOrDefault(); if (lastSyncDate == null || lastSyncronizationDate == null || !lastSyncronizationDate.GetValue().HasValue || lastSyncronizationDate.GetValue().Value.AddMinutes(_storageRepository.GetProfile <BugzillaProfile>().SynchronizationInterval) < DateTime.Now) { var dateValue = GetSyncDate(lastSyncDate); var synchronizationTime = DateTime.Now; int[] changedIds; if (TryGetChangedIds(dateValue, out changedIds)) { if (changedIds.Length > 0) { _logger.InfoFormat("{0} changed bugs found", changedIds.Length); } LastSyncDates.ReplaceWith(new BugTracking.ImportToTp.LastSyncDate(synchronizationTime)); ProcessChangedBugIds(changedIds); } else { FailedSyncDates.ReplaceWith(new FailedSyncDate(dateValue)); } } }
private DateTime?GetSyncDate(DateTime?lastSyncDate) { if (lastSyncDate == null) { return(null); } var lastFailedDate = FailedSyncDates.FirstOrDefault(); var lastSyncronizationDate = LastSyncDates.FirstOrDefault(); return(lastFailedDate != null?lastFailedDate.GetValue() : (lastSyncronizationDate != null ? lastSyncronizationDate.GetValue() : lastSyncDate)); }
private void ProcessChangedBugIds(int[] changedIds) { FailedSyncDates.Clear(); var lastIndex = 0; var bugIdsChunk = changedIds.Skip(lastIndex).Take(_bugChunkSize.Value).ToArray(); while (bugIdsChunk.Any()) { _bus.SendLocal(new ImportBugsChunk { ThirdPartyBugsIds = bugIdsChunk }); lastIndex += _bugChunkSize.Value; bugIdsChunk = changedIds.Skip(lastIndex).Take(_bugChunkSize.Value).ToArray(); } }