Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Versioning_Engine: Add BHoM version in serialisation #2434

Merged
merged 3 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Serialiser_Engine/Compute/RegisterClassMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void RegisterClassMap(Type type)
cm.AutoMap();
cm.SetDiscriminator(type.FullName);
cm.SetDiscriminatorIsRequired(true);
cm.SetIgnoreExtraElements(false); // It would have been nice to use cm.MapExtraElementsProperty("CustomData") but it doesn't work for inherited properties
cm.SetIgnoreExtraElements(true); // It would have been nice to use cm.MapExtraElementsProperty("CustomData") but it doesn't work for inherited properties
cm.SetIdMember(null);

BsonClassMap.RegisterClassMap(cm);
Expand Down
1 change: 0 additions & 1 deletion Serialiser_Engine/Convert/Bson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public static object FromBson(BsonDocument bson)
return bson["_v"].AsString;

bson.Remove("_id");
bson.RemoveVersion();

object obj = BsonSerializer.Deserialize(bson, typeof(object));
if (obj is ExpandoObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public override Color Deserialize(BsonDeserializationContext context, BsonDeseri
int g = context.Reader.ReadInt32();
int b = context.Reader.ReadInt32();

string version = "";
if (context.Reader.FindElement("_bhomVersion"))
version = context.Reader.ReadString();

context.Reader.ReadEndDocument();

return Color.FromArgb(a, r, g, b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public override CustomObject Deserialize(BsonDeserializationContext context, Bso
dic["CustomData"] = value;
}
break;
case "_bhomVersion":
break;
default:
dic[name] = value;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public override IDictionary Deserialize(BsonDeserializationContext context, Bson
dic.Add(key, value);
}
bsonReader.ReadEndArray();

string version = "";
if (bsonReader.FindElement("_bhomVersion"))
version = bsonReader.ReadString();

bsonReader.ReadEndDocument();

return dic;
Expand Down
4 changes: 4 additions & 0 deletions Serialiser_Engine/Objects/BsonSerializers/EnumSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public override Enum Deserialize(BsonDeserializationContext context, BsonDeseria
bsonReader.ReadName();
string valueName = bsonReader.ReadString();

string version = "";
if (bsonReader.FindElement("_bhomVersion"))
version = bsonReader.ReadString();

context.Reader.ReadEndDocument();

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ private object DeserializeDiscriminatedValue(BsonDeserializationContext context,
// Handle the general case of finding the correct deserialiser and calling it
try
{
if (!BsonClassMap.IsClassMapRegistered(actualType))
Compute.RegisterClassMap(actualType); // LookupSerializer creates the classMap if it doesn't exist so important to do it through our own method

IBsonSerializer bsonSerializer = BsonSerializer.LookupSerializer(actualType);

if (bsonSerializer.GetType().Name == "EnumerableInterfaceImplementerSerializer`2" && context.Reader.CurrentBsonType == BsonType.Document)
Expand Down
10 changes: 4 additions & 6 deletions Versioning_Engine/Modify/AddVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,19 @@ public static partial class Modify

public static void AddVersion(this BsonDocument document)
{
// TODO: Uncomment this code after producing the 4.1 beta
/*if (document != null)
document["_bhomVersion"] = Reflection.Query.BHoMVersion();*/
if (document != null)
document["_bhomVersion"] = Reflection.Query.BHoMVersion();
}

/***************************************************/

public static void AddVersion(this IBsonWriter writer)
{
// TODO: Uncomment this code after producing the 4.1 beta
/*if (writer != null)
if (writer != null)
{
writer.WriteName("_bhomVersion");
writer.WriteString(Reflection.Query.BHoMVersion());
}*/
}
}

/***************************************************/
Expand Down