/// <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); } }
/// <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); }
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(); }
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(); } }
private void SaveCache() { CacheBot.Serialize(Cache, _cacheFile); }