-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
111 lines (90 loc) · 2.89 KB
/
Program.cs
File metadata and controls
111 lines (90 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright Gradientspace Corp. All Rights Reserved.
using System.Diagnostics;
using Gradientspace.NodeGraph;
// todo these should be discovered from save file...
using Gradientspace.NodeGraph.Nodes;
using Gradientspace.NodeGraph.Geometry;
using Gradientspace.NodeGraph.Image;
using Gradientspace.NodeGraph.CodeNodes;
namespace GSGraphCL
{
internal class Program
{
static void Main(string[] args)
{
// todo should provide some flags to control these..
DebugManager.GlobalEnableGraphDebugging = true;
GlobalGraphOutput.SetCurrentOutput(new ConsoleGraphOutput());
GlobalGraphOutput.MirrorDebugToConsole = true;
GlobalGraphOutput.MirrorGraphIssuesToConsole = true;
string Filename = args[0];
if (File.Exists(Filename) == false)
{
GlobalGraphOutput.AppendError($"Graph file {Filename} does not exist");
Environment.Exit(-1);
}
if (args.Length > 1)
{
string[] globalArgs = new string[args.Length - 1];
for (int i = 1; i < args.Length; ++i)
globalArgs[i - 1] = args[i];
GSEnvironmentFunctions.GlobalArguments = globalArgs;
}
// Need to initialize libraries so that types can be registered
NodeGraphCoreLibrary.Initialize();
NodeGraphGeometryLibrary.Initialize();
NodeGraphImageLibrary.Initialize();
// should only do this if graph uses python...
//PythonSetup.InitializePython();
//GSPythonNodesLibrary.Initialize();
// could potentially do a faster build if we parsed the file for node names/types first...
DefaultNodeLibrary.Instance.Build();
ExecutionGraph ExecGraph = new ExecutionGraph();
ExecutionGraphEvaluator? GraphEvaluator = null;
try
{
using (FileStream fileStream = File.OpenRead(Filename))
{
bool bOK = ExecutionGraphSerializer.Restore(fileStream, ExecGraph);
if (!bOK)
{
GlobalGraphOutput.AppendError($"Error reading graph from {Filename}");
return;
}
GraphEvaluator = new ExecutionGraphEvaluator(ExecGraph);
GlobalGraphOutput.AppendLog($"Loaded Graph from {Filename}");
}
}
catch (Exception e)
{
GlobalGraphOutput.AppendError($"Error loading Graph file {Filename} - {e.Message}");
Environment.Exit(-1);
}
ExecutionGraphEvaluator.EvaluationErrorEvent errorEvent = (string Error, NodeBase? ErrorAtNode) => {
GlobalGraphOutput.AppendError($"Error at Node {ErrorAtNode?.ToString()} - {Error}");
};
GraphEvaluator.EnableDebugPrinting = true;
GraphEvaluator.OnEvaluationErrorEvent += errorEvent;
GraphEvaluator.EvaluateGraph();
// done?
}
}
public class ConsoleGraphOutput : IGraphOutput
{
public void AppendLine(string Line, EGraphOutputType OutputType = EGraphOutputType.User)
{
if (OutputType == EGraphOutputType.User)
{
System.Console.WriteLine(Line);
#if DEBUG
Debug.WriteLine(Line);
#endif
}
else
{
Debug.WriteLine(Line);
}
}
public void Clear() { }
}
}