Skip to content

Commit

Permalink
PHASE 1 Refactoring the bloody nauseating **multiple** cyclic referen…
Browse files Browse the repository at this point in the history
…ces in the WebLibraryDetails->Library->Document and the library managers, which all reference back to library. This crap has been hackily "resolved" by me in the past using WeakReferences, but it's crap either way, with lots of runtime bugs waiting to happen, such as the ones in #264

So now everyone if refering back to the WebLibraryDetails, which have the longest lifetime of the stuff: the Library takes a long time to load and is alive later.

Of course, the current refactored code still does not check the validate the validity of the Library forward references so null references galore. This is to be fixed in subsequent commit(s).
  • Loading branch information
GerHobbelt committed Nov 1, 2020
1 parent 5ea494f commit 0d35bf6
Show file tree
Hide file tree
Showing 187 changed files with 1,838 additions and 1,726 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Qiqqa.Common.GUI;
using Qiqqa.Common.TagManagement;
using Qiqqa.DocumentLibrary;
using Qiqqa.DocumentLibrary.WebLibraryStuff;
using Qiqqa.Documents.PDF;
using Utilities.GUI.Wizard;

Expand Down Expand Up @@ -56,7 +57,7 @@ private void CmdCancel_Click(object sender, RoutedEventArgs e)

private void CmdGenerate_Click(object sender, RoutedEventArgs e)
{
OnShowTagOptionsComplete(library, pdf_documents, GetAnnotationReportOptions());
OnShowTagOptionsComplete(web_library_detail, pdf_documents, GetAnnotationReportOptions());
Close();
}

Expand All @@ -72,15 +73,15 @@ private void CmdSelectNone_Click(object sender, RoutedEventArgs e)
ListTags.Focus();
}

public delegate void OnShowTagOptionsCompleteDelegate(Library library, List<PDFDocument> pdf_documents, AnnotationReportOptions annotation_report_options);
public delegate void OnShowTagOptionsCompleteDelegate(WebLibraryDetail web_library_detail, List<PDFDocument> pdf_documents, AnnotationReportOptions annotation_report_options);

private Library library;
private WebLibraryDetail web_library_detail;
private List<PDFDocument> pdf_documents;
private OnShowTagOptionsCompleteDelegate OnShowTagOptionsComplete;

