Ejemplo n.º 1
0
 private void CopyFields(WorkflowInfo other)
 {
     this.XamlDefinition = other.XamlDefinition;
     this.NestedXamlDefinition = other.NestedXamlDefinition;
     this._workflowsCalled = other.WorkflowsCalled;
     this._definition = other.Definition;
 }
 internal SessionStateWorkflowEntry(string name, string definition, ScopedItemOptions options, SessionStateEntryVisibility visibility, System.Management.Automation.WorkflowInfo workflow, string helpFile) : base(name, visibility)
 {
     this._definition = definition;
     this._options    = options;
     this._workflow   = workflow;
     this._helpFile   = helpFile;
 }
Ejemplo n.º 3
0
 internal SessionStateWorkflowEntry(string name, string definition, ScopedItemOptions options, SessionStateEntryVisibility visibility, System.Management.Automation.WorkflowInfo workflow, string helpFile) : base(name, visibility)
 {
     this._definition = definition;
     this._options = options;
     this._workflow = workflow;
     this._helpFile = helpFile;
 }
Ejemplo n.º 4
0
        /// <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[] arguments)
        {
            WorkflowInfo copy = new WorkflowInfo(this);

            copy.IsGetCommandCopy = true;
            copy.Arguments        = arguments;
            return(copy);
        }
Ejemplo n.º 5
0
 public WorkflowInfo(
     string name,
     string definition,
     ScriptBlock workflow,
     string xamlDefinition,
     WorkflowInfo[] workflowsCalled)
     : base(name, workflow, null)
 {
 }
Ejemplo n.º 6
0
        } // SetFunctionRaw

        internal WorkflowInfo SetWorkflowRaw(
            WorkflowInfo workflowInfo,
            CommandOrigin origin)
        {
            string originalName = workflowInfo.Name;
            string name         = originalName;

            FunctionLookupPath path = new FunctionLookupPath(name);

            name = path.UnqualifiedPath;

            if (String.IsNullOrEmpty(name))
            {
                SessionStateException exception =
                    new SessionStateException(
                        originalName,
                        SessionStateCategory.Function,
                        "ScopedFunctionMustHaveName",
                        SessionStateStrings.ScopedFunctionMustHaveName,
                        ErrorCategory.InvalidArgument);

                throw exception;
            }

            ScopedItemOptions options = ScopedItemOptions.None;

            if (path.IsPrivate)
            {
                options |= ScopedItemOptions.Private;
            }

            FunctionScopeItemSearcher searcher =
                new FunctionScopeItemSearcher(
                    this,
                    path,
                    origin);

            // The script that defines a workflowInfo wrapper is fully trusted
            workflowInfo.ScriptBlock.LanguageMode = PSLanguageMode.FullLanguage;

            if (workflowInfo.Module == null && this.Module != null)
            {
                workflowInfo.Module = this.Module;
            }

            var wfInfo = (WorkflowInfo)
                         searcher.InitialScope.SetFunction(name, workflowInfo.ScriptBlock, null, options, false, origin, ExecutionContext, null,
                                                           (arg1, arg2, arg3, arg4, arg5, arg6) => workflowInfo);

            foreach (var aliasName in GetFunctionAliases(workflowInfo.ScriptBlock.Ast as IParameterMetadataProvider))
            {
                searcher.InitialScope.SetAliasValue(aliasName, name, ExecutionContext, false, origin);
            }

            return(wfInfo);
        } // SetWorkflowRaw
Ejemplo n.º 7
0
        protected internal override void Update(FunctionInfo function, bool force, ScopedItemOptions options, string helpFile)
        {
            WorkflowInfo other = function as WorkflowInfo;

            if (other == null)
            {
                throw PSTraceSource.NewArgumentException("function");
            }
            base.Update(function, force, options, helpFile);
            this.CopyFields(other);
        }
Ejemplo n.º 8
0
        internal void AddSessionStateEntry(InitialSessionState initialSessionState, SessionStateWorkflowEntry entry)
        {
            var converterInstance = Utils.GetAstToWorkflowConverterAndEnsureWorkflowModuleLoaded(null);

            var workflowInfo = entry.WorkflowInfo ??
                               converterInstance.CompileWorkflow(entry.Name, entry.Definition, initialSessionState);

            WorkflowInfo wf = new WorkflowInfo(workflowInfo);

            wf = this.SetWorkflowRaw(wf, CommandOrigin.Internal);
            wf.Visibility = entry.Visibility;
            wf.Module = entry.Module;
        }
