/// <summary> /// Serializes a list of objects onto a <see cref="MemoryStream"/>. /// </summary> /// <param name="lst">the list of objects to send</param> /// <param name="eagerLoadLists">True if Lists should be eager loaded</param> /// <returns>a memory stream containing all objects and all eagerly loaded auxiliary objects</returns> private MemoryStream SendObjects(IEnumerable <IStreamable> lst, bool eagerLoadLists) { HashSet <IStreamable> sentObjects = new HashSet <IStreamable>(); HashSet <IStreamable> auxObjects = new HashSet <IStreamable>(); MemoryStream result = new MemoryStream(); ZetboxStreamWriter sw = new ZetboxStreamWriter(_map, new BinaryWriter(result)); foreach (IStreamable obj in lst) { sw.Write(true); // don't check sentObjects here, because a list might contain items twice obj.ToStream(sw, auxObjects, eagerLoadLists); sentObjects.Add(obj); } sw.Write(false); SendAuxiliaryObjects(sw, auxObjects, sentObjects, eagerLoadLists); // https://connect.microsoft.com/VisualStudio/feedback/details/541494/wcf-streaming-issue sw.Write(false); sw.Write(false); sw.Write(false); result.Seek(0, SeekOrigin.Begin); return(result); }
public override void ToStream(ZetboxStreamWriter binStream, HashSet <IStreamable> auxObjects, bool eagerLoadLists) { base.ToStream(binStream, auxObjects, eagerLoadLists); binStream.Write(this._MyIntProperty); binStream.Write(this._fk_ObjectProp); binStream.Write(this._StringProp); binStream.Write((int?)((TestObjClass)this).TestEnumProp); }
public void ToStream(ZetboxStreamWriter sw, HashSet <IStreamable> auxObjects, bool eagerLoadLists) { sw.Write(ReadOnlyContext.GetInterfaceType(this).ToSerializableType()); sw.Write(ID); sw.Write(StringProperty); sw.Write(IntProperty); sw.Write(BoolProperty); }
private static void SendObjects(IEnumerable <IPersistenceObject> objects, ZetboxStreamWriter sw) { foreach (var obj in objects) { sw.Write(true); obj.ToStream(sw, new HashSet <IStreamable>(), false); } sw.Write(false); }
public override void ToStream(ZetboxStreamWriter sw, HashSet <IStreamable> auxObjects, bool eagerLoadLists) { base.ToStream(sw, auxObjects, eagerLoadLists); int?id = this.BaseTestObjClass == null ? (int?)null : this.BaseTestObjClass.ID; sw.Write(id); sw.Write(this._StringProp); sw.Write((int)this.TestEnumProp); sw.WriteCollectionEntries(this.TestNamesImpl); }
/// <summary> /// Sends a list of auxiliary objects to the specified ZetboxStreamWriter while avoiding to send objects twice. /// </summary> /// <param name="sw">the stream to write to</param> /// <param name="auxObjects">a set of objects to send; will not be modified by this call</param> /// <param name="sentObjects">a set objects already sent; receives all newly sent objects too</param> /// <param name="eagerLoadLists">True if Lists should be eager loaded</param> private static void SendAuxiliaryObjects(ZetboxStreamWriter sw, HashSet <IStreamable> auxObjects, HashSet <IStreamable> sentObjects, bool eagerLoadLists) { // clone auxObjects to avoid modification auxObjects = new HashSet <IStreamable>(auxObjects); auxObjects.ExceptWith(sentObjects); // send all eagerly loaded objects while (auxObjects.Count > 0) { HashSet <IStreamable> secondTierAuxObjects = new HashSet <IStreamable>(); foreach (var aux in auxObjects.Where(o => o != null)) { sw.Write(true); aux.ToStream(sw, secondTierAuxObjects, eagerLoadLists); sentObjects.Add(aux); } // check whether new objects where eagerly loaded secondTierAuxObjects.ExceptWith(sentObjects); auxObjects = secondTierAuxObjects; } // finish list sw.Write(false); }
public override void ToStream(ZetboxStreamWriter sw, HashSet<IStreamable> auxObjects, bool eagerLoadLists) { base.ToStream(sw, auxObjects, eagerLoadLists); sw.Write((int)ObjectState); sw.Write((int)CurrentAccessRights); }
public override void ToStream(ZetboxStreamWriter sw, HashSet <IStreamable> auxObjects, bool eagerLoadLists) { base.ToStream(sw, auxObjects, eagerLoadLists); sw.Write((int)ObjectState); sw.Write((int)CurrentAccessRights); }
public void should_write_double() { writer.Write(dblTest); ResetStream(); Assert.That(stream.ToArray(), Is.EqualTo(dblExpected)); }
public void ToStream(ZetboxStreamWriter sw, HashSet<IStreamable> auxObjects, bool eagerLoadLists) { sw.Write(ReadOnlyContext.GetInterfaceType(this).ToSerializableType()); sw.Write(ID); sw.Write(StringProperty); sw.Write(IntProperty); sw.Write(BoolProperty); }
/// <summary> /// Serializes a test TestObjClass to the stream sw. /// </summary> /// <param name="sw"></param> public static void ToStream <LOCALINTERFACE, ENUMTYPE>(ZetboxStreamWriter sw, InterfaceType.Factory iftFactory) where LOCALINTERFACE : TestObjClass <LOCALINTERFACE, ENUMTYPE> where ENUMTYPE : struct { // BaseServerPersistenceObject sw.Write(GetSerializableType <LOCALINTERFACE, ENUMTYPE>(iftFactory)); sw.Write(TestObjClassId); sw.Write((int)TestObjectState); sw.Write((int)AccessRights.Full); // TestObjClass // BaseTestObjClass Reference sw.Write(TestBaseClassId); // StringProp sw.Write(TestStringPropValue); //// SubClasses are not serialized, but fetched lazily //foreach (int subClassID in TestSubClassesIds) //{ // BinarySerializer.ToStream(true, sw); // BinarySerializer.ToStream(subClassID, sw); //} //BinarySerializer.ToStream(false, sw); // TestEnumProp sw.Write((int)TestEnum.TestSerializationValue); // TestNames var ceType = GetSerializableCollectionEntryType <LOCALINTERFACE, ENUMTYPE>(iftFactory); for (int i = 0; i < TestTestNamesIds.Length; i++) { sw.Write(true); sw.Write(ceType); sw.Write(TestTestNamesIds[i]); sw.Write((int)TestCollectionEntryState); sw.Write((int)AccessRights.Full); sw.Write(TestTestNamesValues[i]); } sw.Write(false); }
public override void ToStream(ZetboxStreamWriter sw, HashSet<IStreamable> auxObjects, bool eagerLoadLists) { base.ToStream(sw, auxObjects, eagerLoadLists); sw.Write(TestProperty); }
public override void ToStream(ZetboxStreamWriter binStream, HashSet<IStreamable> auxObjects, bool eagerLoadLists) { base.ToStream(binStream, auxObjects, eagerLoadLists); binStream.Write(this._MyIntProperty); binStream.Write(this._fk_ObjectProp); binStream.Write(this._StringProp); binStream.Write((int?)((TestObjClass)this).TestEnumProp); }
public override void ToStream(ZetboxStreamWriter sw, HashSet<IStreamable> auxObjects, bool eagerLoadLists) { base.ToStream(sw, auxObjects, eagerLoadLists); int? id = this.BaseTestObjClass == null ? (int?)null : this.BaseTestObjClass.ID; sw.Write(id); sw.Write(this._StringProp); sw.Write((int)this.TestEnumProp); sw.WriteCollectionEntries(this.TestNamesImpl); }
/// <summary> /// Sends a list of auxiliary objects to the specified ZetboxStreamWriter while avoiding to send objects twice. /// </summary> /// <param name="sw">the stream to write to</param> /// <param name="auxObjects">a set of objects to send; will not be modified by this call</param> /// <param name="sentObjects">a set objects already sent; receives all newly sent objects too</param> /// <param name="eagerLoadLists">True if Lists should be eager loaded</param> private static void SendAuxiliaryObjects(ZetboxStreamWriter sw, HashSet<IStreamable> auxObjects, HashSet<IStreamable> sentObjects, bool eagerLoadLists) { // clone auxObjects to avoid modification auxObjects = new HashSet<IStreamable>(auxObjects); auxObjects.ExceptWith(sentObjects); // send all eagerly loaded objects while (auxObjects.Count > 0) { HashSet<IStreamable> secondTierAuxObjects = new HashSet<IStreamable>(); foreach (var aux in auxObjects.Where(o => o != null)) { sw.Write(true); aux.ToStream(sw, secondTierAuxObjects, eagerLoadLists); sentObjects.Add(aux); } // check whether new objects where eagerly loaded secondTierAuxObjects.ExceptWith(sentObjects); auxObjects = secondTierAuxObjects; } // finish list sw.Write(false); }
public override void ToStream(ZetboxStreamWriter sw, HashSet <IStreamable> auxObjects, bool eagerLoadLists) { base.ToStream(sw, auxObjects, eagerLoadLists); sw.Write(TestInt); sw.Write(TestString); }
public override void ToStream(ZetboxStreamWriter sw, HashSet <IStreamable> auxObjects, bool eagerLoadLists) { base.ToStream(sw, auxObjects, eagerLoadLists); sw.Write(this.Value); sw.Write(this.fk_Parent); }