private async Task SyncWorkerMain()
        {
            var ct = _ctSource.Token;

            ct.ThrowIfCancellationRequested();

            // Get a fresh copy of the story collection
            var storyCollection = _storyContainer.GetAllStories();

            // Loop through stories in the story container
            //foreach (var story in storyCollection)
            while (_lastStoryIndex < storyCollection.Count)
            {
                ct.ThrowIfCancellationRequested();
                var story = storyCollection.ElementAt(_lastStoryIndex);

                var storyStatus = GetStoryStatus(story.ID);

                try
                {
                    // Skip this story if we're still waiting for the ITU pause to be over
                    if (storyStatus.State == StorySyncWorkerStoryState.WaitingItu)
                    {
                        var ituPauseDuration = GetSettings().ItuPauseDuration;
                        if ((storyStatus.LastItu + new TimeSpan(0, 0, ituPauseDuration)) > DateTime.Now) // if the last ITU + the pause duration is in the future
                        {
                            int secondsLeft = Convert.ToInt32((storyStatus.LastItu + new TimeSpan(0, 0, ituPauseDuration) - DateTime.Now).TotalSeconds);
                            _log.Debug($"ITU cooldown for '{story.ID}', {secondsLeft}s remaining");
                            continue;
                        }
                    }

                    // Skip this story if it has an error
                    if (storyStatus.State == StorySyncWorkerStoryState.Error)
                    {
                        _log.Debug($"Skipping story which has experienced an error: {story.ID}");
                        continue;
                    }

                    // Lets do it
                    await SyncStory(story);
                }
                finally
                {
                    // Always up the index
                    _lastStoryIndex++; // Up the index by 1
                }
            } // End of story loop block

            _lastStoryIndex = 0; // Reset the index if we're at the end of the story collection

            SetCurrentStatus(StorySyncWorkerState.Idle, "Idle", string.Empty);
        }
Пример #2
0
        private void RefreshStoryList()
        {
            if (dgvStories.InvokeRequired)
            {
                this.Invoke(new RefreshStoryListDelegate(RefreshStoryList));
                return;
            }

            _log.Debug("Story list refresh");

            // Clear
            dgvStories.Rows.Clear();

            // Fill
            foreach (var story in _storyContainer.GetAllStories())
            {
                _AddStoryRow(story);
            }
        }