Browse Source

CORE - changes to DF data model

Nick-PRSDigital@bitbucket.org 2 years ago
parent
commit
625dcf8e3a

+ 46 - 4
InABox.Core/DigitalForms/DataModel/DigitalFormDataModel.cs

@@ -1,17 +1,42 @@
 using System;
+using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using InABox.Clients;
 
 namespace InABox.Core
 {
+    public enum MobileLogType
+    {
+        START,
+        END
+    }
+    public class MobileLog
+    {
+        public string Message { get; set; }
+
+        public MobileLog(string message, MobileLogType type)
+        {
+            Message = type + " " + message + "(" + DateTime.Now.ToString("m.s.fffff") + ")";        
+        }
+
+        public static string ProduceLog(List<MobileLog> logs)
+        {
+            string finallog = "";
+            foreach (var log in logs)
+            {
+                finallog = finallog + System.Environment.NewLine + log.Message;
+            }
+            return finallog;
+        }
+    }
     public class DigitalFormDataModel<TEntity, TEntityLink, TInstance> : IDigitalFormDataModel
         where TEntity : Entity, IRemotable, IPersistent, new()
         where TEntityLink : EntityLink<TEntity>
         where TInstance : Entity, IRemotable, IPersistent, IDigitalFormInstance<TEntityLink>, new()
     {
         private readonly bool bRequiresLoad = true;
-
+        List<MobileLog> logs = new List<MobileLog>();
         public DigitalFormDataModel(Guid entityid, Guid instanceid)
         {
             Entity = new TEntity();
@@ -55,7 +80,7 @@ namespace InABox.Core
             }
         }
 
-        public IDigitalFormInstance Instance { get; private set; }
+        public IDigitalFormInstance Instance { get; set; }
 
         public event DigitalFormUpdateHandler OnModelSaved;
 
@@ -63,6 +88,7 @@ namespace InABox.Core
 
         public void Load(Action<IDigitalFormDataModel>? callback = null)
         {
+            logs.Add(new MobileLog("Load", MobileLogType.START));
             if (!bRequiresLoad)
             {
                 callback?.Invoke(this);
@@ -73,6 +99,8 @@ namespace InABox.Core
 
             DoAddQueries(client);
 
+            logs.Add(new MobileLog("Query", MobileLogType.START));
+
             if (callback == null)
             {
                 if (client.Count > 0)
@@ -92,6 +120,9 @@ namespace InABox.Core
                 else
                     callback.Invoke(this);
             }
+            logs.Add(new MobileLog("Query", MobileLogType.END));
+            logs.Add(new MobileLog("Load", MobileLogType.END));
+            var log = MobileLog.ProduceLog(logs);
         }
 
         public void Update(Action<IDigitalFormDataModel>? callback = null)
@@ -123,7 +154,7 @@ namespace InABox.Core
                 client.Add(
                     new QueryDef<TEntity>(
                         new Filter<TEntity>(x => x.ID).IsEqualTo(Entity.ID),
-                        null,
+                        new Columns<TEntity>(x => x.ID),
                         null
                     ),
                     typeof(TEntity)
@@ -133,7 +164,18 @@ namespace InABox.Core
                 client.Add(
                     new QueryDef<TInstance>(
                         new Filter<TInstance>(x => x.ID).IsEqualTo(Instance.ID),
-                        null,
+                        new Columns<TInstance>
+                        (
+                            x => x.ID, 
+                            x => x.FormData, 
+                            x => x.Form.ID,
+                            x => x.FormCompleted,
+                            x => x.FormCompletedBy.ID,
+                            x => x.Created,
+                            x => x.FormOpen,
+                            x => x.BlobData
+                            
+                            ),
                         null
                     ),
                     typeof(TInstance)

+ 1 - 1
InABox.Core/DigitalForms/DataModel/IDigitalFormDataModel.cs

@@ -9,7 +9,7 @@ namespace InABox.Core
     public interface IDigitalFormDataModel
     {
         public Entity Entity { get; set; }
-        IDigitalFormInstance Instance { get; }
+        IDigitalFormInstance Instance { get; set;  }
 
         event DigitalFormUpdateHandler OnModelSaved;