示例#1
0
        // 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 (Path.Expression != null)
            {
                targetCommand.AddParameter("Path", Path.Get(context));
            }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
示例#2
0
        public override bool Execute()
        {
            try
            {
                using (var ps = System.Management.Automation.PowerShell.Create())
                {
                    ps.AddCommand("New-ModuleManifest");

                    if (AliasesToExport != null)
                    {
                        ps.AddParameter("AliasesToExport", AliasesToExport.Select(m => m.ItemSpec));
                    }
                    ps.AddParameter("Author", Author.ItemSpec);

                    if (ClrVersion != null)
                    {
                        ps.AddParameter("ClrVersion", ClrVersion.ItemSpec);
                    }

                    if (CmdletsToExport != null)
                    {
                        ps.AddParameter("CmdletsToExport", CmdletsToExport.Select(m => m.ItemSpec));
                    }

                    ps.AddParameter("CompanyName", CompanyName.ItemSpec);
                    ps.AddParameter("Copyright", Copyright.ItemSpec);
                    ps.AddParameter("Description", Description.ItemSpec);

                    if (DotNetFrameworkVersion != null)
                    {
                        ps.AddParameter("DotNetFrameworkVersion", DotNetFrameworkVersion.ItemSpec);
                    }

                    ps.AddParameter("FileList", FileList.Select(m => m.ItemSpec));
                    ps.AddParameter("FormatsToProcess", FormatsToProcess.Select(m => m.ItemSpec));

                    if (FunctionsToProcess != null)
                    {
                        ps.AddParameter("FunctionsToProcess", FunctionsToProcess.Select(m => m.ItemSpec));
                    }

                    if (Guid != null)
                    {
                        ps.AddParameter("Guid", Guid.ItemSpec);
                    }

                    if (ModuleList != null)
                    {
                        ps.AddParameter("ModuleList", ModuleList.Select(m => m.ItemSpec));
                    }

                    ps.AddParameter("ModuleToProcess", ModuleToProcess.ItemSpec);

                    if (ModuleVersion != null)
                    {
                        ps.AddParameter("ModuleVersion", ModuleVersion.ItemSpec);
                    }

                    ps.AddParameter("NestedModules", NestedModules.Select(m => m.ItemSpec));
                    ps.AddParameter("Path", Path.ItemSpec);

                    if (PowerShellHostName != null)
                    {
                        ps.AddParameter("PowerShellHostName", PowerShellHostName.ItemSpec);
                    }

                    if (PowerShellHostVersion != null)
                    {
                        ps.AddParameter("PowerShellHostVersion", PowerShellHostVersion.ItemSpec);
                    }

                    if (PowerShellVersion != null)
                    {
                        ps.AddParameter("PowerShellVersion", PowerShellVersion.ItemSpec);
                    }

                    if (ProcessorArchitecture != null)
                    {
                        ps.AddParameter("ProcessorArchitecture", ProcessorArchitecture.ItemSpec);
                    }

                    ps.AddParameter("RequiredAssemblies", RequiredAssemblies.Select(m => m.ItemSpec));

                    if (RequiredModules != null)
                    {
                        ps.AddParameter("RequiredModules", RequiredModules.Select(m => m.ItemSpec));
                    }

                    if (ScriptsToProcess != null)
                    {
                        ps.AddParameter("ScriptsToProcess", ScriptsToProcess.Select(m => m.ItemSpec));
                    }

                    ps.AddParameter("TypesToProcess", TypesToProcess.Select(m => m.ItemSpec));

                    if (VariablesToExport != null)
                    {
                        ps.AddParameter("VariablesToExport", VariablesToExport.Select(m => m.ItemSpec));
                    }

                    ps.Invoke();
                }
            }
            catch (Exception ex)
            {
                this.Log.LogErrorFromException(ex);
                return(false);
            }


            return(true);
        }