2020-03-24 11:08:37 -07:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
2018-02-13 09:23:53 -08:00
|
|
|
// Licensed under the MIT License.
|
2016-07-29 13:02:49 -07:00
|
|
|
|
2016-03-30 14:20:52 -07:00
|
|
|
using System.Collections.ObjectModel;
|
2019-04-30 10:25:11 +05:00
|
|
|
using System.Management.Automation.Runspaces;
|
2016-03-30 14:20:52 -07:00
|
|
|
|
|
|
|
|
namespace System.Management.Automation
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2019-01-06 04:40:24 +05:00
|
|
|
/// The command information for MSH scripts that are directly executable by MSH.
|
2016-03-30 14:20:52 -07:00
|
|
|
/// </summary>
|
|
|
|
|
public class ScriptInfo : CommandInfo, IScriptCommandInfo
|
|
|
|
|
{
|
|
|
|
|
#region ctor
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates an instance of the ScriptInfo class with the specified name, and script.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">
|
|
|
|
|
/// The name of the script.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="script">
|
|
|
|
|
/// The script definition
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="context">
|
|
|
|
|
/// The execution context for the script.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <exception cref="ArgumentNullException">
|
|
|
|
|
/// If <paramref name="script"/> is null.
|
|
|
|
|
/// </exception>
|
|
|
|
|
internal ScriptInfo(string name, ScriptBlock script, ExecutionContext context)
|
|
|
|
|
: base(name, CommandTypes.Script, context)
|
|
|
|
|
{
|
|
|
|
|
if (script == null)
|
|
|
|
|
{
|
|
|
|
|
throw PSTraceSource.NewArgumentException("script");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.ScriptBlock = script;
|
2018-12-08 18:53:30 +02:00
|
|
|
}
|
2016-03-30 14:20:52 -07:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is a copy constructor, used primarily for get-command.
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal ScriptInfo(ScriptInfo other)
|
|
|
|
|
: base(other)
|
|
|
|
|
{
|
|
|
|
|
this.ScriptBlock = other.ScriptBlock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a copy of commandInfo for GetCommandCommand so that we can generate parameter
|
|
|
|
|
/// sets based on an argument list (so we can get the dynamic parameters.)
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal override CommandInfo CreateGetCommandCopy(object[] argumentList)
|
|
|
|
|
{
|
2016-07-29 13:02:49 -07:00
|
|
|
ScriptInfo copy = new ScriptInfo(this) { IsGetCommandCopy = true, Arguments = argumentList };
|
2016-03-30 14:20:52 -07:00
|
|
|
return copy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion ctor
|
|
|
|
|
|
|
|
|
|
internal override HelpCategory HelpCategory
|
|
|
|
|
{
|
2016-07-29 13:02:49 -07:00
|
|
|
get { return HelpCategory.ScriptCommand; }
|
2016-03-30 14:20:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the ScriptBlock that represents the implementation of the script.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ScriptBlock ScriptBlock { get; private set; }
|
|
|
|
|
|
|
|
|
|
// Path
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the definition of the ScriptBlock for the script. This is the ToString() of
|
|
|
|
|
/// the ScriptBlock.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public override string Definition
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return ScriptBlock.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-01-06 04:40:24 +05:00
|
|
|
/// The output type(s) is specified in the script block.
|
2016-03-30 14:20:52 -07:00
|
|
|
/// </summary>
|
|
|
|
|
public override ReadOnlyCollection<PSTypeName> OutputType
|
|
|
|
|
{
|
|
|
|
|
get { return ScriptBlock.OutputType; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-01-10 02:07:41 +05:00
|
|
|
/// For diagnostic purposes.
|
2016-03-30 14:20:52 -07:00
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return ScriptBlock.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// True if the command has dynamic parameters, false otherwise.
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal override bool ImplementsDynamicParameters
|
|
|
|
|
{
|
|
|
|
|
get { return ScriptBlock.HasDynamicParameters; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The command metadata for the script.
|
|
|
|
|
/// </summary>
|
2016-08-02 19:00:50 -07:00
|
|
|
internal override CommandMetadata CommandMetadata
|
2016-03-30 14:20:52 -07:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _commandMetadata ??
|
|
|
|
|
(_commandMetadata =
|
|
|
|
|
new CommandMetadata(this.ScriptBlock, this.Name, LocalPipeline.GetExecutionContextFromTLS()));
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-23 22:20:06 -08:00
|
|
|
|
2016-07-29 13:02:49 -07:00
|
|
|
private CommandMetadata _commandMetadata;
|
2018-12-08 18:53:30 +02:00
|
|
|
}
|
|
|
|
|
}
|