コード例 #1
0
 public ParameterMetadata(ParameterMetadata other)
 {
     this.Name = other.Name;
     this.ParameterSets = other.ParameterSets;
     this._mandatory = other._mandatory;
     this._position = other._position;
 }
コード例 #2
0
        private void Init(Type commandType, bool shouldGenerateCommonParameters)
        {
            this.type = commandType != null ? commandType : throw CommandMetadata.tracer.NewArgumentNullException("cmdletType");
            InternalParameterMetadata parameterMetadata = InternalParameterMetadata.Get(commandType, (ExecutionContext)null, false);

            this.ConstructCmdletMetadataUsingReflection();
            this.externalParameterMetadata = ParameterMetadata.GetParameterMetadata(this.MergeParameterMetadata((ExecutionContext)null, parameterMetadata, shouldGenerateCommonParameters));
            this.wrappedCommand            = this.commandName;
            this.wrappedCommandType        = CommandTypes.Cmdlet;
            this.wrappedAnyCmdlet          = true;
        }
コード例 #3
0
        private static CommandMetadata GetRestrictedSelectObject()
        {
            string[]          validValues = new string[] { "ModuleName", "Namespace", "OutputType", "Count", "HelpUri", "Name", "CommandType", "ResolvedCommandName", "DefaultParameterSet", "CmdletBinding", "Parameters" };
            ParameterMetadata metadata    = new ParameterMetadata("Property", typeof(string[]))
            {
                Attributes = { new ValidateSetAttribute(validValues), new ValidateCountAttribute(1, validValues.Length) }
            };
            ParameterMetadata metadata2 = new ParameterMetadata("InputObject", typeof(object));

            metadata2.ParameterSets.Add("__AllParameterSets", new ParameterSetMetadata(-2147483648, ParameterSetMetadata.ParameterFlags.Mandatory | ParameterSetMetadata.ParameterFlags.ValueFromPipeline, null));
            return(GetRestrictedCmdlet("Select-Object", null, "http://go.microsoft.com/fwlink/?LinkID=113387", new ParameterMetadata[] { metadata, metadata2 }));
        }
コード例 #4
0
        internal static Dictionary <string, ParameterMetadata> GetParameterMetadata(MergedCommandParameterMetadata cmdParameterMetadata)
        {
            Dictionary <string, ParameterMetadata> dictionary = new Dictionary <string, ParameterMetadata>(StringComparer.OrdinalIgnoreCase);

            foreach (KeyValuePair <string, MergedCompiledCommandParameter> pair in cmdParameterMetadata.BindableParameters)
            {
                string            key      = pair.Key;
                ParameterMetadata metadata = new ParameterMetadata(pair.Value.Parameter);
                dictionary.Add(key, metadata);
            }
            return(dictionary);
        }
コード例 #5
0
        private static CommandMetadata GetRestrictedGetHelp()
        {
            ParameterMetadata metadata = new ParameterMetadata("Name", typeof(string))
            {
                Attributes = { new ValidatePatternAttribute(@"^[-._:\\\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Lm}]{1,100}$"), new ValidateLengthAttribute(0, 0x3e8) }
            };
            ParameterMetadata metadata2 = new ParameterMetadata("Category", typeof(string[]))
            {
                Attributes = { new ValidateSetAttribute(Enum.GetNames(typeof(HelpCategory))), new ValidateCountAttribute(0, 1) }
            };

            return(GetRestrictedCmdlet("Get-Help", null, "http://go.microsoft.com/fwlink/?LinkID=113316", new ParameterMetadata[] { metadata, metadata2 }));
        }
コード例 #6
0
        private static CommandMetadata GetRestrictedGetCommand()
        {
            ParameterMetadata metadata = new ParameterMetadata("Name", typeof(string[]))
            {
                Attributes = { new ValidateLengthAttribute(0, 0x3e8), new ValidateCountAttribute(0, 0x3e8) }
            };
            ParameterMetadata metadata2 = new ParameterMetadata("Module", typeof(string[]))
            {
                Attributes = { new ValidateLengthAttribute(0, 0x3e8), new ValidateCountAttribute(0, 100) }
            };
            ParameterMetadata metadata3 = new ParameterMetadata("ArgumentList", typeof(object[]))
            {
                Attributes = { new ValidateCountAttribute(0, 100) }
            };
            ParameterMetadata metadata4 = new ParameterMetadata("CommandType", typeof(CommandTypes));
            ParameterMetadata metadata5 = new ParameterMetadata("ListImported", typeof(SwitchParameter));

            return(GetRestrictedCmdlet("Get-Command", null, "http://go.microsoft.com/fwlink/?LinkID=113309", new ParameterMetadata[] { metadata, metadata2, metadata3, metadata4, metadata5 }));
        }
コード例 #7
0
ファイル: ParameterMetadata.cs プロジェクト: nickchal/pash
 public ParameterMetadata(ParameterMetadata other)
 {
     if (other == null)
     {
         throw PSTraceSource.NewArgumentNullException("other");
     }
     this.isDynamic = other.isDynamic;
     this.name = other.name;
     this.parameterType = other.parameterType;
     this.aliases = new Collection<string>(new List<string>(other.aliases.Count));
     foreach (string str in other.aliases)
     {
         this.aliases.Add(str);
     }
     if (other.attributes == null)
     {
         this.attributes = null;
     }
     else
     {
         this.attributes = new Collection<Attribute>(new List<Attribute>(other.attributes.Count));
         foreach (Attribute attribute in other.attributes)
         {
             this.attributes.Add(attribute);
         }
     }
     this.parameterSets = null;
     if (other.parameterSets == null)
     {
         this.parameterSets = null;
     }
     else
     {
         this.parameterSets = new Dictionary<string, ParameterSetMetadata>(other.parameterSets.Count);
         foreach (KeyValuePair<string, ParameterSetMetadata> pair in other.parameterSets)
         {
             this.parameterSets.Add(pair.Key, new ParameterSetMetadata(pair.Value));
         }
     }
 }
コード例 #8
0
 public ParameterMetadata(ParameterMetadata other)
 {
     if (other == null)
     {
         throw PSTraceSource.NewArgumentNullException("other");
     }
     this.isDynamic     = other.isDynamic;
     this.name          = other.name;
     this.parameterType = other.parameterType;
     this.aliases       = new Collection <string>(new List <string>(other.aliases.Count));
     foreach (string str in other.aliases)
     {
         this.aliases.Add(str);
     }
     if (other.attributes == null)
     {
         this.attributes = null;
     }
     else
     {
         this.attributes = new Collection <Attribute>(new List <Attribute>(other.attributes.Count));
         foreach (Attribute attribute in other.attributes)
         {
             this.attributes.Add(attribute);
         }
     }
     this.parameterSets = null;
     if (other.parameterSets == null)
     {
         this.parameterSets = null;
     }
     else
     {
         this.parameterSets = new Dictionary <string, ParameterSetMetadata>(other.parameterSets.Count);
         foreach (KeyValuePair <string, ParameterSetMetadata> pair in other.parameterSets)
         {
             this.parameterSets.Add(pair.Key, new ParameterSetMetadata(pair.Value));
         }
     }
 }
コード例 #9
0
        private void Init(ScriptBlock scriptBlock, string name, bool shouldGenerateCommonParameters)
        {
            if (scriptBlock.UsesCmdletBinding)
            {
                this.wrappedAnyCmdlet = true;
            }
            else
            {
                shouldGenerateCommonParameters = false;
            }
            CmdletBindingAttribute bindingAttribute = scriptBlock.CmdletBindingAttribute;

            if (bindingAttribute != null)
            {
                this.ProcessCmdletAttribute((CmdletCommonMetadataAttribute)bindingAttribute);
            }
            else if (scriptBlock.UsesCmdletBinding)
            {
                this.defaultParameterSetName = (string)null;
            }
            this.externalParameterMetadata = ParameterMetadata.GetParameterMetadata(this.MergeParameterMetadata((ExecutionContext)null, InternalParameterMetadata.Get(scriptBlock.RuntimeDefinedParameters, false, scriptBlock.UsesCmdletBinding), shouldGenerateCommonParameters));
            this.wrappedCommand            = this.commandName = name;
        }
コード例 #10
0
 public ParameterMetadata(ParameterMetadata other)
 {
     this.isDynamic     = other != null ? other.isDynamic : throw ParameterMetadata.tracer.NewArgumentNullException(nameof(other));
     this.name          = other.name;
     this.parameterType = other.parameterType;
     this.aliases       = new Collection <string>((IList <string>) new List <string>(other.aliases.Count));
     foreach (string alias in other.aliases)
     {
         this.aliases.Add(alias);
     }
     if (other.attributes == null)
     {
         this.attributes = (Collection <Attribute>)null;
     }
     else
     {
         this.attributes = new Collection <Attribute>((IList <Attribute>) new List <Attribute>(other.attributes.Count));
         foreach (Attribute attribute in other.attributes)
         {
             this.attributes.Add(attribute);
         }
     }
     this.parameterSets = (Dictionary <string, ParameterSetMetadata>)null;
     if (other.parameterSets == null)
     {
         this.parameterSets = (Dictionary <string, ParameterSetMetadata>)null;
     }
     else
     {
         this.parameterSets = new Dictionary <string, ParameterSetMetadata>(other.parameterSets.Count);
         foreach (KeyValuePair <string, ParameterSetMetadata> parameterSet in other.parameterSets)
         {
             this.parameterSets.Add(parameterSet.Key, new ParameterSetMetadata(parameterSet.Value));
         }
     }
 }
コード例 #11
0
ファイル: CommandMetadata.cs プロジェクト: nickchal/pash
 private static CommandMetadata GetRestrictedOutDefault()
 {
     ParameterMetadata metadata = new ParameterMetadata("InputObject", typeof(object));
     metadata.ParameterSets.Add("__AllParameterSets", new ParameterSetMetadata(-2147483648, ParameterSetMetadata.ParameterFlags.Mandatory | ParameterSetMetadata.ParameterFlags.ValueFromPipeline, null));
     return GetRestrictedCmdlet("Out-Default", null, "http://go.microsoft.com/fwlink/?LinkID=113362", new ParameterMetadata[] { metadata });
 }
コード例 #12
0
ファイル: ParameterMetadata.cs プロジェクト: zhuyue1314/Pash
 public ParameterMetadata(ParameterMetadata other)
 {
     throw new NotImplementedException();
 }
