Exemple #1
0
        public void StreamXml(KSoft.IO.XmlElementStream s, FA mode, BXmlSerializerInterface xs)
        {
            bool   should_stream = true;
            string root_name     = Params.GetOptionalRootName();

            if (mode == FA.Read)             // If the stream doesn't have the expected element, don't try to stream
            {
                should_stream = root_name == null || s.ElementsExists(root_name);
            }

            if (should_stream)
            {
                using (s.EnterCursorBookmark(mode, root_name))
                {
                    if (mode == FA.Read)
                    {
                        ReadXmlNodes(s, xs);
                    }
                    else if (mode == FA.Write)
                    {
                        WriteXmlNodes(s, xs);
                    }
                }
            }
        }
Exemple #2
0
        public static void Serialize(KSoft.IO.XmlElementStream s, FA mode, BXmlSerializerInterface xsi,
                                     Collections.BTypeValuesSingle list, BTypeValuesXmlParams <float> @params,
                                     string attr_name = null)
        {
            Contract.Requires(s != null);
            Contract.Requires(xsi != null);
            Contract.Requires(list != null);
            Contract.Requires(@params != null);

            BTypeValuesXmlSerializerBase <float> xs;

#if NO_TLS_STREAMING
            if (attr_name == null)
            {
                xs = new BTypeValuesSingleXmlSerializer(@params, list);
            }
            else
            {
                xs = new BTypeValuesSingleAttrHackXmlSerializer(@params, list, attr_name);
            }
#else
            if (attr_name == null)
            {
                xs = BDatabaseXmlSerializerBase.sBTypeValuesSingleXmlSerializer.Value.Reset(@params, list);
            }
            else
            {
                xs = BDatabaseXmlSerializerBase.sBTypeValuesSingleAttrHackXmlSerializer.Value.Reset(@params, list, attr_name);
            }
#endif
            using (xs)
            {
                xs.StreamXml(s, mode, xsi);
            }
        }
Exemple #3
0
        public static void Serialize(KSoft.IO.XmlElementStream s, FA mode, BXmlSerializerInterface xsi,
                                     Collections.BTypeNames list, BListXmlParams @params, bool forceNoRootElementStreaming = false)
        {
            Contract.Requires(s != null);
            Contract.Requires(xsi != null);
            Contract.Requires(list != null);
            Contract.Requires(@params != null);

            if (forceNoRootElementStreaming)
            {
                @params.SetForceNoRootElementStreaming(true);
            }
            using (var xs =
#if NO_TLS_STREAMING
                       new BTypeNamesXmlSerializer(@params, list)
#else
                       BDatabaseXmlSerializerBase.sBTypeNamesXmlSerializer.Value.Reset(@params, list)
#endif
                   )
            {
                xs.StreamXml(s, mode, xsi);
            }
            if (forceNoRootElementStreaming)
            {
                @params.SetForceNoRootElementStreaming(false);
            }
        }
Exemple #4
0
        protected override void ReadXml(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs, int iteration)
        {
            string name = null;

            mParams.StreamDataName(s, FA.Read, ref name);

            mList.AddItem(name);
        }
Exemple #5
0
        protected override void ReadXml(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs, int iteration)
        {
            int id = PhxLib.Util.kInvalidInt32;

            mParams.kStreamID(s, FA.Read, xs, mParams, mStreamCtxt, ref id);

            mList.AddItem(id);
        }
        void PreloadXml(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs)
        {
            mIsPreloaded = false;

            StreamXml(s, FA.Read, xs);

            mIsPreloaded = true;
        }
Exemple #7
0
 protected virtual void WriteXmlNodes(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs)
 {
     foreach (T data in List)
     {
         using (s.EnterCursorBookmark(WriteXmlGetElementName(data)))
             WriteXml(s, xs, data);
     }
 }
Exemple #8
0
        protected override void ReadXml(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs, int iteration)
        {
            T item = new T();

            item.StreamXml(s, FA.Read, xs);

            List.AddItem(item);
        }
        protected virtual int ReadExplicitIndex(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs)
        {
            int index = -1;

            mParams.StreamExplicitIndex(s, FA.Read, ref index);

            return(index);
        }
Exemple #10
0
        protected override void WriteXmlNodes(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs)
        {
            SetupContext(s, FA.Write, xs);

            base.WriteXmlNodes(s, xs);

            mStreamCtxt = null;
        }
Exemple #11
0
        void SetupContext(KSoft.IO.XmlElementStream s, FA mode, BXmlSerializerInterface xs)
        {
            if (mParams.kGetContext == null)
            {
                return;
            }

            mStreamCtxt = mParams.kGetContext(s, mode, xs);
        }
