Jelajahi Sumber

Some work on database proxy system; certainly not done

Kenric Nugteren 1 tahun lalu
induk
melakukan
7b951322b3

+ 0 - 5
InABox.Client.Local/LocalClient.cs

@@ -52,11 +52,6 @@ namespace InABox.Clients
         
         public override bool IsConnected() => true;
 
-        public override IEnumerable<string> SupportedTypes()
-        {
-            return DbFactory.SupportedTypes();
-        }
-
         protected override IValidationData DoValidate(Guid session)
         {
             return DoValidate(new Filter<User>().None(), session);

+ 0 - 10
InABox.Client.RPC/RPCClient.cs

@@ -52,16 +52,6 @@ namespace InABox.Rpc
             return result.Info;
         }
 
-        private static string[]? _types;
-        public override IEnumerable<string> SupportedTypes()
-        {
-            _types ??= CoreUtils.Entities
-                .Where(x => x.GetInterfaces().Contains(typeof(IPersistent)))
-                .Select(x => x.EntityName().Replace(".", "_"))
-                .ToArray();
-            return _types;
-        }
-        
         #region Validate & 2FA
 
         protected override IValidationData DoValidate(string userid, string password, Guid session = default)

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

@@ -16,8 +16,6 @@ namespace InABox.Clients
         
         public TimeSpan Timeout { get; set; }
 
-        public abstract IEnumerable<string> SupportedTypes();
-
         public abstract bool IsConnected();
 
         public event LogEvent? OnLog;

+ 0 - 14
InABox.Core/Client/Client.cs

@@ -615,20 +615,6 @@ namespace InABox.Clients
             }
         }
 
-        public IEnumerable<string> SupportedTypes()
-        {
-            try
-            {
-                using (new Profiler(true))
-                    return _client.SupportedTypes();
-            }
-            catch (RequestException e)
-            {
-                ClientFactory.RaiseRequestError(e);
-                throw;
-            }
-        }
-
         public new DatabaseInfo Info()
         {
             try

+ 0 - 2
InABox.Core/Client/IClient.cs

@@ -42,8 +42,6 @@ namespace InABox.Clients
 
         byte[]? Installer();
 
-
-        IEnumerable<string> SupportedTypes();
         
         event LogEvent OnLog;
 

+ 9 - 2
InABox.Core/DigitalForms/Forms/DigitalForm.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Linq.Expressions;
 using System.Text;
+using InABox.Core.Reports;
 using Newtonsoft.Json.Linq;
 using TextFieldParserStandard;
 
@@ -79,6 +80,10 @@ namespace InABox.Core
         [EditorSequence(7)]
         public DigitalFormGroupLink Group { get; set; }
 
+        [EditorSequence(8)]
+        [ExpressionEditor(null, ToolTip = "Evaluates to string which becomes the description of the form when saving.")]
+        public string DescriptionExpression { get; set; } = "";
+
         [NullEditor]
         public string Report { get; set; }
         
@@ -93,8 +98,10 @@ namespace InABox.Core
         public IEntityDuplicator GetDuplicator()
         {
             var result = new EntityDuplicator<DigitalForm>();
-            result.AddChild<DigitalForm, DigitalFormVariable>(x => x.Form);
-            result.AddChild<DigitalForm, DigitalFormLayout>(x => x.Form);
+            result.AddChild<DigitalForm, DigitalFormVariable, DigitalFormLink>(x => x.Form);
+            result.AddChild<DigitalForm, DigitalFormLayout, DigitalFormLink>(x => x.Form);
+            result.AddChild<DigitalForm, DigitalFormDocument, DigitalFormLink>(x => x.EntityLink);
+            result.AddChild<DigitalForm, ReportTemplate>(new Column<ReportTemplate>(x => x.Section), x => x.ID.ToString());
             return result;
         }
 

+ 0 - 55
InABox.Database/DbFactory.cs

@@ -385,61 +385,6 @@ public static class DbFactory
         return result;
     }
 
