public async Task <ServiceResponse <StoriesResponse> > GetStoriesById(int?characterId)
        {
            ServiceResponse <StoriesResponse> serviceResponse = new ServiceResponse <StoriesResponse>();
            DataResponse <StoriesResponse>    dataResponse    = new DataResponse <StoriesResponse>();

            try
            {
                this.QueryDataId(Convert.ToInt32(characterId));

                List <StoriesResponse> storiesResponses = new List <StoriesResponse>();

                foreach (var itemStories in this.stories)
                {
                    StoriesResponse storieResponse = new StoriesResponse();
                    storieResponse.id          = itemStories.Id;
                    storieResponse.title       = itemStories.Title;
                    storieResponse.description = itemStories.Description;
                    storieResponse.resourceURI = itemStories.ResourceUri;
                    storieResponse.modified    = Convert.ToString(itemStories.Modified);
                    storieResponse.modified    = Convert.ToString(itemStories.Modified);
                    storiesResponses.Add(storieResponse);
                }

                dataResponse.Results = storiesResponses;
                serviceResponse.data = dataResponse;

                return(serviceResponse);
            }
            catch (Exception)
            {
                return(serviceResponse);
            }
        }
Example #2
0
        private async Task ProcessNewStories(NewsFeed localFeed, StoriesResponse result)
        {
            var addedNewStory = false;

            _dataCacheService.BeginWrite();

            foreach (var story in result.Stories)
            {
                var storyId     = story.Id;
                var storyExists = (await _dataCacheService.GetStories(fe => fe.Id == storyId)).FirstOrDefault();
                if (storyExists == null)
                {
                    string summary = "";
                    if (!string.IsNullOrEmpty(story.Content))
                    {
                        summary = Regex.Replace(story.Content, "<.*?>", string.Empty);
                        if (summary.Length > 150)
                        {
                            summary = summary.Substring(0, 150);
                        }
                    }

                    Story s = new Story
                    {
                        Id         = storyId,
                        Title      = story.Title,
                        FeedId     = story.FeedId,
                        ReadStatus = story.ReadStatus,
                        //story.story_timestamp
                        Author    = story.Authors,
                        TimeStamp = story.Timestamp,
                        ListImage = story.ImageUrls.Any() ? story.ImageUrls[0] : "",
                        Content   = story.Content,
                        Summary   = summary,
                        Feed      = localFeed
                    };

                    _dataCacheService.AddStory(s);
                    addedNewStory = true;
                }
            }
            if (addedNewStory)
            {
                localFeed.UnreadCount = (await _dataCacheService.GetStories(st => st.ReadStatus == 0 && st.Feed == localFeed)).Count;
            }

            // no need to do a story pass until this changes
            localFeed.DownloadedLastStoryDate = localFeed.LastStoryDateFromService;
            _dataCacheService.Commit();
        }
Example #3
0
        private async Task GetNewStoriesForUpdatedFeeds()
        {
            //This would be nice but not supported currenlty
            //var query = DataModelManager.RealmInstance.All<NewsFeed>().Where(ld => ld.DownloadedLastStoryDate != ld.LastStoryDateFromService);

            var query = await _dataCacheService.GetAllNewsFeeds();

            var threadId = Thread.CurrentThread.ManagedThreadId;

            AutoResetEvent ar = new AutoResetEvent(false);

            foreach (var localFeed in query)
            {
                //TODO: full vs only unread
                if (localFeed.DownloadedLastStoryDate == localFeed.LastStoryDateFromService)
                {
                    Debug.WriteLine($"Skipping {localFeed.Title}");
                }
                else
                {
                    Debug.WriteLine($"DateFromService:{localFeed.LastStoryDateFromService} DateFromDownloaded:{localFeed.DownloadedLastStoryDate} ");
                    StoriesResponse result = null;

                    ar.Reset();

                    // ProcessNewStories must be called on the same thread for each iteration of loop
                    // This autroreset approach is necessary since configureawait(true) deson't seem to work reliably
                    // Realm needs a consistent thread per instance
                    // TODO: extract as helper
                    var task = _newsBlurClient.GetStoriesAsync(localFeed.Id).ContinueWith(a =>
                    {
                        result = a.Result;
                        ar.Set();
                    });

                    ar.WaitOne();

                    if (result == null)
                    {
                        throw new Exception("Error: webcall failed");
                    }

                    //ProcessNewStories must be called on the same thread for each iteration of loop
                    Debug.Assert(threadId == Thread.CurrentThread.ManagedThreadId);

                    await ProcessNewStories(localFeed, result);
                }
            }
        }
Example #4
0
        public async Task GetStories()
        {
            StoriesResponse stories = await _subject.GetStoriesAsync(19354);

            Assert.NotNull(stories);
        }