2

我使用 PowerShell 3.0 从 cmdlet 生成了 WWF 活动。

 /// <summary>
    /// Activity to invoke the Microsoft.Ceres.HostController.Cmdlets\Connect-Host command in a Workflow.
    /// </summary>
    [System.CodeDom.Compiler.GeneratedCode("Microsoft.PowerShell.Activities.ActivityGenerator.GenerateFromName", "3.0")]
    public sealed class ConnectHost : PSRemotingActivity
    {
        /// <summary>
        /// Gets the display name of the command invoked by this activity.
        /// </summary>
        public ConnectHost()
        {
            this.DisplayName = "Connect-Host";
        }

        /// <summary>
        /// Gets the fully qualified name of the command invoked by this activity.
        /// </summary>
        public override string PSCommandName
        {
            get { return "Microsoft.Ceres.HostController.Cmdlets\\Connect-Host"; }
        }

        // Arguments

        /// <summary>
        /// Provides access to the Host parameter.
        /// </summary>
        [ParameterSpecificCategory]
        [DefaultValue(null)]
        public InArgument<System.String> Host { get; set; }

        /// <summary>
        /// Provides access to the Port parameter.
        /// </summary>
        [ParameterSpecificCategory]
        [DefaultValue(null)]
        public InArgument<System.String> Port { get; set; }

        /// <summary>
        /// Provides access to the NoConnectionSecurity parameter.
        /// </summary>
        [ParameterSpecificCategory]
        [DefaultValue(null)]
        public InArgument<System.Management.Automation.SwitchParameter> NoConnectionSecurity { get; set; }

        /// <summary>
        /// Provides access to the ServiceIdentity parameter.
        /// </summary>
        [ParameterSpecificCategory]
        [DefaultValue(null)]
        public InArgument<System.String> ServiceIdentity { get; set; }


        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (Host.Expression != null)
            {
                targetCommand.AddParameter("Host", Host.Get(context));
            }

            if (Port.Expression != null)
            {
                targetCommand.AddParameter("Port", Port.Get(context));
            }

            if (NoConnectionSecurity.Expression != null)
            {
                targetCommand.AddParameter("NoConnectionSecurity", NoConnectionSecurity.Get(context));
            }

            if (ServiceIdentity.Expression != null)
            {
                targetCommand.AddParameter("ServiceIdentity", ServiceIdentity.Get(context));
            }

            var cont = new ActivityImplementationContext() {PowerShellInstance = invoker};
            return cont;
        }
    }

创建 activity1.xaml 后,放入“Connect-Host”活动并编写启动代码:

var workflow1 = new Activity1();
    WorkflowInvoker.Invoke(workflow1);

但我收到异常消息:“'Microsoft.PowerShell.Workflow.ActivityHostProcess' 的类型初始化程序引发了异常。” “找不到路径 'C:\Windows\system32\windowspowershell\v1.0\modules\psworkflow\PSWorkflow.types.ps1xml' 的一部分。”

但是这个文件存在于我的系统中。

我如何使用这项技术?

4

1 回答 1

0

这可能是 Windows Powershell 的问题。

解决方案是复制文件夹:“PSWorkflow”"C:\Windows\System32\WindowsPowerShell\v1.0\Modules\"

"C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules"

然后一切正常。

于 2014-09-21T09:34:59.627 回答