示例#1
0
        private void Transform_V1(InanimateData backingData, Inanimate newEntity, XElement docRoot, bool older)
        {
            if (!older)
            {
                //We added dim mods in v1
                var dimModelId       = docRoot.Element("LiveData").Element("DimensionalModel").GetSafeAttributeValue <long>("ID");
                var dimModelLength   = docRoot.Element("LiveData").Element("DimensionalModel").GetSafeAttributeValue <int>("Length");
                var dimModelHeight   = docRoot.Element("LiveData").Element("DimensionalModel").GetSafeAttributeValue <int>("Height");
                var dimModelWidth    = docRoot.Element("LiveData").Element("DimensionalModel").GetSafeAttributeValue <int>("Width");
                var dimModelJson     = docRoot.Element("LiveData").Element("DimensionalModel").GetSafeElementValue("ModellingData");
                var dimModelCompJson = docRoot.Element("LiveData").Element("DimensionalModel").GetSafeElementValue("MaterialCompositions");

                backingData.Model = new DimensionalModel(dimModelLength, dimModelHeight, dimModelWidth, dimModelId, dimModelCompJson);
                newEntity.Model   = new DimensionalModel(dimModelLength, dimModelHeight, dimModelWidth, dimModelJson, dimModelId, dimModelCompJson);
            }
            else //what if we're older
            {
                //Get it from the db
                var backD = DataWrapper.GetOne <InanimateData>(backingData.ID);
                backingData.Model = backD.Model;
                newEntity.Model   = backD.Model;
            }
        }
示例#2
0
        /// <summary>
        /// Deserialize binary stream to this entity
        /// </summary>
        /// <param name="bytes">the binary to turn into an entity</param>
        /// <returns>the entity</returns>
        public override IEntity DeSerialize(byte[] bytes)
        {
            var entityBinaryConvert = new DataUtility.EntityFileData(bytes);
            var xDoc = entityBinaryConvert.XDoc;

            var newEntity = new Inanimate();

            var versionFormat = xDoc.Root.GetSafeAttributeValue <int>("formattingVersion");

            newEntity.BirthMark = xDoc.Root.GetSafeAttributeValue("Birthmark");
            newEntity.Birthdate = xDoc.Root.GetSafeAttributeValue <DateTime>("Birthdate");

            var internalCompositions = xDoc.Root.Element("BackingData").GetSafeAttributeValue("InternalComposition");
            var backingData          = new InanimateData(internalCompositions);

            backingData.ID          = xDoc.Root.Element("BackingData").GetSafeAttributeValue <long>("ID");
            backingData.Name        = xDoc.Root.Element("BackingData").GetSafeAttributeValue("Name");
            backingData.LastRevised = xDoc.Root.Element("BackingData").GetSafeAttributeValue <DateTime>("LastRevised");
            backingData.Created     = xDoc.Root.Element("BackingData").GetSafeAttributeValue <DateTime>("Created");

            foreach (var item in xDoc.Root.Element("BackingData").Element("InanimateContainers").Elements("Item"))
            {
                var newContainer = new EntityContainerData <IInanimate>();
                newContainer.CapacityVolume = item.GetSafeAttributeValue <long>("CapacityVolume");
                newContainer.CapacityWeight = item.GetSafeAttributeValue <long>("CapacityWeight");
                newContainer.Name           = item.GetSafeAttributeValue("Name");

                backingData.InanimateContainers.Add(newContainer);
            }

            //Add a fake entity to get the birthmark over to the next place
            foreach (var item in xDoc.Root.Element("BackingData").Element("MobileContainers").Elements("Item"))
            {
                var newContainer = new EntityContainerData <IMobile>();
                newContainer.CapacityVolume = item.GetSafeAttributeValue <long>("CapacityVolume");
                newContainer.CapacityWeight = item.GetSafeAttributeValue <long>("CapacityWeight");
                newContainer.Name           = item.GetSafeAttributeValue("Name");

                backingData.MobileContainers.Add(newContainer);
            }

            //Add a fake entity to get the birthmark over to the next place
            foreach (var item in xDoc.Root.Element("MobilesInside").Elements("Item"))
            {
                var obj = new Intelligence();
                obj.BirthMark = item.GetSafeAttributeValue("Birthmark");
                var containerName = item.GetSafeAttributeValue("Container");

                if (!String.IsNullOrWhiteSpace(containerName))
                {
                    newEntity.MobilesInside.Add(obj, containerName);
                }
                else
                {
                    newEntity.MobilesInside.Add(obj);
                }
            }


            //Add a fake entity to get the birthmark over to the next place
            foreach (var item in xDoc.Root.Element("Contents").Elements("Item"))
            {
                var obj = new Inanimate();
                obj.BirthMark = item.GetSafeAttributeValue("Birthmark");
                var containerName = item.GetSafeAttributeValue("Container");

                if (!String.IsNullOrWhiteSpace(containerName))
                {
                    newEntity.Contents.Add(obj, containerName);
                }
                else
                {
                    newEntity.Contents.Add(obj);
                }
            }

            //Add new version transformations here, they are meant to be iterative, hence < 1
            Transform_V1(backingData, newEntity, xDoc.Root, versionFormat < 1);

            newEntity.DataTemplate = backingData;

            //keywords is last
            newEntity.Keywords = xDoc.Root.Element("LiveData").Attribute("Keywords").Value.Split(new char[] { ',' });

            return(newEntity);
        }