Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to query the usage log file name for external toolkits to the UI #433

Merged
merged 4 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions UI_Engine/Compute/LogUsage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -182,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<string, string> m_ProjectIDPerFile = new Dictionary<string, string>();

Expand Down
55 changes: 55 additions & 0 deletions UI_Engine/Query/UsageLogFileName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
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))
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;
}
}
49 changes: 49 additions & 0 deletions UI_Engine/Query/UsageLogFolder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using System;
using System.Collections.Generic;
using System.IO;
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";

//Make sure the folder exists
if (!Directory.Exists(logFolder))
Directory.CreateDirectory(logFolder);

return logFolder;
}
}
}
2 changes: 2 additions & 0 deletions UI_Engine/UI_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
<Compile Include="Query\Settings.cs" />
<Compile Include="Query\Hits.cs" />
<Compile Include="Query\Items.cs" />
<Compile Include="Query\UsageLogFileName.cs" />
<Compile Include="Query\UsageLogFolder.cs" />
<Compile Include="Query\Weight.cs" />
<Compile Include="Query\SubType.cs" />
<Compile Include="Query\Depth.cs" />
Expand Down