Example #1
0
        public string GetName(HPBarDataObjectKind kind, int id)
        {
            Contract.Requires <ArgumentOutOfRangeException>(kind != HPBarDataObjectKind.None);

            IProtoDataObjectDatabaseProvider provider = HPBars;

            return(provider.GetName((int)kind, id));
        }
Example #2
0
        internal bool StreamID <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, string xmlName, ref int dbid,
                                               TacticDataObjectKind kind,
                                               bool isOptional = true, IO.TagElementNodeType xmlSource = XML.XmlUtil.kSourceElement)
            where TDoc : class
            where TCursor : class
        {
            Contract.Requires(xmlSource.RequiresName() == (xmlName != XML.XmlUtil.kNoXmlName));
            Contract.Requires(kind != TacticDataObjectKind.None);

            string id_name      = null;
            bool   was_streamed = true;
            bool   to_lower     = false;

            if (s.IsReading)
            {
                if (isOptional)
                {
                    was_streamed = s.StreamStringOpt(xmlName, ref id_name, to_lower, xmlSource, intern: true);
                }
                else
                {
                    s.StreamString(xmlName, ref id_name, to_lower, xmlSource, intern: true);
                }

                if (was_streamed)
                {
                    IProtoDataObjectDatabaseProvider provider = this;
                    dbid = provider.GetId((int)kind, id_name);
                    Contract.Assert(dbid.IsNotNone());
                }
                else
                {
                    dbid = TypeExtensions.kNone;
                }
            }
            else if (s.IsWriting && dbid.IsNotNone())
            {
                IProtoDataObjectDatabaseProvider provider = this;
                id_name = provider.GetName((int)kind, dbid);
                Contract.Assert(!string.IsNullOrEmpty(id_name));

                if (isOptional)
                {
                    s.StreamStringOpt(xmlName, ref id_name, to_lower, xmlSource, intern: true);
                }
                else
                {
                    s.StreamString(xmlName, ref id_name, to_lower, xmlSource, intern: true);
                }
            }

            return(was_streamed);
        }
        public ProtoDataObjectDatabase(IProtoDataObjectDatabaseProvider provider, Type objectKindEnum)
        {
            Provider       = provider;
            ObjectKindEnum = objectKindEnum;

            foreach (object e in Enum.GetValues(ObjectKindEnum))
            {
                ObjectKinds.Add(e);
            }

            ObjectKindIds.AddRange(ObjectKinds.Cast <int>());

            ObjectSourceKind = GetSourceKind();
        }