internal void ShowTagOptions(Library library_, List<PDFDocument> pdf_documents_, OnShowTagOptionsCompleteDelegate OnShowTagOptionsComplete_)
internal void ShowTagOptions(WebLibraryDetail library_, List<PDFDocument> pdf_documents_, OnShowTagOptionsCompleteDelegate OnShowTagOptionsComplete_)
{
library = library_;
web_library_detail = library_;
pdf_documents = pdf_documents_;
OnShowTagOptionsComplete = OnShowTagOptionsComplete_;

Expand Down Expand Up @@ -189,7 +190,7 @@ protected override void OnClosed(EventArgs e)
WizardDPs.ClearPointOfInterest(this);
WizardDPs.ClearPointOfInterest(CmdGenerate);

library = null;
web_library_detail = null;
pdf_documents.Clear();
pdf_documents = null;

Expand Down
13 changes: 7 additions & 6 deletions Qiqqa/AnnotationsReportBuilding/AnnotationWorkGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Windows.Documents;
using Qiqqa.Common.TagManagement;
using Qiqqa.DocumentLibrary;
using Qiqqa.DocumentLibrary.WebLibraryStuff;
using Qiqqa.Documents.PDF;
using Utilities.Misc;

Expand All @@ -13,7 +14,7 @@ internal class AnnotationWorkGenerator
{
public class AnnotationWork
{
public Library library;
public WebLibraryDetail web_library_detail;
public PDFDocument pdf_document;
public PDFAnnotation pdf_annotation;

Expand All @@ -24,13 +25,13 @@ public class AnnotationWork
public Paragraph annotation_paragraph = null;
}

public static List<AnnotationWork> GenerateAnnotationWorks(Library library, List<PDFDocument> pdf_documents, AnnotationReportOptions annotation_report_options)
public static List<AnnotationWork> GenerateAnnotationWorks(WebLibraryDetail web_library_detail, List<PDFDocument> pdf_documents, AnnotationReportOptions annotation_report_options)
{
List<AnnotationWork> annotation_works = new List<AnnotationWork>();

// The caches we will need...
Dictionary<string, byte[]> library_items_highlights_cache = library.LibraryDB.GetLibraryItemsAsCache(PDFDocumentFileLocations.HIGHLIGHTS);
Dictionary<string, byte[]> library_items_inks_cache = library.LibraryDB.GetLibraryItemsAsCache(PDFDocumentFileLocations.INKS);
Dictionary<string, byte[]> library_items_highlights_cache = web_library_detail.Xlibrary.LibraryDB.GetLibraryItemsAsCache(PDFDocumentFileLocations.HIGHLIGHTS);
Dictionary<string, byte[]> library_items_inks_cache = web_library_detail.Xlibrary.LibraryDB.GetLibraryItemsAsCache(PDFDocumentFileLocations.INKS);

for (int j = 0; j < pdf_documents.Count; ++j)
{
Expand All @@ -46,7 +47,7 @@ public static List<AnnotationWork> GenerateAnnotationWorks(Library library, List
{
if (!String.IsNullOrEmpty(pdf_document.Comments) || !String.IsNullOrEmpty(pdf_document.Abstract))
{
annotation_works.Add(new AnnotationWork { library = library, pdf_document = pdf_document, pdf_annotation = null });
annotation_works.Add(new AnnotationWork { web_library_detail = web_library_detail, pdf_document = pdf_document, pdf_annotation = null });
}
}

Expand Down Expand Up @@ -108,7 +109,7 @@ public static List<AnnotationWork> GenerateAnnotationWorks(Library library, List
}
}

annotation_works.Add(new AnnotationWork { library = library, pdf_document = pdf_document, pdf_annotation = pdf_annotation });
annotation_works.Add(new AnnotationWork { web_library_detail = web_library_detail, pdf_document = pdf_document, pdf_annotation = pdf_annotation });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Qiqqa.Common.Common;
using Qiqqa.Common.GUI;
using Qiqqa.DocumentLibrary;
using Qiqqa.DocumentLibrary.WebLibraryStuff;
using Qiqqa.Documents.PDF;
using Qiqqa.Documents.PDF.PDFControls.MetadataControls;
using Qiqqa.Documents.PDF.PDFControls.Page.Tools;
Expand Down Expand Up @@ -92,13 +93,13 @@ public void ExpandClickOptions()
}
}

internal static AnnotationReport BuildReport(Library library, List<PDFDocument> pdf_documents, AnnotationReportOptions annotation_report_options)
internal static AnnotationReport BuildReport(WebLibraryDetail web_library_detail, List<PDFDocument> pdf_documents, AnnotationReportOptions annotation_report_options)
{
AnnotationReport annotation_report = new AnnotationReport();
StandardFlowDocument flow_document = annotation_report.flow_document;

// Create a list of all the work we need to do
List<AnnotationWorkGenerator.AnnotationWork> annotation_works = AnnotationWorkGenerator.GenerateAnnotationWorks(library, pdf_documents, annotation_report_options);
List<AnnotationWorkGenerator.AnnotationWork> annotation_works = AnnotationWorkGenerator.GenerateAnnotationWorks(web_library_detail, pdf_documents, annotation_report_options);

// Now build the report
PDFDocument last_pdf_document = null;
Expand Down Expand Up @@ -720,7 +721,7 @@ private static void Floater_MouseDown(object sender, MouseButtonEventArgs e)
private static void OpenAnnotationWork(AnnotationWorkGenerator.AnnotationWork annotation_work)
{
string fingerprint = annotation_work.pdf_annotation.DocumentFingerprint;
PDFDocument pdf_document = annotation_work.library.GetDocumentByFingerprint(fingerprint);
PDFDocument pdf_document = annotation_work.web_library_detail.Xlibrary.GetDocumentByFingerprint(fingerprint);
if (null == pdf_document)
{
Logging.Error("AsyncAnnotationReportBuilder: Cannot find document anymore for fingerprint {0}", fingerprint);
Expand Down Expand Up @@ -759,7 +760,7 @@ public static void TestTagFilter()
arow.ShowTagOptions(library, pdf_documents, OnShowTagOptionsComplete);
}

private static void OnShowTagOptionsComplete(Library library, List<PDFDocument> pdf_documents, AnnotationReportOptions annotation_report_options)
private static void OnShowTagOptionsComplete(WebLibraryDetail web_library_detail, List<PDFDocument> pdf_documents, AnnotationReportOptions annotation_report_options)
{
var annotation_report = BuildReport(library, pdf_documents, annotation_report_options);
FlowDocumentScrollViewer viewer = new FlowDocumentScrollViewer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using Newtonsoft.Json;
using Qiqqa.DocumentLibrary;
using Qiqqa.DocumentLibrary.WebLibraryStuff;
using Qiqqa.Documents.PDF;
using Qiqqa.UtilisationTracking;
using Directory = Alphaleonis.Win32.Filesystem.Directory;
Expand All @@ -27,13 +28,13 @@ private class AnnotationJSON
public string text { get; set; }
}

internal static void BuildReport(Library library, List<PDFDocument> pdf_documents)
internal static void BuildReport(WebLibraryDetail web_library_detail, List<PDFDocument> pdf_documents)
{
FeatureTrackingManager.Instance.UseFeature(Features.Library_JSONAnnotationReport);

AnnotationReportOptions annotation_report_options = new AnnotationReportOptions();

List<AnnotationWorkGenerator.AnnotationWork> annotation_works = AnnotationWorkGenerator.GenerateAnnotationWorks(library, pdf_documents, annotation_report_options);
List<AnnotationWorkGenerator.AnnotationWork> annotation_works = AnnotationWorkGenerator.GenerateAnnotationWorks(web_library_detail, pdf_documents, annotation_report_options);

IEnumerable<AnnotationJSON> annotation_jsons = annotation_works.Select(annotation_work =>
new AnnotationJSON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Text;
using Qiqqa.DocumentLibrary;
using Qiqqa.DocumentLibrary.WebLibraryStuff;
using Qiqqa.Documents.PDF;
using Qiqqa.UtilisationTracking;
using Directory = Alphaleonis.Win32.Filesystem.Directory;
Expand All @@ -14,12 +15,12 @@ namespace Qiqqa.AnnotationsReportBuilding
internal class LinkedDocsAnnotationReportBuilder
{
// Warning CA1812 'LinkedDocsAnnotationReportBuilder' is an internal class that is apparently never instantiated.
// If this class is intended to contain only static methods, consider adding a private constructor to prevent
// If this class is intended to contain only static methods, consider adding a private constructor to prevent
// the compiler from generating a default constructor.
private LinkedDocsAnnotationReportBuilder()
{ }

internal static void BuildReport(Library library, List<PDFDocument> pdf_documents)
internal static void BuildReport(WebLibraryDetail web_library_detail, List<PDFDocument> pdf_documents)
{
FeatureTrackingManager.Instance.UseFeature(Features.Library_LinkedDocsAnnotationReport);

Expand Down
4 changes: 2 additions & 2 deletions Qiqqa/Brainstorm/DragDropStuff/BasicDragDropBehaviours.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal void RegisterBehaviours()
private void OnDrop_PDFDocument(object drop_object, Point mouse_current_virtual)
{
PDFDocument pdf_document = (PDFDocument)drop_object;
PDFDocumentNodeContent document_node_content = new PDFDocumentNodeContent(pdf_document.Fingerprint, pdf_document.Library.WebLibraryDetail.Id);
PDFDocumentNodeContent document_node_content = new PDFDocumentNodeContent(pdf_document.Fingerprint, pdf_document.LibraryRef.Id);
drag_drop_manager.SceneRenderingControl.AddNewNodeControl(document_node_content, mouse_current_virtual.X, mouse_current_virtual.Y);
}

Expand All @@ -39,7 +39,7 @@ private void OnDrop_PDFDocumentList(object drop_object, Point mouse_current_virt

foreach (PDFDocument pdf_document in pdf_documents)
{
PDFDocumentNodeContent document_node_content = new PDFDocumentNodeContent(pdf_document.Fingerprint, pdf_document.Library.WebLibraryDetail.Id);
PDFDocumentNodeContent document_node_content = new PDFDocumentNodeContent(pdf_document.Fingerprint, pdf_document.LibraryRef.Id);
node_contents.Add(document_node_content);
}

Expand Down
11 changes: 5 additions & 6 deletions Qiqqa/Brainstorm/Nodes/PDFAuthorNodeContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ public class PDFAuthorNodeContent : ISearchable, IRecurrentNodeContent
private string surname;
private string initial;


[NonSerialized]
private Library library = null;
public Library Library
private WebLibraryDetail web_library_detail = null;
public WebLibraryDetail LibraryRef
{
get
{
if (null == library)
if (null == web_library_detail)
{
library = WebLibraryManager.Instance.GetLibrary(library_id);
web_library_detail = WebLibraryManager.Instance.GetLibrary(library_id);
}

return library;
return web_library_detail;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Qiqqa/Brainstorm/Nodes/PDFAuthorNodeContentControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ private void ExpandDocuments()
{
FeatureTrackingManager.Instance.UseFeature(Features.Brainstorm_ExploreLibrary_Author_Documents);

List<PDFDocument> pdf_documents = SimilarAuthors.GetDocumentsBySameAuthorsSurnameAndInitial(pdf_author_node_content.Library, pdf_author_node_content.Surname, pdf_author_node_content.Initial);
List<PDFDocument> pdf_documents = SimilarAuthors.GetDocumentsBySameAuthorsSurnameAndInitial(pdf_author_node_content.LibraryRef, pdf_author_node_content.Surname, pdf_author_node_content.Initial);
foreach (PDFDocument pdf_document in pdf_documents)
{
PDFDocumentNodeContent content = new PDFDocumentNodeContent(pdf_document.Fingerprint, pdf_document.Library.WebLibraryDetail.Id);
PDFDocumentNodeContent content = new PDFDocumentNodeContent(pdf_document.Fingerprint, pdf_document.LibraryRef.Id);
NodeControlAddingByKeyboard.AddChildToNodeControl(node_control, content, false);
}
}
Expand Down
18 changes: 2 additions & 16 deletions Qiqqa/Brainstorm/Nodes/PDFAutoTagNodeContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,6 @@ public class PDFAutoTagNodeContent : ISearchable, IRecurrentNodeContent
private string library_id;
private string tag;

[NonSerialized]
private Library library = null;
public Library Library
{
get
{
if (null == library)
{
library = WebLibraryManager.Instance.GetLibrary(library_id);
}

return library;
}
}


public PDFAutoTagNodeContent(string library_id, string tag)
{
this.library_id = library_id;
Expand All @@ -45,6 +29,8 @@ public bool MatchesKeyword(string keyword)

public string Tag => tag;

public string LibraryId => library_id;

#endregion

public override bool Equals(object obj)
Expand Down
9 changes: 6 additions & 3 deletions Qiqqa/Brainstorm/Nodes/PDFAutoTagNodeContentControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Windows.Input;
using icons;
using Qiqqa.Brainstorm.SceneManager;
using Qiqqa.DocumentLibrary.WebLibraryStuff;
using Qiqqa.Documents.PDF;
using Qiqqa.UtilisationTracking;

Expand Down Expand Up @@ -46,12 +47,14 @@ public void ExpandDocuments()
{
FeatureTrackingManager.Instance.UseFeature(Features.Brainstorm_ExploreLibrary_AutoTag_Documents);

HashSet<string> document_fingerprints = pdf_auto_tag_node_content.Library.AITagManager.AITags.GetDocumentsWithTag(pdf_auto_tag_node_content.Tag);
List<PDFDocument> pdf_documents = pdf_auto_tag_node_content.Library.GetDocumentByFingerprints(document_fingerprints);
WebLibraryDetail web_library_detail = WebLibraryManager.Instance.GetLibrary(pdf_auto_tag_node_content.LibraryId);

HashSet<string> document_fingerprints = web_library_detail.Xlibrary.AITagManager.AITags.GetDocumentsWithTag(pdf_auto_tag_node_content.Tag);
List<PDFDocument> pdf_documents = web_library_detail.Xlibrary.GetDocumentByFingerprints(document_fingerprints);

foreach (PDFDocument pdf_document in pdf_documents)
{
PDFDocumentNodeContent content = new PDFDocumentNodeContent(pdf_document.Fingerprint, pdf_document.Library.WebLibraryDetail.Id);
PDFDocumentNodeContent content = new PDFDocumentNodeContent(pdf_document.Fingerprint, pdf_document.LibraryRef.Id);
NodeControlAddingByKeyboard.AddChildToNodeControl(node_control, content, false);
}
}
Expand Down
Loading

0 comments on commit 0d35bf6

Please sign in to comment.