|
@@ -2,6 +2,7 @@
|
|
|
using InABox.Core;
|
|
using InABox.Core;
|
|
|
using InABox.Database;
|
|
using InABox.Database;
|
|
|
using InABox.Scripting;
|
|
using InABox.Scripting;
|
|
|
|
|
+using Newtonsoft.Json;
|
|
|
using System;
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
@@ -34,13 +35,6 @@ public class SaveEvent<T> : IEvent<SaveEventDataModel<T>>
|
|
|
return notification;
|
|
return notification;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void SerializeBinary(CoreBinaryWriter writer)
|
|
|
|
|
- {
|
|
|
|
|
- }
|
|
|
|
|
- public void DeserializeBinary(CoreBinaryReader reader)
|
|
|
|
|
- {
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public void Init(IStore store, IEventData evData, SaveEventDataModel<T> model)
|
|
public void Init(IStore store, IEventData evData, SaveEventDataModel<T> model)
|
|
|
{
|
|
{
|
|
|
if (model.Entity.ID != Guid.Empty)
|
|
if (model.Entity.ID != Guid.Empty)
|
|
@@ -157,21 +151,25 @@ public class CreatedSaveEventTrigger<T> : IEventTrigger<SaveEvent<T>, SaveEventD
|
|
|
{
|
|
{
|
|
|
return dataModel.Entity.HasOriginalValue(x => x.ID);
|
|
return dataModel.Entity.HasOriginalValue(x => x.ID);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- public void SerializeBinary(CoreBinaryWriter writer)
|
|
|
|
|
- {
|
|
|
|
|
- }
|
|
|
|
|
- public void DeserializeBinary(CoreBinaryReader reader)
|
|
|
|
|
- {
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[Caption("Property Changed")]
|
|
[Caption("Property Changed")]
|
|
|
public class PropertyChangedSaveEventTrigger<T> : IEventTrigger<SaveEvent<T>, SaveEventDataModel<T>>
|
|
public class PropertyChangedSaveEventTrigger<T> : IEventTrigger<SaveEvent<T>, SaveEventDataModel<T>>
|
|
|
where T : Entity, new()
|
|
where T : Entity, new()
|
|
|
{
|
|
{
|
|
|
|
|
+ [JsonIgnore]
|
|
|
public IProperty? TriggerProperty { get; set; }
|
|
public IProperty? TriggerProperty { get; set; }
|
|
|
|
|
|
|
|
|
|
+ [JsonProperty(PropertyName = "TriggerProperty")]
|
|
|
|
|
+ private string? _property
|
|
|
|
|
+ {
|
|
|
|
|
+ get => TriggerProperty?.Name;
|
|
|
|
|
+ set
|
|
|
|
|
+ {
|
|
|
|
|
+ TriggerProperty = value is null ? null : DatabaseSchema.PropertyStrict(typeof(T), value);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public string Description => TriggerProperty is null
|
|
public string Description => TriggerProperty is null
|
|
|
? $"{typeof(T).GetCaption()} changed"
|
|
? $"{typeof(T).GetCaption()} changed"
|
|
|
: $"{typeof(T).GetCaption()}.{TriggerProperty.Name} changed";
|
|
: $"{typeof(T).GetCaption()}.{TriggerProperty.Name} changed";
|
|
@@ -190,30 +188,6 @@ public class PropertyChangedSaveEventTrigger<T> : IEventTrigger<SaveEvent<T>, Sa
|
|
|
}
|
|
}
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- public void SerializeBinary(CoreBinaryWriter writer)
|
|
|
|
|
- {
|
|
|
|
|
- if(TriggerProperty is null)
|
|
|
|
|
- {
|
|
|
|
|
- writer.Write(false);
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- writer.Write(true);
|
|
|
|
|
- writer.Write(TriggerProperty.Name);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- public void DeserializeBinary(CoreBinaryReader reader)
|
|
|
|
|
- {
|
|
|
|
|
- if(reader.ReadBoolean())
|
|
|
|
|
- {
|
|
|
|
|
- TriggerProperty = DatabaseSchema.PropertyStrict(typeof(T), reader.ReadString());
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- TriggerProperty = null;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[Caption("Custom Script")]
|
|
[Caption("Custom Script")]
|
|
@@ -265,24 +239,6 @@ public class Module
|
|
|
}
|
|
}
|
|
|
return _scriptDocument.Execute(methodname: "Check", parameters: [dataModel]);
|
|
return _scriptDocument.Execute(methodname: "Check", parameters: [dataModel]);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- public void SerializeBinary(CoreBinaryWriter writer)
|
|
|
|
|
- {
|
|
|
|
|
- writer.Write(Script ?? "");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void DeserializeBinary(CoreBinaryReader reader)
|
|
|
|
|
- {
|
|
|
|
|
- var script = reader.ReadString();
|
|
|
|
|
- if (script.IsNullOrWhiteSpace())
|
|
|
|
|
- {
|
|
|
|
|
- Script = null;
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- Script = script;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
#endregion
|
|
@@ -349,32 +305,16 @@ public class Module
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- public void SerializeBinary(CoreBinaryWriter writer)
|
|
|
|
|
- {
|
|
|
|
|
- writer.Write(Script ?? "");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void DeserializeBinary(CoreBinaryReader reader)
|
|
|
|
|
- {
|
|
|
|
|
- var script = reader.ReadString();
|
|
|
|
|
- if (script.IsNullOrWhiteSpace())
|
|
|
|
|
- {
|
|
|
|
|
- Script = null;
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- Script = script;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[Caption("Create Entity")]
|
|
[Caption("Create Entity")]
|
|
|
public class CreateEntitySaveEventAction<T> : IEventAction<SaveEvent<T>>
|
|
public class CreateEntitySaveEventAction<T> : IEventAction<SaveEvent<T>>
|
|
|
where T : Entity, new()
|
|
where T : Entity, new()
|
|
|
{
|
|
{
|
|
|
|
|
+ [JsonProperty(Order = 1)]
|
|
|
public Type? EntityType { get; set; }
|
|
public Type? EntityType { get; set; }
|
|
|
|
|
|
|
|
|
|
+ [JsonIgnore]
|
|
|
public List<PropertyInitializer> Initializers { get; set; } = new List<PropertyInitializer>();
|
|
public List<PropertyInitializer> Initializers { get; set; } = new List<PropertyInitializer>();
|
|
|
|
|
|
|
|
public string Description => $"Create New {EntityType?.Name ?? "Entity"}";
|
|
public string Description => $"Create New {EntityType?.Name ?? "Entity"}";
|
|
@@ -396,41 +336,27 @@ public class CreateEntitySaveEventAction<T> : IEventAction<SaveEvent<T>>
|
|
|
return entity;
|
|
return entity;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void SerializeBinary(CoreBinaryWriter writer)
|
|
|
|
|
|
|
+ #region Serialization Stuff
|
|
|
|
|
+
|
|
|
|
|
+ [JsonProperty(Order = 2, PropertyName = "Initializers")]
|
|
|
|
|
+ private PropertyInitializerSerializationItem[] _initializers
|
|
|
{
|
|
{
|
|
|
- if(EntityType is null)
|
|
|
|
|
- {
|
|
|
|
|
- writer.Write(false);
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- writer.Write(true);
|
|
|
|
|
- writer.Write(EntityType.EntityName());
|
|
|
|
|
- }
|
|
|
|
|
- writer.Write(Initializers.Count);
|
|
|
|
|
- foreach(var init in Initializers)
|
|
|
|
|
|
|
+ get => Initializers.ToArray(x => new PropertyInitializerSerializationItem { Property = x.Property.Name, Value = x.Value });
|
|
|
|
|
+ set
|
|
|
{
|
|
{
|
|
|
- init.SerializeBinary(writer);
|
|
|
|
|
|
|
+ Initializers.Clear();
|
|
|
|
|
+ Initializers.AddRange(value.Select(x => new PropertyInitializer(EntityType!, x)));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- public void DeserializeBinary(CoreBinaryReader reader)
|
|
|
|
|
- {
|
|
|
|
|
- if(reader.ReadBoolean())
|
|
|
|
|
- {
|
|
|
|
|
- EntityType = CoreUtils.GetEntity(reader.ReadString());
|
|
|
|
|
- }
|
|
|
|
|
- else
|
|
|
|
|
- {
|
|
|
|
|
- EntityType = null;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- var nInit = reader.ReadInt32();
|
|
|
|
|
- for(int i = 0; i < nInit; ++i)
|
|
|
|
|
- {
|
|
|
|
|
- var init = new PropertyInitializer(reader, EntityType!);
|
|
|
|
|
- Initializers.Add(init);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ #endregion
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+internal class PropertyInitializerSerializationItem
|
|
|
|
|
+{
|
|
|
|
|
+ public string Property { get; set; }
|
|
|
|
|
+
|
|
|
|
|
+ public string Value { get; set; }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public class PropertyInitializer
|
|
public class PropertyInitializer
|
|
@@ -464,12 +390,10 @@ public class PropertyInitializer
|
|
|
|
|
|
|
|
public IEnumerable<string> ReferencedVariables => ValueExpression.ReferencedVariables;
|
|
public IEnumerable<string> ReferencedVariables => ValueExpression.ReferencedVariables;
|
|
|
|
|
|
|
|
- /// <summary>
|
|
|
|
|
- /// <b>Only for use in serialisation.</b>
|
|
|
|
|
- /// </summary>
|
|
|
|
|
- public PropertyInitializer(CoreBinaryReader reader, Type entityType)
|
|
|
|
|
|
|
+ internal PropertyInitializer(Type entityType, PropertyInitializerSerializationItem item)
|
|
|
{
|
|
{
|
|
|
- DeserializeBinary(reader, entityType);
|
|
|
|
|
|
|
+ Value = item.Value;
|
|
|
|
|
+ Property = DatabaseSchema.PropertyStrict(entityType, item.Property);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public PropertyInitializer(IProperty property, string value)
|
|
public PropertyInitializer(IProperty property, string value)
|
|
@@ -482,19 +406,6 @@ public class PropertyInitializer
|
|
|
{
|
|
{
|
|
|
Property.Setter()(entity, ValueExpression.Evaluate(dataModel));
|
|
Property.Setter()(entity, ValueExpression.Evaluate(dataModel));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- public void SerializeBinary(CoreBinaryWriter writer)
|
|
|
|
|
- {
|
|
|
|
|
- writer.Write(Property.Name);
|
|
|
|
|
- writer.Write(Value);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- [MemberNotNull(nameof(Property), nameof(_value))]
|
|
|
|
|
- public void DeserializeBinary(CoreBinaryReader reader, Type entityType)
|
|
|
|
|
- {
|
|
|
|
|
- Property = DatabaseSchema.PropertyStrict(entityType, reader.ReadString());
|
|
|
|
|
- Value = reader.ReadString();
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
#endregion
|