Browse Source

Merge commit '76466fffa28fa668c799c0a6f5a1430fbc6603b5' into frank

Frank van den Bos 1 year ago
parent
commit
7fa89c8e1a

+ 3 - 0
InABox.Core/Classes/Document/DocumentLink.cs

@@ -17,6 +17,9 @@ namespace InABox.Core
         [EditorSequence(3)]
         [EditorSequence(3)]
         public bool Private { get; set; }
         public bool Private { get; set; }
 
 
+        [NullEditor]
+        public string CRC { get; set; }
+
         public override string ToString()
         public override string ToString()
         {
         {
             return FileName;
             return FileName;

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

@@ -26,6 +26,15 @@ namespace InABox.Clients
 
 
         public CoreTable Get<T>() => Results[typeof(T).Name];
         public CoreTable Get<T>() => Results[typeof(T).Name];
 
 
+        /// <summary>
+        /// Like <see cref="Get{T}"/>, but calls <see cref="CoreTable.ToObjects{T}"/> on the table.
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <returns></returns>
+        public IEnumerable<T> GetObjects<T>()
+            where T: BaseObject, new() 
+            => Results[typeof(T).Name].ToObjects<T>();
+
         public CoreTable Get(string name) => Results[name];
         public CoreTable Get(string name) => Results[name];
     }
     }
 
 

+ 3 - 0
InABox.Core/Deletion.cs

@@ -2,6 +2,7 @@
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
+using System.Reflection;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 
 
@@ -32,6 +33,8 @@ namespace InABox.Core
         private static bool IsDeletionColumn(IProperty property)
         private static bool IsDeletionColumn(IProperty property)
         {
         {
             if (property.IsCalculated) return false;
             if (property.IsCalculated) return false;
+            if (property is StandardProperty standardProperty && standardProperty.Property.GetCustomAttribute<DoNotPersist>() != null)
+                return false;
             if (property.Parent is null) return true;
             if (property.Parent is null) return true;
             if (property.Parent.IsEntityLink && !property.Name.EndsWith(".ID")) return false;
             if (property.Parent.IsEntityLink && !property.Name.EndsWith(".ID")) return false;
             if (property.Parent.HasParentEntityLink()) return false;
             if (property.Parent.HasParentEntityLink()) return false;

+ 1 - 1
InABox.Core/Security/AutoSecurityDescriptor.cs

@@ -37,7 +37,7 @@ namespace InABox.Core
 
 
         public string Postfix => "";
         public string Postfix => "";
 
 
-        public bool Value => typeof(TEntity).GetCustomAttribute<AutoEntity>() == null;
+        public bool Value => typeof(TEntity).GetCustomAttribute<AutoEntity>() == null && typeof(TEntity).HasInterface<IImportable>();
     }
     }
 
 
     public class CanExport<TEntity> : IAutoSecurityAction<TEntity>
     public class CanExport<TEntity> : IAutoSecurityAction<TEntity>

+ 50 - 27
inabox.scripting/ScriptDocument.cs

@@ -42,10 +42,9 @@ namespace InABox.Scripting
 
 
         private string _text = "";
         private string _text = "";
         private bool? compiled;
         private bool? compiled;
-        private MethodInfo method;
-        private object obj;
+        private object? obj;
 
 
-        private Type type;
+        private Type? type;
 
 
         static ScriptDocument()
         static ScriptDocument()
         {
         {
@@ -186,10 +185,8 @@ namespace InABox.Scripting
             return prop != null ? prop.Value : defaultvalue;
             return prop != null ? prop.Value : defaultvalue;
         }
         }
 
 
