|
@@ -660,53 +660,17 @@ namespace InABox.Core
|
|
|
DatabaseSchema.Properties(type)
|
|
|
.Where(x => !(x is StandardProperty st) || IsSerializable(type,st));
|
|
|
|
|
|
- private static void GetOriginalValues(BaseObject obj, string? parent, List<Tuple<Type, string, object?>> values)
|
|
|
+ private static void WriteOriginalValues<TObject>(this CoreBinaryWriter writer, TObject obj)
|
|
|
+ where TObject : BaseObject
|
|
|
{
|
|
|
- parent = parent != null ? $"{parent}." : "";
|
|
|
-
|
|
|
+ var originalValues = new List<Tuple<Type, string, object?>>();
|
|
|
foreach (var (key, value) in obj.OriginalValues)
|
|
|
{
|
|
|
- // EnclosedEntities and EntityLinks will be updated through the recursive code below,
|
|
|
- // so we should not need to serialise the entire object again..
|
|
|
- if (DatabaseSchema.Property(obj.GetType(), key) is IProperty prop
|
|
|
- && !prop.PropertyType.GetInterfaces().Contains(typeof(IEnclosedEntity))
|
|
|
- && !prop.PropertyType.GetInterfaces().Contains(typeof(IEntityLink))
|
|
|
- )
|
|
|
- {
|
|
|
- values.Add(new Tuple<Type, string, object?>(prop.PropertyType, parent + key, value));
|
|
|
- }
|
|
|
- }
|
|
|
- var props = obj.GetType().GetProperties().Where(x =>
|
|
|
- x.GetCustomAttribute<DoNotSerialize>() == null
|
|
|
- && x.GetCustomAttribute<DoNotPersist>() == null
|
|
|
- && x.GetCustomAttribute<AggregateAttribute>() == null
|
|
|
- && x.GetCustomAttribute<FormulaAttribute>() == null
|
|
|
- && x.GetCustomAttribute<ConditionAttribute>() == null
|
|
|
- && x.GetCustomAttribute<ComplexFormulaAttribute>() == null
|
|
|
- && x.GetCustomAttribute<ChildEntityAttribute>() == null
|
|
|
- && x.CanWrite);
|
|
|
- foreach (var prop in props)
|
|
|
- {
|
|
|
- if (prop.PropertyType.GetInterfaces().Contains(typeof(IEnclosedEntity)))
|
|
|
- {
|
|
|
- if (prop.GetValue(obj) is BaseObject child)
|
|
|
- GetOriginalValues(child, parent + prop.Name, values);
|
|
|
- }
|
|
|
- else if (prop.PropertyType.GetInterfaces().Contains(typeof(IEntityLink)))
|
|
|
+ if (DatabaseSchema.Property(obj.GetType(), key) is IProperty prop)
|
|
|
{
|
|
|
- if (prop.GetValue(obj) is BaseObject child && child.HasOriginalValue("ID"))
|
|
|
- {
|
|
|
- values.Add(new Tuple<Type, string, object?>(typeof(Guid), parent + prop.Name + ".ID", child.OriginalValues["ID"]));
|
|
|
- }
|
|
|
+ originalValues.Add(new Tuple<Type, string, object?>(prop.PropertyType, key, value));
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- private static void WriteOriginalValues<TObject>(this CoreBinaryWriter writer, TObject obj)
|
|
|
- where TObject : BaseObject
|
|
|
- {
|
|
|
- var originalValues = new List<Tuple<Type, string, object?>>();
|
|
|
- GetOriginalValues(obj, null, originalValues);
|
|
|
|
|
|
writer.Write(originalValues.Count);
|
|
|
foreach (var (type, key, value) in originalValues)
|
|
@@ -718,7 +682,7 @@ namespace InABox.Core
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
-
|
|
|
+ CoreUtils.LogException("", e, "Error serialising OriginalValues");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -732,17 +696,7 @@ namespace InABox.Core
|
|
|
if (DatabaseSchema.Property(obj.GetType(), key) is IProperty prop)
|
|
|
{
|
|
|
var value = reader.ReadBinaryValue(prop.PropertyType);
|
|
|
- if (prop.Parent is null)
|
|
|
- {
|
|
|
- obj.OriginalValues[prop.Name] = value;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (prop.Parent.Getter()(obj) is BaseObject parent)
|
|
|
- {
|
|
|
- parent.OriginalValues[prop.Name.Split('.').Last()] = value;
|
|
|
- }
|
|
|
- }
|
|
|
+ obj.OriginalValues[prop.Name] = value;
|
|
|
}
|
|
|
}
|
|
|
}
|