Esempio n. 1
0
        /// <summary>
        /// Serialize this entity's live data to a binary stream
        /// </summary>
        /// <returns>the binary stream</returns>
        public override byte[] Serialize()
        {
            var settings = new XmlWriterSettings {
                OmitXmlDeclaration = true, Encoding = Encoding.UTF8
            };
            var charData = (IRoomData)DataTemplate;

            var entityData = new XDocument(
                new XElement("root",
                             new XAttribute("formattingVersion", liveDataVersion),
                             new XAttribute("Birthmark", BirthMark),
                             new XAttribute("Birthdate", Birthdate),
                             new XElement("BackingData",
                                          new XAttribute("ID", charData.ID),
                                          new XAttribute("Name", charData.Name),
                                          new XAttribute("Medium", charData.Medium.ID),
                                          new XAttribute("Zone", charData.ZoneAffiliation.ID),
                                          new XAttribute("LastRevised", charData.LastRevised),
                                          new XAttribute("Created", charData.Created),
                                          new XElement("Borders", charData.SerializeBorders())),
                             new XElement("LiveData",
                                          new XAttribute("Keywords", string.Join(",", Keywords)),
                                          new XElement("DimensionalModel",
                                                       new XAttribute("Length", Model.Length),
                                                       new XAttribute("Height", Model.Height),
                                                       new XAttribute("Width", Model.Width))),
                             new XElement("ObjectsInRoom"),
                             new XElement("MobilesInside")
                             ));

            foreach (var item in ObjectsInRoom.EntitiesContained())
            {
                entityData.Root.Element("ObjectsInRoom").Add(new XElement("Item", item.BirthMark));
            }

            foreach (var item in MobilesInside.EntitiesContained().Where(ent => ent.GetType() != typeof(Player)))
            {
                entityData.Root.Element("MobilesInside").Add(new XElement("Item", item.BirthMark));
            }

            //pathways will load themselves

            var entityBinaryConvert = new DataUtility.EntityFileData(entityData);

            using (var memoryStream = new MemoryStream())
                using (var xmlWriter = XmlWriter.Create(memoryStream, settings))
                {
                    entityData.WriteTo(xmlWriter);
                    xmlWriter.Flush();
                    entityBinaryConvert.XmlBinary = memoryStream.ToArray();
                }

            return(entityBinaryConvert.XmlBinary);
        }
Esempio n. 2
0
        /// <summary>
        /// Get all of the entities matching a type inside this
        /// </summary>
        /// <typeparam name="T">the type</typeparam>
        /// <returns>the contained entities</returns>
        public IEnumerable <T> GetContents <T>()
        {
            var implimentedTypes = DataUtility.GetAllImplimentingedTypes(typeof(T));

            var contents = new List <T>();

            if (implimentedTypes.Contains(typeof(IMobile)))
            {
                contents.AddRange(MobilesInside.EntitiesContained().Select(ent => (T)ent));
            }

            if (implimentedTypes.Contains(typeof(IInanimate)))
            {
                contents.AddRange(ObjectsInRoom.EntitiesContained().Select(ent => (T)ent));
            }

            if (implimentedTypes.Contains(typeof(IPathway)))
            {
                contents.AddRange(Pathways.EntitiesContained().Select(ent => (T)ent));
            }

            return(contents);
        }