public async Task GetPosts()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                this.PostsCollection.Clear();
                /*se abrir a partir da UsersPage carrega somente os posts do usuário selecionado, se não, carrega todos*/
                var posts = (_User == null ? await postRep.GetAsync() : await postRep.GetAsync <Post>(x => x.POST_USER_ID == _User.USER_ID));
                foreach (var post in  posts)
                {
                    PostsCollection.Add(post);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
                await Task.FromResult(true);
            }
        }
예제 #2
0
        public override sealed void OnNavigatedTo(
            object parameter,
            NavigationMode mode,
            IDictionary <string, object> state)
        {
            var country = Country.PR;

            CategoriesCollection = new CategoriesCollection(new GetCategoriesRequest(country),
                                                            FindierService);
            HotPostsCollection = new PostsCollection(new GetPostsRequest(country).Sort(PostSort.Hot), FindierService);
            NewPostsCollection = new PostsCollection(new GetPostsRequest(country).Sort(PostSort.New), FindierService);
            TopPostsCollection = new PostsCollection(new GetPostsRequest(country).Sort(PostSort.Top), FindierService);
        }
예제 #3
0
        public override sealed void OnNavigatedTo(
            object parameter,
            NavigationMode mode,
            IDictionary <string, object> state)
        {
            Category = (Category)parameter;

            HotPostsCollection = new PostsCollection(new GetPostsRequest(Category.Id).Sort(PostSort.Hot),
                                                     _findierService);
            NewPostsCollection = new PostsCollection(new GetPostsRequest(Category.Id).Sort(PostSort.New),
                                                     _findierService);
            TopPostsCollection = new PostsCollection(new GetPostsRequest(Category.Id).Sort(PostSort.Top),
                                                     _findierService);
        }
예제 #4
0
        private async Task <PostsCollection> LoadWallPosts()
        {
            long            latestOldPostId = -1;
            PostsCollection res             = new PostsCollection();
            int             loadCount       = FirstLoadCount; // TODO: how to calculate

            var getParams = new WallGetParams()
            {
                OwnerId = _model.WallId
            };
            WallGetObject wallGetRes = null;


            _api.Wall.Get(getParams);


            DownloadingPostsOptions downloadingPostsOptions = new DownloadingPostsOptions(_model.WallId, loadInFirstCount, WallFilter.All, _wallWatcherOptions.TimeForReconnecting);

            // если _prePublishedList пустой, то грузим не до самого нового имющегося поста (так как его у нас нет), а за MonitoringLimits(период и/или количество)
            if (!_postsProvider.AnyExistingPosts(_model.WallId, _publishedType, 0))
            {
                List <Post> publishedPosts = _api.Wall.GetPosts(_logger, downloadingPostsOptions, _model.MonitoringLimits);
                res.AddPosts(publishedPosts);
            }
            else
            {
                res.AddPosts(GetNewAndOldPublishedPosts(downloadingPostsOptions, out latestOldPostId));
            }

            // Download suggests and postpone
            downloadingPostsOptions.CountInFirstLoad = MaxLoadCount;
            downloadingPostsOptions.WallFilter       = WallFilter.Suggests;
            res.AddPosts(_api.Wall.GetPosts(_logger, downloadingPostsOptions));
            downloadingPostsOptions.WallFilter = WallFilter.Postponed;
            res.AddPosts(_api.Wall.GetPosts(_logger, downloadingPostsOptions));
            return(res);
        }
 public CandidatePostsController(HttpClient client)
 {
     _client = client;
     _postsFound = false;
     _posts = new PostsCollection();
 }
예제 #6
0
        /// <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;
                }
            }
        }