Преглед изворни кода

Renaming "Link" properties

Kenric Nugteren пре 3 дана
родитељ
комит
def924b239

+ 3 - 3
InABox.Avalonia/DataModels/Specifics/EntityDocumentShell.cs

@@ -12,9 +12,9 @@ namespace InABox.Avalonia
         protected override void ConfigureColumns(ShellColumns<TModel, TDocument> columns)
         {
             columns
-                .Map(nameof(ParentID), x => x.EntityLink.ID)
-                .Map(nameof(DocumentID), x => x.DocumentLink.ID)
-                .Map(nameof(FileName), x => x.DocumentLink.FileName)
+                .Map(nameof(ParentID), x => x.Entity.ID)
+                .Map(nameof(DocumentID), x => x.Document.ID)
+                .Map(nameof(FileName), x => x.Document.FileName)
                 .Map(nameof(Thumbnail), x => x.Thumbnail);
         }
 

+ 9 - 1
InABox.Core/Classes/Address.cs

@@ -223,8 +223,16 @@ namespace InABox.Core
         [MemoEditor]
         public string Street { get; set; } = "";
 
-        [EditorSequence(2)] public LocalityLink LocalityLink => InitializeField(ref _locality);
+        [EditorSequence(2)]
+        public LocalityLink Locality => InitializeField(ref _locality);
         private LocalityLink _locality;
+
+        [Obsolete("Replaced with Locality")]
+        public LocalityLink LocalityLink
+        {
+            get => Locality;
+            set { }
+        }
         
         [EditorSequence(2)]
         [TextBoxEditor]

+ 27 - 5
InABox.Core/Classes/Document/EntityDocument.cs

