Skip to content

Commit d6c6541

Browse files
author
Fraser Greenroyd
authored
BHoM_Engine: Add methods to query the current event log suppression state (#3307)
2 parents 58ccf39 + cd461c6 commit d6c6541

File tree

3 files changed

+119
-5
lines changed

3 files changed

+119
-5
lines changed

BHoM_Engine/Compute/RecordEvent.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static bool RecordEvent(Event newEvent)
114114
OnEventRecorded(newEvent); //Only raise an event if we're not in switched off mode
115115
}
116116

117-
if (newEvent.Type == EventType.Error && m_ThrowError && !m_SuppressError) //Only throw the event as an exception if someone has asked us to throw it, AND we aren't suppressing them
117+
if (newEvent.Type == EventType.Error && m_ThrowError) //Only throw the event as an exception if someone has asked us to throw it
118118
throw new Exception(newEvent.ToText());
119119

120120
return true;
@@ -145,11 +145,11 @@ private static void OnEventRecorded(Event ev)
145145
/**** Private Variables ****/
146146
/***************************************************/
147147

148-
private static bool m_SuppressError = false; //Default to false, do not suppress any events which come through the system
149-
private static bool m_SuppressWarning = false;
150-
private static bool m_SuppressNote = false;
148+
internal static bool m_SuppressError { get; private set; } = false; //Default to false, do not suppress any events which come through the system
149+
internal static bool m_SuppressWarning { get; private set; } = false;
150+
internal static bool m_SuppressNote { get; private set; } = false;
151151

152-
private static bool m_ThrowError = false; //Default to false - do not throw errors as exceptions. However, if a user (developer user or UI user) has unsuppressed this, then errors will be thrown for try/catch statements to handle.
152+
internal static bool m_ThrowError { get; private set; } = false; //Default to false - do not throw errors as exceptions. However, if a user (developer user or UI user) has unsuppressed this, then errors will be thrown for try/catch statements to handle.
153153
//ToDo: Discuss whether we want this to be true by default and have BHoM_UI switch it off on load, or keep as is. FYI @alelom
154154
}
155155
}

BHoM_Engine/Query/IsSuppressing.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using BH.oM.Base;
24+
using BH.oM.Base.Attributes;
25+
using System.ComponentModel;
26+
using System;
27+
using System.Collections.Generic;
28+
using System.Diagnostics;
29+
using System.Linq;
30+
using System.Runtime.CompilerServices;
31+
32+
namespace BH.Engine.Base
33+
{
34+
public static partial class Query
35+
{
36+
/***************************************************/
37+
/**** Public Methods ****/
38+
/***************************************************/
39+
40+
[Description("Find out if the system is currently suppressing error recording in the main log or not.")]
41+
[Output("errorSuppression", "True if errors are currently being suppressed, false if they are being recorded normally.")]
42+
public static bool IsSuppressingErrors()
43+
{
44+
return Compute.m_SuppressError;
45+
}
46+
47+
/***************************************************/
48+
49+
[Description("Find out if the system is currently suppressing warning recording in the main log or not.")]
50+
[Output("warningSuppression", "True if warnings are currently being suppressed, false if they are being recorded normally.")]
51+
public static bool IsSuppressingWarnings()
52+
{
53+
return Compute.m_SuppressWarning;
54+
}
55+
56+
/***************************************************/
57+
58+
[Description("Find out if the system is currently suppressing note recording in the main log or not.")]
59+
[Output("noteSuppression", "True if notes are currently being suppressed, false if they are being recorded normally.")]
60+
public static bool IsSuppressingNotes()
61+
{
62+
return Compute.m_SuppressNote;
63+
}
64+
65+
/***************************************************/
66+
}
67+
}

BHoM_Engine/Query/IsThrowingErrors.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using BH.oM.Base;
24+
using BH.oM.Base.Attributes;
25+
using System.ComponentModel;
26+
using System;
27+
using System.Collections.Generic;
28+
using System.Diagnostics;
29+
using System.Linq;
30+
using System.Runtime.CompilerServices;
31+
32+
namespace BH.Engine.Base
33+
{
34+
public static partial class Query
35+
{
36+
/***************************************************/
37+
/**** Public Methods ****/
38+
/***************************************************/
39+
40+
[Description("Find out if the system is currently throwing errors as exceptions when recorded to the main log or not.")]
41+
[Output("throwingErrors", "True if errors are currently being thrown as exceptions, false if they are just being recorded in the log normally.")]
42+
public static bool IsThrowingErrors()
43+
{
44+
return Compute.m_ThrowError;
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)