Преглед на файлове

Clients interfacing with external databases can now be set to exclude CustomProperties

frankvandenbos преди 6 месеца
родител
ревизия
883f774ce5

+ 2 - 1
InABox.Client.RPC/RPCClient.cs

@@ -188,7 +188,8 @@ namespace InABox.Rpc
             {
                 Type = typeof(TEntity),
                 Items = items,
-                AuditNote = auditnote
+                AuditNote = auditnote,
+                ExcludeCustomProperties = this.ExcludeCustomProperties
             };
             var result = _transport.Send<RpcSaveCommand, RpcSaveParameters, RpcSaveResult>(parameters);
             for (int i = 0; i < result.Deltas.Length; i++)

+ 3 - 0
InABox.Core/Client/BaseClient.cs

@@ -8,6 +8,9 @@ namespace InABox.Clients
 {
     public abstract class BaseClient<TEntity> : IClient<TEntity> where TEntity : Entity, new()
     {
+        
+        public bool ExcludeCustomProperties { get; set; }
+        
         public TimeSpan Timeout { get; set; } = new TimeSpan(0, 1, 0);
 
         public abstract IEnumerable<string> SupportedTypes();

+ 10 - 1
InABox.Core/Client/Client.cs

@@ -63,6 +63,9 @@ namespace InABox.Clients
     public class ClientQueryProvider<TEntity> : IQueryProvider<TEntity>
         where TEntity : Entity, IRemotable, new()
     {
+        
+        public bool ExcludeCustomProperties { get; set; }
+        
         #region Non-generic
 
         public CoreTable Query(IFilter? filter = null, IColumns? columns = null, ISortOrder? sort = null, CoreRange? range = null)
@@ -129,9 +132,15 @@ namespace InABox.Clients
 
         private class _Factory : IQueryProviderFactory
         {
+
+            public bool ExcludeCustomProperties => false;
+            
             public IQueryProvider Create(Type T)
             {
-                return (typeof(ClientQueryProvider<>).MakeGenericType(T) as IQueryProvider)!;
+                var type = typeof(ClientQueryProvider<>).MakeGenericType(T);
+                var result = (Activator.CreateInstance(type) as IQueryProvider)!;
+                result.ExcludeCustomProperties = ExcludeCustomProperties;
+                return result;
             }
         }
 

+ 8 - 1
InABox.Core/Client/IQueryProvider.cs

@@ -6,6 +6,8 @@ namespace InABox.Core
 {
     public interface IQueryProvider
     {
+        bool ExcludeCustomProperties { get; set; }
+        
         CoreTable Query(IFilter? filter = null, IColumns? columns = null, ISortOrder? sort = null, CoreRange? range = null);
     }
 
@@ -32,12 +34,17 @@ namespace InABox.Core
 
     public interface IQueryProviderFactory
     {
+
+        bool ExcludeCustomProperties { get; }
+        
         IQueryProvider Create(Type T);
 
         IQueryProvider<T> Create<T>()
             where T : BaseObject, new()
         {
-            return (Create(typeof(T)) as IQueryProvider<T>)!;
+            var result = (Create(typeof(T)) as IQueryProvider<T>)!;
+            result.ExcludeCustomProperties = ExcludeCustomProperties;
+            return result;
         }
     }
 

+ 4 - 4
InABox.Core/Serialization.cs

@@ -654,9 +654,9 @@ namespace InABox.Core
             return (result != null ? (T)result : default)!;
         }
 
-        public static IEnumerable<IProperty> SerializableProperties(Type type) =>
+        public static IEnumerable<IProperty> SerializableProperties(Type type, Predicate<IProperty>? filter = null) =>
             DatabaseSchema.Properties(type)
-                .Where(x => !(x is StandardProperty st) || st.IsSerializable);
+                .Where(x => (!(x is StandardProperty st) || st.IsSerializable) && (filter?.Invoke(x) ?? true));
 
         private static void WriteOriginalValues<TObject>(this CoreBinaryWriter writer, TObject obj)
             where TObject : BaseObject
@@ -773,7 +773,7 @@ namespace InABox.Core
         public static void WriteObjects<TObject>(this CoreBinaryWriter writer, ICollection<TObject>? objects)
             where TObject : BaseObject, new() => WriteObjects(writer, typeof(TObject), objects);
 
-        public static void WriteObjects<TObject>(this CoreBinaryWriter writer, Type type, ICollection<TObject>? objects)
+        public static void WriteObjects<TObject>(this CoreBinaryWriter writer, Type type, ICollection<TObject>? objects, Predicate<IProperty>? filter = null)
             where TObject : BaseObject
         {
             if (!typeof(TObject).IsAssignableFrom(type))
@@ -787,7 +787,7 @@ namespace InABox.Core
                 return;
             }
 
-            var properties = SerializableProperties(type).ToList();
+            var properties = SerializableProperties(type, filter).ToList();
             writer.Write(properties.Count);
             foreach (var property in properties)
             {

+ 3 - 0
InABox.Database/IProvider.cs

@@ -111,6 +111,9 @@ public static class ProviderExtensions
     private class ProviderQueryProvider<TEntity>(IProvider provider, string userID) : IQueryProvider<TEntity>
         where TEntity : Entity, new()
     {
+
+        public bool ExcludeCustomProperties { get; set; }
+        
         private IProvider Provider = provider;
 
         private string UserID = userID;

+ 4 - 2
InABox.RPC.Shared/Commands/Save/RpcSaveParameters.cs

@@ -9,6 +9,8 @@ namespace InABox.Rpc
         public Type Type { get; set; }
         public Entity[] Items { get; set; }
         public string AuditNote { get; set; }
+        
+        public bool ExcludeCustomProperties { get; set; }
 
         public string CommandName => "Save";
 
@@ -21,10 +23,10 @@ namespace InABox.Rpc
         public void SerializeBinary(CoreBinaryWriter writer)
         {
             writer.Write(Type.EntityName());
-            writer.WriteObjects(Type, Items);
+            writer.WriteObjects(Type, Items, (p) => ExcludeCustomProperties ? p is StandardProperty : true);
             writer.Write(AuditNote);
         }
-
+        
         public void DeserializeBinary(CoreBinaryReader reader)
         {
             var type = reader.ReadString();