Ejemplo n.º 9
0
        internal void AddSessionStateEntry(InitialSessionState initialSessionState, SessionStateWorkflowEntry entry)
        {
            var converterInstance = Utils.GetAstToWorkflowConverterAndEnsureWorkflowModuleLoaded(null);

            var workflowInfo = entry.WorkflowInfo ??
                               converterInstance.CompileWorkflow(entry.Name, entry.Definition, initialSessionState);

            WorkflowInfo wf = new WorkflowInfo(workflowInfo);

            wf            = this.SetWorkflowRaw(wf, CommandOrigin.Internal);
            wf.Visibility = entry.Visibility;
            wf.Module     = entry.Module;
        }
Ejemplo n.º 10
0
 public WorkflowInfo(string name, string definition, ScriptBlock workflow, string xamlDefinition, WorkflowInfo[] workflowsCalled) : this(name, workflow, null)
 {
     if (string.IsNullOrEmpty(xamlDefinition))
     {
         throw PSTraceSource.NewArgumentNullException("xamlDefinition");
     }
     this._definition = definition;
     this.XamlDefinition = xamlDefinition;
     if (workflowsCalled != null)
     {
         this._workflowsCalled = new ReadOnlyCollection<WorkflowInfo>(workflowsCalled);
     }
 }
Ejemplo n.º 11
0
 internal WorkflowInfo SetWorkflowRaw(WorkflowInfo workflowInfo, CommandOrigin origin)
 {
     string name = workflowInfo.Name;
     string unqualifiedPath = name;
     FunctionLookupPath lookupPath = new FunctionLookupPath(unqualifiedPath);
     unqualifiedPath = lookupPath.UnqualifiedPath;
     if (string.IsNullOrEmpty(unqualifiedPath))
     {
         SessionStateException exception = new SessionStateException(name, SessionStateCategory.Function, "ScopedFunctionMustHaveName", SessionStateStrings.ScopedFunctionMustHaveName, ErrorCategory.InvalidArgument, new object[0]);
         throw exception;
     }
     ScopedItemOptions none = ScopedItemOptions.None;
     if (lookupPath.IsPrivate)
     {
         none |= ScopedItemOptions.Private;
     }
     FunctionScopeItemSearcher searcher = new FunctionScopeItemSearcher(this, lookupPath, origin);
     workflowInfo.ScriptBlock.LanguageMode = 0;
     return (WorkflowInfo) searcher.InitialScope.SetFunction(unqualifiedPath, workflowInfo.ScriptBlock, null, none, false, origin, this.ExecutionContext, null, (arg1, arg2, arg3, arg4, arg5, arg6) => workflowInfo);
 }
Ejemplo n.º 12
0
 internal void AddSessionStateEntry(InitialSessionState initialSessionState, SessionStateWorkflowEntry entry)
 {
     IAstToWorkflowConverter astToWorkflowConverterAndEnsureWorkflowModuleLoaded = Utils.GetAstToWorkflowConverterAndEnsureWorkflowModuleLoaded(null);
     WorkflowInfo workflowInfo = entry.WorkflowInfo;
     if (workflowInfo == null)
     {
         workflowInfo = astToWorkflowConverterAndEnsureWorkflowModuleLoaded.CompileWorkflow(entry.Name, entry.Definition, initialSessionState);
     }
     WorkflowInfo info2 = new WorkflowInfo(workflowInfo);
     info2 = this.SetWorkflowRaw(info2, CommandOrigin.Internal);
     info2.Visibility = entry.Visibility;
     info2.SetModule(entry.Module);
 }
Ejemplo n.º 13
0
        } // SetFunctionRaw

        internal WorkflowInfo SetWorkflowRaw(
            WorkflowInfo workflowInfo,
            CommandOrigin origin)
        {
            string originalName = workflowInfo.Name;
            string name = originalName;

            FunctionLookupPath path = new FunctionLookupPath(name);
            name = path.UnqualifiedPath;

            if (String.IsNullOrEmpty(name))
            {
                SessionStateException exception =
                    new SessionStateException(
                        originalName,
                        SessionStateCategory.Function,
                        "ScopedFunctionMustHaveName",
                        SessionStateStrings.ScopedFunctionMustHaveName,
                        ErrorCategory.InvalidArgument);

                throw exception;
            }

            ScopedItemOptions options = ScopedItemOptions.None;
            if (path.IsPrivate)
            {
                options |= ScopedItemOptions.Private;
            }

            FunctionScopeItemSearcher searcher =
                new FunctionScopeItemSearcher(
                    this,
                    path,
                    origin);

            // The script that defines a workflowInfo wrapper is fully trusted
            workflowInfo.ScriptBlock.LanguageMode = PSLanguageMode.FullLanguage;

            if (workflowInfo.Module == null && this.Module != null)
            {
                workflowInfo.Module = this.Module;
            }

            var wfInfo = (WorkflowInfo)
                searcher.InitialScope.SetFunction(name, workflowInfo.ScriptBlock, null, options, false, origin, ExecutionContext, null,
                                                     (arg1, arg2, arg3, arg4, arg5, arg6) => workflowInfo);
            foreach (var aliasName in GetFunctionAliases(workflowInfo.ScriptBlock.Ast as IParameterMetadataProvider))
            {
                searcher.InitialScope.SetAliasValue(aliasName, name, ExecutionContext, false, origin);
            }

            return wfInfo;
        } // SetWorkflowRaw
