static IEnumerable<TraktListDetail> GetCustomListsFromTrakt(bool ignoreLastSyncTime = false)
{
// get from cache regardless of last sync time
if (ignoreLastSyncTime)
return CustomLists;
// get the last time we did anything to our library online
var lastSyncActivities = LastSyncActivities;
// something bad happened e.g. site not available
if (lastSyncActivities == null || lastSyncActivities.Lists == null)
return null;
// check the last time we have against the online time
// if the times are the same try to load from cache
if (lastSyncActivities.Lists.UpdatedAt == TraktSettings.LastSyncActivities.Lists.UpdatedAt)
{
TraktLogger.Info("Getting current user custom lists from local cache");
var cachedItems = CustomLists;
if (cachedItems != null)
return cachedItems;
}
TraktLogger.Info("Custom Lists cache is out of date, requesting updated data. Local Date = '{0}', Online Date = '{1}'", TraktSettings.LastSyncActivities.Lists.UpdatedAt ?? "<empty>", lastSyncActivities.Lists.UpdatedAt ?? "<empty>");
// we get from online, local cache is not up to date
var onlineItems = TraktAPI.TraktAPI.GetUserLists();
if (onlineItems == null)
return null;
_CustomLists = onlineItems;
// save to local file cache
SaveFileCache(CustomListsFile, _CustomLists.ToJSON());
// save new activity time for next time
TraktSettings.LastSyncActivities.Lists.UpdatedAt = lastSyncActivities.Lists.UpdatedAt;
return onlineItems;
}