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

#246 Removes framework usings from embedded Program.cs to reduce chance of conflicts with other nuget packages #257

Merged
merged 1 commit into from
Aug 31, 2024
Merged
Changes from all commits
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
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
Loading