public void TestIsChangedResetted() { LMTeam t, t1; ObjectChangedParser parser; List <IStorable> storables = null, changed = null; StorableNode parent = null; parser = new ObjectChangedParser(); t = LMTeam.DefaultTemplate(10); storage.Store(t); // After loading an object t1 = DocumentsSerializer.LoadObject(typeof(LMTeam), t.ID, db) as LMTeam; Assert.IsTrue(parser.ParseInternal(out parent, t1, Serializer.JsonSettings)); Assert.IsTrue(parent.ParseTree(ref storables, ref changed)); Assert.AreEqual(0, changed.Count); Assert.NotNull(t1.DocumentID); // After filling an object t1 = new LMTeam(); t1.ID = t.ID; t1.DocumentID = t.ID.ToString(); t1.IsChanged = true; DocumentsSerializer.FillObject(t1, db); Assert.IsTrue(parser.ParseInternal(out parent, t1, Serializer.JsonSettings)); Assert.IsTrue(parent.ParseTree(ref storables, ref changed)); Assert.AreEqual(0, changed.Count); }
void Delete(StorableNode node, Guid rootID) { Guid id = node.Storable.ID; db.GetDocument(DocumentsSerializer.StringFromID(id, rootID)).Delete(); foreach (StorableNode child in node.Children) { Delete(child, rootID); } }
public void persist(T storable) { var asArray = storableAdapter.AsStringArray(storable); var finded = findNodeById(storableAdapter.Identifier(storable)); if (finded == null) { var node = new StorableNode(); node.id = storableAdapter.GenerateIdentifier(storable); node.data = asArray; buffer.Add(node); } else { finded.data = asArray; } writeBuffer(); }
void Update(StorableNode node, SerializationContext context = null) { if (context == null) { context = new SerializationContext(db, node.Storable.GetType()); context.RootID = node.Storable.ID; } if (node.IsChanged) { documentUpdated = true; DocumentsSerializer.SaveObject(node.Storable, db, context, false); } /* Since we are saving single objects manually, we need to keep the stack * updated to avoid problems with circular references */ context.Stack.Push(node.Storable); foreach (StorableNode child in node.Children) { Update(child, context); } context.Stack.Pop(); }
private void loadBuffer() { dataStream.Position = 0; buffer.Clear(); var reader = new StreamReader(dataStream); string id; while ((id = reader.ReadLine()) != null) { var currentNode = new StorableNode(); var data = new string[storableAdapter.AttributeCount()]; currentNode.id = handleDataRead(id); for (int i = 0; i < storableAdapter.AttributeCount(); i++) { data[i] = handleDataRead(reader.ReadLine()); } currentNode.data = data; buffer.Add(currentNode); } }