Как использовать активность рабочего процесса Windows, созданную из командлета?

Я сгенерировал активность WWF из командлета с помощью PowerShell 3.0.

 /// <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'».

Но этот файл существует в моей системе.

Как я могу использовать эту технологию?


person Valery    schedule 14.03.2014    source источник


Ответы (1)


Это может быть проблема с Windows Powershell.

Решение состоит в том, чтобы скопировать папку: "PSWorkflow" из "C:\Windows\System32\WindowsPowerShell\v1.0\Modules\"

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

Тогда все работает нормально.

person Thomas van Veen    schedule 21.09.2014