Exemplo n.º 1
0
        /// <summary>
        /// Emits string representation of '<#PSScriptInfo ... #>' comment and its metadata contents.
        /// </summary>
        internal string[] EmitContent()
        {
            /**
             * PSScriptInfo comment will be in following format:
             * <#PSScriptInfo
             *  .VERSION 1.0
             *  .GUID 544238e3-1751-4065-9227-be105ff11636
             *  .AUTHOR manikb
             *  .COMPANYNAME Microsoft Corporation
             *  .COPYRIGHT (c) 2015 Microsoft Corporation. All rights reserved.
             *  .TAGS Tag1 Tag2 Tag3
             *  .LICENSEURI https://contoso.com/License
             *  .PROJECTURI https://contoso.com/
             *  .ICONURI https://contoso.com/Icon
             *  .EXTERNALMODULEDEPENDENCIES ExternalModule1
             *  .REQUIREDSCRIPTS Start-WFContosoServer,Stop-ContosoServerScript
             *  .EXTERNALSCRIPTDEPENDENCIES Stop-ContosoServerScript
             *  .RELEASENOTES
             *  contoso script now supports following features
             *  Feature 1
             *  Feature 2
             *  Feature 3
             *  Feature 4
             *  Feature 5
             *  .PRIVATEDATA
             #>
             */

            string liceseUriString  = LicenseUri == null ? String.Empty : LicenseUri.ToString();
            string projectUriString = ProjectUri == null ? String.Empty : ProjectUri.ToString();
            string iconUriString    = IconUri == null ? String.Empty : IconUri.ToString();

            string tagsString = String.Join(" ", Tags);
            string externalModuleDependenciesString = String.Join(" ", ExternalModuleDependencies);
            string requiredScriptsString            = String.Join(" ", RequiredScripts);
            string externalScriptDependenciesString = String.Join(" ", ExternalScriptDependencies);

            List <string> psScriptInfoLines = new List <string>();

            // Note: we add a newline to the end of each property entry in HelpInfo so that there's an empty line separating them.
            psScriptInfoLines.Add($"<#PSScriptInfo{Environment.NewLine}");
            psScriptInfoLines.Add($".VERSION {Version.ToString()}{Environment.NewLine}");
            psScriptInfoLines.Add($".GUID {Guid.ToString()}{Environment.NewLine}");
            psScriptInfoLines.Add($".AUTHOR {Author}{Environment.NewLine}");
            psScriptInfoLines.Add($".COMPANYNAME {CompanyName}{Environment.NewLine}");
            psScriptInfoLines.Add($".COPYRIGHT {Copyright}{Environment.NewLine}");
            psScriptInfoLines.Add($".TAGS {tagsString}{Environment.NewLine}");
            psScriptInfoLines.Add($".LICENSEURI {liceseUriString}{Environment.NewLine}");
            psScriptInfoLines.Add($".PROJECTURI {projectUriString}{Environment.NewLine}");
            psScriptInfoLines.Add($".ICONURI {iconUriString}{Environment.NewLine}");
            psScriptInfoLines.Add($".EXTERNALMODULEDEPENDENCIES {externalModuleDependenciesString}{Environment.NewLine}");
            psScriptInfoLines.Add($".REQUIREDSCRIPTS {requiredScriptsString}{Environment.NewLine}");
            psScriptInfoLines.Add($".EXTERNALSCRIPTDEPENDENCIES {externalScriptDependenciesString}{Environment.NewLine}");
            psScriptInfoLines.Add($".RELEASENOTES{Environment.NewLine}{ReleaseNotes}{Environment.NewLine}");
            psScriptInfoLines.Add($".PRIVATEDATA{Environment.NewLine}{PrivateData}{Environment.NewLine}");
            psScriptInfoLines.Add("#>");

            return(psScriptInfoLines.ToArray());
        }
Exemplo n.º 2
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
            });
        }