コード例 #13
0
ファイル: CommandMetadata.cs プロジェクト: dfinke/powershell
        private static Collection<CommandMetadata> GetRestrictedJobCommands()
        {
            // all the job cmdlets take a Name parameter. This needs to be 
            // restricted to safenames in order to allow only valid wildcards

            // construct the parameterset metadata
            ParameterSetMetadata nameParameterSet = new ParameterSetMetadata(0,
                                                                             ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName,
                                                                             string.Empty);
            ParameterSetMetadata instanceIdParameterSet = new ParameterSetMetadata(0,
                                                                                   ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName,
                                                                                   string.Empty);
            ParameterSetMetadata idParameterSet = new ParameterSetMetadata(0,
                                                                           ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName,
                                                                           string.Empty);
            ParameterSetMetadata stateParameterSet = new ParameterSetMetadata(int.MinValue,
                                                                              ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName,
                                                                              string.Empty);
            ParameterSetMetadata commandParameterSet = new ParameterSetMetadata(int.MinValue,
                                                                                ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName,
                                                                                string.Empty);
            ParameterSetMetadata filterParameterSet = new ParameterSetMetadata(0,
                                                                                ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName,
                                                                                string.Empty);
            ParameterSetMetadata jobParameterSet = new ParameterSetMetadata(0,
                                                                            ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName |
                                                                            ParameterSetMetadata.ParameterFlags.ValueFromPipeline |
                                                                            ParameterSetMetadata.ParameterFlags.Mandatory, string.Empty);
            ParameterSetMetadata computerNameParameterSet = new ParameterSetMetadata(0,
                                                                                     ParameterSetMetadata.ParameterFlags.Mandatory |
                                                                                     ParameterSetMetadata.ParameterFlags.ValueFromPipeline |
                                                                                     ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName,
                                                                                     string.Empty);
            ParameterSetMetadata locationParameterSet = new ParameterSetMetadata(0,
                                                                                 ParameterSetMetadata.ParameterFlags.Mandatory |
                                                                                 ParameterSetMetadata.ParameterFlags.ValueFromPipeline |
                                                                                 ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName,
                                                                                 string.Empty);

            Dictionary<string, ParameterSetMetadata> parameterSets = new Dictionary<string, ParameterSetMetadata>();
            parameterSets.Add(JobCmdletBase.NameParameterSet, nameParameterSet);

            Collection<string> emptyCollection = new Collection<string>();

            ParameterMetadata nameParameter = new ParameterMetadata(emptyCollection, false, JobCmdletBase.NameParameter,
                                                                    parameterSets, typeof(string[]));
            nameParameter.Attributes.Add(new ValidatePatternAttribute(isSafeNameOrIdentifierRegex));
            nameParameter.Attributes.Add(new ValidateLengthAttribute(0, 1000));

            // all the other parameters can be safely allowed
            parameterSets = new Dictionary<string, ParameterSetMetadata>();
            parameterSets.Add(JobCmdletBase.InstanceIdParameterSet, instanceIdParameterSet);
            ParameterMetadata instanceIdParameter = new ParameterMetadata(emptyCollection, false,
                                                                          JobCmdletBase.InstanceIdParameter,
                                                                          parameterSets, typeof(Guid[]));
            instanceIdParameter.Attributes.Add(new ValidateNotNullOrEmptyAttribute());

            parameterSets = new Dictionary<string, ParameterSetMetadata>();
            parameterSets.Add(JobCmdletBase.SessionIdParameterSet, idParameterSet);
            ParameterMetadata idParameter = new ParameterMetadata(emptyCollection, false, "Id", parameterSets, typeof(int[]));
            idParameter.Attributes.Add(new ValidateNotNullOrEmptyAttribute());

            parameterSets = new Dictionary<string, ParameterSetMetadata>();
            parameterSets.Add(JobCmdletBase.StateParameterSet, stateParameterSet);
            ParameterMetadata stateParameter = new ParameterMetadata(emptyCollection, false,
                                                                     JobCmdletBase.StateParameter, parameterSets,
                                                                     typeof(JobState));

            parameterSets = new Dictionary<string, ParameterSetMetadata>();
            parameterSets.Add(JobCmdletBase.CommandParameterSet, commandParameterSet);
            ParameterMetadata commandParameter = new ParameterMetadata(emptyCollection, false,
                                                                       JobCmdletBase.CommandParameter, parameterSets,
                                                                       typeof(string[]));

            parameterSets = new Dictionary<string, ParameterSetMetadata>();
            parameterSets.Add(JobCmdletBase.FilterParameterSet, filterParameterSet);
            ParameterMetadata filterParameter = new ParameterMetadata(emptyCollection, false, JobCmdletBase.FilterParameter, parameterSets, typeof(Hashtable));

            parameterSets = new Dictionary<string, ParameterSetMetadata>();
            parameterSets.Add(JobCmdletBase.JobParameter, jobParameterSet);
            ParameterMetadata jobParameter = new ParameterMetadata(emptyCollection, false, JobCmdletBase.JobParameter,
                                                                   parameterSets, typeof(Job[]));
            jobParameter.Attributes.Add(new ValidateNotNullOrEmptyAttribute());

            parameterSets = new Dictionary<string, ParameterSetMetadata>();
            parameterSets.Add("ComputerName", computerNameParameterSet);
            parameterSets.Add("Location", locationParameterSet);
            ParameterMetadata jobParameter2 = new ParameterMetadata(emptyCollection, false, JobCmdletBase.JobParameter,
                                                                    parameterSets, typeof(Job[]));

            // Start-Job is not really required since the user will be using the name 
            // of the workflow to launch them
            Collection<CommandMetadata> restrictedJobCommands = new Collection<CommandMetadata>();

            // Stop-Job cmdlet
            ParameterMetadata passThruParameter = new ParameterMetadata("PassThru", typeof(SwitchParameter));
            ParameterMetadata anyParameter = new ParameterMetadata("Any", typeof(SwitchParameter));

            CommandMetadata stopJob = GetRestrictedCmdlet("Stop-Job", JobCmdletBase.SessionIdParameterSet, "http://go.microsoft.com/fwlink/?LinkID=113413", nameParameter,
                                                          instanceIdParameter, idParameter,
                                                          stateParameter, filterParameter, jobParameter, passThruParameter);
            restrictedJobCommands.Add(stopJob);

            // Wait-Job cmdlet
            ParameterMetadata timeoutParameter = new ParameterMetadata("Timeout", typeof(int));
            timeoutParameter.Attributes.Add(new ValidateRangeAttribute(-1, Int32.MaxValue));

            CommandMetadata waitJob = GetRestrictedCmdlet("Wait-Job", JobCmdletBase.SessionIdParameterSet, "http://go.microsoft.com/fwlink/?LinkID=113422", nameParameter,
                                                          instanceIdParameter, idParameter,
                                                          jobParameter, stateParameter, filterParameter, anyParameter, timeoutParameter);
            restrictedJobCommands.Add(waitJob);

            // Get-Job cmdlet
            CommandMetadata getJob = GetRestrictedCmdlet("Get-Job", JobCmdletBase.SessionIdParameterSet, "http://go.microsoft.com/fwlink/?LinkID=113328", nameParameter,
                                                         instanceIdParameter, idParameter,
                                                         stateParameter, filterParameter, commandParameter);
            restrictedJobCommands.Add(getJob);

            // Receive-Job cmdlet
            parameterSets = new Dictionary<string, ParameterSetMetadata>();
            computerNameParameterSet = new ParameterSetMetadata(1,
                                                                ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName,
                                                                string.Empty);

            parameterSets.Add("ComputerName", computerNameParameterSet);
            ParameterMetadata computerNameParameter = new ParameterMetadata(emptyCollection, false, "ComputerName", parameterSets, typeof(string[]));
            computerNameParameter.Attributes.Add(new ValidateLengthAttribute(0, 1000));
            computerNameParameter.Attributes.Add(new ValidateNotNullOrEmptyAttribute());

            parameterSets = new Dictionary<string, ParameterSetMetadata>();
            locationParameterSet = new ParameterSetMetadata(1,
                                                            ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName,
                                                            string.Empty);

            parameterSets.Add("Location", locationParameterSet);
            ParameterMetadata locationParameter = new ParameterMetadata(emptyCollection, false, "Location", parameterSets, typeof(string[]));
            locationParameter.Attributes.Add(new ValidateLengthAttribute(0, 1000));
            locationParameter.Attributes.Add(new ValidateNotNullOrEmptyAttribute());

            ParameterMetadata norecurseParameter = new ParameterMetadata("NoRecurse", typeof(SwitchParameter));
            ParameterMetadata keepParameter = new ParameterMetadata("Keep", typeof(SwitchParameter));
            ParameterMetadata waitParameter = new ParameterMetadata("Wait", typeof(SwitchParameter));
            ParameterMetadata writeEventsParameter = new ParameterMetadata("WriteEvents", typeof(SwitchParameter));
            ParameterMetadata writeJobParameter = new ParameterMetadata("WriteJobInResults", typeof(SwitchParameter));
            ParameterMetadata autoRemoveParameter = new ParameterMetadata("AutoRemoveJob", typeof(SwitchParameter));

            CommandMetadata receiveJob = GetRestrictedCmdlet("Receive-Job", "Location", "http://go.microsoft.com/fwlink/?LinkID=113372", nameParameter,
                                                             instanceIdParameter,
                                                             idParameter, stateParameter, jobParameter2,
                                                             computerNameParameter, locationParameter,
                                                             norecurseParameter, keepParameter, waitParameter,
                                                             writeEventsParameter, writeJobParameter, autoRemoveParameter);
            restrictedJobCommands.Add(receiveJob);

            // Remove-Job cmdlet
            ParameterMetadata forceParameter = new ParameterMetadata("Force", typeof(SwitchParameter));

            CommandMetadata removeJob = GetRestrictedCmdlet("Remove-Job", JobCmdletBase.SessionIdParameterSet, "http://go.microsoft.com/fwlink/?LinkID=113377",
                                                            nameParameter, instanceIdParameter,
                                                            idParameter, stateParameter, filterParameter, jobParameter, forceParameter);

            restrictedJobCommands.Add(removeJob);

            // Suspend-Job cmdlet
            CommandMetadata suspendJob = GetRestrictedCmdlet("Suspend-Job", JobCmdletBase.SessionIdParameterSet, "http://go.microsoft.com/fwlink/?LinkID=210613",
                                                             nameParameter, instanceIdParameter,
                                                             idParameter, stateParameter, filterParameter, jobParameter, passThruParameter);
            restrictedJobCommands.Add(suspendJob);

            // Suspend-Job cmdlet
            CommandMetadata resumeJob = GetRestrictedCmdlet("Resume-Job", JobCmdletBase.SessionIdParameterSet, "http://go.microsoft.com/fwlink/?LinkID=210611",
                                                             nameParameter, instanceIdParameter,
                                                             idParameter, stateParameter, filterParameter, jobParameter, passThruParameter);
            restrictedJobCommands.Add(resumeJob);

            return restrictedJobCommands;
        }
コード例 #14
0
ファイル: CommandMetadata.cs プロジェクト: nickchal/pash
 private static CommandMetadata GetRestrictedGetFormatData()
 {
     ParameterMetadata metadata = new ParameterMetadata("TypeName", typeof(string[])) {
         Attributes = { new ValidateLengthAttribute(0, 0x3e8), new ValidateCountAttribute(0, 0x3e8) }
     };
     return GetRestrictedCmdlet("Get-FormatData", null, "http://go.microsoft.com/fwlink/?LinkID=144303", new ParameterMetadata[] { metadata });
 }
