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

DYN-6052 Add node info event and API under DynamoServices package for ProtoCore #14234

Merged
merged 8 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion src/DynamoCore/Graph/Nodes/NodeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Runtime.Serialization;
using System.Xml;
using Autodesk.DesignScript.Runtime;
using DesignScript.Builtin;
using Dynamo.Configuration;
using Dynamo.Engine;
using Dynamo.Engine.CodeGeneration;
Expand Down
12 changes: 12 additions & 0 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@ protected DynamoModel(IStartConfiguration config)
#endif

LogWarningMessageEvents.LogWarningMessage += LogWarningMessage;
LogInfoMessageEvents.LogInfoMessage += LogInfoMessage;

StartBackupFilesTimer();

Expand Down Expand Up @@ -1371,6 +1372,7 @@ public void Dispose()
#endif

LogWarningMessageEvents.LogWarningMessage -= LogWarningMessage;
LogInfoMessageEvents.LogInfoMessage -= LogInfoMessage;
foreach (var ws in _workspaces)
{
ws.Dispose();
Expand Down Expand Up @@ -1792,6 +1794,16 @@ private void LogWarningMessage(LogWarningMessageEventArgs args)
EngineController.LiveRunnerRuntimeCore.RuntimeStatus.LogWarning(WarningID.Default, args.message);
}

/// <summary>
/// This info message is displayed on the node associated with the FFI dll
/// </summary>
/// <param name="args"></param>
private void LogInfoMessage(LogInfoMessageEventArgs args)
{
Validity.Assert(EngineController.LiveRunnerRuntimeCore != null);
EngineController.LiveRunnerRuntimeCore.RuntimeStatus.LogInfo(InfoID.Default, args.message);
}

#endregion

#region engine management
Expand Down
99 changes: 99 additions & 0 deletions src/Engine/ProtoCore/RuntimeStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,31 @@ public struct WarningEntry
public int AstID;
public string Filename;
}

public enum InfoID
{
Default
}

public struct InfoEntry
{
public Runtime.InfoID ID;
public string Message;
public int Line;
public int Column;
public int ExpressionID;
public Guid GraphNodeGuid;
public int AstID;
public string Filename;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish we didn’t have to expose more APIs from the engine level

Copy link
Contributor Author

@QilongTang QilongTang Aug 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did look at it but unfortunately because the current public interface ILiveRunner setup, the function involved needs to be public and also the return object as well. VS does throw errors if trying to make this internal. I have made as much as I can internal or private

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really a good candidate for a struct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjkkirschner I am not sure but maybe we could break these changes in 3.0. Right now I am just following the previous design for all these engine related code

}

public class RuntimeStatus
{
private readonly DynamoLock rwl = new DynamoLock();
private ProtoCore.RuntimeCore runtimeCore;
private List<Runtime.WarningEntry> warnings;
private List<Runtime.InfoEntry> infos;

public IOutputStream MessageHandler
{
Expand All @@ -83,6 +101,17 @@ public List<Runtime.WarningEntry> Warnings
}
}

public List<Runtime.InfoEntry> Infos
{
get
{
using (rwl.CreateReadLock())
{
return infos.ToList();
}
}
}

public int WarningCount
{
get
Expand Down Expand Up @@ -196,11 +225,81 @@ public void LogWarning(Runtime.WarningID ID, string message, string filename, in
}
}

public void LogInfo(Runtime.InfoID ID, string message, string filename, int line, int col)
{
filename = filename ?? string.Empty;

if (!runtimeCore.Options.IsDeltaExecution && (string.IsNullOrEmpty(filename) ||
line == Constants.kInvalidIndex ||
col == Constants.kInvalidIndex))
{
AuditCodeLocation(ref filename, ref line, ref col);
}

var warningMsg = string.Format(Resources.kConsoleWarningMessage,
message, filename, line, col);

#if DEBUG
if (runtimeCore.Options.Verbose)
{
System.Console.WriteLine(warningMsg);
}
#endif

if (WebMessageHandler != null)
{
var outputMessage = new OutputMessage(warningMsg);
WebMessageHandler.Write(outputMessage);
}

if (MessageHandler != null)
{
var outputMessage = new OutputMessage(OutputMessage.MessageType.Info,
message.Trim(), filename, line, col);
MessageHandler.Write(outputMessage);
}

AssociativeGraph.GraphNode executingGraphNode = null;
var executive = runtimeCore.CurrentExecutive.CurrentDSASMExec;
if (executive != null)
{
executingGraphNode = executive.Properties.executingGraphNode;
// In delta execution mode, it means the warning is from some
// internal graph node.
if (executingGraphNode != null && executingGraphNode.guid.Equals(System.Guid.Empty))
{
executingGraphNode = runtimeCore.DSExecutable.ExecutingGraphnode;
}
}

var entry = new Runtime.InfoEntry
{
ID = ID,
Message = message,
Column = col,
Line = line,
ExpressionID = runtimeCore.RuntimeExpressionUID,
GraphNodeGuid = executingGraphNode == null ? Guid.Empty : executingGraphNode.guid,
AstID = executingGraphNode == null ? Constants.kInvalidIndex : executingGraphNode.OriginalAstID,
Filename = filename
};

using (rwl.CreateWriteLock())
{
infos.Add(entry);
}
}

public void LogWarning(Runtime.WarningID ID, string message)
{
LogWarning(ID, message, string.Empty, Constants.kInvalidIndex, Constants.kInvalidIndex);
}

public void LogInfo(Runtime.InfoID ID, string message)
{
LogInfo(ID, message, string.Empty, Constants.kInvalidIndex, Constants.kInvalidIndex);
}

private void AuditCodeLocation(ref string filePath, ref int line, ref int column)
{
// We don't attempt to change line and column numbers if
Expand Down
27 changes: 26 additions & 1 deletion src/NodeServices/MessageEvents.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;

namespace DynamoServices
{
Expand All @@ -12,6 +12,19 @@ public LogWarningMessageEventArgs(string msg)
}
}

/// <summary>
/// EventArgs for LogInfoMessageEventHandler
/// </summary>
public class LogInfoMessageEventArgs : EventArgs
{
public string message { get; internal set; }

public LogInfoMessageEventArgs(string msg)
{
message = msg;
}
}
QilongTang marked this conversation as resolved.
Show resolved Hide resolved

public delegate void LogWarningMessageEventHandler(LogWarningMessageEventArgs args);

public static class LogWarningMessageEvents
Expand All @@ -24,6 +37,18 @@ public static void OnLogWarningMessage(string message)
}
}

public delegate void LogInfoMessageEventHandler(LogInfoMessageEventArgs args);

public static class LogInfoMessageEvents
{
public static event LogInfoMessageEventHandler LogInfoMessage;
public static void OnLogInfoMessage(string message)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the new API ProtoGeometry will call to raise info instead of warning

{
if (LogInfoMessage != null)
LogInfoMessage(new LogInfoMessageEventArgs(message));
}
}

internal static class LoadLibraryEvents
{
/// <summary>
Expand Down