예제 #1
0
        void StreamConditions <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s)
            where TDoc : class
            where TCursor : class
        {
            var k_AND_params = BTriggerCondition.kBListXmlParams_And;

            if (s.IsReading)
            {
                if (OrConditions = !s.ElementsExists(k_AND_params.RootName))
                {
                    XML.XmlUtil.Serialize(s, Conditions, BTriggerCondition.kBListXmlParams_Or);
                }
                else
                {
                    XML.XmlUtil.Serialize(s, Conditions, k_AND_params);
                }
            }
            else if (s.IsWriting)
            {
                // Even if there are no conditions, the runtime expects there to be an empty And tag :|
                // Well, technically we could use an empty Or tag as well, but it wouldn't be consistent
                // with the engine. The runtime will assume the the TS is bad if neither tag is present
                if (Conditions.Count == 0)
                {
                    s.WriteElement(k_AND_params.RootName);
                }
                else
                {
                    XML.XmlUtil.Serialize(s, Conditions,
                                          OrConditions ? BTriggerCondition.kBListXmlParams_Or : k_AND_params);
                }
            }
        }
예제 #2
0
        public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s)
            where TDoc : class
            where TCursor : class
        {
            bool   should_stream = true;
            string root_name     = Params.GetOptionalRootName();
            var    xs            = s.GetSerializerInterface();

            if (s.IsReading)             // If the stream doesn't have the expected element, don't try to stream
            {
                should_stream = root_name == null || s.ElementsExists(root_name);
            }
            else if (s.IsWriting)
            {
                should_stream = List != null && List.IsEmpty == false;
            }

            if (should_stream)
            {
                using (s.EnterCursorBookmark(root_name))
                {
                    if (s.IsReading)
                    {
                        ReadNodes(s, xs);
                    }
                    else if (s.IsWriting)
                    {
                        WriteNodes(s, xs);
                    }
                }
            }
        }