public static FileCache Load(string file) { var fn = System.IO.Path.GetFileName(file); var path = file.Substring(0, file.Length - fn.Length); var db = CacheDBContext.Build(path); var cache = new FileCache(db); /* migrate to .json */ if (string.Compare(".xml", System.IO.Path.GetExtension(file), true) == 0) { Console.WriteLine("loading old files..."); var oldStorage = Version1_0Storage.Build(file); foreach (var c in oldStorage.containers) { Console.WriteLine("loading {0} {1} -> {2}", c.id, c.name, c.files.Count); cache.add(c); } } else { if (System.IO.File.Exists(file)) { var str = System.IO.File.ReadAllText(file); var containers = Newtonsoft.Json.JsonConvert.DeserializeObject <ContList>(str); foreach (var c in containers.containers) { cache.add(c); } } } return(cache); }
public static CacheDBContext Build(string path) { var opts = new DbContextOptionsBuilder(); opts.UseSqlite(string.Format("Data Source={0}", System.IO.Path.Combine(path, Db_File))); var db = new CacheDBContext(opts.Options); db.Database.EnsureCreated(); return(db); }
protected FileCache(CacheDBContext db) { _containers = new List <Container>(); _db = db; }