Пример #1
0
 internal ParameterSetMetadata(ParameterSetMetadata other)
 {
     this.helpMessage           = other != null ? other.helpMessage : throw ParameterSetMetadata.tracer.NewArgumentNullException(nameof(other));
     this.helpMessageBaseName   = other.helpMessageBaseName;
     this.helpMessageResourceId = other.helpMessageResourceId;
     this.isMandatory           = other.isMandatory;
     this.position          = other.position;
     this.valueFromPipeline = other.valueFromPipeline;
     this.valueFromPipelineByPropertyName = other.valueFromPipelineByPropertyName;
     this.valueFromRemainingArguments     = other.valueFromRemainingArguments;
 }
Пример #2
0
 internal ParameterSetMetadata(ParameterSetMetadata other)
 {
     if (other == null)
     {
         throw PSTraceSource.NewArgumentNullException("other");
     }
     this.helpMessage = other.helpMessage;
     this.helpMessageBaseName = other.helpMessageBaseName;
     this.helpMessageResourceId = other.helpMessageResourceId;
     this.isMandatory = other.isMandatory;
     this.position = other.position;
     this.valueFromPipeline = other.valueFromPipeline;
     this.valueFromPipelineByPropertyName = other.valueFromPipelineByPropertyName;
     this.valueFromRemainingArguments = other.valueFromRemainingArguments;
 }
Пример #3
0
 internal ParameterSetMetadata(ParameterSetMetadata other)
 {
     if (other == null)
     {
         throw PSTraceSource.NewArgumentNullException("other");
     }
     this.helpMessage           = other.helpMessage;
     this.helpMessageBaseName   = other.helpMessageBaseName;
     this.helpMessageResourceId = other.helpMessageResourceId;
     this.isMandatory           = other.isMandatory;
     this.position          = other.position;
     this.valueFromPipeline = other.valueFromPipeline;
     this.valueFromPipelineByPropertyName = other.valueFromPipelineByPropertyName;
     this.valueFromRemainingArguments     = other.valueFromRemainingArguments;
 }
Пример #4
0
        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();
        }
Пример #5
0
 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);
     }
 }
Пример #6
0
        /// <summary>
        /// Compares this instance with the supplied <paramref name="second"/>.
        /// </summary>
        /// <param name="second">
        /// An object to compare this instance with
        /// </param>
        /// <returns>
        /// true if the metadata is same. false otherwise.
        /// </returns>
        internal bool Equals(ParameterSetMetadata second)
        {
            if ((_isMandatory != second._isMandatory) ||
                (_position != second._position) ||
                (_valueFromPipeline != second._valueFromPipeline) ||
                (_valueFromPipelineByPropertyName != second._valueFromPipelineByPropertyName) ||
                (_valueFromRemainingArguments != second._valueFromRemainingArguments) ||
                (_helpMessage != second._helpMessage) ||
                (_helpMessageBaseName != second._helpMessageBaseName) ||
                (_helpMessageResourceId != second._helpMessageResourceId))
            {
                return false;
            }

            return true;
        }
Пример #7
0
 internal bool Equals(ParameterSetMetadata second)
 {
     return ((((this.isMandatory == second.isMandatory) && (this.position == second.position)) && ((this.valueFromPipeline == second.valueFromPipeline) && (this.valueFromPipelineByPropertyName == second.valueFromPipelineByPropertyName))) && (((this.valueFromRemainingArguments == second.valueFromRemainingArguments) && !(this.helpMessage != second.helpMessage)) && (!(this.helpMessageBaseName != second.helpMessageBaseName) && !(this.helpMessageResourceId != second.helpMessageResourceId))));
 }
Пример #8
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);
        }
Пример #9
0
        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;
        }
Пример #10
0
 internal bool Equals(ParameterSetMetadata second)
 {
     return((((this.isMandatory == second.isMandatory) && (this.position == second.position)) && ((this.valueFromPipeline == second.valueFromPipeline) && (this.valueFromPipelineByPropertyName == second.valueFromPipelineByPropertyName))) && (((this.valueFromRemainingArguments == second.valueFromRemainingArguments) && !(this.helpMessage != second.helpMessage)) && (!(this.helpMessageBaseName != second.helpMessageBaseName) && !(this.helpMessageResourceId != second.helpMessageResourceId))));
 }
Пример #11
0
        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);
            }
        }
Пример #12
0
        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();
        }
Пример #13
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;
 }