コード例 #15
0
ファイル: ParameterMetadata.cs プロジェクト: nickchal/pash
 internal static Dictionary<string, ParameterMetadata> GetParameterMetadata(MergedCommandParameterMetadata cmdParameterMetadata)
 {
     Dictionary<string, ParameterMetadata> dictionary = new Dictionary<string, ParameterMetadata>(StringComparer.OrdinalIgnoreCase);
     foreach (KeyValuePair<string, MergedCompiledCommandParameter> pair in cmdParameterMetadata.BindableParameters)
     {
         string key = pair.Key;
         ParameterMetadata metadata = new ParameterMetadata(pair.Value.Parameter);
         dictionary.Add(key, metadata);
     }
     return dictionary;
 }
コード例 #16
0
ファイル: ScriptWriter.cs プロジェクト: dfinke/powershell
        private void GenerateQueryParametersProcessing(
            InstanceCmdletMetadata instanceCmdlet,
            IEnumerable<string> commonParameterSets,
            IEnumerable<string> queryParameterSets,
            IEnumerable<string> methodParameterSets,
            out string scriptCode,
            out Dictionary<string, ParameterMetadata> queryParameters)
        {
            queryParameters = new Dictionary<string, ParameterMetadata>(StringComparer.OrdinalIgnoreCase);
            StringWriter output = new StringWriter(CultureInfo.InvariantCulture);

            output.WriteLine("    $__cmdletization_queryBuilder = $__cmdletization_objectModelWrapper.GetQueryBuilder()");

            GetCmdletParameters getCmdletParameters = GetGetCmdletParameters(instanceCmdlet);
            if (getCmdletParameters.QueryableProperties != null)
            {
                foreach (PropertyMetadata property in getCmdletParameters.QueryableProperties.Where(p => p.Items != null))
                {
                    for (int i = 0; i < property.Items.Length; i++)
                    {
                        string methodName;
                        switch (property.ItemsElementName[i])
                        {
                            case ItemsChoiceType.RegularQuery:
                                methodName = "FilterByProperty";
                                break;
                            case ItemsChoiceType.ExcludeQuery:
                                methodName = "ExcludeByProperty";
                                break;
                            case ItemsChoiceType.MinValueQuery:
                                methodName = "FilterByMinPropertyValue";
                                break;
                            case ItemsChoiceType.MaxValueQuery:
                                methodName = "FilterByMaxPropertyValue";
                                break;
                            default:
                                Dbg.Assert(false, "Unrecognize query xml element");
                                methodName = "NotAValidMethod";
                                break;
                        }

                        ParameterMetadata parameterMetadata = GenerateQueryClause(
                            commonParameterSets, queryParameterSets, methodParameterSets, methodName, property, property.Items[i], output);

                        switch (property.ItemsElementName[i])
                        {
                            case ItemsChoiceType.RegularQuery:
                            case ItemsChoiceType.ExcludeQuery:
                                parameterMetadata.Attributes.Add(new ValidateNotNullAttribute());
                                break;

                            default:
                                // do nothing
                                break;
                        }

                        try
                        {
                            queryParameters.Add(parameterMetadata.Name, parameterMetadata);
                        }
                        catch (ArgumentException e)
                        {
                            string message = string.Format(
                                CultureInfo.InvariantCulture, // xml element names and parameter names are culture-agnostic
                                CmdletizationCoreResources.ScriptWriter_DuplicateQueryParameterName,
                                "<GetCmdletParameters>",
                                parameterMetadata.Name);
                            throw new XmlException(message, e);
                        }
                    }
                }
            }

            if (getCmdletParameters.QueryableAssociations != null)
            {
                foreach (Association association in getCmdletParameters.QueryableAssociations.Where(a => a.AssociatedInstance != null))
                {
                    ParameterMetadata parameterMetadata = GenerateAssociationClause(
                        commonParameterSets, queryParameterSets, methodParameterSets, association, association.AssociatedInstance, output);
                    try
                    {
                        queryParameters.Add(parameterMetadata.Name, parameterMetadata);
                    }
                    catch (ArgumentException e)
                    {
                        string message = string.Format(
                            CultureInfo.InvariantCulture, // xml element names and parameter names are culture-agnostic
                            CmdletizationCoreResources.ScriptWriter_DuplicateQueryParameterName,
                            "<GetCmdletParameters>",
                            parameterMetadata.Name);
                        throw new XmlException(message, e);
                    }
                }
            }

            if (getCmdletParameters.QueryOptions != null)
            {
                foreach (QueryOption queryOption in getCmdletParameters.QueryOptions)
                {
                    ParameterMetadata parameterMetadata = GenerateOptionClause(
                        commonParameterSets, queryParameterSets, methodParameterSets, queryOption, output);
                    try
                    {
                        queryParameters.Add(parameterMetadata.Name, parameterMetadata);
                    }
                    catch (ArgumentException e)
                    {
                        string message = string.Format(
                            CultureInfo.InvariantCulture, // xml element names and parameter names are culture-agnostic
                            CmdletizationCoreResources.ScriptWriter_DuplicateQueryParameterName,
                            "<GetCmdletParameters>",
                            parameterMetadata.Name);
                        throw new XmlException(message, e);
                    }
                }
            }

            if (instanceCmdlet != null)
            {
                ParameterMetadata inputObjectParameter = new ParameterMetadata("InputObject", _objectInstanceType.MakeArrayType());

                ParameterSetMetadata.ParameterFlags inputObjectFlags = ParameterSetMetadata.ParameterFlags.ValueFromPipeline;
                if (queryParameters.Count > 0)
                {
                    inputObjectFlags |= ParameterSetMetadata.ParameterFlags.Mandatory;
                }

                string psTypeNameOfInputObjectElements;
                if (_objectModelWrapper.FullName.Equals("Microsoft.PowerShell.Cmdletization.Cim.CimCmdletAdapter"))
                {
                    int indexOfLastBackslash = _cmdletizationMetadata.Class.ClassName.LastIndexOf('\\');
                    int indexOfLastForwardSlash = _cmdletizationMetadata.Class.ClassName.LastIndexOf('/');
                    int indexOfLastSeparator = Math.Max(indexOfLastBackslash, indexOfLastForwardSlash);
                    string cimClassName = _cmdletizationMetadata.Class.ClassName.Substring(
                        indexOfLastSeparator + 1,
                        _cmdletizationMetadata.Class.ClassName.Length - indexOfLastSeparator - 1);
                    psTypeNameOfInputObjectElements = string.Format(
                        CultureInfo.InvariantCulture,
                        "{0}#{1}",
                        _objectInstanceType.FullName,
                        cimClassName);
                }
                else
                {
                    psTypeNameOfInputObjectElements = string.Format(
                        CultureInfo.InvariantCulture,
                        "{0}#{1}",
                        _objectInstanceType.FullName,
                        _cmdletizationMetadata.Class.ClassName);
                }
                inputObjectParameter.Attributes.Add(new PSTypeNameAttribute(psTypeNameOfInputObjectElements));

                inputObjectParameter.Attributes.Add(new ValidateNotNullAttribute());
                inputObjectParameter.ParameterSets.Clear();
                ParameterSetMetadata inputObjectPSet = new ParameterSetMetadata(
                    int.MinValue, // non-positional
                    inputObjectFlags,
                    null); // no help message
                inputObjectParameter.ParameterSets.Add(ScriptWriter.InputObjectQueryParameterSetName, inputObjectPSet);
                queryParameters.Add(inputObjectParameter.Name, inputObjectParameter);
            }

            output.WriteLine();
            scriptCode = output.ToString();
        }
コード例 #17
0
ファイル: CommandMetadata.cs プロジェクト: nickchal/pash
 private static CommandMetadata GetRestrictedGetHelp()
 {
     ParameterMetadata metadata = new ParameterMetadata("Name", typeof(string)) {
         Attributes = { new ValidatePatternAttribute(@"^[-._:\\\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Lm}]{1,100}$"), new ValidateLengthAttribute(0, 0x3e8) }
     };
     ParameterMetadata metadata2 = new ParameterMetadata("Category", typeof(string[])) {
         Attributes = { new ValidateSetAttribute(Enum.GetNames(typeof(HelpCategory))), new ValidateCountAttribute(0, 1) }
     };
     return GetRestrictedCmdlet("Get-Help", null, "http://go.microsoft.com/fwlink/?LinkID=113316", new ParameterMetadata[] { metadata, metadata2 });
 }
コード例 #18
0
ファイル: TypeMetadata.cs プロジェクト: dfinke/powershell
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cmdParameterMetadata"></param>
        /// <returns></returns>
        internal static Dictionary<string, ParameterMetadata> GetParameterMetadata(MergedCommandParameterMetadata
            cmdParameterMetadata)
        {
            Dbg.Assert(null != cmdParameterMetadata, "cmdParameterMetadata cannot be null");

            Dictionary<string, ParameterMetadata> result = new Dictionary<string, ParameterMetadata>(StringComparer.OrdinalIgnoreCase);

            foreach (var keyValuePair in cmdParameterMetadata.BindableParameters)
            {
                var key = keyValuePair.Key;
                var mergedCompiledPMD = keyValuePair.Value;
                ParameterMetadata parameterMetaData = new ParameterMetadata(mergedCompiledPMD.Parameter);
                result.Add(key, parameterMetaData);
            }

            return result;
        }
コード例 #19
0
ファイル: CommandMetadata.cs プロジェクト: nickchal/pash
 private static CommandMetadata GetRestrictedSelectObject()
 {
     string[] validValues = new string[] { "ModuleName", "Namespace", "OutputType", "Count", "HelpUri", "Name", "CommandType", "ResolvedCommandName", "DefaultParameterSet", "CmdletBinding", "Parameters" };
     ParameterMetadata metadata = new ParameterMetadata("Property", typeof(string[])) {
         Attributes = { new ValidateSetAttribute(validValues), new ValidateCountAttribute(1, validValues.Length) }
     };
     ParameterMetadata metadata2 = new ParameterMetadata("InputObject", typeof(object));
     metadata2.ParameterSets.Add("__AllParameterSets", new ParameterSetMetadata(-2147483648, ParameterSetMetadata.ParameterFlags.Mandatory | ParameterSetMetadata.ParameterFlags.ValueFromPipeline, null));
     return GetRestrictedCmdlet("Select-Object", null, "http://go.microsoft.com/fwlink/?LinkID=113387", new ParameterMetadata[] { metadata, metadata2 });
 }
