Esempio n. 1
0
        /// <summary>
        /// Kills Index: Removes all files in cache folder and all entries in this cache index.
        /// </summary>
        public void KillIndex()
        {
            try
            {
                lock (syncLock)
                {
                    // Remove all files and directories in cache folder subdirectories.
                    var path = CachePath.AppendPath(BaseUriPath);
                    foreach (var d in Device.File.GetDirectoryNames(path))
                    {
                        Device.File.DeleteDirectory(d, true);
                    }

                    // remove all files in cache folder except for Serializefile
                    foreach (var f in Device.File.GetFileNames(path).Where(f => !f.Equals(SerializeFile)))
                    {
                        Device.File.Delete(f);
                    }


                    // remove all entries in cache index
                    Clear();

                    // Serialize the CacheIndex
                    SerializeCacheIndex(this);
                }
            }
            catch (Exception exc)
            {
                Device.Log.Error("CacheIndex.KillIndex() encountered an exception", exc);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the cache path.
        /// </summary>
        /// <param name="cacheIndexItem">The cache index item.</param>
        /// <returns></returns>
        public string GetCachePath(CacheIndexItem cacheIndexItem)
        {
            var    chars     = new[] { '<', '>', ':', '"', '|', '?', '*' };
            string uriString = CachePath.AppendPath(BaseUriPath).AppendPath(new string(cacheIndexItem.ID.ToCharArray().Select(c => chars.Contains(c) ? '_' : c).ToArray()));

            Uri uri = new Uri(uriString, UriKind.RelativeOrAbsolute);

            // Azure has filepath directory length limitations, so enforcing limit of 248 for cache.
            if (!uri.IsAbsoluteUri)
            {
                return(uriString);
            }
#if !AZURE
            return(uri.LocalPath);
#else
            if (uri.LocalPath.Length <= 247)
            {
                return(uri.LocalPath);
            }

            // To-Do: find better way to manage Azure cache folder, this is under a spell.
            // shrink file name to first 227 and last 20, causes cache file name collisions for BestSellers, due to long api key parameter.
            return(uri.LocalPath.Remove(227) + "~" + uri.LocalPath.Substring(uri.LocalPath.Length - 20));
#endif
        }
Esempio n. 3
0
 /// <summary>
 /// Weeds Index: Remove all files in cache folder and subfolders that do not
 /// have corresponding <see cref="CacheIndexItem"/> entries in this cache index.
 /// </summary>
 public void WeedIndex()
 {
     try
     {
         lock (syncLock)
         {
             // get list of files in cache folder.
             foreach (var f in GetFilesRecursive(CachePath.AppendPath(BaseUriPath))
                      .Where(f => !f.Equals(SerializeFile))
                      .Except(this.Select(i => GetCachePath(i))))
             {
                 Device.File.Delete(f);
             }
         }
     }
     catch (Exception exc)
     {
         Device.Log.Error("CacheIndex.WeedIndex() encountered an exception", exc);
     }
 }