Пример #1
0
        public static void Persists(string fileDb, FileDataBase fdb)
        {
            using (FileStream fs = File.Open(fileDb, FileMode.Truncate))
            using (StreamWriter sw = new StreamWriter(fs))
            using (JsonWriter jw = new JsonTextWriter(sw))
            {
                jw.Formatting = Formatting.Indented;

                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(jw, fdb);
            }
        }
Пример #2
0
        public static FileDataBase GetOrCreate(string fileDb)
        {
            {
                FileDataBase fdb = null;

                if (_staticFilesDataBases.ContainsKey(fileDb))
                {
                    fdb = _staticFilesDataBases[fileDb];
                }
                else
                {
                    fdb = FileDataBaseHelper.GetAllJsonDataBases<FileDataBase>(fileDb).FirstOrDefault();

                    if (fdb == null)
                        fdb = new FileDataBase();

                    _staticFilesDataBases.Add(fileDb, fdb);
                }

                return fdb;
            }
        }