コード例 #20
0
ファイル: ScriptWriter.cs プロジェクト: dfinke/powershell
        private ParameterMetadata GetParameter(
            string parameterSetName,
            string objectModelParameterName,
            TypeMetadata parameterTypeMetadata,
            CmdletParameterMetadata parameterCmdletization,
            bool isValueFromPipeline,
            bool isValueFromPipelineByPropertyName)
        {
            string parameterName;
            if ((parameterCmdletization != null) && (!string.IsNullOrEmpty(parameterCmdletization.PSName)))
            {
                parameterName = parameterCmdletization.PSName;
            }
            else
            {
                parameterName = objectModelParameterName;
            }

            ParameterMetadata parameterMetadata = new ParameterMetadata(parameterName);
            parameterMetadata.ParameterType = GetDotNetType(parameterTypeMetadata);
            if (typeof(PSCredential).Equals(parameterMetadata.ParameterType))
            {
                parameterMetadata.Attributes.Add(new CredentialAttribute());
            }

            if (parameterTypeMetadata.ETSType != null)
            {
                parameterMetadata.Attributes.Add(new PSTypeNameAttribute(parameterTypeMetadata.ETSType));
            }

            if (parameterCmdletization != null)
            {
                if (parameterCmdletization.Aliases != null)
                {
                    foreach (string alias in parameterCmdletization.Aliases)
                    {
                        if (!string.IsNullOrEmpty(alias))
                        {
                            parameterMetadata.Aliases.Add(alias);
                        }
                    }
                }

                if (parameterCmdletization.AllowEmptyCollection != null)
                {
                    parameterMetadata.Attributes.Add(new AllowEmptyCollectionAttribute());
                }

                if (parameterCmdletization.AllowEmptyString != null)
                {
                    parameterMetadata.Attributes.Add(new AllowEmptyStringAttribute());
                }

                if (parameterCmdletization.AllowNull != null)
                {
                    parameterMetadata.Attributes.Add(new AllowNullAttribute());
                }

                if (parameterCmdletization.ValidateCount != null)
                {
                    int min = (int)LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateCount.Min, typeof(int), CultureInfo.InvariantCulture);
                    int max = (int)LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateCount.Max, typeof(int), CultureInfo.InvariantCulture);
                    parameterMetadata.Attributes.Add(new ValidateCountAttribute(min, max));
                }

                if (parameterCmdletization.ValidateLength != null)
                {
                    int min = (int)LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateLength.Min, typeof(int), CultureInfo.InvariantCulture);
                    int max = (int)LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateLength.Max, typeof(int), CultureInfo.InvariantCulture);
                    parameterMetadata.Attributes.Add(new ValidateLengthAttribute(min, max));
                }

                if (parameterCmdletization.Obsolete != null)
                {
                    string obsoleteMessage = parameterCmdletization.Obsolete.Message;
                    parameterMetadata.Attributes.Add(obsoleteMessage != null ? new ObsoleteAttribute(obsoleteMessage) : new ObsoleteAttribute());
                }

                if (parameterCmdletization.ValidateNotNull != null)
                {
                    parameterMetadata.Attributes.Add(new ValidateNotNullAttribute());
                }

                if (parameterCmdletization.ValidateNotNullOrEmpty != null)
                {
                    parameterMetadata.Attributes.Add(new ValidateNotNullOrEmptyAttribute());
                }

                if (parameterCmdletization.ValidateRange != null)
                {
                    Type parameterType = parameterMetadata.ParameterType;
                    Type elementType;
                    if (parameterType == null)
                    {
                        elementType = typeof(string);
                    }
                    else
                    {
                        elementType = parameterType.HasElementType ? parameterType.GetElementType() : parameterType;
                    }
                    object min = LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateRange.Min, elementType, CultureInfo.InvariantCulture);
                    object max = LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateRange.Max, elementType, CultureInfo.InvariantCulture);
                    parameterMetadata.Attributes.Add(new ValidateRangeAttribute(min, max));
                }

                if (parameterCmdletization.ValidateSet != null)
                {
                    List<string> allowedValues = new List<string>();
                    foreach (string allowedValue in parameterCmdletization.ValidateSet)
                    {
                        allowedValues.Add(allowedValue);
                    }
                    parameterMetadata.Attributes.Add(new ValidateSetAttribute(allowedValues.ToArray()));
                }
            }

            int position = int.MinValue;
            ParameterSetMetadata.ParameterFlags parameterFlags = 0;
            if (parameterCmdletization != null)
            {
                if (!string.IsNullOrEmpty(parameterCmdletization.Position))
                {
                    position = (int)LanguagePrimitives.ConvertTo(parameterCmdletization.Position, typeof(int), CultureInfo.InvariantCulture);
                }

                if (parameterCmdletization.IsMandatorySpecified && parameterCmdletization.IsMandatory)
                {
                    parameterFlags |= ParameterSetMetadata.ParameterFlags.Mandatory;
                }
            }
            if (isValueFromPipeline)
            {
                parameterFlags |= ParameterSetMetadata.ParameterFlags.ValueFromPipeline;
            }
            if (isValueFromPipelineByPropertyName)
            {
                parameterFlags |= ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName;
            }
            parameterMetadata.ParameterSets.Add(parameterSetName, new ParameterSetMetadata(position, parameterFlags, null));

            return parameterMetadata;
        }
コード例 #21
0
ファイル: ScriptWriter.cs プロジェクト: dfinke/powershell
        private Dictionary<string, ParameterMetadata> GetCommonParameters()
        {
            Dictionary<string, ParameterMetadata> commonParameters = new Dictionary<string, ParameterMetadata>(StringComparer.OrdinalIgnoreCase);

            InternalParameterMetadata internalParameterMetadata = new InternalParameterMetadata(_objectModelWrapper, false);
            foreach (CompiledCommandParameter compiledCommandParameter in internalParameterMetadata.BindableParameters.Values)
            {
                ParameterMetadata parameterMetadata = new ParameterMetadata(compiledCommandParameter);
                foreach (ParameterSetMetadata psetMetadata in parameterMetadata.ParameterSets.Values)
                {
                    if (psetMetadata.ValueFromPipeline)
                    {
                        string message = string.Format(
                            CultureInfo.InvariantCulture,
                            CmdletizationCoreResources.ScriptWriter_ObjectModelWrapperUsesIgnoredParameterMetadata,
                            _objectModelWrapper.FullName,
                            parameterMetadata.Name,
                            "ValueFromPipeline");
                        throw new XmlException(message);
                    }

                    if (psetMetadata.ValueFromPipelineByPropertyName)
                    {
                        string message = string.Format(
                            CultureInfo.InvariantCulture,
                            CmdletizationCoreResources.ScriptWriter_ObjectModelWrapperUsesIgnoredParameterMetadata,
                            _objectModelWrapper.FullName,
                            parameterMetadata.Name,
                            "ValueFromPipelineByPropertyName");
                        throw new XmlException(message);
                    }

                    if (psetMetadata.ValueFromRemainingArguments)
                    {
                        string message = string.Format(
                            CultureInfo.InvariantCulture,
                            CmdletizationCoreResources.ScriptWriter_ObjectModelWrapperUsesIgnoredParameterMetadata,
                            _objectModelWrapper.FullName,
                            parameterMetadata.Name,
                            "ValueFromRemainingArguments");
                        throw new XmlException(message);
                    }

                    psetMetadata.ValueFromPipeline = false;
                    psetMetadata.ValueFromPipelineByPropertyName = false;
                    psetMetadata.ValueFromRemainingArguments = false;
                }
                commonParameters.Add(parameterMetadata.Name, parameterMetadata);
            }

            List<string> commonParameterSets = GetCommonParameterSets(commonParameters);
            if (commonParameterSets.Count > 1)
            {
                string message = string.Format(
                    CultureInfo.InvariantCulture,
                    CmdletizationCoreResources.ScriptWriter_ObjectModelWrapperDefinesMultipleParameterSets,
                    _objectModelWrapper.FullName);
                throw new XmlException(message);
            }
            foreach (ParameterMetadata parameter in commonParameters.Values)
            {
                if ((parameter.ParameterSets.Count == 1) && (parameter.ParameterSets.ContainsKey(ParameterAttribute.AllParameterSets)))
                {
                    ParameterSetMetadata oldParameterSetMetadata = parameter.ParameterSets[ParameterAttribute.AllParameterSets];

                    parameter.ParameterSets.Clear();
                    foreach (string parameterSetName in commonParameterSets)
                    {
                        parameter.ParameterSets.Add(parameterSetName, oldParameterSetMetadata);
                    }
                }
            }

            return commonParameters;
        }
コード例 #22
0
ファイル: ScriptWriter.cs プロジェクト: dfinke/powershell
        private static void AddPassThruParameter(IDictionary<string, ParameterMetadata> commonParameters, InstanceCmdletMetadata instanceCmdletMetadata)
        {
            Dbg.Assert(commonParameters != null, "Caller should verify commonParameters != null");
            Dbg.Assert(instanceCmdletMetadata != null, "Caller should verify instanceCmdletMetadata != null");

            bool outParametersArePresent = false;
            if (instanceCmdletMetadata.Method.Parameters != null)
            {
                foreach (InstanceMethodParameterMetadata parameter in instanceCmdletMetadata.Method.Parameters)
                {
                    if ((parameter.CmdletOutputMetadata != null) && (parameter.CmdletOutputMetadata.ErrorCode == null))
                    {
                        outParametersArePresent = true;
                        break;
                    }
                }
            }
            if (instanceCmdletMetadata.Method.ReturnValue != null)
            {
                if ((instanceCmdletMetadata.Method.ReturnValue.CmdletOutputMetadata != null) &&
                    (instanceCmdletMetadata.Method.ReturnValue.CmdletOutputMetadata.ErrorCode == null))
                {
                    outParametersArePresent = true;
                }
            }

            if (!outParametersArePresent)
            {
                ParameterMetadata passThruParameter = new ParameterMetadata("PassThru", typeof(SwitchParameter));
                passThruParameter.ParameterSets.Clear();
                ParameterSetMetadata passThruPSet = new ParameterSetMetadata(int.MinValue, 0, null);
                passThruParameter.ParameterSets.Add(ParameterAttribute.AllParameterSets, passThruPSet);

                commonParameters.Add(passThruParameter.Name, passThruParameter);
            }
        }
