Skip to content

Commit

Permalink
#246 Removes framework usings from embedded Program.cs to reduce chan…
Browse files Browse the repository at this point in the history
…ce of conflicts with other nuget packages
  • Loading branch information
tareqimbasher committed Aug 31, 2024
1 parent eaffabf commit 8300dd7
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Diagnostics;
using System.Reflection;
using NetPad.ExecutionModel.External.Interface;
using NetPad.Presentation;

// ReSharper disable RedundantNameQualifier

/// <summary>
/// Meant to be injected into script code so it can initialize <see cref="ExternalProcessDumpSink"/>.
/// Meant to be injected into script code so it can initialize <see cref="NetPad.ExecutionModel.External.Interface.ExternalProcessDumpSink"/>.
/// The class name must be "Program" and must be partial. This is so we augment the base "Program" class
/// .NET will implicitly wrap top-level statements within. Code in the constructor will be called by the runtime
/// before a script's code is executed.
Expand All @@ -13,7 +12,7 @@
/// </summary>
public partial class Program
{
public static readonly UserScript UserScript = new(
public static readonly NetPad.ExecutionModel.External.Interface.UserScript UserScript = new(
new Guid("SCRIPT_ID"),
"SCRIPT_NAME",
"SCRIPT_LOCATION");
Expand All @@ -24,7 +23,7 @@ static Program()

if (args.Contains("-help"))
{
ExternalProcessDumpSink.Instance.UseConsoleOutput(true);
NetPad.ExecutionModel.External.Interface.ExternalProcessDumpSink.Instance.UseConsoleOutput(true);

PrintHelp();

Expand All @@ -35,23 +34,23 @@ static Program()

if (args.Contains("-html"))
{
ExternalProcessDumpSink.Instance.UseHtmlOutput();
NetPad.ExecutionModel.External.Interface.ExternalProcessDumpSink.Instance.UseHtmlOutput();
}
else
{
bool useConsoleColors = !args.Contains("-no-color");

if (args.Contains("-text"))
{
ExternalProcessDumpSink.Instance.UseTextOutput(useConsoleColors);
NetPad.ExecutionModel.External.Interface.ExternalProcessDumpSink.Instance.UseTextOutput(useConsoleColors);
}
else
{
ExternalProcessDumpSink.Instance.UseConsoleOutput(useConsoleColors);
NetPad.ExecutionModel.External.Interface.ExternalProcessDumpSink.Instance.UseConsoleOutput(useConsoleColors);
}
}

DumpExtension.UseSink(ExternalProcessDumpSink.Instance);
DumpExtension.UseSink(NetPad.ExecutionModel.External.Interface.ExternalProcessDumpSink.Instance);

// Use "NetPad.Utilities" qualifier because NetPad.Utilities is a global using in NetPad.Runtime, but not in running script
if (NetPad.Utilities.PlatformUtil.IsOSWindows())
Expand All @@ -62,7 +61,7 @@ static Program()

private static void PrintHelp()
{
var currentAssemblyPath = Assembly.GetExecutingAssembly().Location;
var currentAssemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
if (Environment.CurrentDirectory.Length > 1)
{
currentAssemblyPath = "." + currentAssemblyPath.Replace(Environment.CurrentDirectory, string.Empty);
Expand Down Expand Up @@ -102,11 +101,11 @@ private static void TerminateProcessOnParentExit(string[] args)
return;
}

Process? parentProcess = null;
System.Diagnostics.Process? parentProcess = null;

try
{
parentProcess = Process.GetProcessById(parentProcessId);
parentProcess = System.Diagnostics.Process.GetProcessById(parentProcessId);
parentProcess.EnableRaisingEvents = true;
}
catch
Expand Down

0 comments on commit 8300dd7

Please sign in to comment.