예제 #1
0
 public virtual void Commit()
 {
     _isCommiting = true;
     if (!DirectoryInfo.Exists)
     {
         DirectoryInfo.Create();
     }
     foreach (var item in Cached)
     {
         var filename = Path.Combine(RecordsPath, item.Key + ".json");
         if (Removed.Contains(item.Key))
         {
             if (File.Exists(filename))
             {
                 File.Delete(filename);
             }
         }
         else
         {
             if (item.Value.Changed)
             {
                 var json = InvertJsonExtensions.SerializeObject(item.Value);
                 File.WriteAllText(filename, json.ToString(true));
             }
             item.Value.Changed = false;
         }
     }
     _isCommiting = false;
 }
        public void Commit()
        {
            _isCommiting = true;
            if (!DirectoryInfo.Exists)
            {
                DirectoryInfo.Create();
            }
            foreach (var item in Cached)
            {
                //filename is calculated inside of the if scopes, because, Path.Combine seems to be a bottleneck. ECSDemoProject took around 4000 invokcations to this method and took average
                //time of 1000ms to process all the Path.Combine.
                if (Removed.Contains(item.Key))
                {
                    var filename = Path.Combine(RecordsPath, item.Key + ".json");

                    if (File.Exists(filename))
                    {
                        File.Delete(filename);
                    }
                }
                else
                {
                    if (item.Value.Changed)
                    {
                        var filename = Path.Combine(RecordsPath, item.Key + ".json");
                        var json     = InvertJsonExtensions.SerializeObject(item.Value);
                        File.WriteAllText(filename, json.ToString(true));
                    }
                    item.Value.Changed = false;
                }
            }
            _isCommiting = false;
        }
예제 #3
0
        public static TType Copy <TType>(this TType record) where TType : class, IDataRecord
        {
            var result = InvertJsonExtensions.DeserializeObject <TType>((string)InvertJsonExtensions.SerializeObject(record).ToString()) as TType;

            result.Identifier = Guid.NewGuid().ToString();
            return(result);
        }
예제 #4
0
        public List <ExportedRepository> Export()
        {
            var list = Repositories.Select(p => new ExportedRepository()
            {
                Records = p.Value.GetAll().Select(record => new ExportedRecord()
                {
                    Data       = InvertJsonExtensions.SerializeObject(record).ToString(true),
                    Identifier = record.Identifier
                }).ToList(),
                Type = p.Key.FullName
            }).ToList();

            return(list);
        }