TraktPlugin.TraktCache.GetCustomLists C# (CSharp) Méthode

GetCustomLists() static private méthode

Returns the users custom lists with list item details
static private GetCustomLists ( bool ignoreLastSyncTime = false ) : List>.Dictionary
ignoreLastSyncTime bool
Résultat List>.Dictionary
        internal static Dictionary<TraktListDetail, List<TraktListItem>> GetCustomLists(bool ignoreLastSyncTime = false)
        {
            lock (syncLists)
            {
                if (_CustomListsAndItems == null || (DateTime.Now - CustomListAge) > TimeSpan.FromMinutes(TraktSettings.WebRequestCacheMinutes))
                {
                    TraktLogger.Info("Getting current user custom lists from trakt");

                    // first get the users custom lists from trakt exluding any details for individual lists
                    var userLists = GetCustomListsFromTrakt(ignoreLastSyncTime);
                    if (userLists == null) return null;

                    // get last time individual lists were updated online
                    var lastActivities = TraktSettings.LastListActivities.ToNullableList();

                    // get details of each list including items
                    _CustomListsAndItems = new Dictionary<TraktListDetail, List<TraktListItem>>();

                    foreach (var list in userLists.Where(l => l.ItemCount > 0))
                    {
                        bool listUpdated = false;

                        // load from cache
                        TraktLogger.Info("Getting list details for custom list from local cache. Name = '{0}', ID = '{1}', Slug = '{2}'", list.Name, list.Ids.Trakt, list.Ids.Slug);
                        string filename = CustomListFile.Replace("{listname}", list.Ids.Slug);
                        var userList = LoadFileCache(filename, null).FromJSONArray<TraktListItem>();

                        // check if we have got this list before
                        ListActivity listActivityCache = null;
                        if (lastActivities != null)
                        {
                            listActivityCache = lastActivities.FirstOrDefault(c => c.Id == list.Ids.Trakt);
                        }

                        // check if we need to get update from online
                        if (userList == null || listActivityCache == null || listActivityCache.UpdatedAt != list.UpdatedAt)
                        {
                            TraktLogger.Info("Getting list details for custom list from trakt.tv, local cache is out of date. Name = '{0}', Total Items = '{1}', ID = '{2}', Slug = '{3}', Last Updated = '{4}'", list.Name, list.ItemCount, list.Ids.Trakt, list.Ids.Slug, list.UpdatedAt);
                            userList = TraktAPI.TraktAPI.GetUserListItems("me", list.Ids.Trakt.ToString());
                            listUpdated = true;
                        }

                        if (userList == null)
                            continue;

                        // update cache update time
                        if (listActivityCache != null)
                        {
                            listActivityCache.UpdatedAt = list.UpdatedAt;
                        }
                        else
                        {
                            lastActivities.Add(new ListActivity
                            {
                                Id = list.Ids.Trakt,
                                UpdatedAt = list.UpdatedAt
                            });
                        }

                        // persist cache to disk
                        if (listUpdated)
                        {
                            SaveFileCache(filename, userList.ToJSON());
                        }

                        // add list to the cache
                        _CustomListsAndItems.Add(list, userList.ToList());
                    }
                    CustomListAge = DateTime.Now;
                    TraktSettings.LastListActivities = lastActivities;
                }
            }

            return _CustomListsAndItems;
        }
TraktCache