private void onWallPostSuccessful(object sender, WallPostInfo info)
        {
            Task.Run(async() => {
                try {
                    var userid = 0;
                    var users  = await _api.UsersGet.GetAsync(QueryParameters.No());
                    var user   = users.Content?.FirstOrDefault();
                    if (user != null)
                    {
                        userid = user.ID;
                    }

                    var post = new HistoryPost {
                        OwnerId           = userid,
                        WallId            = info.OwnerId,
                        Message           = info.Message,
                        PostponedDateUnix = info.PostponedDate,
                        IsRepost          = false,
                        Date        = info.PublishingDate,
                        Attachments = info.Attachments.Exposed.Select(attachment => attachment.Photo.GetLargest()).ToList()
                    };

                    await _historyPublisher.LogAsync(post);
                }
                catch (VkException) {
                    //ignore
                }
            });
        }
Beispiel #2
0
        private async Task publishExecute()
        {
            IsBusy       = true;
            IsPublishing = true;
            bool successful = true;

            try {
                var postInfo = new WallPostInfo {
                    OwnerId       = _pullersController.Postponed.WallHolder.ID,
                    Message       = Message,
                    FromGroup     = PostFromGroup,
                    Signed        = SignedPost,
                    PostponedDate = DateUnix,
                    Attachments   = Attachments.Take(10).ToAttachments(),
                };

                logger.Debug($"Публикация отложенного поста от имени пользователя {postInfo.OwnerId} на время {postInfo.PostponedDate}");
                await _vkApi.WallPost.PostponeAsync(postInfo);
            }
            catch (VkException ex) {
                // 150 postpone posts reached (probably)
                if (ex.ErrorCode == 214)
                {
                    logger.Error(ex, "Ошибка при публикации поста, возможно достигнут лимит 150 отложенных записей.");
                    successful = false;
                    MessageBox.Show(ex.Message, "Невозможно отложить пост",
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    logger.Error(ex, "Неизвестная ошибка при публикации поста.");
                    MessageBox.Show($"{ex.Message}\n\nStackTrace:\n{ex.StackTrace}", ex.ToString(), MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }
            }
            finally {
                if (successful)
                {
                    wipe();
                    if (ShrinkAfterPublish)
                    {
                        IsShowing = false;
                    }
                    _eventAggregator.GetEvent <MainBottomEvents.Refresh>().Publish();
                }
                moveToNextMissing();
                IsBusy       = false;
                IsPublishing = false;
            }
        }