Ejemplo n.º 14
0
 /// <summary>
 /// Creates an instance of the workflowInfo class with the specified name and ScriptBlock
 /// </summary> 
 /// <param name="name">
 /// The name of the workflow.
 /// </param> 
 /// <param name="definition">
 /// The script body defining the workflow.
 /// </param>
 /// <param name="workflow">
 /// The ScriptBlock for the workflow
 /// </param> 
 /// <param name="xamlDefinition">
 /// The XAML used to define the workflow
 /// </param>
 /// <param name="workflowsCalled">
 /// The workflows referenced within <paramref name="xamlDefinition"/>.
 /// </param>
 /// <param name="module">module</param> 
 /// <exception cref="ArgumentNullException">
 /// If <paramref name="workflow"/> is null.
 /// </exception> 
 public WorkflowInfo(string name, string definition, ScriptBlock workflow, string xamlDefinition, WorkflowInfo[] workflowsCalled, PSModuleInfo module)
     : this(name, definition, workflow, xamlDefinition, workflowsCalled)
 {
     this.Module = module;
 }
Ejemplo n.º 15
0
 /// <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[] arguments)
 {
     WorkflowInfo copy = new WorkflowInfo(this);
     copy.IsGetCommandCopy = true;
     copy.Arguments = arguments;
     return copy;
 }
Ejemplo n.º 16
0
 internal WorkflowInfo(string name, WorkflowInfo other) : base(name, other)
 {
     this._definition = "";
     base.SetCommandType(CommandTypes.Workflow);
     this.CopyFields(other);
 }
Ejemplo n.º 17
0
		private void UpdateFunctionFromXaml(ImportWorkflowCommand.FunctionDetails details)
		{
			string str = string.Concat("function:\\script:", details.Name);
			ScriptBlock scriptBlock = null;
			PSLanguageMode languageMode = base.SessionState.LanguageMode;
			try
			{
				base.SessionState.LanguageMode = PSLanguageMode.FullLanguage;
				scriptBlock = ScriptBlock.Create(details.FunctionDefinition);
			}
			finally
			{
				base.SessionState.LanguageMode = languageMode;
			}
			WorkflowInfo workflowInfo = new WorkflowInfo(details.Name, "", scriptBlock, details.Xaml, null);
			base.SessionState.InvokeProvider.Item.Set(str, workflowInfo);
		}
Ejemplo n.º 18
0
        internal static HelpInfo CreateFromComments(ExecutionContext context, CommandInfo commandInfo, HelpCommentsParser helpCommentsParser, bool dontSearchOnRemoteComputer)
        {
            if (!dontSearchOnRemoteComputer)
            {
                RemoteHelpInfo remoteHelpInfo = helpCommentsParser.GetRemoteHelpInfo(context, commandInfo);
                if (remoteHelpInfo != null)
                {
                    if (remoteHelpInfo.GetUriForOnlineHelp() == null)
                    {
                        DefaultCommandHelpObjectBuilder.AddRelatedLinksProperties(remoteHelpInfo.FullHelp, commandInfo.CommandMetadata.HelpUri);
                    }
                    return(remoteHelpInfo);
                }
            }
            XmlDocument         document     = helpCommentsParser.BuildXmlFromComments();
            HelpCategory        helpCategory = commandInfo.HelpCategory;
            MamlCommandHelpInfo helpInfo     = MamlCommandHelpInfo.Load(document.DocumentElement, helpCategory);

            if (helpInfo != null)
            {
                helpCommentsParser.SetAdditionalData(helpInfo);
                if (!string.IsNullOrEmpty(helpCommentsParser._sections.ForwardHelpTargetName) || !string.IsNullOrEmpty(helpCommentsParser._sections.ForwardHelpCategory))
                {
                    if (string.IsNullOrEmpty(helpCommentsParser._sections.ForwardHelpTargetName))
                    {
                        helpInfo.ForwardTarget = helpInfo.Name;
                    }
                    else
                    {
                        helpInfo.ForwardTarget = helpCommentsParser._sections.ForwardHelpTargetName;
                    }
                    if (!string.IsNullOrEmpty(helpCommentsParser._sections.ForwardHelpCategory))
                    {
                        try
                        {
                            helpInfo.ForwardHelpCategory = (HelpCategory)Enum.Parse(typeof(HelpCategory), helpCommentsParser._sections.ForwardHelpCategory, true);
                        }
                        catch (ArgumentException)
                        {
                        }
                    }
                    else
                    {
                        helpInfo.ForwardHelpCategory = HelpCategory.Workflow | HelpCategory.ExternalScript | HelpCategory.Filter | HelpCategory.Function | HelpCategory.ScriptCommand | HelpCategory.Cmdlet | HelpCategory.Alias;
                    }
                }
                WorkflowInfo info3 = commandInfo as WorkflowInfo;
                if (info3 != null)
                {
                    bool flag  = DefaultCommandHelpObjectBuilder.HasCommonParameters(commandInfo.Parameters);
                    bool flag2 = (commandInfo.CommandType & CommandTypes.Workflow) == CommandTypes.Workflow;
                    helpInfo.FullHelp.Properties.Add(new PSNoteProperty("CommonParameters", flag));
                    helpInfo.FullHelp.Properties.Add(new PSNoteProperty("WorkflowCommonParameters", flag2));
                    DefaultCommandHelpObjectBuilder.AddDetailsProperties(helpInfo.FullHelp, info3.Name, info3.Noun, info3.Verb, "MamlCommandHelpInfo", helpInfo.Synopsis);
                    DefaultCommandHelpObjectBuilder.AddSyntaxProperties(helpInfo.FullHelp, info3.Name, info3.ParameterSets, flag, flag2, "MamlCommandHelpInfo");
                }
                if (helpInfo.GetUriForOnlineHelp() == null)
                {
                    DefaultCommandHelpObjectBuilder.AddRelatedLinksProperties(helpInfo.FullHelp, commandInfo.CommandMetadata.HelpUri);
                }
            }
            return(helpInfo);
        }
