Пример #1
0
 public static void Serialize(zContext cont)
 {
     Directory.CreateDirectory(cont.Path.Substring(0, cont.Path.LastIndexOf("\\")));
     using (StreamWriter file = File.CreateText(cont.Path + "_")) {
         CurrentSerializer.Serialize(file, cont);
     }
     File.Replace(cont.Path + "_", cont.Path, cont.Path + ".bk");
     File.Delete(cont.Path + ".bk");
 }
Пример #2
0
        public static zContext Deserialize(string Path)
        {
            zContext c;

            try {
                //TODO check if bk file exists and is older than current one

                using (StreamReader file = File.OpenText(Path)) {
                    c = (zContext)CurrentSerializer.Deserialize(file, typeof(zContext));
                }
                //c = JsonConvert.DeserializeObject<zContext>(File.ReadAllText(Path), new DB_JSONConverter());
            } catch {
                c = new zContext();
            }
            c.Path = Path;
            return(c);
        }