Indent and whitespace cleanup powershell-run.cs

This commit is contained in:
Andrew Schwartzmeyer 2015-06-17 11:36:19 -07:00
parent 9351c05c82
commit 8f96a9e786

View file

@ -13,7 +13,7 @@ namespace ps_hello_world
{
// this is all from https://msdn.microsoft.com/en-us/library/ee706570%28v=vs.85%29.aspx
internal class MyRawUserInterface : PSHostRawUserInterface
internal class MyRawUserInterface : PSHostRawUserInterface
{
/// <summary>
/// Gets or sets the background color of the displayed text.
@ -45,9 +45,9 @@ namespace ps_hello_world
public override Coordinates CursorPosition
{
get { throw new NotImplementedException(
"The method or operation is not implemented."); }
"The method or operation is not implemented."); }
set { throw new NotImplementedException(
"The method or operation is not implemented."); }
"The method or operation is not implemented."); }
}
/// <summary>
@ -79,8 +79,8 @@ namespace ps_hello_world
/// </summary>
public override bool KeyAvailable
{
get { return false; }
// get { return Console.KeyAvailable; }
get { return false; }
// get { return Console.KeyAvailable; }
}
/// <summary>
@ -92,8 +92,8 @@ namespace ps_hello_world
/// </summary>
public override Size MaxPhysicalWindowSize
{
// get { return new Size(Console.LargestWindowWidth, Console.LargestWindowHeight); }
get { return new Size(1024,768); }
// get { return new Size(Console.LargestWindowWidth, Console.LargestWindowHeight); }
get { return new Size(1024,768); }
}
/// <summary>
@ -104,8 +104,8 @@ namespace ps_hello_world
/// </summary>
public override Size MaxWindowSize
{
// get { return new Size(Console.LargestWindowWidth, Console.LargestWindowHeight); }
get { return new Size(1024,768); }
// get { return new Size(Console.LargestWindowWidth, Console.LargestWindowHeight); }
get { return new Size(1024,768); }
}
/// <summary>
@ -115,8 +115,8 @@ namespace ps_hello_world
/// </summary>
public override Coordinates WindowPosition
{
// get { return new Coordinates(Console.WindowLeft, Console.WindowTop); }
// set { Console.SetWindowPosition(value.X, value.Y); }
// get { return new Coordinates(Console.WindowLeft, Console.WindowTop); }
// set { Console.SetWindowPosition(value.X, value.Y); }
get { return new Coordinates(0,0); }
set { }
}
@ -128,8 +128,8 @@ namespace ps_hello_world
/// </summary>
public override Size WindowSize
{
// get { return new Size(Console.WindowWidth, Console.WindowHeight); }
// set { Console.SetWindowSize(value.Width, value.Height); }
// get { return new Size(Console.WindowWidth, Console.WindowHeight); }
// set { Console.SetWindowSize(value.Width, value.Height); }
get { return new Size(1024,768); }
set { }
}
@ -140,8 +140,8 @@ namespace ps_hello_world
/// </summary>
public override string WindowTitle
{
// get { return Console.Title; }
// set { Console.Title = value; }
// get { return Console.Title; }
// set { Console.Title = value; }
get { return "window title"; }
set { }
}
@ -164,7 +164,7 @@ namespace ps_hello_world
public override BufferCell[,] GetBufferContents(Rectangle rectangle)
{
throw new NotImplementedException(
"The method or operation is not implemented.");
"The method or operation is not implemented.");
}
/// <summary>
@ -180,7 +180,7 @@ namespace ps_hello_world
public override KeyInfo ReadKey(ReadKeyOptions options)
{
throw new NotImplementedException(
"The method or operation is not implemented.");
"The method or operation is not implemented.");
}
/// <summary>
@ -196,7 +196,7 @@ namespace ps_hello_world
public override void ScrollBufferContents(Rectangle source, Coordinates destination, Rectangle clip, BufferCell fill)
{
throw new NotImplementedException(
"The method or operation is not implemented.");
"The method or operation is not implemented.");
}
/// <summary>
@ -210,7 +210,7 @@ namespace ps_hello_world
BufferCell[,] contents)
{
throw new NotImplementedException(
"The method or operation is not implemented.");
"The method or operation is not implemented.");
}
/// <summary>
@ -223,52 +223,52 @@ namespace ps_hello_world
public override void SetBufferContents(Rectangle rectangle, BufferCell fill)
{
throw new NotImplementedException(
"The method or operation is not implemented.");
"The method or operation is not implemented.");
}
}
internal class MyHostUI : PSHostUserInterface
{
private MyRawUserInterface myRawUi = new MyRawUserInterface();
internal class MyHostUI : PSHostUserInterface
{
private MyRawUserInterface myRawUi = new MyRawUserInterface();
public override PSHostRawUserInterface RawUI
{
get { return this.myRawUi; }
}
public override PSHostRawUserInterface RawUI
{
get { return this.myRawUi; }
}
public override Dictionary<string, PSObject> Prompt(
string caption,
string message,
System.Collections.ObjectModel.Collection<FieldDescription> descriptions)
{
throw new NotImplementedException(
"The method or operation is not implemented.");
}
public override Dictionary<string, PSObject> Prompt(
string caption,
string message,
System.Collections.ObjectModel.Collection<FieldDescription> descriptions)
{
throw new NotImplementedException(
"The method or operation is not implemented.");
}
public override int PromptForChoice(string caption, string message, System.Collections.ObjectModel.Collection<ChoiceDescription> choices, int defaultChoice)
{
throw new NotImplementedException("The method or operation is not implemented.");
}
public override PSCredential PromptForCredential(
string caption,
string message,
string userName,
string targetName)
public override int PromptForChoice(string caption, string message, System.Collections.ObjectModel.Collection<ChoiceDescription> choices, int defaultChoice)
{
throw new NotImplementedException("The method or operation is not implemented.");
}
public override PSCredential PromptForCredential(
string caption,
string message,
string userName,
string targetName,
PSCredentialTypes allowedCredentialTypes,
PSCredentialUIOptions options)
string caption,
string message,
string userName,
string targetName)
{
throw new NotImplementedException("The method or operation is not implemented.");
throw new NotImplementedException("The method or operation is not implemented.");
}
public override PSCredential PromptForCredential(
string caption,
string message,
string userName,
string targetName,
PSCredentialTypes allowedCredentialTypes,
PSCredentialUIOptions options)
{
throw new NotImplementedException("The method or operation is not implemented.");
}
public override string ReadLine()
@ -283,9 +283,9 @@ namespace ps_hello_world
public override void Write(string value)
{
Console.BackgroundColor = ConsoleColor.Green;
Console.BackgroundColor = ConsoleColor.Green;
Console.Write(value);
Console.ResetColor();
Console.ResetColor();
}
public override void Write(
@ -294,32 +294,32 @@ namespace ps_hello_world
string value)
{
// Colors are ignored.
Console.ForegroundColor = foregroundColor;
Console.BackgroundColor = backgroundColor;
Console.ForegroundColor = foregroundColor;
Console.BackgroundColor = backgroundColor;
Console.Write(value);
Console.ResetColor();
Console.ResetColor();
}
public override void WriteDebugLine(string message)
{
Console.BackgroundColor = ConsoleColor.Gray;
Console.BackgroundColor = ConsoleColor.Gray;
Console.Write(String.Format(
CultureInfo.CurrentCulture,
"DEBUG: {0}",
message));
Console.ResetColor();
Console.WriteLine();
CultureInfo.CurrentCulture,
"DEBUG: {0}",
message));
Console.ResetColor();
Console.WriteLine();
}
public override void WriteErrorLine(string value)
{
Console.BackgroundColor = ConsoleColor.Red;
Console.BackgroundColor = ConsoleColor.Red;
Console.Write(String.Format(
CultureInfo.CurrentCulture,
"ERROR: {0}",
value));
Console.ResetColor();
Console.WriteLine();
CultureInfo.CurrentCulture,
"ERROR: {0}",
value));
Console.ResetColor();
Console.WriteLine();
}
public override void WriteLine()
@ -331,14 +331,14 @@ namespace ps_hello_world
public override void WriteLine(string value)
{
Write(value);
Console.WriteLine();
Write(value);
Console.WriteLine();
}
public override void WriteLine(ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value)
{
Write(foregroundColor,backgroundColor,value);
Console.WriteLine();
Write(foregroundColor,backgroundColor,value);
Console.WriteLine();
}
public override void WriteProgress(long sourceId, ProgressRecord record)
@ -347,89 +347,89 @@ namespace ps_hello_world
public override void WriteVerboseLine(string message)
{
Console.BackgroundColor = ConsoleColor.DarkGray;
Console.BackgroundColor = ConsoleColor.DarkGray;
Console.WriteLine(String.Format(CultureInfo.CurrentCulture, "VERBOSE: {0}", message));
Console.ResetColor();
Console.ResetColor();
}
public override void WriteWarningLine(string message)
{
Console.BackgroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.Yellow;
Console.WriteLine(String.Format(CultureInfo.CurrentCulture, "WARNING: {0}", message));
Console.ResetColor();
Console.ResetColor();
}
}
}
internal class MyHost : PSHost
{
private Program program;
private CultureInfo originalCultureInfo = new CultureInfo("en-US");
private CultureInfo originalUICultureInfo = new CultureInfo("en-US");
private Guid myId = Guid.NewGuid();
internal class MyHost : PSHost
{
private Program program;
private CultureInfo originalCultureInfo = new CultureInfo("en-US");
private CultureInfo originalUICultureInfo = new CultureInfo("en-US");
private Guid myId = Guid.NewGuid();
public MyHost(Program program)
{
this.program = program;
}
public MyHost(Program program)
{
this.program = program;
}
private MyHostUI myHostUI = new MyHostUI();
private MyHostUI myHostUI = new MyHostUI();
public override System.Globalization.CultureInfo CurrentCulture
{
get { return this.originalCultureInfo; }
}
public override System.Globalization.CultureInfo CurrentCulture
{
get { return this.originalCultureInfo; }
}
public override System.Globalization.CultureInfo CurrentUICulture
{
get { return this.originalUICultureInfo; }
}
public override System.Globalization.CultureInfo CurrentUICulture
{
get { return this.originalUICultureInfo; }
}
public override Guid InstanceId
{
get { return myId; }
}
public override Guid InstanceId
{
get { return myId; }
}
public override string Name
{
get { return "MyHost"; }
}
public override string Name
{
get { return "MyHost"; }
}
public override PSHostUserInterface UI
{
get { return myHostUI; }
}
public override PSHostUserInterface UI
{
get { return myHostUI; }
}
public override Version Version
{
get { return new Version(0,0,0,0); }
}
public override Version Version
{
get { return new Version(0,0,0,0); }
}
public override void EnterNestedPrompt()
{
throw new NotImplementedException("EnterNestedPrompt not implemented");
}
public override void EnterNestedPrompt()
{
throw new NotImplementedException("EnterNestedPrompt not implemented");
}
public override void ExitNestedPrompt()
{
throw new NotImplementedException("ExitNestedPrompt not implemented");
}
public override void ExitNestedPrompt()
{
throw new NotImplementedException("ExitNestedPrompt not implemented");
}
public override void NotifyBeginApplication()
{
Console.WriteLine("MyHost: NotifyBeginApplication");
return;
}
public override void NotifyBeginApplication()
{
Console.WriteLine("MyHost: NotifyBeginApplication");
return;
}
public override void NotifyEndApplication()
{
return;
}
public override void NotifyEndApplication()
{
return;
}
public override void SetShouldExit(int exitCode)
{
Console.WriteLine("SetShouldExit: " + exitCode);
}
}
public override void SetShouldExit(int exitCode)
{
Console.WriteLine("SetShouldExit: " + exitCode);
}
}
class Program
{
@ -441,16 +441,16 @@ namespace ps_hello_world
// PH: this debugging requires a change in the core PS stuff that was stashed away
// during source cleanup
/*
PowerShellAssemblyLoadContext asmLoadContext = PowerShellAssemblyLoadContextInitializer.AsmLoadContext;
IEnumerable<Assembly> assemblies = asmLoadContext.GetAssemblies("System.Management.Automation");
foreach (Assembly a in assemblies)
{
Console.WriteLine("a: " + a);
}*/
PowerShellAssemblyLoadContext asmLoadContext = PowerShellAssemblyLoadContextInitializer.AsmLoadContext;
IEnumerable<Assembly> assemblies = asmLoadContext.GetAssemblies("System.Management.Automation");
foreach (Assembly a in assemblies)
{
Console.WriteLine("a: " + a);
}*/
}
static void test1(string[] args)
{
static void test1(string[] args)
{
InitialSessionState iss = InitialSessionState.CreateDefault2();
Runspace rs = RunspaceFactory.CreateRunspace(iss);
rs.Open();
@ -464,40 +464,39 @@ namespace ps_hello_world
{
Console.Write(str);
}
}
}
static void test2(string[] args)
{
MyHost myHost = new MyHost(new Program());
static void test2(string[] args)
{
MyHost myHost = new MyHost(new Program());
InitialSessionState iss = InitialSessionState.CreateDefault2();
InitialSessionState iss = InitialSessionState.CreateDefault2();
using (Runspace rs = RunspaceFactory.CreateRunspace(myHost,iss))
{
rs.Open();
using (PowerShell ps = PowerShell.Create())
{
ps.Runspace = rs;
using (Runspace rs = RunspaceFactory.CreateRunspace(myHost,iss))
{
rs.Open();
using (PowerShell ps = PowerShell.Create())
{
ps.Runspace = rs;
foreach (var arg in args)
{
Console.WriteLine("script: " + arg);
ps.AddScript(arg);
}
ps.AddCommand("out-default");
ps.Commands.Commands[0].MergeMyResults(PipelineResultTypes.Error,PipelineResultTypes.Output);
ps.Invoke();
}
}
}
foreach (var arg in args)
{
Console.WriteLine("script: " + arg);
ps.AddScript(arg);
}
ps.AddCommand("out-default");
ps.Commands.Commands[0].MergeMyResults(PipelineResultTypes.Error,PipelineResultTypes.Output);
ps.Invoke();
}
}
}
static void Main(string[] args)
{
init();
//test1(args);
test2(args);
//test1(args);
test2(args);
}
}
}