/********************************************************************++ Copyright (c) Microsoft Corporation. All rights reserved. --********************************************************************/ using System.Collections.ObjectModel; namespace System.Management.Automation { /// /// Provides information about a workflow that is stored in session state. /// public class WorkflowInfo : FunctionInfo { #region ctor /// /// Creates an instance of the workflowInfo class with the specified name and ScriptBlock /// /// /// /// The name of the workflow. /// /// /// /// The script body defining the workflow. /// /// /// /// The ScriptBlock for the workflow /// /// /// /// The XAML used to define the workflow /// /// /// /// The workflows referenced within . /// /// /// /// If is null. /// public WorkflowInfo(string name, string definition, ScriptBlock workflow, string xamlDefinition, WorkflowInfo[] workflowsCalled) : this(name, workflow, (ExecutionContext)null) { if (string.IsNullOrEmpty(xamlDefinition)) { throw PSTraceSource.NewArgumentNullException("xamlDefinition"); } _definition = definition; this.XamlDefinition = xamlDefinition; if (workflowsCalled != null) { _workflowsCalled = new ReadOnlyCollection(workflowsCalled); } } /// /// Creates an instance of the workflowInfo class with the specified name and ScriptBlock /// /// /// The name of the workflow. /// /// /// The script body defining the workflow. /// /// /// The ScriptBlock for the workflow /// /// /// The XAML used to define the workflow /// /// /// The workflows referenced within . /// /// module /// /// If is null. /// public WorkflowInfo(string name, string definition, ScriptBlock workflow, string xamlDefinition, WorkflowInfo[] workflowsCalled, PSModuleInfo module) : this(name, definition, workflow, xamlDefinition, workflowsCalled) { this.Module = module; } /// /// Creates an instance of the workflowInfo class with the specified name and ScriptBlock /// /// /// /// The name of the workflow. /// /// /// /// The ScriptBlock for the workflow /// /// /// /// The ExecutionContext for the workflow. /// /// /// /// If is null. /// /// internal WorkflowInfo(string name, ScriptBlock workflow, ExecutionContext context) : this(name, workflow, context, null) { } /// /// Creates an instance of the workflowInfo class with the specified name and ScriptBlock /// /// /// /// The name of the workflow. /// /// /// /// The ScriptBlock for the workflow /// /// /// /// The ExecutionContext for the workflow. /// /// /// /// The helpfile for the workflow. /// /// /// /// If is null. /// /// internal WorkflowInfo(string name, ScriptBlock workflow, ExecutionContext context, string helpFile) : base(name, workflow, context, helpFile) { SetCommandType(CommandTypes.Workflow); } /// /// Creates an instance of the WorkflowInfo class with the specified name and ScriptBlock /// /// /// /// The name of the workflow. /// /// /// /// The ScriptBlock for the workflow /// /// /// /// The options to set on the function. Note, Constant can only be set at creation time. /// /// /// /// The execution context for the workflow. /// /// /// /// If is null. /// /// internal WorkflowInfo(string name, ScriptBlock workflow, ScopedItemOptions options, ExecutionContext context) : this(name, workflow, options, context, null) { } // workflowInfo ctor /// /// Creates an instance of the WorkflowInfo class with the specified name and ScriptBlock /// /// /// /// The name of the workflow. /// /// /// /// The ScriptBlock for the workflow /// /// /// /// The options to set on the function. Note, Constant can only be set at creation time. /// /// /// /// The execution context for the workflow. /// /// /// /// The helpfile for the workflow. /// /// /// /// If is null. /// /// internal WorkflowInfo(string name, ScriptBlock workflow, ScopedItemOptions options, ExecutionContext context, string helpFile) : base(name, workflow, options, context, helpFile) { SetCommandType(CommandTypes.Workflow); } // workflowInfo ctor /// /// This is a copy constructor. /// internal WorkflowInfo(WorkflowInfo other) : base(other) { SetCommandType(CommandTypes.Workflow); CopyFields(other); } /// /// This is a copy constructor. /// internal WorkflowInfo(string name, WorkflowInfo other) : base(name, other) { SetCommandType(CommandTypes.Workflow); CopyFields(other); } private void CopyFields(WorkflowInfo other) { this.XamlDefinition = other.XamlDefinition; this.NestedXamlDefinition = other.NestedXamlDefinition; _workflowsCalled = other.WorkflowsCalled; _definition = other.Definition; } /// /// Update a workflow /// /// /// The script block that the function should represent. /// /// /// /// If true, the script block will be applied even if the filter is ReadOnly. /// /// /// /// Any options to set on the new function, null if none. /// /// /// /// Helpfile for this function /// protected internal override void Update(FunctionInfo function, bool force, ScopedItemOptions options, string helpFile) { var other = function as WorkflowInfo; if (other == null) { throw PSTraceSource.NewArgumentException("function"); } base.Update(function, force, options, helpFile); CopyFields(other); } /// /// 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.) /// internal override CommandInfo CreateGetCommandCopy(object[] arguments) { WorkflowInfo copy = new WorkflowInfo(this); copy.IsGetCommandCopy = true; copy.Arguments = arguments; return copy; } #endregion ctor /// /// Returns the definition of the workflow. /// public override string Definition { get { return _definition; } } private string _definition = ""; /// /// Gets the XAML that represents the definition of the workflow. /// public string XamlDefinition { get; internal set; } /// /// Gets or sets the XAML that represents the definition of the workflow /// when called from another workflow. /// public string NestedXamlDefinition { get; set; } /// /// Gets the XAML for workflows called by this workflow. /// public ReadOnlyCollection WorkflowsCalled { get { return _workflowsCalled ?? Utils.EmptyReadOnlyCollection(); } } private ReadOnlyCollection _workflowsCalled; internal override HelpCategory HelpCategory { get { return HelpCategory.Workflow; } } } // WorkflowInfo } // namespace System.Management.Automation