Ejemplo n.º 1
0
 /// <summary>
 /// Serialize file to specified destination using ProtoBuf
 /// </summary>
 /// <param name="cacheCollection"></param>
 /// <param name="destinationFile"></param>
 public static void Serialize(CacheBot cacheCollection, string destinationFile)
 {
     using (var file = File.Create(destinationFile))
     {
         Serializer.Serialize(file, cacheCollection);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Deserialize specified file, returns null if file don't exists
        /// </summary>
        /// <param name="sourceFilePath"></param>
        /// <returns></returns>
        public static CacheBot LoadFile(string sourceFilePath)
        {
            CacheBot cache = null;

            if (File.Exists(sourceFilePath))
            {
                using (var file = File.OpenRead(sourceFilePath))
                {
                    cache = Serializer.Deserialize <CacheBot>(file);
                }
            }

            return(cache);
        }
Ejemplo n.º 3
0
        private void LoadCache()
        {
            Cache = null;
            var file = new FileInfo(_cacheFile);

            //Delete file if exceeds limit size
            if (file.Exists && Options.LimitCacheSize)
            {
                var limitSizeBytes = Options.CacheMaxSize * 1024 * 1024;
                if (file.Length > limitSizeBytes)
                {
                    file.Delete();
                }
            }

            Cache = CacheBot.LoadFile(_cacheFile) ?? new CacheBot();
        }
Ejemplo n.º 4
0
        public GmtBot(List <TrackFile> fileList, GmtBotOptions options)
        {
            _files     = fileList;
            Options    = options;
            _cacheFile = CoreVars.GetFilePath(PluginSettings.Folder, "cache.bin");

            Logger = new LogBot();

            if (Options.UsePersistentCache)
            {
                LoadCache();
            }
            else
            {
                Cache = new CacheBot();
            }
        }
Ejemplo n.º 5
0
 private void SaveCache()
 {
     CacheBot.Serialize(Cache, _cacheFile);
 }