本文整理汇总了C#中System.Management.Automation.ScriptBlock类的典型用法代码示例。如果您正苦于以下问题:C# ScriptBlock类的具体用法?C# ScriptBlock怎么用?C# ScriptBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ScriptBlock类属于System.Management.Automation命名空间,在下文中一共展示了ScriptBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CimActivityImplementationContext
public CimActivityImplementationContext(ActivityImplementationContext activityImplementationContext, string computerName, PSCredential credential, string certificateThumbprint, AuthenticationMechanism? authenticationMechanism, bool useSsl, uint port, PSSessionOption sessionOption, CimSession session, CimSessionOptions cimSessionOptions, string moduleDefinition, Uri resourceUri)
{
if (activityImplementationContext != null)
{
base.PowerShellInstance = activityImplementationContext.PowerShellInstance;
this.ResourceUri = resourceUri;
this.ComputerName = computerName;
base.PSCredential = credential;
base.PSCertificateThumbprint = certificateThumbprint;
base.PSAuthentication = authenticationMechanism;
base.PSUseSsl = new bool?(useSsl);
base.PSPort = new uint?(port);
base.PSSessionOption = sessionOption;
this.Session = session;
this.SessionOptions = cimSessionOptions;
if (moduleDefinition != null)
{
CimActivityImplementationContext._moduleScriptBlock = ScriptBlock.Create(moduleDefinition);
this._moduleDefinition = moduleDefinition;
}
return;
}
else
{
throw new ArgumentNullException("activityImplementationContext");
}
}
示例2: SessionStateFunctionEntry
internal SessionStateFunctionEntry(string name, string definition, ScopedItemOptions options, SessionStateEntryVisibility visibility, System.Management.Automation.ScriptBlock scriptBlock, string helpFile) : base(name, visibility)
{
this._definition = definition;
this._options = options;
this._scriptBlock = scriptBlock;
this._helpFile = helpFile;
}
示例3: InvokeScript
private static object InvokeScript(string methodName, ScriptBlock script, object @this, object[] arguments)
{
object obj2;
try
{
obj2 = script.DoInvokeReturnAsIs(true, ScriptBlock.ErrorHandlingBehavior.WriteToExternalErrorPipe, AutomationNull.Value, AutomationNull.Value, @this, arguments);
}
catch (SessionStateOverflowException exception)
{
throw new MethodInvocationException("ScriptMethodSessionStateOverflowException", exception, ExtendedTypeSystem.MethodInvocationException, new object[] { methodName, arguments.Length, exception.Message });
}
catch (RuntimeException exception2)
{
throw new MethodInvocationException("ScriptMethodRuntimeException", exception2, ExtendedTypeSystem.MethodInvocationException, new object[] { methodName, arguments.Length, exception2.Message });
}
catch (TerminateException)
{
throw;
}
catch (FlowControlException exception3)
{
throw new MethodInvocationException("ScriptMethodFlowControlException", exception3, ExtendedTypeSystem.MethodInvocationException, new object[] { methodName, arguments.Length, exception3.Message });
}
catch (PSInvalidOperationException exception4)
{
throw new MethodInvocationException("ScriptMethodInvalidOperationException", exception4, ExtendedTypeSystem.MethodInvocationException, new object[] { methodName, arguments.Length, exception4.Message });
}
return obj2;
}
示例4: DynamicVariable
/// <summary>
/// </summary>
/// <param name="name">The name of the variable, without the preceeding $.</param>
/// <param name="onGet">The get accessor for the variable. The return value will be used as the variable's value.</param>
/// <param name="onSet">The set accessor for the variable. Use $Args[0] to access the new variable.</param>
/// <param name="isCollection">True to wrap the value of the variable in a collection even if only a single value is returned.</param>
public DynamicVariable(string name, ScriptBlock onGet, ScriptBlock onSet, bool isCollection)
: base(name, null, ScopedItemOptions.AllScope)
{
OnGet = onGet;
OnSet = onSet;
IsCollection = isCollection;
}
示例5: HelpCommentsParser
private HelpCommentsParser(CommandInfo commandInfo, List<string> parameterDescriptions)
{
this._sections = new CommentHelpInfo();
this._parameters = new Dictionary<string, string>();
this._examples = new List<string>();
this._inputs = new List<string>();
this._outputs = new List<string>();
this._links = new List<string>();
FunctionInfo info = commandInfo as FunctionInfo;
if (info != null)
{
this.scriptBlock = info.ScriptBlock;
this.commandName = info.Name;
}
else
{
ExternalScriptInfo info2 = commandInfo as ExternalScriptInfo;
if (info2 != null)
{
this.scriptBlock = info2.ScriptBlock;
this.commandName = info2.Path;
}
}
this.commandMetadata = commandInfo.CommandMetadata;
this.parameterDescriptions = parameterDescriptions;
}
示例6: FunctionInfo
internal FunctionInfo(string name, ScriptBlock function, ScopedItemOptions options)
: base(name, CommandTypes.Function)
{
ScriptBlock = function;
Options = options;
ScopeUsage = ScopeUsages.NewScope;
}
示例7: FunctionInfo
internal FunctionInfo(string verb, string noun, ScriptBlock function, IEnumerable<ParameterAst> explicitParams,
ScopedItemOptions options)
: this(verb + "-" + noun, function, explicitParams, options)
{
Verb = verb;
Noun = noun;
}
示例8: Set
public void Set(string name, ScriptBlock function, string description = "")
{
var qualName = new SessionStateScope<FunctionInfo>.QualifiedName(name);
var info = new FunctionInfo(qualName.UnqualifiedName, function);
info.Description = description;
_scope.Set(name, info, true, true);
}
示例9: ScriptCommandProcessorBase
protected ScriptCommandProcessorBase(ScriptBlock scriptBlock, ExecutionContext context, bool useLocalScope, CommandOrigin origin, SessionStateInternal sessionState)
{
this._dontUseScopeCommandOrigin = false;
base.CommandInfo = new ScriptInfo(string.Empty, scriptBlock, context);
base._fromScriptFile = false;
this.CommonInitialization(scriptBlock, context, useLocalScope, sessionState);
base.Command.CommandOriginInternal = origin;
}
示例10: AsyncJob
public AsyncJob(ScriptBlock Script, Hashtable Parameters)
: this(Script)
{
foreach(DictionaryEntry param in Parameters)
{
this.Pipeline.AddParameter((string)param.Key, param.Value);
}
}
示例11: Breakpoint
internal Breakpoint(string script, ScriptBlock action)
{
Enabled = true;
Script = script;
Id = s_lastID++;
Action = action;
HitCount = 0;
}
示例12: MshExpression
/// <summary>
/// constructor
/// </summary>
/// <param name="scriptBlock"></param>
/// <exception cref="ArgumentNullException"></exception>
internal MshExpression(ScriptBlock scriptBlock)
{
if (scriptBlock == null)
{
throw PSTraceSource.NewArgumentNullException("scriptBlock");
}
Script = scriptBlock;
}
示例13: Breakpoint
internal Breakpoint(string script, ScriptBlock action)
{
this.Enabled = true;
this.Script = script;
this.Id = _lastID++;
this.Action = action;
this.HitCount = 0;
}
示例14: LogFile
public LogFile(string filename, StreamType streams = StreamType.All, ScriptBlock errorCallback = null)
{
fileName = System.IO.Path.GetFileName(filename);
path = System.IO.Path.GetDirectoryName(filename);
Streams = streams;
ErrorCallback = errorCallback;
}
示例15: PowerShellProcessInstance
public PowerShellProcessInstance(Version powerShellVersion, PSCredential credential, ScriptBlock initializationScript, bool useWow64)
{
this._syncObject = new object();
string pSExePath = PSExePath;
if (useWow64)
{
string environmentVariable = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
if (!string.IsNullOrEmpty(environmentVariable) && (environmentVariable.Equals("amd64", StringComparison.OrdinalIgnoreCase) || environmentVariable.Equals("ia64", StringComparison.OrdinalIgnoreCase)))
{
pSExePath = PSExePath.ToLowerInvariant().Replace(@"\system32\", @"\syswow64\");
if (!System.IO.File.Exists(pSExePath))
{
throw new PSInvalidOperationException(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.IPCWowComponentNotPresent, new object[] { pSExePath }));
}
}
}
string str4 = string.Empty;
Version version = powerShellVersion ?? PSVersionInfo.PSVersion;
if (null == version)
{
version = new Version(3, 0);
}
str4 = string.Format(CultureInfo.InvariantCulture, "-Version {0}", new object[] { new Version(version.Major, version.Minor) });
str4 = string.Format(CultureInfo.InvariantCulture, "{0} -s -NoLogo -NoProfile", new object[] { str4 });
if (initializationScript != null)
{
string str5 = initializationScript.ToString();
if (!string.IsNullOrEmpty(str5))
{
string str6 = Convert.ToBase64String(Encoding.Unicode.GetBytes(str5));
str4 = string.Format(CultureInfo.InvariantCulture, "{0} -EncodedCommand {1}", new object[] { str4, str6 });
}
}
ProcessStartInfo info = new ProcessStartInfo {
FileName = useWow64 ? pSExePath : PSExePath,
Arguments = str4,
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
LoadUserProfile = true
};
this._startInfo = info;
if (credential != null)
{
NetworkCredential networkCredential = credential.GetNetworkCredential();
this._startInfo.UserName = networkCredential.UserName;
this._startInfo.Domain = string.IsNullOrEmpty(networkCredential.Domain) ? "." : networkCredential.Domain;
this._startInfo.Password = credential.Password;
}
System.Diagnostics.Process process = new System.Diagnostics.Process {
StartInfo = this._startInfo,
EnableRaisingEvents = true
};
this._process = process;
}