-        public bool Execute(string classname = "Module", string methodname = "Execute", object[] parameters = null, bool defaultResult = false)
+        private Type? GetClassType(string className = "Module")
         {
         {
-            var result = defaultResult;
-
             if (!compiled.HasValue)
             if (!compiled.HasValue)
             {
             {
                 compiled = false;
                 compiled = false;
@@ -198,7 +195,7 @@ namespace InABox.Scripting
                 if (emitResult.Success)
                 if (emitResult.Success)
                 {
                 {
                     var asm = Assembly.Load(stream.ToArray());
                     var asm = Assembly.Load(stream.ToArray());
-                    type = asm.GetTypes().Where(x => x.Name.Equals(classname)).FirstOrDefault();
+                    type = asm.GetTypes().Where(x => x.Name.Equals(className)).FirstOrDefault();
                     if (type != null)
                     if (type != null)
                     {
                     {
                         obj = Activator.CreateInstance(type);
                         obj = Activator.CreateInstance(type);
@@ -206,36 +203,62 @@ namespace InABox.Scripting
                     }
                     }
                 }
                 }
             }
             }
+            return type;
+        }
 
 
-            if (compiled.Value)
+        public object? GetObject(string className = "Module")
+        {
+            GetClassType(className);
+            return obj;
+        }
+
+        public MethodInfo? GetMethod(string className = "Module", string methodName = "Execute")
+        {
+            var type = GetClassType(className);
+            if (compiled == true && type != null)
+            {
+                return type.GetMethod(methodName);
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        public bool Execute(string classname = "Module", string methodname = "Execute", object[]? parameters = null, bool defaultResult = false)
+        {
+            var result = defaultResult;
+
+            var type = GetClassType(classname);
+            var obj = GetObject(classname);
+            var method = GetMethod(classname, methodname);
+
+            if (compiled == true && type != null && method != null)
             {
             {
                 foreach (var property in Properties)
                 foreach (var property in Properties)
                 {
                 {
                     var prop = type.GetProperty(property.Name);
                     var prop = type.GetProperty(property.Name);
-                    if (prop != null)
-                        prop.SetValue(obj, property.Value);
+                    prop?.SetValue(obj, property.Value);
                 }
                 }
 
 
-                method = type.GetMethod(methodname);
-                if (method != null)
+                if (method.ReturnType == typeof(bool))
                 {
                 {
-                    if (method.ReturnType == typeof(bool))
-                    {
-                        result = (bool)(method.Invoke(obj, parameters ?? Array.Empty<object>()) ?? false);
-                    }
-                    else
+                    result = (bool)(method.Invoke(obj, parameters ?? Array.Empty<object>()) ?? false);
+                }
+                else
+                {
+                    method.Invoke(obj, parameters ?? Array.Empty<object>());
+                    result = true;
+                }
+
+                if (result)
+                {
+                    foreach (var property in Properties)
                     {
                     {
-                        method.Invoke(obj, parameters ?? Array.Empty<object>());
-                        result = true;
+                        var prop = type.GetProperty(property.Name);
+                        if (prop != null)
+                            property.Value = prop.GetValue(obj);
                     }
                     }
-
-                    if (result)
-                        foreach (var property in Properties)
-                        {
-                            var prop = type.GetProperty(property.Name);
-                            if (prop != null)
-                                property.Value = prop.GetValue(obj);
-                        }
                 }
                 }
             }
             }
 
 

+ 1 - 1
inabox.wpf/DynamicGrid/BaseDynamicGrid.cs

@@ -134,7 +134,7 @@ namespace InABox.DynamicGrid
         }
         }
         public virtual bool EditItems(object[] items, Func<Type, CoreTable>? PageDataHandler = null, bool PreloadPages = false)
         public virtual bool EditItems(object[] items, Func<Type, CoreTable>? PageDataHandler = null, bool PreloadPages = false)
         {
         {
-            var values = items.Select(x => (T)x).ToArray();
+            var values = items.Cast<T>().ToArray();
             return EditItems(values, PageDataHandler, PreloadPages);
             return EditItems(values, PageDataHandler, PreloadPages);
         }
         }
 
 

+ 6 - 2
inabox.wpf/DynamicGrid/DynamicDataGrid.cs

@@ -105,9 +105,9 @@ namespace InABox.DynamicGrid
                 options.Add(DynamicGridOption.AddRows).Add(DynamicGridOption.EditRows);
                 options.Add(DynamicGridOption.AddRows).Add(DynamicGridOption.EditRows);
             if (Security.CanDelete<TEntity>())
             if (Security.CanDelete<TEntity>())
                 options.Add(DynamicGridOption.DeleteRows);
                 options.Add(DynamicGridOption.DeleteRows);
-            if (Security.CanImport<TEntity>())
+            if (Security.CanImport<TEntity>() && typeof(TEntity).HasInterface<IImportable>())
                 options.Add(DynamicGridOption.ImportData);
                 options.Add(DynamicGridOption.ImportData);
-            if (Security.CanExport<TEntity>())
+            if (Security.CanExport<TEntity>() && typeof(TEntity).HasInterface<IExportable>())
                 options.Add(DynamicGridOption.ExportData);
                 options.Add(DynamicGridOption.ExportData);
             if (Security.CanMerge<TEntity>())
             if (Security.CanMerge<TEntity>())
                 options.Add(DynamicGridOption.MultiSelect);
                 options.Add(DynamicGridOption.MultiSelect);
@@ -495,6 +495,10 @@ namespace InABox.DynamicGrid
             return columns;
             return columns;
         }
         }
 
 
