示例#1
0
        private async void FeedUpdateTimer_Tick(object sender, EventArgs e)
        {
            FhFeedObject[] feed;

            try
            {
                feed = await fhCient.GetFeed();
            }
            catch (FhRequestException exception)
            {
                var requestsLimitCount = int.Parse(exception.Error.OwnerResponse.Message.Headers.GetValues("X-Ratelimit-Remaining").First()); // отладка
                return;
            }
            catch (Exception exception) // ignore
            {
                return;
            }

            var newFeed = feed
                          .Where(feedObject => feedObject.IsNew)
                          .OrderByDescending(feedObject => feedObject.CreatedAt);

            GenerateFeed(feed, newFeed.ToArray());

            if (newFeed.Count() == 0)
            {
                return;
            }

            if (newFeed.First().OwnerDataObject.Id == Settings.Default.LastShownMessageId)
            {
                return;
            }

            if (Visible)
            {
                return;
            }

            ActivePopupMessage = PopupMessageForm.PopUp(newFeed.First().Message, newFeed.Count(),
                                                        TimeSpan.FromSeconds(Settings.Default.MessageShowingSeconds),
                                                        onClick: async() =>
            {
                await fhCient.MarkFeedAsRead();
                Invoke(new Action(Show));
            });

            Settings.Default.LastShownMessageId = newFeed.First().OwnerDataObject.Id;
            Settings.Default.Save();
        }
        private async Task <bool> IsApiTokenCorrect(string token)
        {
            using (var client = new FhClient(token))
            {
                try
                {
                    await client.GetFeed();
                }
                catch (FhRequestException exception)
                {
                    if (exception.Error.Status == 401)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }