internal void Serialize(XmlWriter writer, SoodaSerializeOptions options) { if (count == 0) { return; } writer.WriteStartElement("relation"); writer.WriteAttributeString("type", GetType().AssemblyQualifiedName); writer.WriteAttributeString("tupleCount", count.ToString()); for (int i = 0; i < count; ++i) { string modeString = null; if (tuples[i].tupleMode == 1) { modeString = "add"; } else if (tuples[i].tupleMode == -1) { modeString = "remove"; } else { continue; } writer.WriteStartElement("tuple"); writer.WriteAttributeString("mode", modeString); writer.WriteAttributeString("r1", tuples[i].ref1.ToString()); writer.WriteAttributeString("r2", tuples[i].ref2.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); }
public void Serialize(TextWriter tw, SoodaSerializeOptions options) { XmlTextWriter xtw = new XmlTextWriter(tw); xtw.Formatting = Formatting.Indented; Serialize(xtw, options); }
public string Serialize(SoodaSerializeOptions opt) { StringWriter sw = new StringWriter(); Serialize(sw, opt); return(sw.ToString()); }
public void Serialize(XmlWriter xw, SoodaSerializeOptions options) { xw.WriteStartElement("transaction"); List <SoodaObject> orderedObjects = new List <SoodaObject>(); foreach (WeakSoodaObject wr in _objectList) { SoodaObject obj = wr.TargetSoodaObject; if (obj != null) { orderedObjects.Add(obj); } } if ((options & SoodaSerializeOptions.Canonical) != 0) { orderedObjects.Sort(Compare); } foreach (SoodaObject o in DeletedObjects) { o.PreSerialize(xw, options); } foreach (SoodaObject o in orderedObjects) { if (!o.IsMarkedForDelete()) { if (o.IsObjectDirty() || (options & SoodaSerializeOptions.IncludeNonDirtyObjects) != 0) { o.PreSerialize(xw, options); } } } foreach (SoodaObject o in orderedObjects) { if (o.IsObjectDirty() || (options & SoodaSerializeOptions.IncludeNonDirtyObjects) != 0) { o.Serialize(xw, options); } } // serialize N-N relation tables foreach (SoodaRelationTable rel in _relationTables.Values) { rel.Serialize(xw, options); } xw.WriteEndElement(); }
internal void Serialize(XmlWriter xw, SoodaSerializeOptions options) { if (IsMarkedForDelete()) return; xw.WriteStartElement("object"); xw.WriteAttributeString("mode", "update"); xw.WriteAttributeString("class", GetClassInfo().Name); if (!IsObjectDirty()) xw.WriteAttributeString("dirty", "false"); if (!AreObjectTriggersEnabled()) xw.WriteAttributeString("disableobjecttriggers", "true"); if (PostCommitForced) xw.WriteAttributeString("forcepostcommit", "true"); logger.Trace("Serializing {0}...", GetObjectKeyString()); EnsureFieldsInited(); if ((options & SoodaSerializeOptions.IncludeNonDirtyFields) != 0 && !IsAllDataLoaded()) LoadAllData(); SerializePrimaryKey(xw); foreach (Sooda.Schema.FieldInfo fi in GetClassInfo().UnifiedFields) { if (fi.IsPrimaryKey) continue; int ordinal = fi.ClassUnifiedOrdinal; bool dirty = IsFieldDirty(ordinal); if (dirty || (options & SoodaSerializeOptions.IncludeNonDirtyFields) != 0) { xw.WriteStartElement("field"); xw.WriteAttributeString("name", fi.Name); GetFieldHandler(ordinal).Serialize(_fieldValues.GetBoxedFieldValue(ordinal), xw); if (!dirty) xw.WriteAttributeString("dirty", "false"); xw.WriteEndElement(); } } if ((options & SoodaSerializeOptions.IncludeDebugInfo) != 0) { xw.WriteStartElement("debug"); xw.WriteAttributeString("transaction", (_transaction != null) ? "notnull" : "null"); xw.WriteAttributeString("objectDirty", IsObjectDirty() ? "true" : "false"); xw.WriteAttributeString("dataLoaded", IsAllDataLoaded() ? "true" : "false"); xw.WriteAttributeString("disableTriggers", AreFieldUpdateTriggersEnabled() ? "false" : "true"); xw.WriteAttributeString("disableObjectTriggers", AreObjectTriggersEnabled() ? "false" : "true"); xw.WriteEndElement(); } NameValueCollection persistentValues = GetTransaction().GetPersistentValues(this); if (persistentValues != null) { foreach (string s in persistentValues.AllKeys) { xw.WriteStartElement("persistent"); xw.WriteAttributeString("name", s); xw.WriteAttributeString("value", persistentValues[s]); xw.WriteEndElement(); } } xw.WriteEndElement(); }
// create an empty object just to make sure that the deserialization // will find it before any references are used. // internal void PreSerialize(XmlWriter xw, SoodaSerializeOptions options) { if (!IsInsertMode() && !IsMarkedForDelete()) return; xw.WriteStartElement("object"); xw.WriteAttributeString("mode", IsMarkedForDelete() ? "update" : "insert"); xw.WriteAttributeString("class", GetClassInfo().Name); if (IsMarkedForDelete()) xw.WriteAttributeString("delete", "true"); SerializePrimaryKey(xw); xw.WriteEndElement(); }
public void Serialize(XmlWriter xw, SoodaSerializeOptions options) { xw.WriteStartElement("transaction"); List<SoodaObject> orderedObjects = new List<SoodaObject>(); foreach (WeakSoodaObject wr in _objectList) { SoodaObject obj = wr.TargetSoodaObject; if (obj != null) orderedObjects.Add(obj); } if ((options & SoodaSerializeOptions.Canonical) != 0) { orderedObjects.Sort(Compare); } foreach (SoodaObject o in DeletedObjects) { o.PreSerialize(xw, options); } foreach (SoodaObject o in orderedObjects) { if (!o.IsMarkedForDelete()) { if (o.IsObjectDirty() || (options & SoodaSerializeOptions.IncludeNonDirtyObjects) != 0) o.PreSerialize(xw, options); } } foreach (SoodaObject o in orderedObjects) { if (o.IsObjectDirty() || (options & SoodaSerializeOptions.IncludeNonDirtyObjects) != 0) o.Serialize(xw, options); } // serialize N-N relation tables foreach (SoodaRelationTable rel in _relationTables.Values) { rel.Serialize(xw, options); } xw.WriteEndElement(); }
public string Serialize(SoodaSerializeOptions opt) { StringWriter sw = new StringWriter(); Serialize(sw, opt); return sw.ToString(); }
internal void Serialize(XmlWriter writer, SoodaSerializeOptions options) { if (count == 0) return; writer.WriteStartElement("relation"); writer.WriteAttributeString("type", GetType().AssemblyQualifiedName); writer.WriteAttributeString("tupleCount", count.ToString()); for (int i = 0; i < count; ++i) { string modeString = null; if (tuples[i].tupleMode == 1) modeString = "add"; else if (tuples[i].tupleMode == -1) modeString = "remove"; else continue; writer.WriteStartElement("tuple"); writer.WriteAttributeString("mode", modeString); writer.WriteAttributeString("r1", tuples[i].ref1.ToString()); writer.WriteAttributeString("r2", tuples[i].ref2.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); }