@@ -4,7 +4,15 @@ namespace InABox.Core
 {
     public interface IEntityDocument<T> : IEntityDocument where T : IEntityLink
     {
-        T EntityLink { get; }
+        new T Entity { get; }
+
+        [Obsolete("Replaced by Entity")]
+        new T EntityLink { get; }
+
+        IEntityLink IEntityDocument.Entity => Entity;
+
+        [Obsolete]
+        IEntityLink IEntityDocument.EntityLink => EntityLink;
     }
 
     [UserTracking(typeof(User))]
@@ -17,13 +25,27 @@ namespace InABox.Core
 
         [EntityRelationship(DeleteAction.Cascade)]
         [NullEditor]
-        public T EntityLink => InitializeField(ref _entityLink, nameof(EntityLink));
-        private T? _entityLink;
+        public T Entity => InitializeField(ref _entity, nameof(Entity));
+        private T? _entity;
+
+        [Obsolete("Replaced with Entity")]
+        public T EntityLink
+        {
+            get => Entity;
+            set { }
+        }
         
         [EntityRelationship(DeleteAction.Cascade)]
         [EditorSequence(1)]
-        public DocumentLink DocumentLink => InitializeField(ref _documentLink, nameof(DocumentLink));
-        private DocumentLink? _documentLink;
+        public DocumentLink Document => InitializeField(ref _document, nameof(Document));
+        private DocumentLink? _document;
+
+        [Obsolete("Replaced with Document")]
+        public DocumentLink DocumentLink
+        {
+            get => Document;
+            set { }
+        }
 
         [TimestampEditor(Visible = Visible.Optional)]
         [EditorSequence(3)]

+ 8 - 0
InABox.Core/Classes/Document/IEntityDocument.cs

@@ -4,8 +4,16 @@ namespace InABox.Core
 {
     public interface IEntityDocument : IEntity
     {
+        IEntityLink Entity { get; }
+
+        [Obsolete("Replaced by Entity")]
+        IEntityLink EntityLink { get; }
         
+        DocumentLink Document { get; }
+
+        [Obsolete("Replaced by Document")]
         DocumentLink DocumentLink { get; }
+        
 
         DateTime Superceded { get; set; }
         

+ 6 - 0
InABox.Core/DatabaseSchema/DatabaseSchema.cs

@@ -428,6 +428,10 @@ namespace InABox.Core
 
             return prop;
         }
+
+        public static IProperty? Property<T>(Type type, Expression<Func<T, object?>> expression) =>
+            Property(type, CoreUtils.GetFullPropertyName(expression, "."));
+
         public static IProperty? Property<T>(Expression<Func<T, object?>> expression) =>
             Property(typeof(T), CoreUtils.GetFullPropertyName(expression, "."));
         public static IProperty? Property<T, TType>(Expression<Func<T, TType>> expression) =>
@@ -435,6 +439,8 @@ namespace InABox.Core
 
         public static IProperty PropertyStrict(Type type, string name) =>
             Property(type, name) ?? throw new PropertyNotFoundException(type, name);
+        public static IProperty PropertyStrict<T>(Type type, Expression<Func<T, object?>> expression) =>
+            Property(type, expression) ?? throw new PropertyNotFoundException(type, CoreUtils.GetFullPropertyName(expression, "."));
         public static IProperty PropertyStrict<T>(Expression<Func<T, object?>> expression) =>
             Property(expression) ?? throw new PropertyNotFoundException(typeof(T), CoreUtils.GetFullPropertyName(expression, "."));
         public static IProperty PropertyStrict<T, TType>(Expression<Func<T, TType>> expression) =>

+ 5 - 5
InABox.Core/DigitalForms/DataModel/DigitalFormDocumentDataModel.cs

@@ -42,7 +42,7 @@ namespace InABox.Core
             base.AddQueries(client);
             client.Add(
                 new QueryDef<TDocument>(
-                    new Filter<TDocument>("EntityLink.ID").IsEqualTo(Entity.ID),
+                    Filter<TDocument>.Where(x => x.Entity.ID).IsEqualTo(Entity.ID),
                     null,
                     null
                 ),
@@ -56,7 +56,7 @@ namespace InABox.Core
             if (client.Contains(typeof(TDocument)))
             {
                 DocumentLinks.AddRange(client.Get(typeof(TDocument)).Rows.Select(x => x.ToObject<TDocument>()));
-                var docids = DocumentLinks.Select(x => x.DocumentLink.ID).ToArray();
+                var docids = DocumentLinks.Select(x => x.Document.ID).ToArray();
                 new Client<Document>().Query(
                     Filter<Document>.Where(x => x.ID).InList(docids),
                     null,
@@ -91,16 +91,16 @@ namespace InABox.Core
             base.AddSecondaryUpdates(client);
 
             foreach (var doc in Documents)
-                if (!DocumentLinks.Any(x => x.DocumentLink.ID.Equals(doc.ID)))
+                if (!DocumentLinks.Any(x => x.Document.ID.Equals(doc.ID)))
                 {
                     var link = new TDocument();
-                    link.DocumentLink.ID = doc.ID;
+                    link.Document.ID = doc.ID;
                     DocumentLinks.Add(link);
                 }
 
             foreach (var link in DocumentLinks)
             {
-                CoreUtils.SetPropertyValue(link, "EntityLink.ID", Entity.ID);
+                CoreUtils.SetPropertyValue(link, "Entity.ID", Entity.ID);
                 if (link.IsChanged())
                     client.Add(typeof(TDocument), (Entity)link);
             }

+ 3 - 3
InABox.Mobile/InABox.Mobile.Shared/DataModels/Specifics/EntityDocumentShell.cs

@@ -12,9 +12,9 @@ namespace InABox.Mobile
         protected override void ConfigureColumns(ShellColumns<TModel, TDocument> columns)
         {
             columns
-                .Map(nameof(ParentID), x => x.EntityLink.ID)
-                .Map(nameof(DocumentID), x => x.DocumentLink.ID)
-                .Map(nameof(FileName), x => x.DocumentLink.FileName)
+                .Map(nameof(ParentID), x => x.Entity.ID)
+                .Map(nameof(DocumentID), x => x.Document.ID)
+                .Map(nameof(FileName), x => x.Document.FileName)
                 .Map(nameof(Thumbnail), x => x.Thumbnail);
         }
 

+ 6 - 6
inabox.wpf/DigitalForms/DigitalFormGrid.cs

@@ -260,9 +260,9 @@ namespace InABox.DynamicGrid
                         .Add(x=>x.RDL)
                         .Add(x=>x.Section)),
                 new KeyedQueryDef<DigitalFormDocument>(
-                    Filter<DigitalFormDocument>.Where(x => x.EntityLink.ID).IsEqualTo(form.ID),
+                    Filter<DigitalFormDocument>.Where(x => x.Entity.ID).IsEqualTo(form.ID),
                     Columns.None<DigitalFormDocument>().Add(x => x.Type)
-                        .Add(x => x.DocumentLink.ID)
+                        .Add(x => x.Document.ID)
                         .Add(x => x.Superceded)
                         .Add(x => x.Thumbnail)
                         .Add(x => x.Notes)));
@@ -556,8 +556,8 @@ namespace InABox.DynamicGrid
                     Client.Save(document, "");
 
                     var digitalFormDocument = new DigitalFormDocument();
-                    digitalFormDocument.DocumentLink.ID = document.ID;
-                    digitalFormDocument.DocumentLink.Synchronise(document);
+                    digitalFormDocument.Document.ID = document.ID;
+                    digitalFormDocument.Document.Synchronise(document);
                     formDocuments.Add(digitalFormDocument);
                 }
 
@@ -629,8 +629,8 @@ namespace InABox.DynamicGrid
                         .Add(x => x.Sequence)),
                 new KeyedQueryDef<Document>(
                     Filter<Document>.Where(x => x.ID).InQuery(
-                        Filter<DigitalFormDocument>.Where(x => x.EntityLink.ID).IsEqualTo(formID),
-                        x => x.DocumentLink.ID),
+                        Filter<DigitalFormDocument>.Where(x => x.Entity.ID).IsEqualTo(formID),
+                        x => x.Document.ID),
                     Columns.None<Document>().Add(x => x.FileName)
                         .Add(x => x.Data)));
 

