示例#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);
     }
 }
示例#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);
        }
示例#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();
        }
示例#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();
            }
        }
示例#5
0
 private void SaveCache()
 {
     CacheBot.Serialize(Cache, _cacheFile);
 }