Skip to content

Commit

Permalink
add logger method
Browse files Browse the repository at this point in the history
log
shorten legacy check
  • Loading branch information
mjkkirschner committed Nov 17, 2023
1 parent 37a666e commit 87c8860
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,7 @@ protected DynamoModel(IStartConfiguration config)

LogWarningMessageEvents.LogWarningMessage += LogWarningMessage;
LogWarningMessageEvents.LogInfoMessage += LogInfoMessage;
DynamoConsoleLogger.LogMessageToDynamoConsole += LogMessageWrapper;
StartBackupFilesTimer();

TraceReconciliationProcessor = this;
Expand Down Expand Up @@ -1426,6 +1427,7 @@ public void Dispose()

LogWarningMessageEvents.LogWarningMessage -= LogWarningMessage;
LogWarningMessageEvents.LogInfoMessage -= LogInfoMessage;
DynamoConsoleLogger.LogMessageToDynamoConsole -= LogMessageWrapper;
foreach (var ws in _workspaces)
{
ws.Dispose();
Expand Down
16 changes: 8 additions & 8 deletions src/Engine/ProtoCore/Lang/CallSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using DynamoServices;
using Newtonsoft.Json;
using ProtoCore.DSASM;
using ProtoCore.Exceptions;
Expand Down Expand Up @@ -280,9 +281,9 @@ public void LoadSerializedDataIntoTraceCache(string serializedTraceData)
var decompressedTraceData = DecompressSerializedTraceData(serializedTraceData);
newTraceData = JsonConvert.DeserializeObject<List<SingleRunTraceData>>(decompressedTraceData);
}
catch
catch(Exception e)
{
//do nothing.
DynamoConsoleLogger.OnLogMessageToDynamoConsole($"issue while deserializing trace data for callsite {callsiteID} : {e}");
}

if (newTraceData == null)
Expand Down Expand Up @@ -564,14 +565,13 @@ private void UpdateCallsiteExecutionState(Object callsiteData, RuntimeCore runti
}
}*/
}
//TODO write a unit test for this.
private static bool CheckIfTraceDataIsLegacySOAPFormat(string base64EncodedTraceData)
{
var data = Convert.FromBase64String(base64EncodedTraceData);
if (data.Length > 71)
if (data.Length > 17)
{
var header = Encoding.UTF8.GetString(data, 0, 72);
if (header == @"<SOAP-ENV:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""")
var header = Encoding.UTF8.GetString(data, 0, 18);
if (header == @"<SOAP-ENV:Envelope")
{
return true;
}
Expand Down Expand Up @@ -1907,9 +1907,9 @@ public static IList<string> GetAllSerializablesFromSingleRunTraceData(
var data = DecompressSerializedTraceData(callSiteData.Data);
traceData = JsonConvert.DeserializeObject<List<SingleRunTraceData>>(data);
}
catch
catch (Exception e)
{
//Do nothing.
DynamoConsoleLogger.OnLogMessageToDynamoConsole($"issue while deserializing trace data for callsite {callSiteData.ID} : {e}");
}

if (traceData == null)
Expand Down
13 changes: 13 additions & 0 deletions src/NodeServices/MessageEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,17 @@ internal static void OnLoadLibraryFailure(string failureMessage, string messageB
LoadLibraryFailure?.Invoke(failureMessage, messageBoxTitle);
}
}
/// <summary>
/// Used to log to the dynamo console from places where we do not have a reference
/// to the Dynamo console.
/// </summary>
internal static class DynamoConsoleLogger
{
public static event Action<string> LogMessageToDynamoConsole;

public static void OnLogMessageToDynamoConsole(string message)
{
LogMessageToDynamoConsole?.Invoke(message);
}
}
}

0 comments on commit 87c8860

Please sign in to comment.