+        /// <summary>
+        /// Provide a set of columns which is the default for this grid.
+        /// </summary>
+        /// <param name="columns"></param>
         protected virtual void GenerateColumns(DynamicGridColumns columns)
         protected virtual void GenerateColumns(DynamicGridColumns columns)
         {
         {
             var cols = new Columns<TEntity>().Default(HasOption(DynamicGridOption.DirectEdit)
             var cols = new Columns<TEntity>().Default(HasOption(DynamicGridOption.DirectEdit)

+ 1 - 0
inabox.wpf/DynamicGrid/DynamicGrid.cs

@@ -21,6 +21,7 @@ using InABox.Clients;
 using InABox.Core;
 using InABox.Core;
 using InABox.WPF;
 using InABox.WPF;
 using Syncfusion.Data;
 using Syncfusion.Data;
+using Syncfusion.DocIO.ReaderWriter.DataStreamParser.Escher;
 using Syncfusion.UI.Xaml.Grid;
 using Syncfusion.UI.Xaml.Grid;
 using Syncfusion.UI.Xaml.Grid.Cells;
 using Syncfusion.UI.Xaml.Grid.Cells;
 using Syncfusion.UI.Xaml.Grid.Helpers;
 using Syncfusion.UI.Xaml.Grid.Helpers;

+ 25 - 17
inabox.wpf/DynamicGrid/PDF/DocumentApprovalControl.xaml.cs

@@ -24,17 +24,17 @@ namespace InABox.Wpf
     /// </summary>
     /// </summary>
     public partial class DocumentApprovalControl : UserControl, IDocumentEditor
     public partial class DocumentApprovalControl : UserControl, IDocumentEditor
     {
     {
-        public delegate void MarkupSelected(IEntityDocument document);
-        public event MarkupSelected OnMarkupSelected;
+        public delegate void MarkupSelected(IEntityDocument? document);
+        public event MarkupSelected? OnMarkupSelected;
 
 
-        public delegate void MarkupComplete(IEntityDocument document);
-        public event MarkupComplete OnMarkupComplete;
+        public delegate void MarkupComplete(IEntityDocument? document);
+        public event MarkupComplete? OnMarkupComplete;
 
 
-        public delegate void Approved(IEntityDocument document);
-        public event Approved OnApproved;
+        public delegate void Approved(IEntityDocument? document);
+        public event Approved? OnApproved;
 
 
-        public delegate void Rejected(IEntityDocument document);
-        public event Rejected OnRejected;
+        public delegate void Rejected(IEntityDocument? document);
+        public event Rejected? OnRejected;
         public enum ControlMode
         public enum ControlMode
         {
         {
             Markup,
             Markup,
@@ -81,8 +81,8 @@ namespace InABox.Wpf
             rejectButton.Visibility = rejectVisible? Visibility.Visible : Visibility.Collapsed;
             rejectButton.Visibility = rejectVisible? Visibility.Visible : Visibility.Collapsed;
         }
         }
 
 
-        private IEntityDocument _document;
-        public IEntityDocument Document
+        private IEntityDocument? _document;
+        public IEntityDocument? Document
         {
         {
             get => _document;
             get => _document;
             set
             set
@@ -104,10 +104,18 @@ namespace InABox.Wpf
         private void Render()
         private void Render()
         {
         {
             viewer.Children.Clear();
             viewer.Children.Clear();
-            var table = new Client<Document>().Query(new Filter<Document>(x => x.ID).IsEqualTo(_document.DocumentLink.ID));
-            if (!table.Rows.Any())
+            if(Document is null)
+            {
+                return;
+            }
+
+            var table = new Client<Document>().Query(
+                new Filter<Document>(x => x.ID).IsEqualTo(Document.DocumentLink.ID),
+                new Columns<Document>(x => x.Data));
+            var first = table.Rows.FirstOrDefault();
+            if (first is null)
                 return;
                 return;
-            var data = table.Rows.FirstOrDefault().Get<Document, byte[]>(x => x.Data);
+            var data = first.Get<Document, byte[]>(x => x.Data);
             var images = ImageUtils.RenderPDFToImages(data);
             var images = ImageUtils.RenderPDFToImages(data);
             foreach (var image in images)
             foreach (var image in images)
             {
             {
@@ -125,23 +133,23 @@ namespace InABox.Wpf
             {
             {
                 Mode = ControlMode.Complete;
                 Mode = ControlMode.Complete;
                 MessageBox.Show("IMPORTANT - press save in your document editor, then press the Complete Button in PRS");
                 MessageBox.Show("IMPORTANT - press save in your document editor, then press the Complete Button in PRS");
-                OnMarkupSelected?.Invoke(_document);
+                OnMarkupSelected?.Invoke(Document);
             }
             }
             else
             else
             {
             {
-                OnMarkupComplete?.Invoke(_document);
+                OnMarkupComplete?.Invoke(Document);
                 Mode = ControlMode.Markup;
                 Mode = ControlMode.Markup;
             }
             }
         }
         }
 
 
         private void ApproveButton_Click(object sender, RoutedEventArgs e)
         private void ApproveButton_Click(object sender, RoutedEventArgs e)
         {
         {
-            OnApproved?.Invoke(_document);
+            OnApproved?.Invoke(Document);
         }
         }
 
 
         private void RejectButton_Click(object sender, RoutedEventArgs e)
         private void RejectButton_Click(object sender, RoutedEventArgs e)
         {
         {
-            OnRejected?.Invoke(_document);
+            OnRejected?.Invoke(Document);
         }
         }
     }
     }
 }
 }

+ 2 - 4
inabox.wpf/DynamicGrid/PDF/DocumentEditor.xaml.cs

@@ -67,11 +67,9 @@ namespace InABox.DynamicGrid
 
 
             for (var i = 0; i < e.RemovedItems.Count; i++)
             for (var i = 0; i < e.RemovedItems.Count; i++)
             {
             {
-                var item = e.RemovedItems[i] as DynamicTabItem;
-                if (item != null)
+                if (e.RemovedItems[i] is DynamicTabItem item)
                 {
                 {
-                    var viewer = item.Content as IDocumentEditor;
-                    if (viewer != null)
+                    if (item.Content is IDocumentEditor viewer)
                         viewer.Document = null;
                         viewer.Document = null;
                     item.Content = null;
                     item.Content = null;
                 }
                 }

+ 1 - 1
inabox.wpf/DynamicGrid/PDF/IDocumentEditor.cs

@@ -4,6 +4,6 @@ namespace InABox.DynamicGrid
 {
 {
     public interface IDocumentEditor
     public interface IDocumentEditor
     {
     {
-        IEntityDocument Document { get; set; }
+        IEntityDocument? Document { get; set; }
     }
     }
 }
 }