Exemple #1
0
        /// <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);
        }
Exemple #2
0
 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);
 }
Exemple #3
0
 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);
 }
Exemple #4
0
 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);
 }
Exemple #5
0
        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);
        }
Exemple #6
0
 /// <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);
 }
Exemple #8
0
 public override void ToStream(ZetboxStreamWriter sw, HashSet <IStreamable> auxObjects, bool eagerLoadLists)
 {
     base.ToStream(sw, auxObjects, eagerLoadLists);
     sw.Write((int)ObjectState);
     sw.Write((int)CurrentAccessRights);
 }
Exemple #9
0
 public void should_write_double()
 {
     writer.Write(dblTest);
     ResetStream();
     Assert.That(stream.ToArray(), Is.EqualTo(dblExpected));
 }
Exemple #10
0
 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);
 }
Exemple #11
0
        /// <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);
        }
Exemple #12
0
 public override void ToStream(ZetboxStreamWriter sw, HashSet<IStreamable> auxObjects, bool eagerLoadLists)
 {
     base.ToStream(sw, auxObjects, eagerLoadLists);
     sw.Write(TestProperty);
 }
Exemple #13
0
 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);
 }
Exemple #14
0
 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);
 }
Exemple #15
0
 /// <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);
 }
Exemple #16
0
 public override void ToStream(ZetboxStreamWriter sw, HashSet <IStreamable> auxObjects, bool eagerLoadLists)
 {
     base.ToStream(sw, auxObjects, eagerLoadLists);
     sw.Write(TestInt);
     sw.Write(TestString);
 }
Exemple #17
0
 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);
 }