-    #region Supported Types
-
-    private class ModuleConfiguration : Dictionary<string, bool>, ILocalConfigurationSettings
-    {
-    }
-
-    private static Type[]? _dbtypes;
-
-    public static IEnumerable<string> SupportedTypes()
-    {
-        _dbtypes ??= LoadSupportedTypes();
-        return _dbtypes.Select(x => x.EntityName().Replace(".", "_"));
-    }
-
-    private static Type[] LoadSupportedTypes()
-    {
-        var result = new List<Type>();
-
-        var path = Provider.URL.ToLower();
-        var config = new LocalConfiguration<ModuleConfiguration>(Path.GetDirectoryName(path) ?? "", Path.GetFileName(path)).Load();
-        var bChanged = false;
-        foreach (var type in Entities)
-        {
-            var key = type.EntityName();
-            if (config.ContainsKey(key))
-            {
-                if (config[key])
-                    //Logger.Send(LogType.Information, "", String.Format("{0} is enabled", key));
-                    result.Add(type);
-                else
-                    Logger.Send(LogType.Information, "", string.Format("Entity [{0}] is disabled", key));
-            }
-            else
-            {
-                //Logger.Send(LogType.Information, "", String.Format("{0} does not exist - enabling", key));
-
-                config[key] = true;
-                result.Add(type);
-                bChanged = true;
-            }
-        }
-
-        if (bChanged)
-            new LocalConfiguration<ModuleConfiguration>(Path.GetDirectoryName(path) ?? "", Path.GetFileName(path)).Save(config);
-        return result.ToArray();
-    }
-
-    public static bool IsSupported<T>() where T : Entity
-    {
-        _dbtypes ??= LoadSupportedTypes();
-        return _dbtypes.Contains(typeof(T));
-    }
-
-    #endregion
-
     //public static void OpenSession(bool write)
     //{
     //	Provider.OpenSession(write);

+ 26 - 35
InABox.Database/Stores/Store.cs

@@ -59,9 +59,6 @@ namespace InABox.Database
             if (IsSubStore)
                 return;
 
-            if (!DbFactory.IsSupported<UserTracking>())
-                return;
-
             if (string.IsNullOrWhiteSpace(UserID))
                 return;
 
@@ -454,15 +451,12 @@ namespace InABox.Database
             
             OnSave(entity, ref auditnote);
 
-            if (DbFactory.IsSupported<AuditTrail>())
-            {
-                var notes = new List<string>();
-                if (!string.IsNullOrEmpty(auditnote))
-                    notes.Add(auditnote);
-                if (!string.IsNullOrEmpty(changes))
-                    notes.Add(changes);
-                if (notes.Any()) AuditTrail(entity, notes);
-            }
+            var notes = new List<string>();
+            if (!string.IsNullOrEmpty(auditnote))
+                notes.Add(auditnote);
+            if (!string.IsNullOrEmpty(changes))
+                notes.Add(changes);
+            if (notes.Any()) AuditTrail(entity, notes);
 
             AfterSave(entity);
 
@@ -556,37 +550,34 @@ namespace InABox.Database
                 throw e;
             }
 
-            if (DbFactory.IsSupported<AuditTrail>())
+            var audittrails = new List<AuditTrail>();
+            foreach (var entity in entities)
             {
-                var audittrails = new List<AuditTrail>();
-                foreach (var entity in entities)
-                {
-                    var notes = new List<string>();
+                var notes = new List<string>();
 
-                    if (!string.IsNullOrEmpty(auditnote))
-                        notes.Add(auditnote);
+                if (!string.IsNullOrEmpty(auditnote))
+                    notes.Add(auditnote);
 
-                    if (changes.ContainsKey(entity) && !string.IsNullOrEmpty(changes[entity]))
-                        notes.Add(changes[entity]);
+                if (changes.ContainsKey(entity) && !string.IsNullOrEmpty(changes[entity]))
+                    notes.Add(changes[entity]);
 
-                    if (notes.Any())
+                if (notes.Any())
+                {
+                    var audit = new AuditTrail
                     {
-                        var audit = new AuditTrail
-                        {
-                            EntityID = entity.ID,
-                            Timestamp = DateTime.Now,
-                            User = UserID,
-                            Note = string.Join(": ", notes)
-                        };
-                        audittrails.Add(audit);
-                        //Provider.Save<AuditTrail>(audit);
-                    }
+                        EntityID = entity.ID,
+                        Timestamp = DateTime.Now,
+                        User = UserID,
+                        Note = string.Join(": ", notes)
+                    };
+                    audittrails.Add(audit);
+                    //Provider.Save<AuditTrail>(audit);
                 }
-
-                if (audittrails.Any())
-                    Provider.Save(audittrails);
             }
 