+ 12 - 12
inabox.wpf/DynamicGrid/Grids/DynamicDocumentGrid.cs

@@ -64,9 +64,9 @@ public class DynamicDocumentGridImplementation<TDocument, TEntity, TEntityLink>(
 
     public void Init()
     {
-        grid.HiddenColumns.Add(x => x.DocumentLink.ID);
+        grid.HiddenColumns.Add(x => x.Document.ID);
         grid.HiddenColumns.Add(x => x.Superceded);
-        grid.HiddenColumns.Add(x => x.DocumentLink.FileName);
+        grid.HiddenColumns.Add(x => x.Document.FileName);
         grid.HiddenColumns.Add(x => x.Thumbnail);
         grid.HiddenColumns.Add(x => x.Notes);
         //ActionColumns.Add(new DynamicImageColumn(DocumentImage, ViewDocument) { Position = DynamicActionColumnPosition.Start });
@@ -184,7 +184,7 @@ public class DynamicDocumentGridImplementation<TDocument, TEntity, TEntityLink>(
         {
             FontWeight = FontWeights.Bold
         };
-        filename.SetBinding(Label.ContentProperty, new Binding("DocumentLink_FileName"));
+        filename.SetBinding(Label.ContentProperty, new Binding("Document_FileName"));
         filename.SetValue(DockPanel.DockProperty, Dock.Left);
         dock.Children.Add(filename);
 
@@ -312,7 +312,7 @@ public class DynamicDocumentGridImplementation<TDocument, TEntity, TEntityLink>(
             HorizontalContentAlignment = HorizontalAlignment.Center,
             FontSize = 10
         };
-        filename.SetBinding(Label.ContentProperty, new Binding("DocumentLink_FileName"));
+        filename.SetBinding(Label.ContentProperty, new Binding("Document_FileName"));
         filename.SetValue(Grid.RowProperty,1);
         grid.Children.Add(filename);
         
@@ -321,7 +321,7 @@ public class DynamicDocumentGridImplementation<TDocument, TEntity, TEntityLink>(
 
     private void GetDocuments(Action<Dictionary<string,byte[]>> action)
     {
-        var ids = grid.SelectedRows.Select(r => r.Get<IEntityDocument, Guid>(c => c.DocumentLink.ID)).ToArray();
+        var ids = grid.SelectedRows.Select(r => r.Get<IEntityDocument, Guid>(c => c.Document.ID)).ToArray();
         var files = Client.Query(
             Filter<Document>.Where(x => x.ID).InList(ids),
             Columns.None<Document>().Add(x => x.FileName).Add(x => x.Data)
@@ -483,7 +483,7 @@ public class DynamicDocumentGridImplementation<TDocument, TEntity, TEntityLink>(
             var columns = Columns.None<Document>().Add(x => x.ID);
             foreach (var column in grid.VisibleColumns)
             {
-                if (column.ColumnName.StartsWith("DocumentLink."))
+                if (column.ColumnName.StartsWith(nameof(IEntityDocument<TEntityLink>.Document) + "."))
                 {
                     columns.Add(string.Join('.', column.ColumnName.Split('.').Skip(1)));
                 }
@@ -495,7 +495,7 @@ public class DynamicDocumentGridImplementation<TDocument, TEntity, TEntityLink>(
             foreach (var doc in docs.ToObjects<Document>())
             {
                 var entityDocument = grid.CreateItem();
-                entityDocument.DocumentLink.CopyFrom(doc);
+                entityDocument.Document.CopyFrom(doc);
                 grid.SaveItem(entityDocument);
                 refresh = true;
             }
@@ -523,7 +523,7 @@ public class DynamicDocumentGridImplementation<TDocument, TEntity, TEntityLink>(
             foreach (var doc in documents)
             {
                 var newitem = grid.CreateItem();
-                newitem.DocumentLink.CopyFrom(doc);
+                newitem.Document.CopyFrom(doc);
                 grid.SaveItem(newitem);
             }
             grid.DoChanged();
@@ -560,7 +560,7 @@ public class DynamicDocumentGridImplementation<TDocument, TEntity, TEntityLink>(
         // Download Hi Res images in the background and replace them when available
         if (t != null && SimpleTemplate)
         {
-            var ids = t.ExtractValues<TDocument, Guid>(x => x.DocumentLink.ID).Distinct().ToArray();
+            var ids = t.ExtractValues<TDocument, Guid>(x => x.Document.ID).Distinct().ToArray();
             Client.Query(
                 Filter<Document>.Where(x => x.ID).InList(ids),
                 Columns.None<Document>().Add(x => x.ID).Add(x => x.Data),
@@ -575,7 +575,7 @@ public class DynamicDocumentGridImplementation<TDocument, TEntity, TEntityLink>(
                     var docs = d.ToDictionary<Document, Guid, byte[]>(x => x.ID, x => x.Data);
                     foreach (var row in t.Rows)
                     {
-                        if (docs.TryGetValue(row.Get<TDocument, Guid>(x => x.DocumentLink.ID),
+                        if (docs.TryGetValue(row.Get<TDocument, Guid>(x => x.Document.ID),
                                 out byte[]? data) && (data?.Any() == true))
                         {
                             if (ImageUtils.IsPdf(data))
@@ -664,7 +664,7 @@ public class DynamicDocumentDataGrid<TDocument, TEntity, TEntityLink> : DynamicD
     public override TDocument CreateItem()
     {
         var item = base.CreateItem();
-        item.EntityLink.ID = Item?.ID ?? Guid.Empty;
+        item.Entity.ID = Item?.ID ?? Guid.Empty;
         return item;
     }
 
@@ -678,7 +678,7 @@ public class DynamicDocumentDataGrid<TDocument, TEntity, TEntityLink> : DynamicD
         }
         else
         {
-            criteria.Add(Filter<TDocument>.Where(x => x.EntityLink.ID).IsEqualTo(Item.ID));
+            criteria.Add(Filter<TDocument>.Where(x => x.Entity.ID).IsEqualTo(Item.ID));
         }
         base.Reload(criteria, columns, ref sort, token, (t, e) =>
         {

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

@@ -46,7 +46,7 @@ namespace InABox.DynamicGrid
             foreach (var doc in documents)
             {
                 var tab = new DynamicTabItem();
-                tab.Header = Path.GetFileName(doc.DocumentLink.FileName);
+                tab.Header = Path.GetFileName(doc.Document.FileName);
                 tab.Tag = doc;
                 Documents.Items.Add(tab);
             }
@@ -87,7 +87,7 @@ namespace InABox.DynamicGrid
                         {
                             IDocumentEditor editor = null;
 
-                            var extension = Path.GetExtension(doc.DocumentLink.FileName).ToLower();
+                            var extension = Path.GetExtension(doc.Document.FileName).ToLower();
 
                             if (extension.Equals(".pdf"))
                             {

+ 4 - 4
inabox.wpf/DynamicGrid/PDF/ImageEditorControl.xaml.cs

@@ -75,13 +75,13 @@ namespace InABox.DynamicGrid
             if (_document is null)
                 return;
 
-            var cachefile = Path.Combine(CoreUtils.GetPath(), string.Format("{0}.ffd", _document.DocumentLink.ID.ToString()));
+            var cachefile = Path.Combine(CoreUtils.GetPath(), string.Format("{0}.ffd", _document.Document.ID.ToString()));
 
             using (new WaitCursor())
             {
-                if (DownloadNeeded(_document.DocumentLink.ID))
+                if (DownloadNeeded(_document.Document.ID))
                 {
-                    var dbdoc = new Client<Document>().Load(Filter<Document>.Where(x => x.ID).IsEqualTo(_document.DocumentLink.ID)).FirstOrDefault();
+                    var dbdoc = new Client<Document>().Load(Filter<Document>.Where(x => x.ID).IsEqualTo(_document.Document.ID)).FirstOrDefault();
                     if (dbdoc == null)
                     {
                         MessageBox.Show("Unable to Load File!");
@@ -96,7 +96,7 @@ namespace InABox.DynamicGrid
                         index = Serialization.Deserialize<Dictionary<Guid, string>>(json);
                     }
 
-                    index[_document.DocumentLink.ID] = dbdoc.CRC;
+                    index[_document.Document.ID] = dbdoc.CRC;
                     File.WriteAllText(indexfile, Serialization.Serialize(index));
 
                     documentdata = dbdoc.Data;

+ 6 - 6
inabox.wpf/DynamicGrid/PDF/PDFEditorControl.xaml.cs

@@ -289,13 +289,13 @@ namespace InABox.DynamicGrid
             if (Document == null)
                 return;
 
-            var cachefile = Path.Combine(CoreUtils.GetPath(), string.Format("{0}.ffd", Document.DocumentLink.ID.ToString()));
+            var cachefile = Path.Combine(CoreUtils.GetPath(), string.Format("{0}.ffd", Document.Document.ID.ToString()));
 
             using (new WaitCursor())
             {
-                if (DownloadNeeded(Document.DocumentLink.ID))
+                if (DownloadNeeded(Document.Document.ID))
                 {
-                    CoreTable table = new Client<Document>().Query(Filter<Document>.Where(x => x.ID).IsEqualTo(Document.DocumentLink.ID));
+                    CoreTable table = new Client<Document>().Query(Filter<Document>.Where(x => x.ID).IsEqualTo(Document.Document.ID));
                     if (!table.Rows.Any())
                     {
                         MessageBox.Show("Unable to Load File!");
@@ -311,7 +311,7 @@ namespace InABox.DynamicGrid
                         index = Serialization.Deserialize<Dictionary<Guid, string>>(json);
                     }
 
-                    index[Document.DocumentLink.ID] = dbdoc.CRC;
+                    index[Document.Document.ID] = dbdoc.CRC;
                     File.WriteAllText(indexfile, Serialization.Serialize(index));
 
                     AnnotationError = false;
@@ -558,7 +558,7 @@ namespace InABox.DynamicGrid
         private void RefreshPDF_Click(object sender, RoutedEventArgs e)
         {
             UnloadPDF();
-            var cachefile = Path.Combine(CoreUtils.GetPath(), string.Format("{0}.ffd", Document.DocumentLink.ID.ToString()));
+            var cachefile = Path.Combine(CoreUtils.GetPath(), string.Format("{0}.ffd", Document.Document.ID.ToString()));
             if (File.Exists(cachefile))
                 File.Delete(cachefile);
             LoadPDF();
@@ -694,7 +694,7 @@ namespace InABox.DynamicGrid
 
             var dlg = new SaveFileDialog();
             dlg.Filter = "PDF Files (*.pdf)|*.pdf";
-            dlg.FileName = Path.ChangeExtension(Document.DocumentLink.FileName, ".pdf");
+            dlg.FileName = Path.ChangeExtension(Document.Document.FileName, ".pdf");
             if (dlg.ShowDialog() == true)
             {
                 var ms = new MemoryStream();

+ 5 - 5
inabox.wpf/DynamicGrid/PDF/RichTextEditorControl.xaml.cs

@@ -69,14 +69,14 @@ namespace InABox.DynamicGrid
             if (_document == null)
                 return;
 
-            var cachefile = Path.Combine(CoreUtils.GetPath(), string.Format("{0}.ffd", _document.DocumentLink.ID.ToString()));
+            var cachefile = Path.Combine(CoreUtils.GetPath(), string.Format("{0}.ffd", _document.Document.ID.ToString()));
 
             using (new WaitCursor())
             {
                 byte[] documentdata;
-                if (DownloadNeeded(_document.DocumentLink.ID))
+                if (DownloadNeeded(_document.Document.ID))
                 {
-                    var dbdoc = new Client<Document>().Load(Filter<Document>.Where(x => x.ID).IsEqualTo(_document.DocumentLink.ID)).FirstOrDefault();
+                    var dbdoc = new Client<Document>().Load(Filter<Document>.Where(x => x.ID).IsEqualTo(_document.Document.ID)).FirstOrDefault();
                     if (dbdoc == null)
                     {
                         MessageBox.Show("Unable to Load File!");
@@ -91,7 +91,7 @@ namespace InABox.DynamicGrid
                         index = Serialization.Deserialize<Dictionary<Guid, string>>(json);
                     }
 
-                    index[_document.DocumentLink.ID] = dbdoc.CRC;
+                    index[_document.Document.ID] = dbdoc.CRC;
                     File.WriteAllText(indexfile, Serialization.Serialize(index));
 
                     documentdata = dbdoc.Data;
@@ -104,7 +104,7 @@ namespace InABox.DynamicGrid
                 
                 using (var ms = new MemoryStream(documentdata))
                 {
-                    var format = Path.GetExtension(_document.DocumentLink.FileName).ToLower() switch
+                    var format = Path.GetExtension(_document.Document.FileName).ToLower() switch
                     {
                         "docx" => FormatType.Docx,
                         "doc" => FormatType.Doc,

+ 4 - 4
inabox.wpf/DynamicGrid/PDF/SpreadsheetEditorControl.xaml.cs

@@ -72,13 +72,13 @@ namespace InABox.DynamicGrid
             if (_document == null)
                 return;
 
-            var cachefile = Path.Combine(CoreUtils.GetPath(), string.Format("{0}.ffd", _document.DocumentLink.ID.ToString()));
+            var cachefile = Path.Combine(CoreUtils.GetPath(), string.Format("{0}.ffd", _document.Document.ID.ToString()));
 
             using (new WaitCursor())
             {
-                if (DownloadNeeded(_document.DocumentLink.ID))
+                if (DownloadNeeded(_document.Document.ID))
                 {
-                    var dbdoc = new Client<Document>().Load(Filter<Document>.Where(x => x.ID).IsEqualTo(_document.DocumentLink.ID)).FirstOrDefault();
+                    var dbdoc = new Client<Document>().Load(Filter<Document>.Where(x => x.ID).IsEqualTo(_document.Document.ID)).FirstOrDefault();
                     if (dbdoc == null)
                     {
                         MessageBox.Show("Unable to Load File!");
@@ -93,7 +93,7 @@ namespace InABox.DynamicGrid
                         index = Serialization.Deserialize<Dictionary<Guid, string>>(json);
                     }
 
-                    index[_document.DocumentLink.ID] = dbdoc.CRC;
+                    index[_document.Document.ID] = dbdoc.CRC;
                     File.WriteAllText(indexfile, Serialization.Serialize(index));
 
                     documentdata = dbdoc.Data;