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

Trigger for UI Loading events during analytics logging #438

Merged
merged 4 commits into from
Nov 24, 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
7 changes: 6 additions & 1 deletion BHoM_UI/Global/DocumentListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/*************************************/
Expand All @@ -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);
}

/*************************************/
Expand All @@ -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);
}


Expand Down Expand Up @@ -212,7 +218,6 @@ private static Label GetCell(string text)
private static Dictionary<string, long> m_OpeningTimes = new Dictionary<string, long>();
private static Thread m_VersioningFormThead = null;


/*************************************/
}

Expand Down
20 changes: 16 additions & 4 deletions UI_Engine/Compute/LogUsage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -141,7 +145,6 @@ private static void RemoveDeprecatedLogs(string logFolder)
}
}
}

}

/*************************************/
Expand Down Expand Up @@ -169,8 +172,8 @@ public static string BHoMVersion()

private static void TriggerUsageLog(TriggerLogUsageArgs e)
{
if (m_UsageLogTriggered != null)
m_UsageLogTriggered.Invoke(null, e);
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
}

/*************************************/
Expand All @@ -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 ****/
/*************************************/
Expand All @@ -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;

/*************************************/
}
Expand Down
40 changes: 40 additions & 0 deletions UI_Engine/Objects/DocumentLoading.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.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;
}
}
}
1 change: 1 addition & 0 deletions UI_Engine/UI_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<Compile Include="Create\OutputAccessor.cs" />
<Compile Include="Create\InputAccessor.cs" />
<Compile Include="Create\ParamInfo.cs" />
<Compile Include="Objects\DocumentLoading.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Query\MatchWith.cs" />
<Compile Include="Query\Changes.cs" />
Expand Down