From 31744d5cb9ffc4eae17f3140fc83a6feaac49d5f Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Tue, 1 Nov 2022 15:35:56 +0000 Subject: [PATCH 1/4] Add ability to query the usage log file name for external toolkits to the UI --- UI_Engine/Compute/LogUsage.cs | 7 ++----- UI_Engine/Query/UsageLogFileName.cs | 27 +++++++++++++++++++++++++++ UI_Engine/Query/UsageLogFolder.cs | 23 +++++++++++++++++++++++ 3 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 UI_Engine/Query/UsageLogFileName.cs create mode 100644 UI_Engine/Query/UsageLogFolder.cs diff --git a/UI_Engine/Compute/LogUsage.cs b/UI_Engine/Compute/LogUsage.cs index 353d643..37ad11e 100644 --- a/UI_Engine/Compute/LogUsage.cs +++ b/UI_Engine/Compute/LogUsage.cs @@ -104,16 +104,13 @@ private static StreamWriter GetUsageLog(string uiName) { if (m_UsageLog == null) { - // Make sure teh folder exists - string logFolder = @"C:\ProgramData\BHoM\Logs"; - if (!Directory.Exists(logFolder)) - Directory.CreateDirectory(logFolder); + string logFolder = Query.UsageLogFolder(); // Get rid of log files old enough to be deleted RemoveDeprecatedLogs(logFolder); // Create the new log file - string filePath = Path.Combine(logFolder, "Usage_" + uiName + "_" + DateTime.UtcNow.Ticks + ".log"); + string filePath = Query.UsageLogFileName(uiName); FileStream stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read); m_UsageLog = new StreamWriter(stream); diff --git a/UI_Engine/Query/UsageLogFileName.cs b/UI_Engine/Query/UsageLogFileName.cs new file mode 100644 index 0000000..145d71f --- /dev/null +++ b/UI_Engine/Query/UsageLogFileName.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.NetworkInformation; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Engine.UI +{ + public static partial class Query + { + public static string UsageLogFileName(string uiName) + { + if (!string.IsNullOrEmpty(m_usageLogFileName)) + return m_usageLogFileName; + + string logFolder = UsageLogFolder(); + + m_usageLogFileName = Path.Combine(logFolder, "Usage_" + uiName + "_" + DateTime.UtcNow.Ticks + ".log"); + + return m_usageLogFileName; + } + + private static string m_usageLogFileName; + } +} diff --git a/UI_Engine/Query/UsageLogFolder.cs b/UI_Engine/Query/UsageLogFolder.cs new file mode 100644 index 0000000..462125f --- /dev/null +++ b/UI_Engine/Query/UsageLogFolder.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Engine.UI +{ + public static partial class Query + { + public static string UsageLogFolder() + { + string logFolder = @"C:\ProgramData\BHoM\Logs"; + + //Make sure the folder exists + if (!Directory.Exists(logFolder)) + Directory.CreateDirectory(logFolder); + + return logFolder; + } + } +} From 1c22a08fe288dfcd72aaf713021550df8bb8b633 Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Tue, 1 Nov 2022 15:37:22 +0000 Subject: [PATCH 2/4] #431 - extending deprecation --- 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 37ad11e..64862d1 100644 --- a/UI_Engine/Compute/LogUsage.cs +++ b/UI_Engine/Compute/LogUsage.cs @@ -179,7 +179,7 @@ private static void TriggerUsageLog(TriggerLogUsageArgs e) private static string m_BHoMVersion = null; - private static long m_DeprecationPeriod = 7 * TimeSpan.TicksPerDay; // 7 days in ticks + private static long m_DeprecationPeriod = 28 * TimeSpan.TicksPerDay; // 28 days in ticks private static Dictionary m_ProjectIDPerFile = new Dictionary(); From e41e56b6d70e521fe07d81832735a68eb5be5139 Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Tue, 1 Nov 2022 15:43:29 +0000 Subject: [PATCH 3/4] Add documentation for new methods. --- UI_Engine/Query/UsageLogFileName.cs | 6 ++++++ UI_Engine/Query/UsageLogFolder.cs | 4 ++++ UI_Engine/UI_Engine.csproj | 2 ++ 3 files changed, 12 insertions(+) diff --git a/UI_Engine/Query/UsageLogFileName.cs b/UI_Engine/Query/UsageLogFileName.cs index 145d71f..3006c65 100644 --- a/UI_Engine/Query/UsageLogFileName.cs +++ b/UI_Engine/Query/UsageLogFileName.cs @@ -6,10 +6,16 @@ using System.Text; using System.Threading.Tasks; +using System.ComponentModel; +using BH.oM.Base.Attributes; + namespace BH.Engine.UI { public static partial class Query { + [Description("Obtain the file name of the current instance of a usage log file for the provided UI.")] + [Input("uiName", "The UI currently using the usage log to obtain the log file name for.")] + [Output("usageLogFileName", "The full file path to the current usage log file for the given UI.")] public static string UsageLogFileName(string uiName) { if (!string.IsNullOrEmpty(m_usageLogFileName)) diff --git a/UI_Engine/Query/UsageLogFolder.cs b/UI_Engine/Query/UsageLogFolder.cs index 462125f..0716635 100644 --- a/UI_Engine/Query/UsageLogFolder.cs +++ b/UI_Engine/Query/UsageLogFolder.cs @@ -4,11 +4,15 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.ComponentModel; +using BH.oM.Base.Attributes; namespace BH.Engine.UI { public static partial class Query { + [Description("Obtain the directory path to the logs folder.")] + [Output("logFolder", "The directory path to the logs folder for the BHoM.")] public static string UsageLogFolder() { string logFolder = @"C:\ProgramData\BHoM\Logs"; diff --git a/UI_Engine/UI_Engine.csproj b/UI_Engine/UI_Engine.csproj index e9b0166..7569cd2 100644 --- a/UI_Engine/UI_Engine.csproj +++ b/UI_Engine/UI_Engine.csproj @@ -101,6 +101,8 @@ + + From a629ba5702b20f7d1be6afdc7625347358bb8e13 Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Tue, 1 Nov 2022 15:47:23 +0000 Subject: [PATCH 4/4] Add copyright headers for new files --- UI_Engine/Query/UsageLogFileName.cs | 24 +++++++++++++++++++++++- UI_Engine/Query/UsageLogFolder.cs | 24 +++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/UI_Engine/Query/UsageLogFileName.cs b/UI_Engine/Query/UsageLogFileName.cs index 3006c65..6145f70 100644 --- a/UI_Engine/Query/UsageLogFileName.cs +++ b/UI_Engine/Query/UsageLogFileName.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.IO; using System.Linq; diff --git a/UI_Engine/Query/UsageLogFolder.cs b/UI_Engine/Query/UsageLogFolder.cs index 0716635..be0a3aa 100644 --- a/UI_Engine/Query/UsageLogFolder.cs +++ b/UI_Engine/Query/UsageLogFolder.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.IO; using System.Linq;