Exemple #12
0
        protected virtual void ReadXmlDetermineListSize(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs)
        {
            int xml_node_count = s.Cursor.ChildNodes.Count;

            if (List.Capacity < xml_node_count)
            {
                List.Capacity = xml_node_count;
            }
        }
Exemple #13
0
        protected override void ReadXml(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs, int iteration)
        {
            int index = ReadExplicitIndex(s, xs);

            ListExplicitIndex.InitializeItem(index);
            string value = null;

            s.ReadCursor(ref value);
            ListExplicitIndex[index] = value;
        }
Exemple #14
0
        protected override void ReadXml(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs, int iteration)
        {
            int index = ReadExplicitIndex(s, xs);

            ListExplicitIndex.InitializeItem(index);
            float value = 0;

            s.ReadAttribute(kAttrName, ref value);
            ListExplicitIndex[index] = value;
        }
Exemple #15
0
        protected override void ReadXml(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs, int iteration)
        {
            int index = ReadExplicitIndex(s, xs);

            ListExplicitIndex.InitializeItem(index);
            T data = new T();

            data.StreamXml(s, FA.Read, xs);
            ListExplicitIndex[index] = data;
        }
Exemple #16
0
        protected override int ReadExplicitIndex(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs)
        {
            string name = null;

            Params.StreamDataName(s, FA.Read, ref name);

            int index = mList.TypeValuesParams.kGetProtoEnumFromDB(xs.Database).GetMemberId(name);

            return(index);
        }
        protected override void ReadXml(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs, int iteration)
        {
            int index = ReadExplicitIndex(s, xs);

            Contract.Assert(index != PhxLib.Util.kInvalidInt32);

            mList.InitializeItem(index);
            T data = new T();

            data.StreamXml(s, FA.Read, xs);
            mList[index] = data;
        }
        protected override void WriteXml(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs, T data)
        {
            const FA k_mode = FA.Write;

            string item_name = data.Data;

            if (item_name != null)
            {
                Params.StreamDataName(s, k_mode, ref item_name);
            }

            data.StreamXml(s, k_mode, xs);
        }
        public void StreamXmlUpdate(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs)
        {
            mIsUpdating        = true;
            mCountBeforeUpdate = mList.Count;

            if (RequiresDataNamePreloading)
            {
                PreloadXml(s, xs);
            }
            StreamXml(s, FA.Read, xs);

            mIsUpdating = false;
            //mCountBeforeUpdate = 0;
        }
        protected override void ReadXml(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs, int iteration)
        {
            const FA k_mode = FA.Read;

            string item_name = null;

            Params.StreamDataName(s, k_mode, ref item_name);

            T item;

            if (SetupItem(out item, item_name, iteration))
            {
                item.StreamXml(s, k_mode, xs);
            }
        }
        public static void Serialize(KSoft.IO.XmlElementStream s, FA mode, BXmlSerializerInterface xsi,
                                     IBListAutoIdXmlSerializer xs, bool forceNoRootElementStreaming = false)
        {
            Contract.Requires(s != null);
            Contract.Requires(xsi != null);
            Contract.Requires(xs != null);
            Contract.Requires(!xs.IsDisposed);

            if (forceNoRootElementStreaming)
            {
                xs.Params.SetForceNoRootElementStreaming(true);
            }
            xs.StreamXml(s, mode, xsi);
            if (forceNoRootElementStreaming)
            {
                xs.Params.SetForceNoRootElementStreaming(false);
            }
        }
Exemple #22
0
        protected override void WriteXmlNodes(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs)
        {
            var tvp = mList.TypeValuesParams;

            var   penum     = tvp.kGetProtoEnumFromDB(xs.Database);
            float k_invalid = tvp.kTypeGetInvalid();

            for (int x = 0; x < mList.Count; x++)
            {
                float data = mList[x];

                if (tvp.kComparer.Compare(data, k_invalid) != 0)
                {
                    string name = penum.GetMemberName(x);
                    s.WriteAttribute(name, data);
                }
            }
        }
Exemple #23
0
        public void StreamXml(KSoft.IO.XmlElementStream s, FA mode, BXmlSerializerInterface xs)
        {
            using (s.EnterCursorBookmark(mode, Params.GetOptionalRootName()))
            {
                if (mode == FA.Read)
                {
                    ReadXmlNodes(s, xs);
                }
                else if (mode == FA.Write)
                {
                    WriteXmlNodes(s, xs);
                }
            }

#if !NO_TLS_STREAMING
            FinishTlsStreaming();
#endif
        }
