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 connect and trigger events when Usage Log is triggered #425

Merged
merged 6 commits into from
Aug 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
26 changes: 24 additions & 2 deletions UI_Engine/Compute/LogUsage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
using System.Text;
using System.Threading.Tasks;

using System.ComponentModel;

namespace BH.Engine.UI
{
public static partial class Compute
Expand All @@ -44,10 +46,21 @@ public static partial class Compute

public static void LogUsage(string uiName, string uiVersion, Guid componentId, string callerName, object selectedItem, List<Event> events = null, string fileId = "", string fileName = "")
{
TriggerLogUsageArgs args = new TriggerLogUsageArgs()
{
UIName = uiName,
UIVersion = uiVersion,
ComponentID = componentId,
CallerName = callerName,
SelectedItem = selectedItem,
};
TriggerUsageLog(args);

// If a projectID event is available, save the project code for this file
if (events != null)
var allEvents = BH.Engine.Base.Query.AllEvents();
if (allEvents != null)
{
ProjectIDEvent e = events.OfType<ProjectIDEvent>().FirstOrDefault();
ProjectIDEvent e = allEvents.OfType<ProjectIDEvent>().FirstOrDefault();
if (e != null && !string.IsNullOrEmpty(fileId))
m_ProjectIDPerFile[fileId] = e.ProjectID;
}
Expand Down Expand Up @@ -152,6 +165,13 @@ public static string BHoMVersion()
return m_BHoMVersion;
}

/*************************************/

private static void TriggerUsageLog(TriggerLogUsageArgs e)
{
if (m_UsageLogTriggered != null)
m_UsageLogTriggered.Invoke(null, e);
}

/*************************************/
/**** Static Fields ****/
Expand All @@ -165,6 +185,8 @@ public static string BHoMVersion()

private static Dictionary<string, string> m_ProjectIDPerFile = new Dictionary<string, string>();

public static event EventHandler m_UsageLogTriggered;

/*************************************/
}
}
Expand Down
4 changes: 2 additions & 2 deletions UI_Engine/UI_Engine.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -125,4 +125,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
41 changes: 41 additions & 0 deletions UI_oM/TriggerLogUsageArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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;

using BH.oM.Base;

namespace BH.oM.UI
FraserGreenroyd marked this conversation as resolved.
Show resolved Hide resolved
{
public class TriggerLogUsageArgs : EventArgs, IObject
{
public virtual object SelectedItem { get; set; } = null;
public virtual string CallerName { get; set; } = "";
public virtual string UIName { get; set; } = "";
public virtual string UIVersion { get; set; } = "";
public virtual Guid ComponentID { get; set; } = Guid.Empty;
}
}
5 changes: 3 additions & 2 deletions UI_oM/UI_oM.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -54,6 +54,7 @@
<Compile Include="ComponentRequest.cs" />
<Compile Include="Interfaces\IDataAccessor.cs" />
<Compile Include="PreviousNamesFragment.cs" />
<Compile Include="TriggerLogUsageArgs.cs" />
<Compile Include="Updates\OutputsUpdate.cs" />
<Compile Include="Updates\InputsUpdate.cs" />
<Compile Include="Updates\ParamReplaced.cs" />
Expand Down Expand Up @@ -90,4 +91,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>