コード例 #23
0
ファイル: CommandMetadata.cs プロジェクト: nickchal/pash
 private static Collection<CommandMetadata> GetRestrictedJobCommands()
 {
     ParameterSetMetadata metadata = new ParameterSetMetadata(0, ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
     ParameterSetMetadata metadata2 = new ParameterSetMetadata(0, ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
     ParameterSetMetadata metadata3 = new ParameterSetMetadata(0, ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
     ParameterSetMetadata metadata4 = new ParameterSetMetadata(-2147483648, ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
     ParameterSetMetadata metadata5 = new ParameterSetMetadata(-2147483648, ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
     ParameterSetMetadata metadata6 = new ParameterSetMetadata(0, ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
     ParameterSetMetadata metadata7 = new ParameterSetMetadata(0, ParameterSetMetadata.ParameterFlags.Mandatory | ParameterSetMetadata.ParameterFlags.ValueFromPipeline | ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
     ParameterSetMetadata metadata8 = new ParameterSetMetadata(0, ParameterSetMetadata.ParameterFlags.Mandatory | ParameterSetMetadata.ParameterFlags.ValueFromPipeline | ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
     ParameterSetMetadata metadata9 = new ParameterSetMetadata(0, ParameterSetMetadata.ParameterFlags.Mandatory | ParameterSetMetadata.ParameterFlags.ValueFromPipeline | ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
     Dictionary<string, ParameterSetMetadata> parameterSets = new Dictionary<string, ParameterSetMetadata>();
     parameterSets.Add("NameParameterSet", metadata);
     Collection<string> aliases = new Collection<string>();
     ParameterMetadata metadata10 = new ParameterMetadata(aliases, false, "Name", parameterSets, typeof(string[])) {
         Attributes = { new ValidatePatternAttribute(@"^[-._:\\\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Lm}]{1,100}$"), new ValidateLengthAttribute(0, 0x3e8) }
     };
     parameterSets = new Dictionary<string, ParameterSetMetadata>();
     parameterSets.Add("InstanceIdParameterSet", metadata2);
     ParameterMetadata metadata11 = new ParameterMetadata(aliases, false, "InstanceId", parameterSets, typeof(Guid[])) {
         Attributes = { new ValidateNotNullOrEmptyAttribute() }
     };
     parameterSets = new Dictionary<string, ParameterSetMetadata>();
     parameterSets.Add("SessionIdParameterSet", metadata3);
     ParameterMetadata metadata12 = new ParameterMetadata(aliases, false, "Id", parameterSets, typeof(int[])) {
         Attributes = { new ValidateNotNullOrEmptyAttribute() }
     };
     parameterSets = new Dictionary<string, ParameterSetMetadata>();
     parameterSets.Add("StateParameterSet", metadata4);
     ParameterMetadata metadata13 = new ParameterMetadata(aliases, false, "State", parameterSets, typeof(JobState));
     parameterSets = new Dictionary<string, ParameterSetMetadata>();
     parameterSets.Add("CommandParameterSet", metadata5);
     ParameterMetadata metadata14 = new ParameterMetadata(aliases, false, "Command", parameterSets, typeof(string[]));
     parameterSets = new Dictionary<string, ParameterSetMetadata>();
     parameterSets.Add("FilterParameterSet", metadata6);
     ParameterMetadata metadata15 = new ParameterMetadata(aliases, false, "Filter", parameterSets, typeof(Hashtable));
     parameterSets = new Dictionary<string, ParameterSetMetadata>();
     parameterSets.Add("Job", metadata7);
     ParameterMetadata metadata16 = new ParameterMetadata(aliases, false, "Job", parameterSets, typeof(Job[])) {
         Attributes = { new ValidateNotNullOrEmptyAttribute() }
     };
     parameterSets = new Dictionary<string, ParameterSetMetadata>();
     parameterSets.Add("ComputerName", metadata8);
     parameterSets.Add("Location", metadata9);
     ParameterMetadata metadata17 = new ParameterMetadata(aliases, false, "Job", parameterSets, typeof(Job[]));
     Collection<CommandMetadata> collection2 = new Collection<CommandMetadata>();
     ParameterMetadata metadata18 = new ParameterMetadata("PassThru", typeof(SwitchParameter));
     ParameterMetadata metadata19 = new ParameterMetadata("Any", typeof(SwitchParameter));
     CommandMetadata item = GetRestrictedCmdlet("Stop-Job", "SessionIdParameterSet", "http://go.microsoft.com/fwlink/?LinkID=113413", new ParameterMetadata[] { metadata10, metadata11, metadata12, metadata13, metadata15, metadata16, metadata18 });
     collection2.Add(item);
     ParameterMetadata metadata21 = new ParameterMetadata("Timeout", typeof(int)) {
         Attributes = { new ValidateRangeAttribute(-1, 0x7fffffff) }
     };
     CommandMetadata metadata22 = GetRestrictedCmdlet("Wait-Job", "SessionIdParameterSet", "http://go.microsoft.com/fwlink/?LinkID=113422", new ParameterMetadata[] { metadata10, metadata11, metadata12, metadata16, metadata13, metadata15, metadata19, metadata21 });
     collection2.Add(metadata22);
     CommandMetadata metadata23 = GetRestrictedCmdlet("Get-Job", "SessionIdParameterSet", "http://go.microsoft.com/fwlink/?LinkID=113328", new ParameterMetadata[] { metadata10, metadata11, metadata12, metadata13, metadata15, metadata14 });
     collection2.Add(metadata23);
     parameterSets = new Dictionary<string, ParameterSetMetadata>();
     metadata8 = new ParameterSetMetadata(1, ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
     parameterSets.Add("ComputerName", metadata8);
     ParameterMetadata metadata24 = new ParameterMetadata(aliases, false, "ComputerName", parameterSets, typeof(string[])) {
         Attributes = { new ValidateLengthAttribute(0, 0x3e8), new ValidateNotNullOrEmptyAttribute() }
     };
     parameterSets = new Dictionary<string, ParameterSetMetadata>();
     metadata9 = new ParameterSetMetadata(1, ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
     parameterSets.Add("Location", metadata9);
     ParameterMetadata metadata25 = new ParameterMetadata(aliases, false, "Location", parameterSets, typeof(string[])) {
         Attributes = { new ValidateLengthAttribute(0, 0x3e8), new ValidateNotNullOrEmptyAttribute() }
     };
     ParameterMetadata metadata26 = new ParameterMetadata("NoRecurse", typeof(SwitchParameter));
     ParameterMetadata metadata27 = new ParameterMetadata("Keep", typeof(SwitchParameter));
     ParameterMetadata metadata28 = new ParameterMetadata("Wait", typeof(SwitchParameter));
     ParameterMetadata metadata29 = new ParameterMetadata("WriteEvents", typeof(SwitchParameter));
     ParameterMetadata metadata30 = new ParameterMetadata("WriteJobInResults", typeof(SwitchParameter));
     ParameterMetadata metadata31 = new ParameterMetadata("AutoRemoveJob", typeof(SwitchParameter));
     CommandMetadata metadata32 = GetRestrictedCmdlet("Receive-Job", "Location", "http://go.microsoft.com/fwlink/?LinkID=113372", new ParameterMetadata[] { metadata10, metadata11, metadata12, metadata13, metadata17, metadata24, metadata25, metadata26, metadata27, metadata28, metadata29, metadata30, metadata31 });
     collection2.Add(metadata32);
     ParameterMetadata metadata33 = new ParameterMetadata("Force", typeof(SwitchParameter));
     CommandMetadata metadata34 = GetRestrictedCmdlet("Remove-Job", "SessionIdParameterSet", "http://go.microsoft.com/fwlink/?LinkID=113377", new ParameterMetadata[] { metadata10, metadata11, metadata12, metadata13, metadata15, metadata16, metadata33 });
     collection2.Add(metadata34);
     CommandMetadata metadata35 = GetRestrictedCmdlet("Suspend-Job", "SessionIdParameterSet", "http://go.microsoft.com/fwlink/?LinkID=210613", new ParameterMetadata[] { metadata10, metadata11, metadata12, metadata13, metadata15, metadata16, metadata18 });
     collection2.Add(metadata35);
     CommandMetadata metadata36 = GetRestrictedCmdlet("Resume-Job", "SessionIdParameterSet", "http://go.microsoft.com/fwlink/?LinkID=210611", new ParameterMetadata[] { metadata10, metadata11, metadata12, metadata13, metadata15, metadata16, metadata18 });
     collection2.Add(metadata36);
     return collection2;
 }
コード例 #24
0
        private static Collection <CommandMetadata> GetRestrictedJobCommands()
        {
            ParameterSetMetadata metadata  = new ParameterSetMetadata(0, ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
            ParameterSetMetadata metadata2 = new ParameterSetMetadata(0, ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
            ParameterSetMetadata metadata3 = new ParameterSetMetadata(0, ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
            ParameterSetMetadata metadata4 = new ParameterSetMetadata(-2147483648, ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
            ParameterSetMetadata metadata5 = new ParameterSetMetadata(-2147483648, ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
            ParameterSetMetadata metadata6 = new ParameterSetMetadata(0, ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
            ParameterSetMetadata metadata7 = new ParameterSetMetadata(0, ParameterSetMetadata.ParameterFlags.Mandatory | ParameterSetMetadata.ParameterFlags.ValueFromPipeline | ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
            ParameterSetMetadata metadata8 = new ParameterSetMetadata(0, ParameterSetMetadata.ParameterFlags.Mandatory | ParameterSetMetadata.ParameterFlags.ValueFromPipeline | ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
            ParameterSetMetadata metadata9 = new ParameterSetMetadata(0, ParameterSetMetadata.ParameterFlags.Mandatory | ParameterSetMetadata.ParameterFlags.ValueFromPipeline | ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
            Dictionary <string, ParameterSetMetadata> parameterSets = new Dictionary <string, ParameterSetMetadata>();

            parameterSets.Add("NameParameterSet", metadata);
            Collection <string> aliases    = new Collection <string>();
            ParameterMetadata   metadata10 = new ParameterMetadata(aliases, false, "Name", parameterSets, typeof(string[]))
            {
                Attributes = { new ValidatePatternAttribute(@"^[-._:\\\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Lm}]{1,100}$"), new ValidateLengthAttribute(0, 0x3e8) }
            };

            parameterSets = new Dictionary <string, ParameterSetMetadata>();
            parameterSets.Add("InstanceIdParameterSet", metadata2);
            ParameterMetadata metadata11 = new ParameterMetadata(aliases, false, "InstanceId", parameterSets, typeof(Guid[]))
            {
                Attributes = { new ValidateNotNullOrEmptyAttribute() }
            };

            parameterSets = new Dictionary <string, ParameterSetMetadata>();
            parameterSets.Add("SessionIdParameterSet", metadata3);
            ParameterMetadata metadata12 = new ParameterMetadata(aliases, false, "Id", parameterSets, typeof(int[]))
            {
                Attributes = { new ValidateNotNullOrEmptyAttribute() }
            };

            parameterSets = new Dictionary <string, ParameterSetMetadata>();
            parameterSets.Add("StateParameterSet", metadata4);
            ParameterMetadata metadata13 = new ParameterMetadata(aliases, false, "State", parameterSets, typeof(JobState));

            parameterSets = new Dictionary <string, ParameterSetMetadata>();
            parameterSets.Add("CommandParameterSet", metadata5);
            ParameterMetadata metadata14 = new ParameterMetadata(aliases, false, "Command", parameterSets, typeof(string[]));

            parameterSets = new Dictionary <string, ParameterSetMetadata>();
            parameterSets.Add("FilterParameterSet", metadata6);
            ParameterMetadata metadata15 = new ParameterMetadata(aliases, false, "Filter", parameterSets, typeof(Hashtable));

            parameterSets = new Dictionary <string, ParameterSetMetadata>();
            parameterSets.Add("Job", metadata7);
            ParameterMetadata metadata16 = new ParameterMetadata(aliases, false, "Job", parameterSets, typeof(Job[]))
            {
                Attributes = { new ValidateNotNullOrEmptyAttribute() }
            };

            parameterSets = new Dictionary <string, ParameterSetMetadata>();
            parameterSets.Add("ComputerName", metadata8);
            parameterSets.Add("Location", metadata9);
            ParameterMetadata            metadata17  = new ParameterMetadata(aliases, false, "Job", parameterSets, typeof(Job[]));
            Collection <CommandMetadata> collection2 = new Collection <CommandMetadata>();
            ParameterMetadata            metadata18  = new ParameterMetadata("PassThru", typeof(SwitchParameter));
            ParameterMetadata            metadata19  = new ParameterMetadata("Any", typeof(SwitchParameter));
            CommandMetadata item = GetRestrictedCmdlet("Stop-Job", "SessionIdParameterSet", "http://go.microsoft.com/fwlink/?LinkID=113413", new ParameterMetadata[] { metadata10, metadata11, metadata12, metadata13, metadata15, metadata16, metadata18 });

            collection2.Add(item);
            ParameterMetadata metadata21 = new ParameterMetadata("Timeout", typeof(int))
            {
                Attributes = { new ValidateRangeAttribute(-1, 0x7fffffff) }
            };
            CommandMetadata metadata22 = GetRestrictedCmdlet("Wait-Job", "SessionIdParameterSet", "http://go.microsoft.com/fwlink/?LinkID=113422", new ParameterMetadata[] { metadata10, metadata11, metadata12, metadata16, metadata13, metadata15, metadata19, metadata21 });

            collection2.Add(metadata22);
            CommandMetadata metadata23 = GetRestrictedCmdlet("Get-Job", "SessionIdParameterSet", "http://go.microsoft.com/fwlink/?LinkID=113328", new ParameterMetadata[] { metadata10, metadata11, metadata12, metadata13, metadata15, metadata14 });

            collection2.Add(metadata23);
            parameterSets = new Dictionary <string, ParameterSetMetadata>();
            metadata8     = new ParameterSetMetadata(1, ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
            parameterSets.Add("ComputerName", metadata8);
            ParameterMetadata metadata24 = new ParameterMetadata(aliases, false, "ComputerName", parameterSets, typeof(string[]))
            {
                Attributes = { new ValidateLengthAttribute(0, 0x3e8), new ValidateNotNullOrEmptyAttribute() }
            };

            parameterSets = new Dictionary <string, ParameterSetMetadata>();
            metadata9     = new ParameterSetMetadata(1, ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName, string.Empty);
            parameterSets.Add("Location", metadata9);
            ParameterMetadata metadata25 = new ParameterMetadata(aliases, false, "Location", parameterSets, typeof(string[]))
            {
                Attributes = { new ValidateLengthAttribute(0, 0x3e8), new ValidateNotNullOrEmptyAttribute() }
            };
            ParameterMetadata metadata26 = new ParameterMetadata("NoRecurse", typeof(SwitchParameter));
            ParameterMetadata metadata27 = new ParameterMetadata("Keep", typeof(SwitchParameter));
            ParameterMetadata metadata28 = new ParameterMetadata("Wait", typeof(SwitchParameter));
            ParameterMetadata metadata29 = new ParameterMetadata("WriteEvents", typeof(SwitchParameter));
            ParameterMetadata metadata30 = new ParameterMetadata("WriteJobInResults", typeof(SwitchParameter));
            ParameterMetadata metadata31 = new ParameterMetadata("AutoRemoveJob", typeof(SwitchParameter));
            CommandMetadata   metadata32 = GetRestrictedCmdlet("Receive-Job", "Location", "http://go.microsoft.com/fwlink/?LinkID=113372", new ParameterMetadata[] { metadata10, metadata11, metadata12, metadata13, metadata17, metadata24, metadata25, metadata26, metadata27, metadata28, metadata29, metadata30, metadata31 });

            collection2.Add(metadata32);
            ParameterMetadata metadata33 = new ParameterMetadata("Force", typeof(SwitchParameter));
            CommandMetadata   metadata34 = GetRestrictedCmdlet("Remove-Job", "SessionIdParameterSet", "http://go.microsoft.com/fwlink/?LinkID=113377", new ParameterMetadata[] { metadata10, metadata11, metadata12, metadata13, metadata15, metadata16, metadata33 });

            collection2.Add(metadata34);
            CommandMetadata metadata35 = GetRestrictedCmdlet("Suspend-Job", "SessionIdParameterSet", "http://go.microsoft.com/fwlink/?LinkID=210613", new ParameterMetadata[] { metadata10, metadata11, metadata12, metadata13, metadata15, metadata16, metadata18 });

            collection2.Add(metadata35);
            CommandMetadata metadata36 = GetRestrictedCmdlet("Resume-Job", "SessionIdParameterSet", "http://go.microsoft.com/fwlink/?LinkID=210611", new ParameterMetadata[] { metadata10, metadata11, metadata12, metadata13, metadata15, metadata16, metadata18 });

            collection2.Add(metadata36);
            return(collection2);
        }
コード例 #25
0
ファイル: ScriptWriter.cs プロジェクト: nickchal/pash
 private void GenerateIfBoundParameter(IEnumerable<string> commonParameterSets, IEnumerable<string> methodParameterSets, ParameterMetadata cmdletParameterMetadata, TextWriter output)
 {
     output.Write("    if ($PSBoundParameters.ContainsKey('{0}') -and (@(", CommandMetadata.EscapeSingleQuotedString(cmdletParameterMetadata.Name));
     bool flag = true;
     foreach (string str in cmdletParameterMetadata.ParameterSets.Keys)
     {
         foreach (string str2 in MultiplyParameterSets(str, "{0}", new IEnumerable<string>[] { commonParameterSets, methodParameterSets }))
         {
             if (!flag)
             {
                 output.Write(", ");
             }
             flag = false;
             output.Write("'{0}'", CommandMetadata.EscapeSingleQuotedString(str2));
         }
     }
     output.WriteLine(") -contains $PSCmdlet.ParameterSetName )) {");
 }
コード例 #26
0
ファイル: ScriptWriter.cs プロジェクト: nickchal/pash
 private Dictionary<string, ParameterMetadata> GetCommonParameters()
 {
     Dictionary<string, ParameterMetadata> commonParameters = new Dictionary<string, ParameterMetadata>(StringComparer.OrdinalIgnoreCase);
     InternalParameterMetadata metadata = new InternalParameterMetadata(this.objectModelWrapper, false);
     foreach (CompiledCommandParameter parameter in metadata.BindableParameters.Values)
     {
         ParameterMetadata metadata2 = new ParameterMetadata(parameter);
         foreach (ParameterSetMetadata metadata3 in metadata2.ParameterSets.Values)
         {
             if (metadata3.ValueFromPipeline)
             {
                 throw new XmlException(string.Format(CultureInfo.InvariantCulture, CmdletizationCoreResources.ScriptWriter_ObjectModelWrapperUsesIgnoredParameterMetadata, new object[] { this.objectModelWrapper.FullName, metadata2.Name, "ValueFromPipeline" }));
             }
             if (metadata3.ValueFromPipelineByPropertyName)
             {
                 throw new XmlException(string.Format(CultureInfo.InvariantCulture, CmdletizationCoreResources.ScriptWriter_ObjectModelWrapperUsesIgnoredParameterMetadata, new object[] { this.objectModelWrapper.FullName, metadata2.Name, "ValueFromPipelineByPropertyName" }));
             }
             if (metadata3.ValueFromRemainingArguments)
             {
                 throw new XmlException(string.Format(CultureInfo.InvariantCulture, CmdletizationCoreResources.ScriptWriter_ObjectModelWrapperUsesIgnoredParameterMetadata, new object[] { this.objectModelWrapper.FullName, metadata2.Name, "ValueFromRemainingArguments" }));
             }
             metadata3.ValueFromPipeline = false;
             metadata3.ValueFromPipelineByPropertyName = false;
             metadata3.ValueFromRemainingArguments = false;
         }
         commonParameters.Add(metadata2.Name, metadata2);
     }
     List<string> commonParameterSets = GetCommonParameterSets(commonParameters);
     if (commonParameterSets.Count > 1)
     {
         throw new XmlException(string.Format(CultureInfo.InvariantCulture, CmdletizationCoreResources.ScriptWriter_ObjectModelWrapperDefinesMultipleParameterSets, new object[] { this.objectModelWrapper.FullName }));
     }
     foreach (ParameterMetadata metadata4 in commonParameters.Values)
     {
         if ((metadata4.ParameterSets.Count == 1) && metadata4.ParameterSets.ContainsKey("__AllParameterSets"))
         {
             ParameterSetMetadata metadata5 = metadata4.ParameterSets["__AllParameterSets"];
             metadata4.ParameterSets.Clear();
             foreach (string str5 in commonParameterSets)
             {
                 metadata4.ParameterSets.Add(str5, metadata5);
             }
         }
     }
     return commonParameters;
 }
コード例 #27
0
ファイル: ScriptWriter.cs プロジェクト: dfinke/powershell
 private void GenerateIfBoundParameter(
     IEnumerable<string> commonParameterSets,
     IEnumerable<string> methodParameterSets,
     ParameterMetadata cmdletParameterMetadata,
     TextWriter output)
 {
     output.Write("    if ($PSBoundParameters.ContainsKey('{0}') -and (@(", CodeGeneration.EscapeSingleQuotedStringContent(cmdletParameterMetadata.Name));
     bool firstParameterSet = true;
     foreach (string queryParameterSetName in cmdletParameterMetadata.ParameterSets.Keys)
         foreach (string parameterSetName in MultiplyParameterSets(queryParameterSetName, InstanceQueryParameterSetTemplate, commonParameterSets, methodParameterSets))
         {
             if (!firstParameterSet) output.Write(", ");
             firstParameterSet = false;
             output.Write("'{0}'", CodeGeneration.EscapeSingleQuotedStringContent(parameterSetName));
         }
     output.WriteLine(") -contains $PSCmdlet.ParameterSetName )) {");
 }
コード例 #28
0
ファイル: ParameterMetadata.cs プロジェクト: mauve/Pash
 public ParameterMetadata(ParameterMetadata other)
 {
     throw new NotImplementedException();
 }
コード例 #29
0
ファイル: CommandMetadata.cs プロジェクト: dfinke/powershell
        private static CommandMetadata GetRestrictedGetCommand()
        {
            // remote Get-Command called by Import/Export-PSSession to get metadata for remote commands that user wants to import

            // remote Get-Command is also called by interactive remoting before entering the remote session to verify
            // that Out-Default and Exit-PSSession commands are present in the remote session

            // value passed directly from Import-PSSession -CommandName to Get-Command -Name
            // can't really restrict beyond basics
            ParameterMetadata nameParameter = new ParameterMetadata("Name", typeof(string[]));
            nameParameter.Attributes.Add(new ValidateLengthAttribute(0, 1000));
            nameParameter.Attributes.Add(new ValidateCountAttribute(0, 1000));

            // value passed directly from Import-PSSession -PSSnapIn to Get-Command -Module
            // can't really restrict beyond basics
            ParameterMetadata moduleParameter = new ParameterMetadata("Module", typeof(string[]));
            moduleParameter.Attributes.Add(new ValidateLengthAttribute(0, 1000));
            moduleParameter.Attributes.Add(new ValidateCountAttribute(0, 100));

            // value passed directly from Import-PSSession -ArgumentList to Get-Command -ArgumentList
            // can't really restrict beyond basics
            ParameterMetadata argumentListParameter = new ParameterMetadata("ArgumentList", typeof(object[]));
            argumentListParameter.Attributes.Add(new ValidateCountAttribute(0, 100));

            // value passed directly from Import-PSSession -CommandType to Get-Command -CommandType
            // can't really restrict beyond basics
            ParameterMetadata commandTypeParameter = new ParameterMetadata("CommandType", typeof(CommandTypes));

            // we do allow -ListImported switch
            ParameterMetadata listImportedParameter = new ParameterMetadata("ListImported", typeof(SwitchParameter));

            // Need to expose ShowCommandInfo parameter for remote ShowCommand support.
            ParameterMetadata showCommandInfo = new ParameterMetadata("ShowCommandInfo", typeof(SwitchParameter));

            return GetRestrictedCmdlet(
                "Get-Command",
                null, // defaultParameterSet 
                "http://go.microsoft.com/fwlink/?LinkID=113309", // helpUri
                nameParameter,
                moduleParameter,
                argumentListParameter,
                commandTypeParameter,
                listImportedParameter,
                showCommandInfo);
        }
コード例 #30
0
ファイル: TypeMetadata.cs プロジェクト: dfinke/powershell
        /// <summary>
        /// A copy constructor that creates a deep copy of the <paramref name="other"/> ParameterMetadata object.
        /// Instances of Attribute and Type classes are copied by reference.
        /// </summary>
        /// <param name="other">object to copy</param>
        public ParameterMetadata(ParameterMetadata other)
        {
            if (other == null)
            {
                throw PSTraceSource.NewArgumentNullException("other");
            }

            _isDynamic = other._isDynamic;
            _name = other._name;
            _parameterType = other._parameterType;

            // deep copy
            _aliases = new Collection<string>(new List<string>(other._aliases.Count));
            foreach (string alias in other._aliases)
            {
                _aliases.Add(alias);
            }

            // deep copy of the collection, collection items (Attributes) copied by reference
            if (other._attributes == null)
            {
                _attributes = null;
            }
            else
            {
                _attributes = new Collection<Attribute>(new List<Attribute>(other._attributes.Count));
                foreach (Attribute attribute in other._attributes)
                {
                    _attributes.Add(attribute);
                }
            }

            // deep copy
            _parameterSets = null;
            if (other._parameterSets == null)
            {
                _parameterSets = null;
            }
            else
            {
                _parameterSets = new Dictionary<string, ParameterSetMetadata>(other._parameterSets.Count);
                foreach (KeyValuePair<string, ParameterSetMetadata> entry in other._parameterSets)
                {
                    _parameterSets.Add(entry.Key, new ParameterSetMetadata(entry.Value));
                }
            }
        }
コード例 #31
0
ファイル: CommandMetadata.cs プロジェクト: dfinke/powershell
        private static CommandMetadata GetRestrictedGetFormatData()
        {
            // remote Get-FormatData called by Import/Export-PSSession to get F&O metadata from remote session

            // value passed directly from Import-PSSession -FormatTypeName to Get-FormatData -TypeName
            // can't really restrict beyond basics
            ParameterMetadata typeNameParameter = new ParameterMetadata("TypeName", typeof(string[]));
            typeNameParameter.Attributes.Add(new ValidateLengthAttribute(0, 1000));
            typeNameParameter.Attributes.Add(new ValidateCountAttribute(0, 1000));

            return GetRestrictedCmdlet("Get-FormatData", null, "http://go.microsoft.com/fwlink/?LinkID=144303", typeNameParameter);
        }
コード例 #32
0
ファイル: ScriptWriter.cs プロジェクト: nickchal/pash
 private static void AddPassThruParameter(IDictionary<string, ParameterMetadata> commonParameters, InstanceCmdletMetadata instanceCmdletMetadata)
 {
     bool flag = false;
     if (instanceCmdletMetadata.Method.Parameters != null)
     {
         foreach (InstanceMethodParameterMetadata metadata in instanceCmdletMetadata.Method.Parameters)
         {
             if ((metadata.CmdletOutputMetadata != null) && (metadata.CmdletOutputMetadata.ErrorCode == null))
             {
                 flag = true;
                 break;
             }
         }
     }
     if (((instanceCmdletMetadata.Method.ReturnValue != null) && (instanceCmdletMetadata.Method.ReturnValue.CmdletOutputMetadata != null)) && (instanceCmdletMetadata.Method.ReturnValue.CmdletOutputMetadata.ErrorCode == null))
     {
         flag = true;
     }
     if (!flag)
     {
         ParameterMetadata metadata2 = new ParameterMetadata("PassThru", typeof(SwitchParameter));
         metadata2.ParameterSets.Clear();
         ParameterSetMetadata metadata3 = new ParameterSetMetadata(-2147483648, 0, null);
         metadata2.ParameterSets.Add("__AllParameterSets", metadata3);
         commonParameters.Add(metadata2.Name, metadata2);
     }
 }
コード例 #33
0
ファイル: CommandMetadata.cs プロジェクト: dfinke/powershell
        private static CommandMetadata GetRestrictedGetHelp()
        {
            // remote Get-Help is called when help for implicit remoting proxy tries to fetch help content for a remote command

            // This should only be called with 1 "safe" command name (unless ipsn is called with -Force)
            // (it seems ok to disallow getting help for "unsafe" commands [possible when ipsn is called with -Force] 
            //  - host can always generate its own proxy for Get-Help if it cares about "unsafe" command names)
            ParameterMetadata nameParameter = new ParameterMetadata("Name", typeof(string));
            nameParameter.Attributes.Add(new ValidatePatternAttribute(isSafeNameOrIdentifierRegex));
            nameParameter.Attributes.Add(new ValidateLengthAttribute(0, 1000));

            // This should only be called with 1 valid category
            ParameterMetadata categoryParameter = new ParameterMetadata("Category", typeof(string[]));
            categoryParameter.Attributes.Add(new ValidateSetAttribute(Enum.GetNames(typeof(HelpCategory))));
            categoryParameter.Attributes.Add(new ValidateCountAttribute(0, 1));

            return GetRestrictedCmdlet("Get-Help", null, "http://go.microsoft.com/fwlink/?LinkID=113316", nameParameter, categoryParameter);
        }
コード例 #34
0
ファイル: ScriptWriter.cs プロジェクト: nickchal/pash
        private void GenerateQueryParametersProcessing(InstanceCmdletMetadata instanceCmdlet, IEnumerable<string> commonParameterSets, IEnumerable<string> queryParameterSets, IEnumerable<string> methodParameterSets, out string scriptCode, out Dictionary<string, ParameterMetadata> queryParameters)
        {
            queryParameters = new Dictionary<string, ParameterMetadata>(StringComparer.OrdinalIgnoreCase);
            StringWriter output = new StringWriter(CultureInfo.InvariantCulture);
            output.WriteLine("    $__cmdletization_queryBuilder = $__cmdletization_objectModelWrapper.GetQueryBuilder()");
            GetCmdletParameters getCmdletParameters = this.GetGetCmdletParameters(instanceCmdlet);
            if (getCmdletParameters.QueryableProperties != null)
            {
                foreach (PropertyMetadata metadata in from p in getCmdletParameters.QueryableProperties
                    where p.Items != null
                    select p)
                {
                    for (int i = 0; i < metadata.Items.Length; i++)
                    {
                        string str;
                        switch (metadata.ItemsElementName[i])
                        {
                            case ItemsChoiceType.ExcludeQuery:
                                str = "ExcludeByProperty";
                                break;

                            case ItemsChoiceType.MaxValueQuery:
                                str = "FilterByMaxPropertyValue";
                                break;

                            case ItemsChoiceType.MinValueQuery:
                                str = "FilterByMinPropertyValue";
                                break;

                            case ItemsChoiceType.RegularQuery:
                                str = "FilterByProperty";
                                break;

                            default:
                                str = "NotAValidMethod";
                                break;
                        }
                        ParameterMetadata metadata2 = this.GenerateQueryClause(commonParameterSets, queryParameterSets, methodParameterSets, str, metadata, metadata.Items[i], output);
                        switch (metadata.ItemsElementName[i])
                        {
                            case ItemsChoiceType.ExcludeQuery:
                            case ItemsChoiceType.RegularQuery:
                                metadata2.Attributes.Add(new ValidateNotNullAttribute());
                                break;
                        }
                        try
                        {
                            queryParameters.Add(metadata2.Name, metadata2);
                        }
                        catch (ArgumentException exception)
                        {
                            throw new XmlException(string.Format(CultureInfo.InvariantCulture, CmdletizationCoreResources.ScriptWriter_DuplicateQueryParameterName, new object[] { "<GetCmdletParameters>", metadata2.Name }), exception);
                        }
                    }
                }
            }
            if (getCmdletParameters.QueryableAssociations != null)
            {
                foreach (Association association in from a in getCmdletParameters.QueryableAssociations
                    where a.AssociatedInstance != null
                    select a)
                {
                    ParameterMetadata metadata3 = this.GenerateAssociationClause(commonParameterSets, queryParameterSets, methodParameterSets, association, association.AssociatedInstance, output);
                    try
                    {
                        queryParameters.Add(metadata3.Name, metadata3);
                    }
                    catch (ArgumentException exception2)
                    {
                        throw new XmlException(string.Format(CultureInfo.InvariantCulture, CmdletizationCoreResources.ScriptWriter_DuplicateQueryParameterName, new object[] { "<GetCmdletParameters>", metadata3.Name }), exception2);
                    }
                }
            }
            if (getCmdletParameters.QueryOptions != null)
            {
                foreach (QueryOption option in getCmdletParameters.QueryOptions)
                {
                    ParameterMetadata metadata4 = this.GenerateOptionClause(commonParameterSets, queryParameterSets, methodParameterSets, option, output);
                    try
                    {
                        queryParameters.Add(metadata4.Name, metadata4);
                    }
                    catch (ArgumentException exception3)
                    {
                        throw new XmlException(string.Format(CultureInfo.InvariantCulture, CmdletizationCoreResources.ScriptWriter_DuplicateQueryParameterName, new object[] { "<GetCmdletParameters>", metadata4.Name }), exception3);
                    }
                }
            }
            if (instanceCmdlet != null)
            {
                string str5;
                ParameterMetadata metadata5 = new ParameterMetadata("InputObject", this.objectInstanceType.MakeArrayType());
                ParameterSetMetadata.ParameterFlags valueFromPipeline = ParameterSetMetadata.ParameterFlags.ValueFromPipeline;
                if (queryParameters.Count > 0)
                {
                    valueFromPipeline |= ParameterSetMetadata.ParameterFlags.Mandatory;
                }
                if (this.objectModelWrapper.FullName.Equals("Microsoft.PowerShell.Cmdletization.Cim.CimCmdletAdapter"))
                {
                    int num2 = this.cmdletizationMetadata.Class.ClassName.LastIndexOf('\\');
                    int num3 = this.cmdletizationMetadata.Class.ClassName.LastIndexOf('/');
                    int num4 = Math.Max(num2, num3);
                    string str6 = this.cmdletizationMetadata.Class.ClassName.Substring(num4 + 1, (this.cmdletizationMetadata.Class.ClassName.Length - num4) - 1);
                    str5 = string.Format(CultureInfo.InvariantCulture, "{0}#{1}", new object[] { this.objectInstanceType.FullName, str6 });
                }
                else
                {
                    str5 = string.Format(CultureInfo.InvariantCulture, "{0}#{1}", new object[] { this.objectInstanceType.FullName, this.cmdletizationMetadata.Class.ClassName });
                }
                metadata5.Attributes.Add(new PSTypeNameAttribute(str5));
                metadata5.Attributes.Add(new ValidateNotNullAttribute());
                metadata5.ParameterSets.Clear();
                ParameterSetMetadata metadata6 = new ParameterSetMetadata(-2147483648, valueFromPipeline, null);
                metadata5.ParameterSets.Add("InputObject (cdxml)", metadata6);
                queryParameters.Add(metadata5.Name, metadata5);
            }
            output.WriteLine();
            scriptCode = output.ToString();
        }
コード例 #35
0
ファイル: CommandMetadata.cs プロジェクト: dfinke/powershell
        private static CommandMetadata GetRestrictedSelectObject()
        {
            // remote Select-Object is called by Import/Export-PSSession to 
            // 1) restrict what properties are serialized
            // 2) artificially increase serialization depth of selected properties (especially "Parameters" property)

            // only called with a fixed set of values
            string[] validPropertyValues = new string[] {
                "ModuleName", "Namespace", "OutputType", "Count", "HelpUri",
                "Name", "CommandType", "ResolvedCommandName", "DefaultParameterSet", "CmdletBinding", "Parameters" };
            ParameterMetadata propertyParameter = new ParameterMetadata("Property", typeof(string[]));
            propertyParameter.Attributes.Add(new ValidateSetAttribute(validPropertyValues));
            propertyParameter.Attributes.Add(new ValidateCountAttribute(1, validPropertyValues.Length));

            // needed for pipeline input if cmdlet binding has to be used (i.e. if Windows 7: #477218 is not fixed)
            ParameterMetadata inputParameter = new ParameterMetadata("InputObject", typeof(object));
            inputParameter.ParameterSets.Add(
                ParameterAttribute.AllParameterSets,
                new ParameterSetMetadata(
                    int.MinValue, // not positional
                    ParameterSetMetadata.ParameterFlags.ValueFromPipeline | ParameterSetMetadata.ParameterFlags.Mandatory,
                    null)); // no help message

            return GetRestrictedCmdlet("Select-Object", null, "http://go.microsoft.com/fwlink/?LinkID=113387", propertyParameter, inputParameter);
        }
コード例 #36
0
ファイル: ScriptWriter.cs プロジェクト: nickchal/pash
 private ParameterMetadata GetParameter(string parameterSetName, string objectModelParameterName, TypeMetadata parameterTypeMetadata, CmdletParameterMetadata parameterCmdletization, bool isValueFromPipeline, bool isValueFromPipelineByPropertyName)
 {
     string pSName;
     if ((parameterCmdletization != null) && !string.IsNullOrEmpty(parameterCmdletization.PSName))
     {
         pSName = parameterCmdletization.PSName;
     }
     else
     {
         pSName = objectModelParameterName;
     }
     ParameterMetadata metadata = new ParameterMetadata(pSName) {
         ParameterType = this.GetDotNetType(parameterTypeMetadata)
     };
     if (parameterTypeMetadata.ETSType != null)
     {
         metadata.Attributes.Add(new PSTypeNameAttribute(parameterTypeMetadata.ETSType));
     }
     if (parameterCmdletization != null)
     {
         if (parameterCmdletization.Aliases != null)
         {
             foreach (string str2 in parameterCmdletization.Aliases)
             {
                 if (!string.IsNullOrEmpty(str2))
                 {
                     metadata.Aliases.Add(str2);
                 }
             }
         }
         if (parameterCmdletization.AllowEmptyCollection != null)
         {
             metadata.Attributes.Add(new AllowEmptyCollectionAttribute());
         }
         if (parameterCmdletization.AllowEmptyString != null)
         {
             metadata.Attributes.Add(new AllowEmptyStringAttribute());
         }
         if (parameterCmdletization.AllowNull != null)
         {
             metadata.Attributes.Add(new AllowNullAttribute());
         }
         if (parameterCmdletization.ValidateCount != null)
         {
             int minLength = (int) LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateCount.Min, typeof(int), CultureInfo.InvariantCulture);
             int maxLength = (int) LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateCount.Max, typeof(int), CultureInfo.InvariantCulture);
             metadata.Attributes.Add(new ValidateCountAttribute(minLength, maxLength));
         }
         if (parameterCmdletization.ValidateLength != null)
         {
             int num3 = (int) LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateLength.Min, typeof(int), CultureInfo.InvariantCulture);
             int num4 = (int) LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateLength.Max, typeof(int), CultureInfo.InvariantCulture);
             metadata.Attributes.Add(new ValidateLengthAttribute(num3, num4));
         }
         if (parameterCmdletization.ValidateNotNull != null)
         {
             metadata.Attributes.Add(new ValidateNotNullAttribute());
         }
         if (parameterCmdletization.ValidateNotNullOrEmpty != null)
         {
             metadata.Attributes.Add(new ValidateNotNullOrEmptyAttribute());
         }
         if (parameterCmdletization.ValidateRange != null)
         {
             Type type2;
             Type parameterType = metadata.ParameterType;
             if (parameterType == null)
             {
                 type2 = typeof(string);
             }
             else
             {
                 type2 = parameterType.HasElementType ? parameterType.GetElementType() : parameterType;
             }
             object minRange = LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateRange.Min, type2, CultureInfo.InvariantCulture);
             object maxRange = LanguagePrimitives.ConvertTo(parameterCmdletization.ValidateRange.Max, type2, CultureInfo.InvariantCulture);
             metadata.Attributes.Add(new ValidateRangeAttribute(minRange, maxRange));
         }
         if (parameterCmdletization.ValidateSet != null)
         {
             List<string> list = new List<string>();
             foreach (string str3 in parameterCmdletization.ValidateSet)
             {
                 list.Add(str3);
             }
             metadata.Attributes.Add(new ValidateSetAttribute(list.ToArray()));
         }
     }
     int position = -2147483648;
     ParameterSetMetadata.ParameterFlags flags = 0;
     if (parameterCmdletization != null)
     {
         if (!string.IsNullOrEmpty(parameterCmdletization.Position))
         {
             position = (int) LanguagePrimitives.ConvertTo(parameterCmdletization.Position, typeof(int), CultureInfo.InvariantCulture);
         }
         if (parameterCmdletization.IsMandatorySpecified && parameterCmdletization.IsMandatory)
         {
             flags |= ParameterSetMetadata.ParameterFlags.Mandatory;
         }
     }
     if (isValueFromPipeline)
     {
         flags |= ParameterSetMetadata.ParameterFlags.ValueFromPipeline;
     }
     if (isValueFromPipelineByPropertyName)
     {
         flags |= ParameterSetMetadata.ParameterFlags.ValueFromPipelineByPropertyName;
     }
     metadata.ParameterSets.Add(parameterSetName, new ParameterSetMetadata(position, flags, null));
     return metadata;
 }
コード例 #37
0
ファイル: CommandMetadata.cs プロジェクト: dfinke/powershell
        private static CommandMetadata GetRestrictedMeasureObject()
        {
            // remote Measure-Object is called by Import/Export-PSSession to measure how many objects
            // it is going to receive and to display a nice progress bar

            // needed for pipeline input if cmdlet binding has to be used (i.e. if Windows 7: #477218 is not fixed)
            ParameterMetadata inputParameter = new ParameterMetadata("InputObject", typeof(object));
            inputParameter.ParameterSets.Add(
                ParameterAttribute.AllParameterSets,
                new ParameterSetMetadata(
                    int.MinValue, // not positional
                    ParameterSetMetadata.ParameterFlags.ValueFromPipeline | ParameterSetMetadata.ParameterFlags.Mandatory,
                    null)); // no help message

            return GetRestrictedCmdlet("Measure-Object", null, "http://go.microsoft.com/fwlink/?LinkID=113349", inputParameter);
        }
コード例 #38
0
ファイル: CommandMetadata.cs プロジェクト: dfinke/powershell
        private static CommandMetadata GetRestrictedOutDefault()
        {
            // remote Out-Default is called by interactive remoting (without any parameters, only using pipelines to pass data)

            // needed for pipeline input if cmdlet binding has to be used (i.e. if Windows 7: #477218 is not fixed)
            ParameterMetadata inputParameter = new ParameterMetadata("InputObject", typeof(object));
            inputParameter.ParameterSets.Add(
                ParameterAttribute.AllParameterSets,
                new ParameterSetMetadata(
                    int.MinValue, // not positional
                    ParameterSetMetadata.ParameterFlags.ValueFromPipeline | ParameterSetMetadata.ParameterFlags.Mandatory,
                    null)); // no help message

            return GetRestrictedCmdlet("Out-Default", null, "http://go.microsoft.com/fwlink/?LinkID=113362", inputParameter);
        }
コード例 #39
0
ファイル: CommandMetadata.cs プロジェクト: nickchal/pash
 private static CommandMetadata GetRestrictedGetCommand()
 {
     ParameterMetadata metadata = new ParameterMetadata("Name", typeof(string[])) {
         Attributes = { new ValidateLengthAttribute(0, 0x3e8), new ValidateCountAttribute(0, 0x3e8) }
     };
     ParameterMetadata metadata2 = new ParameterMetadata("Module", typeof(string[])) {
         Attributes = { new ValidateLengthAttribute(0, 0x3e8), new ValidateCountAttribute(0, 100) }
     };
     ParameterMetadata metadata3 = new ParameterMetadata("ArgumentList", typeof(object[])) {
         Attributes = { new ValidateCountAttribute(0, 100) }
     };
     ParameterMetadata metadata4 = new ParameterMetadata("CommandType", typeof(CommandTypes));
     ParameterMetadata metadata5 = new ParameterMetadata("ListImported", typeof(SwitchParameter));
     return GetRestrictedCmdlet("Get-Command", null, "http://go.microsoft.com/fwlink/?LinkID=113309", new ParameterMetadata[] { metadata, metadata2, metadata3, metadata4, metadata5 });
 }