예제 #1
0
        private async ValueTask GetAndUpdateStatusesAsync(TwitterTimeline timeline)
        {
            var mentions = await GetMentionsAsync().ConfigureAwait(true);

            var statuses = await TwitterService.GetHomeTimeline().ConfigureAwait(true);

            await UpdateStatuses.Execute(statuses.Concat(mentions), timeline).ConfigureAwait(true);
        }
예제 #2
0
        private async ValueTask CommandHandlerAsync()
        {
            try
            {
                ComposeControlViewModel.IsUpdating = false;

                // AttachmentUrl != null means tweet is being quoted (Retweet with comment).
                // Ignore InReplyTo.Id to register as a quoted tweet.
                // Twitter rules, not mine.
                var replyId = string.IsNullOrEmpty(ComposeControlViewModel.AttachmentUrl)
                    ? ComposeControlViewModel.InReplyTo?.Id
                    : null;

                var mediaIds = ComposeControlViewModel.Media
                               .Select(media => media.MediaId)
                               .ToArray();

                var statusText     = ComposeControlViewModel.StatusText;
                var attachementUrl = ComposeControlViewModel.AttachmentUrl;

                var status = await TwitterService.UpdateStatus(
                    statusText,
                    replyId,
                    attachementUrl,
                    mediaIds)
                             .ConfigureAwait(true);

                // Something strange going on here. If I use the usual await
                // mechanism here it works but I see a consistent 2-5% CPU usage
                // when the program should be idling. It remains that way for
                // the life of the program. Debugging shows WPF is cycling in an
                // internal render loop. Since I don't need to wait for this
                // task to complete I can just fire and forget it which seems to
                // fix the problem. Total hack but I don't have the smarts to
                // fix the issue correctly.
                _ = UpdateStatuses.Execute(new[] { status }, HomeTimelineControlViewModel);

                TabBarControlViewModel.ShowComposeControl = false;
                ComposeControlViewModel.Clear();
            }
            catch (WebException ex)
            {
                var stream = ex.Response.GetResponseStream();
                using var reader = new StreamReader(stream);
                var message = await reader.ReadToEndAsync().ConfigureAwait(false);

                await MessageBoxService.ShowMessageBoxAsync(message).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                await MessageBoxService.ShowMessageBoxAsync(ex.Message).ConfigureAwait(false);
            }
            finally
            {
                ComposeControlViewModel.IsUpdating = false;
            }
        }
예제 #3
0
        private async void CommandHandler(object sender, ExecutedRoutedEventArgs ea)
        {
            try
            {
                ComposeControlViewModel.IsUpdating = false;

                // AttachmentUrl != null means tweet is being quoted (Retweet with comment).
                // Ignore InReplyTo.Id to register as a quoted tweet.
                // Twitter rules, not mine.
                var replyId = string.IsNullOrEmpty(ComposeControlViewModel.AttachmentUrl)
                    ? ComposeControlViewModel.InReplyTo?.Id
                    : null;

                var mediaIds = ComposeControlViewModel.Media
                               .Select(media => media.MediaId)
                               .ToArray();

                var statusText     = ComposeControlViewModel.StatusText;
                var attachementUrl = ComposeControlViewModel.AttachmentUrl;

                var status = await TwitterService.TwitterApi.UpdateStatus(
                    statusText,
                    replyId,
                    attachementUrl,
                    mediaIds)
                             .ConfigureAwait(true);

                await Application.Current.Dispatcher.InvokeAsync(() => UpdateStatuses.Execute(new[] { status }, HomeTimelineControlViewModel));

                TabBarControlViewModel.ShowComposeControl = false;
                ComposeControlViewModel.Clear();
            }
            catch (WebException ex)
            {
                var stream = ex.Response?.GetResponseStream();
                if (stream is null)
                {
                    return;
                }

                using var reader = new StreamReader(stream);
                var message = await reader.ReadToEndAsync().ConfigureAwait(true);

                await MessageBoxService.ShowMessageBoxAsync(message).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                await MessageBoxService.ShowMessageBoxAsync(ex.Message).ConfigureAwait(false);
            }
            finally
            {
                ComposeControlViewModel.IsUpdating = false;
            }
        }
예제 #4
0
        private async ValueTask GetAndUpdateFavoritesAsync(TwitterTimeline timeline)
        {
            var statuses = await TwitterService.GetFavoritesTimeline().ConfigureAwait(true);

            await UpdateStatuses.Execute(statuses, timeline).ConfigureAwait(true);
        }
예제 #5
0
 public UpdateAnswer(string error)
 {
     this.error = error;
     status     = UpdateStatuses.Failed;
 }
예제 #6
0
 public UpdateAnswer(List <Tuple <Threat, Threat> > changes)
 {
     status       = UpdateStatuses.Success;
     this.changes = changes;
 }