Class DataDocConverter
Provides methods for Doc to/from BSONDocument conversion
Inheritance
System.Object
DataDocConverter
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Assembly: Azos.dll
Syntax
public class DataDocConverter : IConfigurable
Constructors
DataDocConverter()
Declaration
public DataDocConverter()
Fields
DECIMAL_LONG_MUL
Declaration
public const decimal DECIMAL_LONG_MUL = 1000M
Field Value
Type |
Description |
System.Decimal |
|
m_BSONtoCLR
Declaration
protected Dictionary<Type, Func<BSONElement, object>> m_BSONtoCLR
Field Value
Type |
Description |
System.Collections.Generic.Dictionary<System.Type, System.Func<BSONElement, System.Object>> |
|
m_CLRtoBSON
Declaration
protected Dictionary<Type, Func<string, object, BSONElement>> m_CLRtoBSON
Field Value
Type |
Description |
System.Collections.Generic.Dictionary<System.Type, System.Func<System.String, System.Object, BSONElement>> |
|
MAX_BYTE_BUFFER_SIZE
Maximum size of a byte[] field.
Large filed (> 12Mbyte) should not be stored as fields in the database
Declaration
public const int MAX_BYTE_BUFFER_SIZE = 12582912
Field Value
Type |
Description |
System.Int32 |
|
MAX_DECIMAL
Declaration
public const decimal MAX_DECIMAL = 9223372036854775.807M
Field Value
Type |
Description |
System.Decimal |
|
MIN_DECIMAL
Declaration
public const decimal MIN_DECIMAL = -9223372036854775.808M
Field Value
Type |
Description |
System.Decimal |
|
s_BSONtoCLR
Declaration
protected static Dictionary<Type, Func<BSONElement, object>> s_BSONtoCLR
Field Value
Type |
Description |
System.Collections.Generic.Dictionary<System.Type, System.Func<BSONElement, System.Object>> |
|
s_CLRtoBSON
Declaration
protected static Dictionary<Type, Func<string, object, BSONElement>> s_CLRtoBSON
Field Value
Type |
Description |
System.Collections.Generic.Dictionary<System.Type, System.Func<System.String, System.Object, BSONElement>> |
|
Properties
DefaultInstance
Returns the default instance
Declaration
public static DataDocConverter DefaultInstance { get; }
Property Value
Methods
Amount_BSONtoCLR(BSONDocumentElement)
Declaration
public static Amount Amount_BSONtoCLR(BSONDocumentElement el)
Parameters
Returns
Amount_CLRtoBSON(String, Amount)
Declaration
public static BSONDocumentElement Amount_CLRtoBSON(string name, Amount amount)
Parameters
Type |
Name |
Description |
System.String |
name |
|
Amount |
amount |
|
Returns
BSONDocumentToDataDoc(BSONDocument, Doc, String, Boolean, Func<BSONDocument, BSONElement, Boolean>)
Converts BSON document into data document by filling the supplied doc instance making necessary type transforms to
suit Doc.Schema field definitions per target name. If the passed data document supports IAmorphousData, then
the fields either not found in row, or the fields that could not be type-converted to CLR type will be
stowed in amorphous data dictionary
Declaration
public virtual void BSONDocumentToDataDoc(BSONDocument bsonDoc, Doc dataDoc, string targetName, bool useAmorphousData = true, Func<BSONDocument, BSONElement, bool> filter = null)
Parameters
BSONDocumentToJSONMap(BSONDocument, Func<BSONDocument, BSONElement, Boolean>)
Converts BSON document to JSON data map by directly mapping
BSON types into corresponding CLR types. The sub-documents get mapped into JSONDataObjects,
and BSON arrays get mapped into CLR object[]
Declaration
public virtual JSONDataMap BSONDocumentToJSONMap(BSONDocument doc, Func<BSONDocument, BSONElement, bool> filter = null)
Parameters
Returns
ByteBuffer_CLRtoBSON(String, Byte[])
Declaration
public static BSONElement ByteBuffer_CLRtoBSON(string name, byte[] buf)
Parameters
Type |
Name |
Description |
System.String |
name |
|
System.Byte[] |
buf |
|
Returns
ByteBufferID_CLRtoBSON(String, Byte[])
Encodes byte buffer purposed for id, using proper binary subtype
Declaration
public static BSONElement ByteBufferID_CLRtoBSON(string name, byte[] buf)
Parameters
Type |
Name |
Description |
System.String |
name |
|
System.Byte[] |
buf |
|
Returns
Declaration
public virtual void Configure(IConfigSectionNode node)
Parameters
ConvertCLRtoBSON(String, Object, String)
Converts CLR value to BSON. The following values are supported:
primitives+scaled decimal, enums, TypedRows, GDID, Guid, Amount, IDictionary, IEnumerable (including arrays).
If conversion could not be made then exception is thrown
Declaration
public BSONElement ConvertCLRtoBSON(string fieldName, object data, string targetName)
Parameters
Type |
Name |
Description |
System.String |
fieldName |
|
System.Object |
data |
|
System.String |
targetName |
|
Returns
DataDocToBSONDocument(Doc, String, Boolean, FieldFilterFunc)
Converts row to BSON document suitable for storage in MONGO.DB.
Pass target name (name of particular store/epoch/implementation) to get targeted field metadata.
Note: the supplied row MAY NOT CONTAIN REFERENCE CYCLES - either direct or transitive
Declaration
public virtual BSONDocument DataDocToBSONDocument(Doc doc, string targetName, bool useAmorphousData = true, FieldFilterFunc filter = null)
Parameters
Type |
Name |
Description |
Doc |
doc |
|
System.String |
targetName |
|
System.Boolean |
useAmorphousData |
|
FieldFilterFunc |
filter |
|
Returns
DataDocToBSONDocumentElement(Doc, String, Boolean, String, FieldFilterFunc)
Converts row to BSON document suitable for storage in MONGO.DB.
Pass target name (name of particular store/epoch/implementation) to get targeted field metadata.
Note: the supplied row MAY NOT CONTAIN REFERENCE CYCLES - either direct or transitive
Declaration
public virtual BSONDocumentElement DataDocToBSONDocumentElement(Doc doc, string targetName, bool useAmorphousData = true, string name = null, FieldFilterFunc filter = null)
Parameters
Type |
Name |
Description |
Doc |
doc |
|
System.String |
targetName |
|
System.Boolean |
useAmorphousData |
|
System.String |
name |
|
FieldFilterFunc |
filter |
|
Returns
Decimal_BSONtoCLR(BSONElement)
Declaration
public static decimal Decimal_BSONtoCLR(BSONElement el)
Parameters
Returns
Type |
Description |
System.Decimal |
|
Decimal_BSONtoCLR(BSONInt32Element)
Declaration
public static decimal Decimal_BSONtoCLR(BSONInt32Element el)
Parameters
Returns
Type |
Description |
System.Decimal |
|
Decimal_BSONtoCLR(BSONInt64Element)
Declaration
public static decimal Decimal_BSONtoCLR(BSONInt64Element el)
Parameters
Returns
Type |
Description |
System.Decimal |
|
Decimal_CLRtoBSON(String, Decimal)
Declaration
public static BSONInt64Element Decimal_CLRtoBSON(string name, decimal v)
Parameters
Type |
Name |
Description |
System.String |
name |
|
System.Decimal |
v |
|
Returns
DirectConvertBSONValue(BSONElement, Func<BSONDocument, BSONElement, Boolean>)
Converts BSON to CLR value 1:1, without type change
Declaration
protected virtual object DirectConvertBSONValue(BSONElement element, Func<BSONDocument, BSONElement, bool> filter = null)
Parameters
Returns
Type |
Description |
System.Object |
|
DoConvertCLRtoBSON(String, Object, Type, String)
override to perform the conversion. the data is never null here, and ref cycles a ruled out
Declaration
protected virtual BSONElement DoConvertCLRtoBSON(string name, object data, Type dataType, string targetName)
Parameters
Type |
Name |
Description |
System.String |
name |
|
System.Object |
data |
|
System.Type |
dataType |
|
System.String |
targetName |
|
Returns
GDID_BSONtoCLR(BSONBinaryElement)
Declaration
public static GDID GDID_BSONtoCLR(BSONBinaryElement el)
Parameters
Returns
GDID_CLRtoBSON(String, GDID)
Declaration
public static BSONElement GDID_CLRtoBSON(string name, GDID gdid)
Parameters
Type |
Name |
Description |
System.String |
name |
|
GDID |
gdid |
|
Returns
GDID_CLRtoBSONBinary(GDID)
Declaration
public static BSONBinary GDID_CLRtoBSONBinary(GDID gdid)
Parameters
Type |
Name |
Description |
GDID |
gdid |
|
Returns
GetAmorphousFieldAsBSON(KeyValuePair<String, Object>, String)
Declaration
protected virtual BSONElement GetAmorphousFieldAsBSON(KeyValuePair<string, object> field, string targetName)
Parameters
Type |
Name |
Description |
System.Collections.Generic.KeyValuePair<System.String, System.Object> |
field |
|
System.String |
targetName |
|
Returns
GetFieldAsBSON(Doc, Schema.FieldDef, String)
Declaration
protected virtual BSONElement GetFieldAsBSON(Doc doc, Schema.FieldDef field, string targetName)
Parameters
Returns
GUID_BSONtoCLR(BSONBinaryElement)
Declaration
public static Guid GUID_BSONtoCLR(BSONBinaryElement el)
Parameters
Returns
Type |
Description |
System.Guid |
|
GUID_CLRtoBSON(String, Guid)
Declaration
public static BSONElement GUID_CLRtoBSON(string name, Guid guid)
Parameters
Type |
Name |
Description |
System.String |
name |
|
System.Guid |
guid |
|
Returns
InferSchemaFromBSONDocument(BSONDocument, String)
Makes CRUD Schema out of BSON document. The types of all fields are object as documents do not have
a predictable type of every field (they are dynamic and can change form doc to doc)
Declaration
public virtual Schema InferSchemaFromBSONDocument(BSONDocument doc, string schemaName = null)
Parameters
Type |
Name |
Description |
BSONDocument |
doc |
|
System.String |
schemaName |
|
Returns
MapBSONFieldNameToSchemaFieldDef(Schema, String, String)
Maps bsonFieldName to targeted fieldDef from specified schema using cache for TypedRows
Declaration
protected static Schema.FieldDef MapBSONFieldNameToSchemaFieldDef(Schema schema, string targetName, string bsonFieldName)
Parameters
Type |
Name |
Description |
Schema |
schema |
|
System.String |
targetName |
|
System.String |
bsonFieldName |
|
Returns
SetAmorphousFieldAsCLR(IAmorphousData, BSONElement, String, Func<BSONDocument, BSONElement, Boolean>)
Declaration
protected virtual bool SetAmorphousFieldAsCLR(IAmorphousData amorph, BSONElement bsonElement, string targetName, Func<BSONDocument, BSONElement, bool> filter)
Parameters
Returns
Type |
Description |
System.Boolean |
|
String_CLRtoBSON(String, String)
Declaration
public static BSONElement String_CLRtoBSON(string name, string str)
Parameters
Type |
Name |
Description |
System.String |
name |
|
System.String |
str |
|
Returns
TryConvertBSONtoCLR(Type, BSONElement, String, out Object, Func<BSONDocument, BSONElement, Boolean>)
Tries to convert the BSON value into target CLR type. Returns true if conversion was successfull
Declaration
protected virtual bool TryConvertBSONtoCLR(Type target, BSONElement element, string targetName, out object clrValue, Func<BSONDocument, BSONElement, bool> filter)
Parameters
Type |
Name |
Description |
System.Type |
target |
|
BSONElement |
element |
|
System.String |
targetName |
|
System.Object |
clrValue |
|
System.Func<BSONDocument, BSONElement, System.Boolean> |
filter |
|
Returns
Type |
Description |
System.Boolean |
|
TrySetFieldAsCLR(Doc, Schema.FieldDef, BSONElement, String, Func<BSONDocument, BSONElement, Boolean>)
Declaration
protected virtual bool TrySetFieldAsCLR(Doc doc, Schema.FieldDef field, BSONElement value, string targetName, Func<BSONDocument, BSONElement, bool> filter)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Implements
Extension Methods