//public OXmlPictureElement _Deserialize(BsonDocument document) //{ //} //public OXmlPictureElement _Deserialize(BsonReader bsonReader, IBsonSerializationOptions options) //{ // OXmlPictureElement element = new OXmlPictureElement(); // OXmlPictureDrawing pictureDrawing = new OXmlPictureDrawing(); // element.PictureDrawing = pictureDrawing; // OXmlPictureDrawingMode? drawingMode = null; // while (true) // { // BsonType bsonType = bsonReader.ReadBsonType(); // if (bsonType == BsonType.EndOfDocument) // break; // string name = bsonReader.ReadName(); // switch (name.ToLower()) // { // case "type": // if (bsonType != BsonType.String) // throw new PBException($"wrong type value {bsonType}"); // string type = bsonReader.ReadString(); // if (type.ToLower() != "picture") // throw new PBException($"invalid Type {type} when deserialize OXmlPictureElement"); // break; // case "file": // if (bsonType == BsonType.Null) // break; // if (bsonType != BsonType.String) // throw new PBException($"wrong File value {bsonType}"); // element.File = bsonReader.ReadString(); // break; // case "name": // if (bsonType == BsonType.Null) // break; // if (bsonType != BsonType.String) // throw new PBException($"wrong Name value {bsonType}"); // element.Name = bsonReader.ReadString(); // break; // case "description": // if (bsonType == BsonType.Null) // break; // if (bsonType != BsonType.String) // throw new PBException($"wrong Description value {bsonType}"); // element.Description = bsonReader.ReadString(); // break; // case "width": // if (bsonType == BsonType.Null) // break; // if (bsonType != BsonType.Int32) // throw new PBException($"wrong Width value {bsonType}"); // element.Width = bsonReader.ReadInt32(); // break; // case "height": // if (bsonType == BsonType.Null) // break; // if (bsonType != BsonType.Int32) // throw new PBException($"wrong Height value {bsonType}"); // element.Height = bsonReader.ReadInt32(); // break; // case "rotation": // if (bsonType == BsonType.Null) // break; // if (bsonType != BsonType.Int32) // throw new PBException($"wrong Rotation value {bsonType}"); // element.Rotation = bsonReader.ReadInt32(); // break; // case "horizontalflip": // if (bsonType == BsonType.Null) // break; // if (bsonType != BsonType.Boolean) // throw new PBException($"wrong HorizontalFlip value {bsonType}"); // element.HorizontalFlip = bsonReader.ReadBoolean(); // break; // case "verticalflip": // if (bsonType == BsonType.Null) // break; // if (bsonType != BsonType.Boolean) // throw new PBException($"wrong VerticalFlip value {bsonType}"); // element.VerticalFlip = bsonReader.ReadBoolean(); // break; // case "compressionstate": // if (bsonType == BsonType.Null) // break; // if (bsonType != BsonType.String) // throw new PBException($"wrong CompressionState value {bsonType}"); // element.CompressionState = bsonReader.ReadString().zParseEnum<A.BlipCompressionValues>(ignoreCase: true); // break; // case "presetshape": // if (bsonType == BsonType.Null) // break; // if (bsonType != BsonType.String) // throw new PBException($"wrong PresetShape value {bsonType}"); // element.PresetShape = bsonReader.ReadString().zParseEnum<A.ShapeTypeValues>(ignoreCase: true); // break; // //case "picturedrawing": // // if (bsonType == BsonType.Null) // // break; // // if (bsonType != BsonType.Document) // // throw new PBException($"wrong PictureDrawing value {bsonType}"); // // element.PictureDrawing = ReadPictureDrawing(bsonReader); // // break; // case "drawingmode": // if (bsonType == BsonType.Null) // break; // if (bsonType != BsonType.String) // throw new PBException($"wrong DrawingMode value {bsonType}"); // OXmlPictureDrawingMode drawingMode2 = bsonReader.ReadString().zParseEnum<OXmlPictureDrawingMode>(ignoreCase: true); // if (drawingMode != null && drawingMode != drawingMode2) // throw new PBException($"wrong DrawingMode {drawingMode2}"); // drawingMode = drawingMode2; // pictureDrawing.DrawingMode = drawingMode2; // break; // case "wraptype": // if (bsonType == BsonType.Null) // break; // if (bsonType != BsonType.String) // throw new PBException($"wrong WrapType value {bsonType}"); // element.WrapType = bsonReader.ReadString().zParseEnum<A.ShapeTypeValues>(ignoreCase: true); // break; // default: // throw new PBException($"unknow Text value \"{name}\""); // } // //OXmlInlinePictureDrawing // //OXmlAnchorPictureDrawing // } // return element; //} public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options) { if (_trace) { pb.Trace.WriteLine("OXmlPictureElementSerializer.Deserialize()"); } VerifyTypes(nominalType, actualType, typeof(OXmlPictureElement)); var bsonType = bsonReader.GetCurrentBsonType(); if (bsonType != BsonType.Document) { throw new PBException($"deserialize OXmlPictureElement, invalid BsonType {bsonType}."); } //bsonReader.ReadStartDocument(); //object value = _Deserialize(bsonReader, options); //bsonReader.ReadEndDocument(); //return value; //return _Deserialize(BsonSerializer.Deserialize<BsonDocument>(bsonReader)); return(OXmlPictureElementCreator.CreatePicture(BsonSerializer.Deserialize <BsonDocument>(bsonReader))); }
// public methods /// <summary> /// Deserializes an object from a BsonReader. /// </summary> /// <param name="bsonReader">The BsonReader.</param> /// <param name="nominalType">The nominal type of the object.</param> /// <param name="actualType">The actual type of the object.</param> /// <param name="options">The serialization options.</param> /// <returns>An object.</returns> // actualType ignored public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options) { if (_trace) { pb.Trace.WriteLine("OXmlElementSerializer.Deserialize()"); } var bsonType = bsonReader.GetCurrentBsonType(); if (bsonType == BsonType.Null) { bsonReader.ReadNull(); return(null); } else if (bsonType != BsonType.Document) { throw new PBException($"deserialize OXmlElement, invalid BsonType {bsonType}."); } bsonReader.ReadStartDocument(); string type = bsonReader.FindStringElement("Type"); OXmlElement value; switch (type.ToLower()) { case "line": value = new OXmlElement { Type = OXmlElementType.Line }; break; case "tabstop": value = new OXmlElement { Type = OXmlElementType.TabStop }; break; case "paragraph": //value = OXmlParagraphElementSerializer.Instance.Deserialize(bsonReader, typeof(OXmlParagraphElement), options); value = OXmlParagraphElementSerializer.Instance._Deserialize(bsonReader, options); break; case "break": value = OXmlBreakElementSerializer.Instance._Deserialize(bsonReader, options); break; case "text": value = OXmlTextElementSerializer.Instance._Deserialize(bsonReader, options); break; case "simplefield": value = OXmlSimpleFieldElementSerializer.Instance._Deserialize(bsonReader, options); break; case "docsection": value = OXmlDocSectionElementSerializer.Instance._Deserialize(bsonReader, options); break; case "docdefaultsrunproperties": value = OXmlDocDefaultsRunPropertiesElementSerializer.Instance._Deserialize(bsonReader, options); break; case "docdefaultsparagraphproperties": //value = new OXmlDocDefaultsParagraphPropertiesElement(); value = new OXmlElement { Type = OXmlElementType.DocDefaultsParagraphProperties }; break; case "openheader": value = OXmlOpenHeaderElementSerializer.Instance._Deserialize(bsonReader, options); break; case "closeheader": value = new OXmlElement { Type = OXmlElementType.CloseHeader }; break; case "openfooter": value = OXmlOpenFooterElementSerializer.Instance._Deserialize(bsonReader, options); break; case "closefooter": value = new OXmlElement { Type = OXmlElementType.CloseFooter }; break; case "style": value = OXmlStyleElementSerializer.Instance._Deserialize(bsonReader, options); break; case "picture": //value = OXmlPictureElementSerializer.Instance._Deserialize(bsonReader, options); value = OXmlPictureElementCreator.CreatePicture(zMongo.ReadBsonDocumentWOStartEnd(bsonReader)); break; default: throw new PBException($"deserialize OXmlElement, invalid Type {type}."); } bsonReader.ReadEndDocument(); return(value); //switch (bsonType) //{ // case BsonType.Array: return (ZValue)ZStringArraySerializer.Instance.Deserialize(bsonReader, typeof(ZStringArray), options); // //case BsonType.Binary: return (BsonValue)BsonBinaryDataSerializer.Instance.Deserialize(bsonReader, typeof(BsonBinaryData), options); // //case BsonType.Boolean: return (BsonValue)BsonBooleanSerializer.Instance.Deserialize(bsonReader, typeof(BsonBoolean), options); // //case BsonType.DateTime: return (BsonValue)BsonDateTimeSerializer.Instance.Deserialize(bsonReader, typeof(BsonDateTime), options); // //case BsonType.Document: return (BsonValue)BsonDocumentSerializer.Instance.Deserialize(bsonReader, typeof(BsonDocument), options); // //case BsonType.Double: return (BsonValue)BsonDoubleSerializer.Instance.Deserialize(bsonReader, typeof(BsonDouble), options); // case BsonType.Int32: return (ZValue)ZIntSerializer.Instance.Deserialize(bsonReader, typeof(ZInt), options); // //case BsonType.Int64: return (BsonValue)BsonInt64Serializer.Instance.Deserialize(bsonReader, typeof(BsonInt64), options); // //case BsonType.JavaScript: return (BsonValue)BsonJavaScriptSerializer.Instance.Deserialize(bsonReader, typeof(BsonJavaScript), options); // //case BsonType.JavaScriptWithScope: return (BsonValue)BsonJavaScriptWithScopeSerializer.Instance.Deserialize(bsonReader, typeof(BsonJavaScriptWithScope), options); // //case BsonType.MaxKey: return (BsonValue)BsonMaxKeySerializer.Instance.Deserialize(bsonReader, typeof(BsonMaxKey), options); // //case BsonType.MinKey: return (BsonValue)BsonMinKeySerializer.Instance.Deserialize(bsonReader, typeof(BsonMinKey), options); // //case BsonType.Null: return (BsonValue)BsonNullSerializer.Instance.Deserialize(bsonReader, typeof(BsonNull), options); // case BsonType.Document: // return ReadZValueFromBsonDocument(bsonReader); // case BsonType.Null: // bsonReader.ReadNull(); // return null; // //case BsonType.ObjectId: return (BsonValue)BsonObjectIdSerializer.Instance.Deserialize(bsonReader, typeof(BsonObjectId), options); // //case BsonType.RegularExpression: return (BsonValue)BsonRegularExpressionSerializer.Instance.Deserialize(bsonReader, typeof(BsonRegularExpression), options); // //case BsonType.String: return (BsonValue)BsonStringSerializer.Instance.Deserialize(bsonReader, typeof(BsonString), options); // case BsonType.String: return (ZValue)ZStringSerializer.Instance.Deserialize(bsonReader, typeof(ZString), options); // // ZStringSerializer // //case BsonType.Symbol: return (BsonValue)BsonSymbolSerializer.Instance.Deserialize(bsonReader, typeof(BsonSymbol), options); // //case BsonType.Timestamp: return (BsonValue)BsonTimestampSerializer.Instance.Deserialize(bsonReader, typeof(BsonTimestamp), options); // //case BsonType.Undefined: return (BsonValue)BsonUndefinedSerializer.Instance.Deserialize(bsonReader, typeof(BsonUndefined), options); // default: // //var message = string.Format("Invalid BsonType {0}.", bsonType); // //throw new BsonInternalException(message); // throw new PBException("error deserialize ZValue, invalid BsonType {0}.", bsonType); //} }