Ejemplo n.º 19
0
 internal WorkflowInfo(string name, WorkflowInfo other) : base(name, other)
 {
     this._definition = "";
     base.SetCommandType(CommandTypes.Workflow);
     this.CopyFields(other);
 }
Ejemplo n.º 20
0
        } // workflowInfo ctor

        /// <summary>
        /// This is a copy constructor.
        /// </summary>
        internal WorkflowInfo(WorkflowInfo other)
            : base(other)
        {
            SetCommandType(CommandTypes.Workflow);

            CopyFields(other);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// This is a copy constructor.
        /// </summary>
        internal WorkflowInfo(string name, WorkflowInfo other)
            : base(name, other)
        {
            SetCommandType(CommandTypes.Workflow);

            CopyFields(other);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Generate a function in the current session using the specified
        /// function details
        /// </summary>
        /// <param name="details">details of the function</param>
        private void UpdateFunctionFromXaml(FunctionDetails details)
        {
            // Bind the command into the caller's command table. Note that if
            // ~/ has been passed to this cmdlet, then the Set operation will also be logged
            // the verbose stream. This is desirable as it shows the generated function...
            string functionName = "function:\\script:" + details.Name;

            // This script block is defined as FullLanguage mode, since it contains
            // no text that can be injected by the user.
            ScriptBlock xamlFunctionDefinition = null;
            PSLanguageMode oldLanguageMode = this.SessionState.LanguageMode;
            try
            {
                this.SessionState.LanguageMode = PSLanguageMode.FullLanguage;
                xamlFunctionDefinition = ScriptBlock.Create(details.FunctionDefinition);
            }
            finally
            {
                this.SessionState.LanguageMode = oldLanguageMode;
            }

            WorkflowInfo workflow = new WorkflowInfo(details.Name, "", xamlFunctionDefinition, details.Xaml, null);

            SessionState.InvokeProvider.Item.Set(functionName, workflow);
        }
Ejemplo n.º 23
0
        private static FunctionInfo CreateFunction(string name, ScriptBlock function, FunctionInfo originalFunction,
            ScopedItemOptions options, ExecutionContext context, string helpFile)
        {
            FunctionInfo newValue = null;

            if (options == ScopedItemOptions.Unspecified)
            {
                options = ScopedItemOptions.None;
            }

            // First use the copy constructors
            if (originalFunction is FilterInfo)
            {
                newValue = new FilterInfo(name, (FilterInfo)originalFunction);
            }
            else if (originalFunction is WorkflowInfo)
            {
                newValue = new WorkflowInfo(name, (WorkflowInfo)originalFunction);
            }
            else if (originalFunction is ConfigurationInfo)
            {
                newValue = new ConfigurationInfo(name, (ConfigurationInfo)originalFunction);
            }
            else if (originalFunction != null)
            {
                newValue = new FunctionInfo(name, originalFunction);
            }

            // Then use the creation constructors - workflows don't get here because the workflow info
            // is created during compilation.
            else if (function.IsFilter) { newValue = new FilterInfo(name, function, options, context, helpFile); }
            else if (function.IsConfiguration)
            {
                newValue = new ConfigurationInfo(name, function, options, context, helpFile, function.IsMetaConfiguration());
            }
            else newValue = new FunctionInfo(name, function, options, context, helpFile);

            return newValue;
        }