コード例 #1
0
        public T Find(int id)
        {
            var cached = CachedItems.FirstOrDefault(_ => _.Id == id);

            if (cached == null)
            {
                var item = ItemsProvider.Find(id);
                if (item == null)
                {
                    return(null);
                }
                var index = FetchIndexForItem(item);
                if (index == -1)
                {
                    return(null);
                }

                int pageIndex  = index / PageSize;
                int pageOffset = index % PageSize;

                RequestPage(pageIndex);

                return(pages[pageIndex][pageOffset]);
            }
            return(cached);
        }
コード例 #2
0
 void QueueCachedValue(T current)
 {
     lock (CachedItems)
     {
         CachedItems.Enqueue(current);
     }
 }
コード例 #3
0
 /// <summary>
 /// Not supported.
 /// </summary>
 /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param>
 /// <returns>
 /// Always false.
 /// </returns>
 public bool Contains(T item) // where T:IEntity
 {
     if (item == null)
     {
         return(false);
     }
     return(CachedItems.Contains(item) || Find(item.Id) != null);
 }
コード例 #4
0
 public void ResetCache()
 {
     Pagination   = PaginationParameters.MaxPagesToLoad(1);
     IsLoading    = true;
     HasMoreItems = true;
     Items.Clear();
     CachedItems.Clear();
     FirstRun = true;
 }
コード例 #5
0
        /// <summary>
        /// Method for doing initialization related to first launch of the application
        /// </summary>
        private static void FirstLaunch()
        {
            // On the first launch, just add everything from the OPML file
            StreamResourceInfo xml      = App.GetResourceStream(new Uri("/RSSReader;component/sample-opml.xml", UriKind.Relative));
            List <RSSPage>     rssPages = ParseOPML(xml.Stream);

            // Add the pages to the data model
            CachedItems.AddPages(rssPages);

            GetFeedImages();
        }
コード例 #6
0
 bool TryTakeCachedValue()
 {
     lock (CachedItems)
     {
         if (CachedItems.Count > 0)
         {
             Current = CachedItems.Dequeue();
             return(true);
         }
     }
     return(false);
 }
コード例 #7
0
        public async void LoadCachedItems()
        {
            var fileList = await SaveFolder.GetFilesAsync();

            CachedItems.Clear();
            foreach (var file in fileList)
            {
                if (file.FileType == ".mp3" || file.FileType == ".mp4")
                {
                    CachedItems.Add(new CachedItem(file.Name, file.Path));
                }
            }
        }
コード例 #8
0
        protected override Task <int> FetchData(int page, int pageSize)
        {
            TaskCompletionSource <int> taskCompletionSource = new TaskCompletionSource <int>();

            CachingService.GetActivities(page, pageSize).Subscribe(result =>
            {
                if (!string.IsNullOrEmpty(result))
                {
                    IEnumerable <ActivitySummary> activities = Unmarshaller <IEnumerable <ActivitySummary> > .Unmarshal(result);
                    if (activities != null && activities.Any())
                    {
                        //CachedItems.EditDiff(activities, EqualityComparer<ActivitySummary>.Default);
                        CachedItems.AddOrUpdate(activities); //TODO: Glenn - The AddOrUpdate does look a bit to harsh - flashing list!
                    }
                    taskCompletionSource.TrySetResult(activities.Count());
                }

                taskCompletionSource.TrySetResult(0);
            });

            return(taskCompletionSource.Task);
        }
コード例 #9
0
        async Task LoadMoreItemsAsync(bool refresh = false)
        {
            if (!HasMoreItems && !refresh)
            {
                IsLoading = false;
                return;
            }
            try
            {
                if (refresh)
                {
                    PageCount  = 1;
                    Pagination = PaginationParameters.MaxPagesToLoad(1);
                }
                Views.Main.ActivitiesView.Current?.ShowTopLoadingFollowers();
                var result = await InstaApi.UserProcessor.GetUserFollowingByIdAsync(CurrentUser.Pk, Pagination);

                PageCount++;
                FirstRun = false;
                Pagination.MaximumPagesToLoad = 2;
                if (!result.Succeeded)
                {
                    IsLoading = false;
                    if (result.Value == null || result.Value?.Count == 0)
                    {
                        Views.Main.ActivitiesView.Current?.HideTopLoadingFollowers();
                        return;
                    }
                }

                if (string.IsNullOrEmpty(result.Value.NextMaxId))
                {
                    HasMoreItems = false;
                }

                Pagination.NextMaxId = result.Value.NextMaxId;
                if (refresh)
                {
                    Items.Clear(); CachedItems.Clear();
                }
                var userIds = new List <long>();
                if (result.Value?.Count > 0)
                {
                    result.Value.ForEach(x =>
                    {
                        userIds.Add(x.Pk);
                        CachedItems.Add(x.ToUserShortFriendship());
                    });
                }
                try
                {
                    if (userIds.Count > 0)
                    {
                        await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                        {
                            var friendshipStatuses = await InstaApi.UserProcessor.GetFriendshipStatusesAsync(userIds.ToArray());
                            if (friendshipStatuses.Succeeded)
                            {
                                var friends = friendshipStatuses.Value;
                                friends.ForEach(x =>
                                {
                                    var t = CachedItems.FirstOrDefault(u => u.Pk == x.Pk);
                                    if (t != null)
                                    {
                                        t.FriendshipStatus = x;
                                    }
                                });
                            }
                            CachedItems.ForEach(x =>
                            {
                                if (x.FriendshipStatus != null)
                                {
                                    if (!x.FriendshipStatus.Following)
                                    {
                                        Items.Add(x);
                                    }
                                }
                            });

                            Views.Main.ActivitiesView.Current?.HideTopLoadingFollowers();
                        });
                    }
                }
                catch
                {
                    Views.Main.ActivitiesView.Current?.HideTopLoadingFollowers();
                }
                await Task.Delay(1000);

                IsLoading = false;
            }
            catch (Exception ex)
            {
                FirstRun      =
                    IsLoading = false;
                ex.PrintException("FollowingGenerator.LoadMoreItemsAsync");

                Views.Main.ActivitiesView.Current?.HideTopLoadingFollowers();
            }
        }
コード例 #10
0
 /// <summary>
 /// Persists the cache to disk
 /// </summary>
 public static void PersistCache()
 {
     CachedItems.Save();
 }