From 3f819271396776e0cd24551d59792c9ebff38da5 Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Thu, 24 Nov 2022 12:29:42 +0000 Subject: [PATCH 1/4] Prevent log usage triggering when loading a script --- BHoM_UI/Global/DocumentListener.cs | 7 ++++++- UI_Engine/Compute/LogUsage.cs | 2 +- UI_Engine/Objects/DocumentLoading.cs | 18 ++++++++++++++++++ UI_Engine/UI_Engine.csproj | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 UI_Engine/Objects/DocumentLoading.cs diff --git a/BHoM_UI/Global/DocumentListener.cs b/BHoM_UI/Global/DocumentListener.cs index d6125f1..d79284a 100644 --- a/BHoM_UI/Global/DocumentListener.cs +++ b/BHoM_UI/Global/DocumentListener.cs @@ -55,6 +55,8 @@ public static void OnDocumentBeginOpening(string documentName) m_OpeningTimes[documentName] = DateTime.Now.Ticks; Debug.WriteLine($"DocumentBeginOpening at {DateTime.Now.ToString("HH:mm:ss.ffffzzz")}"); + + BH.Engine.UI.Compute.SetDocumentOpeningState(true); } /*************************************/ @@ -76,6 +78,8 @@ public static void OnDocumentEndOpening(string documentName) m_VersioningFormThead = new Thread(ShowForm); m_VersioningFormThead.Start(events); } + + BH.Engine.UI.Compute.SetDocumentOpeningState(false); } /*************************************/ @@ -90,6 +94,8 @@ public static void OnDocumentClosing(string documentName) if (!string.IsNullOrEmpty(documentName) && m_OpeningTimes.ContainsKey(documentName)) m_OpeningTimes.Remove(documentName); + + BH.Engine.UI.Compute.SetDocumentOpeningState(false); } @@ -212,7 +218,6 @@ private static Label GetCell(string text) private static Dictionary m_OpeningTimes = new Dictionary(); private static Thread m_VersioningFormThead = null; - /*************************************/ } diff --git a/UI_Engine/Compute/LogUsage.cs b/UI_Engine/Compute/LogUsage.cs index 5b6d60b..b97720a 100644 --- a/UI_Engine/Compute/LogUsage.cs +++ b/UI_Engine/Compute/LogUsage.cs @@ -169,7 +169,7 @@ public static string BHoMVersion() private static void TriggerUsageLog(TriggerLogUsageArgs e) { - if (m_UsageLogTriggered != null) + if (m_UsageLogTriggered != null && !Compute.m_documentOpening) m_UsageLogTriggered.Invoke(null, e); } diff --git a/UI_Engine/Objects/DocumentLoading.cs b/UI_Engine/Objects/DocumentLoading.cs new file mode 100644 index 0000000..4659e5c --- /dev/null +++ b/UI_Engine/Objects/DocumentLoading.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Engine.UI +{ + public static partial class Compute + { + private static bool m_documentOpening = false; + + public static void SetDocumentOpeningState(bool state) + { + m_documentOpening = state; + } + } +} diff --git a/UI_Engine/UI_Engine.csproj b/UI_Engine/UI_Engine.csproj index 7569cd2..cf7993f 100644 --- a/UI_Engine/UI_Engine.csproj +++ b/UI_Engine/UI_Engine.csproj @@ -91,6 +91,7 @@ + From 53a315f8a60aa54451a1a3688cab10823a1a7174 Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Thu, 24 Nov 2022 16:04:50 +0000 Subject: [PATCH 2/4] Add ability to trigger onload project ID events --- UI_Engine/Compute/LogUsage.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/UI_Engine/Compute/LogUsage.cs b/UI_Engine/Compute/LogUsage.cs index b97720a..d52167f 100644 --- a/UI_Engine/Compute/LogUsage.cs +++ b/UI_Engine/Compute/LogUsage.cs @@ -55,7 +55,11 @@ public static void LogUsage(string uiName, string uiVersion, Guid componentId, s SelectedItem = selectedItem, FileID = fileId, }; - TriggerUsageLog(args); + + if (m_documentOpening) + TriggerUIOpening(args); + else + TriggerUsageLog(args); // If a projectID event is available, save the project code for this file var allEvents = BH.Engine.Base.Query.AllEvents(); @@ -141,7 +145,6 @@ private static void RemoveDeprecatedLogs(string logFolder) } } } - } /*************************************/ @@ -169,8 +172,8 @@ public static string BHoMVersion() private static void TriggerUsageLog(TriggerLogUsageArgs e) { - if (m_UsageLogTriggered != null && !Compute.m_documentOpening) - m_UsageLogTriggered.Invoke(null, e); + if (m_UsageLogTriggered != null && (!Compute.m_documentOpening || e.SelectedItem.ToString() == "Boolean SetProjectID(System.String)")) + m_UsageLogTriggered.Invoke(null, e); //Force the data to be set if the set project ID component is being run during the script load } /*************************************/ @@ -181,6 +184,14 @@ private static void TriggerUIClose() m_UIClosed.Invoke(null, null); } + /*************************************/ + + private static void TriggerUIOpening(TriggerLogUsageArgs e) + { + if (m_UIOpening != null) + m_UIOpening.Invoke(null, e); + } + /*************************************/ /**** Static Fields ****/ /*************************************/ @@ -195,6 +206,7 @@ private static void TriggerUIClose() public static event EventHandler m_UsageLogTriggered; public static event EventHandler m_UIClosed; + public static event EventHandler m_UIOpening; /*************************************/ } From 54a83665fc2098a4fd9f32bda018410585c884b9 Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Thu, 24 Nov 2022 16:49:02 +0000 Subject: [PATCH 3/4] Remove old code --- UI_Engine/Compute/LogUsage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UI_Engine/Compute/LogUsage.cs b/UI_Engine/Compute/LogUsage.cs index d52167f..9e8debf 100644 --- a/UI_Engine/Compute/LogUsage.cs +++ b/UI_Engine/Compute/LogUsage.cs @@ -172,7 +172,7 @@ public static string BHoMVersion() private static void TriggerUsageLog(TriggerLogUsageArgs e) { - if (m_UsageLogTriggered != null && (!Compute.m_documentOpening || e.SelectedItem.ToString() == "Boolean SetProjectID(System.String)")) + if (m_UsageLogTriggered != null && !Compute.m_documentOpening) m_UsageLogTriggered.Invoke(null, e); //Force the data to be set if the set project ID component is being run during the script load } From 7a493adbbf7f9b6516b4044ef76fd895ae4c89de Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Thu, 24 Nov 2022 18:05:04 +0000 Subject: [PATCH 4/4] Fix copyright --- UI_Engine/Objects/DocumentLoading.cs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/UI_Engine/Objects/DocumentLoading.cs b/UI_Engine/Objects/DocumentLoading.cs index 4659e5c..835043d 100644 --- a/UI_Engine/Objects/DocumentLoading.cs +++ b/UI_Engine/Objects/DocumentLoading.cs @@ -1,4 +1,26 @@ -using System; +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2022, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using System; using System.Collections.Generic; using System.Linq; using System.Text;