Beispiel #1
0
        /// <summary>
        /// Gets an item from the artwork cache.
        /// </summary>
        /// <param name="trackID">The item's ID.</param>
        /// <returns>A CacheReceipt that indicates the success of the request and the Uri of the image, if possible.</returns>
        internal static CacheReceipt <Uri> GetArtworkCacheItem(uint trackID)
        {
            var x = _local.CreateContainer(ArtContainerGuid.ToString(), Windows.Storage.ApplicationDataCreateDisposition.Always).Values[trackID.ToString()] as string;

            if (x == null)
            {
                return(new CacheReceipt <Uri>(CacheStatus.Uncached, null));
            }
            else if (x.Length == 0)
            {
                return(new CacheReceipt <Uri>(CacheStatus.CannotCache, null));
            }
            else
            {
                return(new CacheReceipt <Uri>(CacheStatus.Cached, new Uri(x)));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Deletes any album artwork containers that are not the current one in the local storage.
        /// API consumers should periodically call this function during normal app operation.
        /// </summary>
        public static async void CleanArtworkCache()
        {
            try
            {
                string artFolder = ArtContainerGuid.ToString();

                var subfolders = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFoldersAsync();

                foreach (var folder in subfolders)
                {
                    if (folder.Name != artFolder)
                    {
                        await folder.DeleteAsync();
                    }
                }
            }
            catch (Exception)
            {
                // Justification: artwork cache cleaning happens automatically, and failure does not harm user
            }
        }
Beispiel #3
0
        /// <summary>
        /// Sets an item in the artwork cache.
        /// </summary>
        /// <param name="artGuid">The ArtContainerGuid at the start of the cache operation. If it is different from the current ArtContainerGuid, the cache will be ignored.</param>
        /// <param name="status">The status of the cache operation.</param>
        /// <param name="trackID">The item's ID.</param>
        /// <param name="path">The path to the image, if status is CacheStatus.Cached.</param>
        /// <returns>Whether the cache was successful.</returns>
        internal static bool SetArtworkCacheItem(Guid artGuid, CacheStatus status, uint trackID, Uri path)
        {
            if (artGuid == ArtContainerGuid)
            {
                switch (status)
                {
                case CacheStatus.Cached:
                    _local.CreateContainer(ArtContainerGuid.ToString(), Windows.Storage.ApplicationDataCreateDisposition.Always).Values[trackID.ToString()] = path.ToString();
                    break;

                case CacheStatus.CannotCache:
                    _local.CreateContainer(ArtContainerGuid.ToString(), Windows.Storage.ApplicationDataCreateDisposition.Always).Values[trackID.ToString()] = string.Empty;
                    break;

                case CacheStatus.Uncached:
                    break;
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }