/// <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 backingData = new PathwayData(); var newEntity = new Pathway(); var versionFormat = xDoc.Root.GetSafeAttributeValue <int>("formattingVersion"); newEntity.BirthMark = xDoc.Root.GetSafeAttributeValue("Birthmark"); newEntity.Birthdate = xDoc.Root.GetSafeAttributeValue <DateTime>("Birthdate"); 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"); backingData.DegreesFromNorth = xDoc.Root.Element("BackingData").GetSafeAttributeValue <int>("DegreesFromNorth"); backingData.ToLocationID = xDoc.Root.Element("BackingData").GetSafeAttributeValue("ToLocationID"); backingData.ToLocationType = xDoc.Root.Element("BackingData").GetSafeAttributeValue("ToLocationType"); backingData.FromLocationID = xDoc.Root.Element("BackingData").GetSafeAttributeValue("FromLocationID"); backingData.FromLocationType = xDoc.Root.Element("BackingData").GetSafeAttributeValue("FromLocationType"); backingData.MessageToActor = xDoc.Root.Element("BackingData").GetSafeAttributeValue("MessageToActor"); backingData.MessageToOrigin = xDoc.Root.Element("BackingData").GetSafeAttributeValue("MessageToOrigin"); backingData.MessageToDestination = xDoc.Root.Element("BackingData").GetSafeAttributeValue("MessageToDestination"); backingData.AudibleToSurroundings = xDoc.Root.Element("BackingData").GetSafeAttributeValue("AudibleToSurroundings"); backingData.AudibleStrength = xDoc.Root.Element("BackingData").GetSafeAttributeValue <int>("AudibleStrength"); backingData.VisibleToSurroundings = xDoc.Root.Element("BackingData").GetSafeAttributeValue("VisibleToSurroundings"); backingData.VisibleStrength = xDoc.Root.Element("BackingData").GetSafeAttributeValue <int>("VisibleStrength"); var obj = new Room(); obj.BirthMark = xDoc.Root.Element("LiveData").GetSafeAttributeValue("RoomFrom"); newEntity.FromLocation = obj; var toObj = new Room(); toObj.BirthMark = xDoc.Root.Element("LiveData").GetSafeAttributeValue("RoomTo"); newEntity.ToLocation = toObj; //keywords is last newEntity.Keywords = xDoc.Root.Element("LiveData").GetSafeAttributeValue("Keywords").Split(new char[] { ',' }); //Add new version transformations here, they are meant to be iterative, hence < 1 Transform_V1(backingData, newEntity, xDoc.Root, versionFormat < 1); newEntity.DataTemplate = backingData; return(newEntity); }
private void Transform_V1(PathwayData backingData, Pathway 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 <PathwayData>(backingData.ID); backingData.Model = backD.Model; newEntity.Model = backD.Model; } }