Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public static Version1_0Storage Build(string filename)
        {
            if (string.Compare(".xml", Path.GetExtension(filename), true) != 0)
            {
                throw new ArgumentException("only xml files!");
            }

            if (!File.Exists(filename))
            {
                throw new ArgumentException("file dne!");
            }

            var v1s = new Version1_0Storage();

            v1s.load(filename);

            return(v1s);
        }