private void OnProcessException(Exception ex, T item) { var tempException = ProcessExceptionEvent; Interlocked.CompareExchange(ref ProcessExceptionEvent, null, null); if (tempException != null) { ProcessExceptionEvent?.Invoke(this, ex, item); } }
/// <summary> /// проверка опубликованных постов на удаление и редактирование /// </summary> private async Task ProcessWallWatch(TypesOfChecking checkType) { PostsCollection newPosts = null; #region 1. ЗАГРУЖАЕМ НОВЫЕ ПОСТЫ try { newPosts = await LoadWallPosts(); } catch (FlurlHttpException ex) { _logger.LogError($"No Internet connection. WallWatchService ended up with error event.\n{ex}"); ProcessExceptionEvent?.Invoke(null, ex); } catch (UserAuthorizationFailException ex) { _logger.LogError($"User authorization was failed. Try to get new api instance.\n{ex}"); ProcessExceptionEvent?.Invoke(null, ex); } catch (VkApiException ex) { _logger.LogError($"User authorization was failed. Try to get new api instance.\n{ex}"); ProcessExceptionEvent?.Invoke(null, ex); } catch (Exception ex) { _logger.LogError($"Unexpected error while downloading posts in {TypesOfChecking.Long.ToString()} check in wall with id {-_model.WallId}. " + $"Try to pray to God(means developer).\n{ex}"); ProcessExceptionEvent?.Invoke(null, ex); } #endregion #region 2. СВЕРКА НОВЫХ И СТАРЫХ ПОСТОВ List <PrimaryWallEvent> lastWallEvents = new List <PrimaryWallEvent>(); // Сравниваем полученные посты с тем, что уже было. Пишем результаты в NewWallPosts, DeletedWallPosts, EditedWallPosts lastWallEvents.AddRange(ComparePosts(newPosts[_publishedType], _publishedType, idBorderInPreList)); lastWallEvents.AddRange(ComparePosts(newPosts[_suggestedType], _suggestedType, 0)); lastWallEvents.AddRange(ComparePosts(newPosts[_postponedType], _postponedType, 0)); #endregion #region 3. ПУБЛИКАЦИЯ СОБЫТИЙ НА СТЕНЕ if (lastWallEvents.Any()) { try { PrimaryWallPostsEvents?.Invoke(lastWallEvents); } catch (Exception ex) { _logger.LogError($"Error of handling {nameof(PrimaryWallPostsEvents)}event{ex.Message}"); } } #endregion if (lastWallEvents.Any()) { _shortCheckPeriod = null; _longCheckPeriod = null; } else { _shortCheckPeriod = (_shortCheckPeriod ?? _model.ShortMonitoringPeriod) + _wallWatcherOptions.IncrementSleepTimeForShortCheck; _longCheckPeriod = (_longCheckPeriod ?? _model.MonitoringPeriod) + _wallWatcherOptions.IncrementSleepTimeForLongCheck; if (_shortCheckPeriod > _wallWatcherOptions.MaxSleepTimeForShortCheck) { _shortCheckPeriod = _wallWatcherOptions.MaxSleepTimeForShortCheck; } if (_longCheckPeriod > _wallWatcherOptions.MaxSleepTime) { _longCheckPeriod = _wallWatcherOptions.MaxSleepTime; } } }