BadScript 2
Loading...
Searching...
No Matches
BadOperatingSystemApi.cs
Go to the documentation of this file.
1using System.Diagnostics;
2
7
9
13[BadInteropApi("OS")]
14internal partial class BadOperatingSystemApi
15{
21 {
22 BadTable env = new BadTable();
23
24 new BadEnvironmentApi().LoadRawApi(env);
25
26 return env;
27 }
28
29
36 private IEnumerator<BadObject> WaitForProcessExit(Process p, Func<BadInteropRunnable> r)
37 {
38 while (!p.HasExited)
39 {
40 yield return BadObject.Null;
41 }
42
43 r().SetReturn(p.ExitCode);
44 }
45
46
52 private BadTable CreateProcessTable(Process p)
53 {
54 BadInteropRunnable r = null!;
55
56 // ReSharper disable once AccessToModifiedClosure
57 r = new BadInteropRunnable(WaitForProcessExit(p, () => r));
58
59 BadTable t = new BadTable();
60 t.SetProperty("Awaitable", new BadTask(r, "WaitForProcessExit"));
61 t.SetProperty("HasExited", p.HasExited);
62 t.SetProperty("Id", p.Id);
63 t.SetProperty("MachineName", p.MachineName);
64 t.SetProperty("Responding", p.Responding);
65 t.SetProperty("SessionId", p.SessionId);
66 t.SetProperty("HandleCount", p.HandleCount);
67 t.SetProperty("ProcessName", p.ProcessName);
68 t.SetProperty("WorkingSet64", p.WorkingSet64);
69 t.SetProperty("MainWindowTitle", p.MainWindowTitle);
70 t.SetProperty("PagedMemorySize64", p.PagedMemorySize64);
71 t.SetProperty("PagedSystemMemorySize64", p.PagedSystemMemorySize64);
72 t.SetProperty("PeakPagedMemorySize64", p.PeakPagedMemorySize64);
73 t.SetProperty("PeakVirtualMemorySize64", p.PeakVirtualMemorySize64);
74 t.SetProperty("PeakWorkingSet64", p.PeakWorkingSet64);
75 t.SetProperty("PrivateMemorySize64", p.PrivateMemorySize64);
76 t.SetProperty("VirtualMemorySize64", p.VirtualMemorySize64);
77 t.SetProperty("NonpagedSystemMemorySize64", p.NonpagedSystemMemorySize64);
78 t.SetFunction("Kill", p.Kill);
79 t.SetFunction("Refresh", p.Refresh);
80
81 return t;
82 }
83
84
85 [BadMethod(description: "Runs a Process")]
86 [return: BadReturn("Process Table")]
87 private BadTable Run(
88 [BadParameter(
89 description:
90 "The name of the application to start, or the name of a document of a file type that is associated with an application and that has a default open action available to it. The default is an empty string (\"\")."
91 )]
92 string fileName,
93 [BadParameter(
94 description:
95 "A single string containing the arguments to pass to the target application specified in the FileName property. The default is an empty string (\"\"). On Windows Vista and earlier versions of the Windows operating system, the length of the arguments added to the length of the full path to the process must be less than 2080. On Windows 7 and later versions, the length must be less than 32699. Arguments are parsed and interpreted by the target application, so must align with the expectations of that application. For.NET applications as demonstrated in the Examples below, spaces are interpreted as a separator between multiple arguments. A single argument that includes spaces must be surrounded by quotation marks, but those quotation marks are not carried through to the target application. In include quotation marks in the final parsed argument, triple-escape each mark."
96 )]
97 string arguments,
98 [BadParameter(
99 description:
100 "When UseShellExecute is true, the fully qualified name of the directory that contains the process to be started. When the UseShellExecute property is false, the working directory for the process to be started. The default is an empty string (\"\")"
101 )]
102 string workingDirectory,
103 [BadParameter(description: "\ntrue if the process should be started without creating a new window to contain it; otherwise, false. The default is false.")]
104 bool createNoWindow,
105 [BadParameter(
106 description: "true if the shell should be used when starting the process; false if the process should be created directly from the executable file. The default is true"
107 )]
108 bool useShellExecute)
109 {
110 Process p = new Process();
111 p.StartInfo.FileName = fileName;
112 p.StartInfo.Arguments = arguments;
113 p.StartInfo.WorkingDirectory = workingDirectory;
114 p.StartInfo.CreateNoWindow = createNoWindow;
115 p.StartInfo.UseShellExecute = useShellExecute;
116 p.Start();
117
118 return CreateProcessTable(p);
119 }
120
121 protected override void AdditionalData(BadTable target)
122 {
123 target.SetProperty("Environment", CreateEnvironmentTable());
124 }
125}
IEnumerator< BadObject > WaitForProcessExit(Process p, Func< BadInteropRunnable > r)
Wrapper that creates an awaitable enumeration for a process.
BadTable Run([BadParameter(description:"The name of the application to start, or the name of a document of a file type that is associated with an application and that has a default open action available to it. The default is an empty string (\"\").")] string fileName, [BadParameter(description:"A single string containing the arguments to pass to the target application specified in the FileName property. The default is an empty string (\"\"). On Windows Vista and earlier versions of the Windows operating system, the length of the arguments added to the length of the full path to the process must be less than 2080. On Windows 7 and later versions, the length must be less than 32699. Arguments are parsed and interpreted by the target application, so must align with the expectations of that application. For.NET applications as demonstrated in the Examples below, spaces are interpreted as a separator between multiple arguments. A single argument that includes spaces must be surrounded by quotation marks, but those quotation marks are not carried through to the target application. In include quotation marks in the final parsed argument, triple-escape each mark.")] string arguments, [BadParameter(description:"When UseShellExecute is true, the fully qualified name of the directory that contains the process to be started. When the UseShellExecute property is false, the working directory for the process to be started. The default is an empty string (\"\")")] string workingDirectory, [BadParameter(description:"\ntrue if the process should be started without creating a new window to contain it; otherwise, false. The default is false.")] bool createNoWindow, [BadParameter(description:"true if the shell should be used when starting the process; false if the process should be created directly from the executable file. The default is true")] bool useShellExecute)
BadTable CreateEnvironmentTable()
Creates the "Environment" Table.
BadTable CreateProcessTable(Process p)
Creates the "Process" Table for a given Process.
Implements a Runnable that can return a value.
Implements a Task Object.
Definition BadTask.cs:17
Implements an Interop API for the BS2 Language.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements a Table Structure for the BadScript Language.
Definition BadTable.cs:14
Contains Common Interop APIs for the BadScript2 Runtime.
Contains task/async Extensions and Integrations for the BadScript2 Runtime.
Contains the Extension Classes for Functions.
Contains the Interop Abstractions and Implementations for the BadScript2 Language.
Contains the Runtime Objects.
Definition BadArray.cs:10