Exemple #24
0
        public static void SerializeCostHack(KSoft.IO.XmlElementStream s, FA mode, BXmlSerializerInterface xsi,
                                             Collections.BTypeValuesSingle list)
        {
            Contract.Requires(s != null);
            Contract.Requires(xsi != null);
            Contract.Requires(list != null);

            using (var xs =
#if NO_TLS_STREAMING
                       new BCostTypeValuesSingleAttrHackXmlSerializer(list)
#else
                       BDatabaseXmlSerializerBase.sBCostTypeValuesSingleAttrHackXmlSerializer.Value.Reset(list)
#endif
                   )
            {
                xs.StreamXml(s, mode, xsi);
            }
        }
Exemple #25
0
        protected virtual void ReadXmlNodes(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs)
        {
            ReadXmlDetermineListSize(s, xs);

            int x = 0;

            foreach (XmlNode n in s.Cursor.ChildNodes)
            {
                if (ReadXmlShouldSkipNode(n))
                {
                    continue;
                }

                using (s.EnterCursorBookmark(n as XmlElement))
                    ReadXml(s, xs, x++);
            }

            List.OptimizeStorage();
        }
Exemple #26
0
        public static void Serialize(KSoft.IO.XmlElementStream s, FA mode, BXmlSerializerInterface xsi,
                                     Collections.BBitSet bits, BBitSetXmlParams @params)
        {
            Contract.Requires(s != null);
            Contract.Requires(xsi != null);
            Contract.Requires(bits != null);
            Contract.Requires(@params != null);

            using (var xs =
#if NO_TLS_STREAMING
                       new BBitSetXmlSerializer(@params, bits)
#else
                       BDatabaseXmlSerializerBase.sBBitSetXmlSerializer.Value.Reset(@params, bits)
#endif
                   )
            {
                xs.StreamXml(s, mode, xsi);
            }
        }
Exemple #27
0
        public static void Serialize(KSoft.IO.XmlElementStream s, FA mode, BXmlSerializerInterface xsi,
                                     Collections.BTypeValuesInt32 list, BTypeValuesXmlParams <int> @params)
        {
            Contract.Requires(s != null);
            Contract.Requires(xsi != null);
            Contract.Requires(list != null);
            Contract.Requires(@params != null);

            using (var xs =
#if NO_TLS_STREAMING
                       new BTypeValuesInt32XmlSerializer(@params, list)
#else
                       BDatabaseXmlSerializerBase.sBTypeValuesInt32XmlSerializer.Value.Reset(@params, list)
#endif
                   )
            {
                xs.StreamXml(s, mode, xsi);
            }
        }
Exemple #28
0
        protected override void ReadXmlNodes(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs)
        {
            var penum = mList.TypeValuesParams.kGetProtoEnumFromDB(xs.Database);

            foreach (XmlAttribute attr in s.Cursor.Attributes)
            {
                // The only attributes in this are actual member names so we don't waste time calling
                // penum.IsValidMemberName only to call GetMemberId when we can just compare id to -1
                int index = penum.GetMemberId(attr.Name);
                if (index == PhxLib.Util.kInvalidInt32)
                {
                    continue;
                }

                mList.InitializeItem(index);
                float value = PhxLib.Util.kInvalidSingle;
                s.ReadAttribute(attr.Name, ref value);
                mList[index] = value;
            }
        }
Exemple #29
0
        public static void Serialize <T>(KSoft.IO.XmlElementStream s, FA mode, BXmlSerializerInterface xsi,
                                         Collections.BListArray <T> list, BListXmlParams @params)
            where T : IO.IPhxXmlStreamable, new()
        {
            Contract.Requires(s != null);
            Contract.Requires(xsi != null);
            Contract.Requires(list != null);
            Contract.Requires(@params != null);

            using (var xs =
#if NO_TLS_STREAMING
                       new BListArrayXmlSerializer <T>(@params, list)
#else
                       BDatabaseXmlSerializerBase._BListArray <T> .sXmlSerializer.Value.Reset(@params, list)
#endif
                   )
            {
                xs.StreamXml(s, mode, xsi);
            }
        }
Exemple #30
0
        void WriteXmlNodes(KSoft.IO.XmlElementStream s, BXmlSerializerInterface xs)
        {
            if (Bits.EnabledCount == 0)
            {
                return;
            }

            Collections.IProtoEnum penum = GetProtoEnum(xs.Database);

            for (int x = 0; x < Bits.Count; x++)
            {
                if (Bits[x])
                {
                    using (s.EnterCursorBookmark(Params.ElementName))
                    {
                        string name = penum.GetMemberName(x);
                        Params.StreamDataName(s, FA.Write, ref name);
                    }
                }
            }
        }