+            if (audittrails.Any())
+                Provider.Save(audittrails);
+
             foreach (var entity in entities)
             {
                 AfterSave(entity);

+ 4 - 55
InABox.Server/Rest/RestHandler.cs

@@ -14,36 +14,9 @@ namespace InABox.API
 {
     public class RestHandler : IHandler
     {
-        private readonly List<string> endpoints;
-        private readonly List<string> operations;
-
         public RestHandler(IHandler parent)
         {
             Parent = parent;
-
-            endpoints = new();
-            operations = new();
-
-            var types = CoreUtils.TypeList(
-                x => x.IsSubclassOf(typeof(Entity))
-                     && x.GetInterfaces().Contains(typeof(IRemotable))
-            );
-            var DBTypes = DbFactory.SupportedTypes();
-
-            foreach (var t in types)
-                if (DBTypes.Contains(t.EntityName().Replace(".", "_")))
-                {
-                    operations.Add(t.EntityName().Replace(".", "_"));
-
-                    endpoints.Add(string.Format("List{0}", t.Name));
-                    endpoints.Add(string.Format("Load{0}", t.Name));
-                    endpoints.Add(string.Format("Save{0}", t.Name));
-                    endpoints.Add(string.Format("MultiSave{0}", t.Name));
-                    endpoints.Add(string.Format("Delete{0}", t.Name));
-                    endpoints.Add(string.Format("MultiDelete{0}", t.Name));
-                }
-
-            endpoints.Add("QueryMultiple");
         }
         
         private RequestData GetRequestData(IRequest request)
@@ -90,9 +63,11 @@ namespace InABox.API
                         switch (current)
                         {
                             case "operations" or "supported_operations":
-                                return new ValueTask<IResponse?>(GetSupportedOperations(request).Build());
+                                Logger.Send(LogType.Error, "", "Supported operations is no longer supported");
+                                return new ValueTask<IResponse?>(request.Respond().Status(ResponseStatus.NotFound).Build());
                             case "classes" or "supported_classes":
-                                return new ValueTask<IResponse?>(GetSupportedClasses(request).Build());
+                                Logger.Send(LogType.Error, "", "Supported classes is no longer supported");
+                                return new ValueTask<IResponse?>(request.Respond().Status(ResponseStatus.NotFound).Build());
                             case "version" or "releasenotes" or "release_notes" or "install" or "install_desktop":
                                 return new ValueTask<IResponse?>(GetUpdateFile(request).Build());
                             case "info":
@@ -128,32 +103,6 @@ namespace InABox.API
             }
         }
         
-        /// <summary>
-        /// Returns a JSON list of operation names; used for checking support of operations client side
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
-        private IResponseBuilder GetSupportedOperations(IRequest request)
-        {
-            var serialized = Core.Serialization.Serialize(endpoints, true) ?? "";
-            return request.Respond()
-                .Type(new FlexibleContentType(ContentType.ApplicationJson))
-                .Content(new ResourceContent(Resource.FromString(serialized).Build()));
-        }
-
-        /// <summary>
-        /// Returns a JSON list of class names; used for checking support of operations client side
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
-        private IResponseBuilder GetSupportedClasses(IRequest request)
-        {
-            var serialized = Serialization.Serialize(operations) ?? "";
-            return request.Respond()
-                .Type(new FlexibleContentType(ContentType.ApplicationJson))
-                .Content(new ResourceContent(Resource.FromString(serialized).Build()));
-        }
-        
         /// <summary>
         /// Returns the Splash Logo and Color Scheme for this Database
         /// </summary>

+ 0 - 10
inabox.client.ipc/IPCClient.cs

@@ -23,16 +23,6 @@ namespace InABox.IPC
 
         public override bool IsConnected() => _pipe?.Disconnected == false;
 
-        private static string[]? _types;
-        public override string[] SupportedTypes()
-        {
-            _types ??= CoreUtils.Entities
-                .Where(x => x.GetInterfaces().Contains(typeof(IPersistent)))
-                .Select(x => x.EntityName().Replace(".", "_"))
-                .ToArray();
-            return _types;
-        }
-
         public override DatabaseInfo Info()
         {
             try

+ 0 - 31
inabox.client.rest/InABox.Client.Rest/RestClient.cs

@@ -560,37 +560,6 @@ namespace InABox.Clients
 
         #endregion
         
-        public override IEnumerable<string> SupportedTypes()
-        {
-            var result = new List<string>();
-
-            var cli = StaticRestClients.GetClient(RestClientCache.URL(_server));
-            var req = new RestRequest("/classes", Method.Get) { Timeout = 20000 };
-
-            try
-            {
-                var res = cli.Execute(req);
-                if (res.ErrorException == null)
-                {
-                    var list = res.Content.Trim('[', ']').Split(',');
-                    foreach (var operation in list)
-                    {
-                        var trimmed = operation.Trim('"');
-                        if (!result.Contains(trimmed)) result.Add(trimmed);
-                        //if (svc.Equals("Comal_Classes_Login"))
-                        //    result.Add("InABox_Core_Login");
-                    }
-                }
-            }
-            catch (Exception e)
-            {
-            }
-
-            req = null;
-            cli = null;
-            return result.ToArray();
-        }
-
         public override DatabaseInfo Info()
         {
             return RestClientCache.Info(_server);