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); }
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; }
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); }
private void LoadRecord(FileInfo file) { if (Cached.ContainsKey(Path.GetFileNameWithoutExtension(file.Name))) { return; } var record = InvertJsonExtensions.DeserializeObject(For, JSON.Parse(File.ReadAllText(file.FullName))) as IDataRecord; if (record != null) { record.Repository = this.Repository; Cached.Add(record.Identifier, record); record.Changed = false; } }
public void Import(ExportedRecord record) { LoadRecordsIntoCache(); if (Cached.ContainsKey(record.Identifier)) { InvertJsonExtensions.DeserializeExistingObject(Cached[record.Identifier], JSON.Parse(record.Data).AsObject); } else { var dataRecord = InvertJsonExtensions.DeserializeObject(For, JSON.Parse(record.Data)) as IDataRecord; if (dataRecord != null) { Add(dataRecord); } } }
private void LoadRecord(string file) { if (Cached.ContainsKey(Path.GetFileNameWithoutExtension(file))) { return; } try { var record = InvertJsonExtensions.DeserializeObject(For, JSON.Parse(ReadFile(file))) as IDataRecord; if (record != null) { record.Repository = this.Repository; Cached.Add(record.Identifier, record); record.Changed = false; } } catch (Exception ex) { throw new Exception(string.Format("Error parsing file {0}", file), ex); } }