protected object CreateVirtualMachineScaleSetVMListNextDynamicParameters()
        {
            dynamicParameters = new RuntimeDefinedParameterDictionary();
            var pNextPageLink = new RuntimeDefinedParameter();
            pNextPageLink.Name = "NextPageLink";
            pNextPageLink.ParameterType = typeof(string);
            pNextPageLink.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 1,
                Mandatory = true
            });
            pNextPageLink.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("NextPageLink", pNextPageLink);

            var pArgumentList = new RuntimeDefinedParameter();
            pArgumentList.Name = "ArgumentList";
            pArgumentList.ParameterType = typeof(object[]);
            pArgumentList.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByStaticParameters",
                Position = 2,
                Mandatory = true
            });
            pArgumentList.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ArgumentList", pArgumentList);

            return dynamicParameters;
        }
예제 #2
0
        public object GetDynamicParameters()
        {
            if (Path == null || !Path.Exists) return GetRuntimeDefinedParameterDictionary(null);

            var tableNames = new List<string>();
            if (TablesCache.ContainsKey(Path.FullName))
            {
                tableNames = TablesCache[Path.FullName];
            }
            else
            {
                try
                {
                    tableNames = DbContext.GetTableNamesContent(Path.FullName);
                    tableNames.Add("All");
                    TablesCache.Add(Path.FullName, tableNames);
                }
                catch (Exception e)
                {
                }
            }

            _staticStroage = GetRuntimeDefinedParameterDictionary(tableNames);
            return _staticStroage;
        }
        protected object CreateVirtualMachineOSImageGetDetailsDynamicParameters()
        {
            dynamicParameters = new RuntimeDefinedParameterDictionary();
            var pImageName = new RuntimeDefinedParameter();
            pImageName.Name = "ImageName";
            pImageName.ParameterType = typeof(System.String);
            pImageName.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 1,
                Mandatory = true
            });
            pImageName.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ImageName", pImageName);

            var pArgumentList = new RuntimeDefinedParameter();
            pArgumentList.Name = "ArgumentList";
            pArgumentList.ParameterType = typeof(object[]);
            pArgumentList.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByStaticParameters",
                Position = 2,
                Mandatory = true
            });
            pArgumentList.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ArgumentList", pArgumentList);

            return dynamicParameters;
        }
        protected object CreateHostedServiceListExtensionsDynamicParameters()
        {
            dynamicParameters = new RuntimeDefinedParameterDictionary();
            var pServiceName = new RuntimeDefinedParameter();
            pServiceName.Name = "ServiceName";
            pServiceName.ParameterType = typeof(System.String);
            pServiceName.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 1,
                Mandatory = true
            });
            pServiceName.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ServiceName", pServiceName);

            var pArgumentList = new RuntimeDefinedParameter();
            pArgumentList.Name = "ArgumentList";
            pArgumentList.ParameterType = typeof(object[]);
            pArgumentList.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByStaticParameters",
                Position = 2,
                Mandatory = true
            });
            pArgumentList.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ArgumentList", pArgumentList);

            return dynamicParameters;
        }
        protected object CreateExtensionImageRegisterDynamicParameters()
        {
            dynamicParameters = new RuntimeDefinedParameterDictionary();
            var pParameters = new RuntimeDefinedParameter();
            pParameters.Name = "ExtensionImageRegisterParameters";
            pParameters.ParameterType = typeof(Microsoft.WindowsAzure.Management.Compute.Models.ExtensionImageRegisterParameters);
            pParameters.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 1,
                Mandatory = true
            });
            pParameters.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ExtensionImageRegisterParameters", pParameters);

            var pArgumentList = new RuntimeDefinedParameter();
            pArgumentList.Name = "ArgumentList";
            pArgumentList.ParameterType = typeof(object[]);
            pArgumentList.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByStaticParameters",
                Position = 2,
                Mandatory = true
            });
            pArgumentList.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ArgumentList", pArgumentList);

            return dynamicParameters;
        }
        protected object CreateVirtualMachineScaleSetListDynamicParameters()
        {
            dynamicParameters = new RuntimeDefinedParameterDictionary();
            var pResourceGroupName = new RuntimeDefinedParameter();
            pResourceGroupName.Name = "ResourceGroupName";
            pResourceGroupName.ParameterType = typeof(string);
            pResourceGroupName.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 1,
                Mandatory = true
            });
            pResourceGroupName.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ResourceGroupName", pResourceGroupName);

            var pArgumentList = new RuntimeDefinedParameter();
            pArgumentList.Name = "ArgumentList";
            pArgumentList.ParameterType = typeof(object[]);
            pArgumentList.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByStaticParameters",
                Position = 2,
                Mandatory = true
            });
            pArgumentList.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ArgumentList", pArgumentList);

            return dynamicParameters;
        }
        protected static bool AddDynamicParameter(Type type, string name, ref RuntimeDefinedParameterDictionary dic, bool valueFromPipeline)
        {
            bool paramAdded = false;

            if (dic == null || !dic.ContainsKey(name))
            {
                var attrib = new ParameterAttribute
                    {
                        Mandatory = false,
                        ValueFromPipeline = valueFromPipeline,
                    };

                var param = new RuntimeDefinedParameter
                    {
                        IsSet = false,
                        Name = name,
                        ParameterType = type
                    };
                param.Attributes.Add(attrib);

                if (dic == null)
                {
                    dic = new RuntimeDefinedParameterDictionary();
                }
                dic.Add(name, param);
                paramAdded = true;
            }

            return paramAdded;
        }
예제 #8
0
        public RuntimeDefinedParameterDictionary CreateForNewItem()
        {
            var parameters = new RuntimeDefinedParameterDictionary();

            var attrs = from row in _columns
                        let nullable = (bool)row["IS_NULLABLE"] 
                        let primaryKey = (bool)row["PRIMARY_KEY"]
                        let columnName = row["COLUMN_NAME"].ToString()
                        let dataType = ConvertSqliteTypeToType( row["DATA_TYPE"].ToString() )
                        select new RuntimeDefinedParameter(
                            columnName,
                            dataType,
                            new Collection<Attribute>
                                    {
                                        new ParameterAttribute()
                                            {
                                                Mandatory = ! nullable && ! primaryKey,
                                                ValueFromPipelineByPropertyName = true,                                                
                                            },
                                            
                                    }
                            );

            attrs.ToList().ForEach(attr => parameters.Add(attr.Name, attr));
            return parameters;
        }
예제 #9
0
        /// <summary>
        /// Constructs the parameter binder with the specified type metadata. The binder is only valid
        /// for a single instance of a bindable runtime-defined parameter collection and only for the duration of a command.
        /// </summary>
        /// 
        /// <param name="target">
        /// The target runtime-defined parameter collection that the parameter values will be bound to.
        /// </param>
        /// 
        /// <param name="command">
        /// An instance of the command so that attributes can access the context.
        /// </param>
        /// 
        /// <param name="commandLineParameters">
        /// The Command line parameter collection to update...
        /// </param>
        /// 
        internal RuntimeDefinedParameterBinder(
            RuntimeDefinedParameterDictionary target,
            InternalCommand command,
            CommandLineParameters commandLineParameters)
            : base(target, command.MyInvocation, command.Context, command)
        {
            // NTRAID#Windows Out Of Band Releases-927103-2006/01/25-JonN
            foreach (var pair in target)
            {
                string key = pair.Key;
                RuntimeDefinedParameter pp = pair.Value;
                string ppName = (null == pp) ? null : pp.Name;
                if (null == pp || key != ppName)
                {
                    ParameterBindingException bindingException =
                        new ParameterBindingException(
                            ErrorCategory.InvalidArgument,
                            command.MyInvocation,
                            null,
                            ppName,
                            null,
                            null,
                            ParameterBinderStrings.RuntimeDefinedParameterNameMismatch,
                            "RuntimeDefinedParameterNameMismatch",
                            key);

                    throw bindingException;
                }
            }
            this.CommandLineParameters = commandLineParameters;
        }
예제 #10
0
 protected override object NewDriveDynamicParameters()
 {
     try{
         WriteVerbose("TmxProvider::NewDriveDynamicParameters()");
         dynamicParameters =
             new RuntimeDefinedParameterDictionary();
         var atts1 = new Collection<Attribute>();
         var parameterAttribute1 = new ParameterAttribute {Mandatory = true};
         //ParameterAttribute parameterAttribute1 = new ParameterAttribute();
         //parameterAttribute1.Mandatory = true;
         //parameterAttribute2.ParameterSetName = "WindowNameParameterSet";
         atts1.Add(parameterAttribute1);
         var attr1 = new AllowEmptyStringAttribute();
         atts1.Add(attr1);
         dynamicParameters.Add(
             "windowName", 
             new RuntimeDefinedParameter(
                 "windowName", 
                 typeof(string), 
                 atts1));
         
         var atts2 = new Collection<Attribute>();
         var parameterAttribute2 = new ParameterAttribute {Mandatory = true};
         //ParameterAttribute parameterAttribute2 = new ParameterAttribute();
         //parameterAttribute2.Mandatory = true;
         //parameterAttribute2.ParameterSetName = "ProcessNameParameterSet";
         atts2.Add(parameterAttribute2);
         var attr2 = new AllowEmptyStringAttribute();
         atts2.Add(attr2);
         dynamicParameters.Add(
             "processName", 
             new RuntimeDefinedParameter(
                 "processName", 
                 typeof(string), 
                 atts2));
         
         var atts3 = new Collection<Attribute>();
         var parameterAttribute3 = new ParameterAttribute {Mandatory = true};
         //ParameterAttribute parameterAttribute3 = new ParameterAttribute();
         //parameterAttribute3.Mandatory = true;
         //parameterAttribute3.ParameterSetName = "ProcessIdParameterSet";
         atts3.Add(parameterAttribute3);
         var attr3 = new AllowEmptyStringAttribute();
         atts3.Add(attr3);
         dynamicParameters.Add(
             "processId", 
             new RuntimeDefinedParameter(
                 "processId", 
                 typeof(int), 
                 atts3));
         
         return dynamicParameters;
     }
     catch (Exception e) {
         WriteVerbose(e.Message);
         WriteVerbose("TmxProvider::NewDriveDynamicParameters()");
         return null;
     }
 }
        protected static object[] ConvertDynamicParameters(RuntimeDefinedParameterDictionary parameters)
        {
            List<object> paramList = new List<object>();

            foreach (var param in parameters)
            {
                paramList.Add(param.Value.Value);
            }

            return paramList.ToArray();
        }
예제 #12
0
 internal InternalParameterMetadata(RuntimeDefinedParameterDictionary runtimeDefinedParameters, bool processingDynamicParameters, bool checkNames)
 {
     this.typeName = string.Empty;
     this.bindableParameters = new Dictionary<string, CompiledCommandParameter>(StringComparer.OrdinalIgnoreCase);
     this.aliasedParameters = new Dictionary<string, CompiledCommandParameter>(StringComparer.OrdinalIgnoreCase);
     if (runtimeDefinedParameters == null)
     {
         throw PSTraceSource.NewArgumentNullException("runtimeDefinedParameters");
     }
     this.ConstructCompiledParametersUsingRuntimeDefinedParameters(runtimeDefinedParameters, processingDynamicParameters, checkNames);
 }
        public object GetDynamicParameters()
        {
            RuntimeDefinedParameterDictionary parameters = new RuntimeDefinedParameterDictionary();

            foreach(IDynamicParameter dynamicParameter in DynamicParameters)
            {
                dynamicParameter.AddRuntimeDefinedParameterTo(parameters);
            }

            return parameters;
        }
        protected object CreateVirtualMachineRestartDynamicParameters()
        {
            dynamicParameters = new RuntimeDefinedParameterDictionary();
            var pServiceName = new RuntimeDefinedParameter();
            pServiceName.Name = "ServiceName";
            pServiceName.ParameterType = typeof(System.String);
            pServiceName.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 1,
                Mandatory = true
            });
            pServiceName.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ServiceName", pServiceName);

            var pDeploymentName = new RuntimeDefinedParameter();
            pDeploymentName.Name = "DeploymentName";
            pDeploymentName.ParameterType = typeof(System.String);
            pDeploymentName.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 2,
                Mandatory = true
            });
            pDeploymentName.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("DeploymentName", pDeploymentName);

            var pVirtualMachineName = new RuntimeDefinedParameter();
            pVirtualMachineName.Name = "VirtualMachineName";
            pVirtualMachineName.ParameterType = typeof(System.String);
            pVirtualMachineName.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 3,
                Mandatory = true
            });
            pVirtualMachineName.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("VirtualMachineName", pVirtualMachineName);

            var pArgumentList = new RuntimeDefinedParameter();
            pArgumentList.Name = "ArgumentList";
            pArgumentList.ParameterType = typeof(object[]);
            pArgumentList.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByStaticParameters",
                Position = 4,
                Mandatory = true
            });
            pArgumentList.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ArgumentList", pArgumentList);

            return dynamicParameters;
        }
        protected object CreateExtensionImageUnregisterDynamicParameters()
        {
            dynamicParameters = new RuntimeDefinedParameterDictionary();
            var pProviderNamespace = new RuntimeDefinedParameter();
            pProviderNamespace.Name = "ProviderNamespace";
            pProviderNamespace.ParameterType = typeof(System.String);
            pProviderNamespace.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 1,
                Mandatory = true
            });
            pProviderNamespace.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ProviderNamespace", pProviderNamespace);

            var pType = new RuntimeDefinedParameter();
            pType.Name = "Type";
            pType.ParameterType = typeof(System.String);
            pType.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 2,
                Mandatory = true
            });
            pType.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("Type", pType);

            var pVersion = new RuntimeDefinedParameter();
            pVersion.Name = "Version";
            pVersion.ParameterType = typeof(System.String);
            pVersion.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 3,
                Mandatory = true
            });
            pVersion.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("Version", pVersion);

            var pArgumentList = new RuntimeDefinedParameter();
            pArgumentList.Name = "ArgumentList";
            pArgumentList.ParameterType = typeof(object[]);
            pArgumentList.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByStaticParameters",
                Position = 4,
                Mandatory = true
            });
            pArgumentList.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ArgumentList", pArgumentList);

            return dynamicParameters;
        }
        protected object CreateVirtualMachineStartRolesDynamicParameters()
        {
            dynamicParameters = new RuntimeDefinedParameterDictionary();
            var pServiceName = new RuntimeDefinedParameter();
            pServiceName.Name = "ServiceName";
            pServiceName.ParameterType = typeof(System.String);
            pServiceName.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 1,
                Mandatory = true
            });
            pServiceName.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ServiceName", pServiceName);

            var pDeploymentName = new RuntimeDefinedParameter();
            pDeploymentName.Name = "DeploymentName";
            pDeploymentName.ParameterType = typeof(System.String);
            pDeploymentName.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 2,
                Mandatory = true
            });
            pDeploymentName.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("DeploymentName", pDeploymentName);

            var pParameters = new RuntimeDefinedParameter();
            pParameters.Name = "VirtualMachineStartRolesParameters";
            pParameters.ParameterType = typeof(Microsoft.WindowsAzure.Management.Compute.Models.VirtualMachineStartRolesParameters);
            pParameters.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 3,
                Mandatory = true
            });
            pParameters.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("VirtualMachineStartRolesParameters", pParameters);

            var pArgumentList = new RuntimeDefinedParameter();
            pArgumentList.Name = "ArgumentList";
            pArgumentList.ParameterType = typeof(object[]);
            pArgumentList.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByStaticParameters",
                Position = 4,
                Mandatory = true
            });
            pArgumentList.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ArgumentList", pArgumentList);

            return dynamicParameters;
        }
예제 #17
0
        public AssemblyCacheProvider()
        {
            var dynamic = new DynamicParameterBuilder();
            dynamic.AddParam<Version>("Version", false, null);
            dynamic.AddParam<ProcessorArchitecture>("ProcessorArchitecture", false, null);
            dynamic.AddParam<CultureInfo>("CultureInfo", false, null);
            dynamic.AddSwitchParam("Refresh");

            _sharedDynamicParameters = dynamic.GetDictionary();

            _iiDynamicParameters = GetInvokeItemDynamicParameters();
        }
        protected object CreateContainerServiceCreateOrUpdateDynamicParameters()
        {
            dynamicParameters = new RuntimeDefinedParameterDictionary();
            var pResourceGroupName = new RuntimeDefinedParameter();
            pResourceGroupName.Name = "ResourceGroupName";
            pResourceGroupName.ParameterType = typeof(string);
            pResourceGroupName.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 1,
                Mandatory = true
            });
            pResourceGroupName.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ResourceGroupName", pResourceGroupName);

            var pContainerServiceName = new RuntimeDefinedParameter();
            pContainerServiceName.Name = "Name";
            pContainerServiceName.ParameterType = typeof(string);
            pContainerServiceName.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 2,
                Mandatory = true
            });
            pContainerServiceName.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("Name", pContainerServiceName);

            var pParameters = new RuntimeDefinedParameter();
            pParameters.Name = "ContainerService";
            pParameters.ParameterType = typeof(ContainerService);
            pParameters.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 3,
                Mandatory = true
            });
            pParameters.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ContainerService", pParameters);

            var pArgumentList = new RuntimeDefinedParameter();
            pArgumentList.Name = "ArgumentList";
            pArgumentList.ParameterType = typeof(object[]);
            pArgumentList.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByStaticParameters",
                Position = 4,
                Mandatory = true
            });
            pArgumentList.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ArgumentList", pArgumentList);

            return dynamicParameters;
        }
예제 #19
0
 internal RuntimeDefinedParameterBinder(RuntimeDefinedParameterDictionary target, InternalCommand command, CommandLineParameters commandLineParameters) : base(target, command.MyInvocation, command.Context, command)
 {
     foreach (string str in target.Keys)
     {
         RuntimeDefinedParameter parameter = target[str];
         string parameterName = (parameter == null) ? null : parameter.Name;
         if ((parameter == null) || (str != parameterName))
         {
             ParameterBindingException exception = new ParameterBindingException(ErrorCategory.InvalidArgument, command.MyInvocation, null, parameterName, null, null, "ParameterBinderStrings", "RuntimeDefinedParameterNameMismatch", new object[] { str });
             throw exception;
         }
     }
     base.CommandLineParameters = commandLineParameters;
 }
예제 #20
0
        public static ScriptBlock CloneWithIsolatedParameterDefinition(this ScriptBlock source)
        {
            var destination = source.Clone(false);

            var srcParamList = source.Get_RuntimeDefinedParameterList();
            var dstParamList = destination.Get_RuntimeDefinedParameterList();
            dstParamList = new List<RuntimeDefinedParameter>(srcParamList);
            destination.Set__runtimeDefinedParameterList(dstParamList);

            var srcParamDic = source.Get_RuntimeDefinedParameters();
            var dstParamDic = destination.Get_RuntimeDefinedParameters();
            dstParamDic = new RuntimeDefinedParameterDictionary();
            dstParamDic.AddRange(srcParamDic);
            destination.Set__runtimeDefinedParameters(dstParamDic);

            return destination;
        }
        protected object CreateOperatingSystemListDynamicParameters()
        {
            dynamicParameters = new RuntimeDefinedParameterDictionary();
            var pArgumentList = new RuntimeDefinedParameter();
            pArgumentList.Name = "ArgumentList";
            pArgumentList.ParameterType = typeof(object[]);
            pArgumentList.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByStaticParameters",
                Position = 1,
                Mandatory = true
            });
            pArgumentList.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ArgumentList", pArgumentList);

            return dynamicParameters;
        }
        protected object CreateVirtualMachineDeallocateDynamicParameters()
        {
            dynamicParameters = new RuntimeDefinedParameterDictionary();
            var pResourceGroupName = new RuntimeDefinedParameter();

            pResourceGroupName.Name          = "ResourceGroupName";
            pResourceGroupName.ParameterType = typeof(string);
            pResourceGroupName.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position         = 1,
                Mandatory        = true
            });
            pResourceGroupName.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ResourceGroupName", pResourceGroupName);

            var pVMName = new RuntimeDefinedParameter();

            pVMName.Name          = "VMName";
            pVMName.ParameterType = typeof(string);
            pVMName.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position         = 2,
                Mandatory        = true
            });
            pVMName.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("VMName", pVMName);

            var pArgumentList = new RuntimeDefinedParameter();

            pArgumentList.Name          = "ArgumentList";
            pArgumentList.ParameterType = typeof(object[]);
            pArgumentList.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByStaticParameters",
                Position         = 3,
                Mandatory        = true
            });
            pArgumentList.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ArgumentList", pArgumentList);

            return(dynamicParameters);
        }
        protected object CreateVirtualMachineRunCommandGetDynamicParameters()
        {
            dynamicParameters = new RuntimeDefinedParameterDictionary();
            var pLocation = new RuntimeDefinedParameter();

            pLocation.Name          = "Location";
            pLocation.ParameterType = typeof(string);
            pLocation.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position         = 1,
                Mandatory        = true
            });
            pLocation.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("Location", pLocation);

            var pCommandId = new RuntimeDefinedParameter();

            pCommandId.Name          = "CommandId";
            pCommandId.ParameterType = typeof(string);
            pCommandId.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position         = 2,
                Mandatory        = true
            });
            pCommandId.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("CommandId", pCommandId);

            var pArgumentList = new RuntimeDefinedParameter();

            pArgumentList.Name          = "ArgumentList";
            pArgumentList.ParameterType = typeof(object[]);
            pArgumentList.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByStaticParameters",
                Position         = 3,
                Mandatory        = true
            });
            pArgumentList.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ArgumentList", pArgumentList);

            return(dynamicParameters);
        }
        public object GetDynamicParameters()
        {
            // make sure the commands are relate to the project type, so read project to ensure right method to invoke.
            Project resp = this.DataMigrationClient.Projects.Get(ResourceGroupName, ServiceName, ProjectName);
            RuntimeDefinedParameterDictionary dynamicParams = null;
            string cmd = string.IsNullOrWhiteSpace(CommandType) ? " " : CommandType.ToLowerInvariant();

            if (resp.SourcePlatform.ToLowerInvariant() == "mongodb")
            {
                commandCmdlet = new MongoDbObjectCommandCmdlet(this.MyInvocation, cmd);
            }
            else
            {
                commandCmdlet = new CompleteCommandCmdlet(this.MyInvocation);
            }

            dynamicParams = commandCmdlet.RuntimeDefinedParams;
            return(dynamicParams);
        }
        public object GetDynamicParameters()
        {
            var profileNames = UserProfileDirectory.GetUserProfiles(ShowHidden).Select(p => p.Name).ToArray();

            var attributeCollection = new Collection <Attribute>
            {
                new ParameterAttribute {
                    Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true
                },
                new ValidateSetAttribute(profileNames)
            };

            var runtimeDictionary = new RuntimeDefinedParameterDictionary
            {
                { "UserName", new RuntimeDefinedParameter("UserName", typeof(string), attributeCollection) }
            };

            return(runtimeDictionary);
        }
예제 #26
0
        public object GetDynamicParameters()
        {
            // var classAttribute = this.GetType().GetCustomAttributes(false).FirstOrDefault(a => a is PropertyLoadingAttribute);
            const string parameterName = "Scopes";

            var parameterDictionary = new RuntimeDefinedParameterDictionary();
            var attributeCollection = new System.Collections.ObjectModel.Collection <Attribute>();

            // Scopes
            var parameterAttribute = new ParameterAttribute
            {
                ValueFromPipeline = false,
                ValueFromPipelineByPropertyName = false,
                Mandatory = false
            };

            attributeCollection.Add(parameterAttribute);
            attributeCollection.Add(new ObsoleteAttribute("Use either -GraphApplicationPermissions, -GraphDelegatePermissions, -SharePointApplicationPermissions or -SharePointDelegatePermissions"));

            var identifiers = new PermissionScopes().GetIdentifiers();

            var validateSetAttribute = new ValidateSetAttribute(identifiers);

            attributeCollection.Add(validateSetAttribute);

            var runtimeParameter = new RuntimeDefinedParameter(parameterName, typeof(string[]), attributeCollection);

            parameterDictionary.Add(parameterName, runtimeParameter);

            // Graph
            parameterDictionary.Add("GraphApplicationPermissions", GetParameter("GraphApplicationPermissions", PermissionScopes.ResourceAppId_Graph, "Role"));
            parameterDictionary.Add("GraphDelegatePermissions", GetParameter("GraphDelegatePermissions", PermissionScopes.ResourceAppId_Graph, "Scope"));

            // SharePoint
            parameterDictionary.Add("SharePointApplicationPermissions", GetParameter("SharePointApplicationPermissions", PermissionScopes.ResourceAppId_SPO, "Role"));
            parameterDictionary.Add("SharePointDelegatePermissions", GetParameter("SharePointDelegatePermissions", PermissionScopes.ResourceAppId_SPO, "Scope"));

            // O365 Management
            parameterDictionary.Add("O365ManagementApplicationPermissions", GetParameter("O365ManagementApplicationPermissions", PermissionScopes.ResourceAppID_O365Management, "Role"));
            parameterDictionary.Add("O365ManagementDelegatePermissions", GetParameter("O365ManagementDelegatePermissions", PermissionScopes.ResourceAppID_O365Management, "Scope"));

            return(parameterDictionary);
        }
예제 #27
0
        /// <summary>
        /// Returns an instance of an object that defines the
        /// dynamic parameters for this
        /// <see cref="T:System.Management.Automation.Cmdlet" /> or <see cref="T:System.Management.Automation.Provider.CmdletProvider" />.
        /// </summary>
        /// <returns>This method should return an object that has properties and fields
        /// decorated with parameter attributes similar to a
        /// <see cref="T:System.Management.Automation.Cmdlet" /> or <see cref="T:System.Management.Automation.Provider.CmdletProvider" />.
        /// These attributes include <see cref="T:System.Management.Automation.ParameterAttribute" />,
        /// <see cref="T:System.Management.Automation.AliasAttribute" />, argument transformation and
        /// validation attributes, etc.
        /// Alternately, it can return a
        /// <see cref="T:System.Management.Automation.RuntimeDefinedParameterDictionary" />
        /// instead.
        /// The <see cref="T:System.Management.Automation.Cmdlet" /> or <see cref="T:System.Management.Automation.Provider.CmdletProvider" />
        /// should hold on to a reference to the object which it returns from
        /// this method, since the argument values for the dynamic parameters
        /// specified by that object will be set in that object.
        /// This method will be called after all formal (command-line)
        /// parameters are set, but before <see cref="M:System.Management.Automation.Cmdlet.BeginProcessing" />
        /// is called and before any incoming pipeline objects are read.
        /// Therefore, parameters which allow input from the pipeline
        /// may not be set at the time this method is called,
        /// even if the parameters are mandatory.</returns>
        public object GetDynamicParameters()
        {
            var parameterName = "AccountName";
            var runTimeParameterDictionary = new RuntimeDefinedParameterDictionary();
            var attributeCollection        = new Collection <Attribute>();
            var parameterAttribute         = new ParameterAttribute();

            parameterAttribute.Mandatory = true;
            parameterAttribute.Position  = 1;
            attributeCollection.Add(parameterAttribute);
            var arraySet             = AzureDevOpsConfiguration.Config.Accounts.GetAccountNames();
            var validateSetAttribute = new ValidateSetAttribute(arraySet);

            attributeCollection.Add(validateSetAttribute);
            var runtimeParameter = new RuntimeDefinedParameter(parameterName, typeof(string), attributeCollection);

            runTimeParameterDictionary.Add(parameterName, runtimeParameter);
            return(runTimeParameterDictionary);
        }
예제 #28
0
        private RuntimeDefinedParameterDictionary GetInvokeItemDynamicParameters()
        {
            var iiDynamicParameters = new RuntimeDefinedParameterDictionary();

            // copy shared parameters to ii dynamic parameters
            foreach (string key in _sharedDynamicParameters.Keys)
            {
                iiDynamicParameters.Add(key, _sharedDynamicParameters[key]);
            }

            // add an invoke-item specific dynamic parameter for reflection-only loading
            var dynamic = new DynamicParameterBuilder();

            dynamic.AddParam <SwitchParameter>(REFLECTION_ONLY, false, null);

            iiDynamicParameters.Add(REFLECTION_ONLY, dynamic.GetDictionary()[REFLECTION_ONLY]);

            return(iiDynamicParameters);
        }
        public object Create()
        {
            var type = _metadata.GetMappedClass(EntityMode.Poco);

            var parameters = new RuntimeDefinedParameterDictionary();

            var attrs = from prop in type.GetProperties()
                        // where prop.Name != _metadata.IdentifierPropertyName
                        select new RuntimeDefinedParameter(
                            prop.Name,
                            prop.PropertyType,
                            new Collection<Attribute>
                                    {
                                        new ParameterAttribute()
                                    }
                            );
            attrs.ToList().ForEach(attr => parameters.Add(attr.Name, attr));
            return parameters;
        }
        public void GetTemplateParametersFromFileWithSchema2MergesObjects()
        {
            Hashtable hashtable = new Hashtable();

            hashtable["Bool"] = true;
            hashtable["Foo"]  = "bar";
            RuntimeDefinedParameterDictionary result = TemplateUtility.GetTemplateParametersFromFile(
                templateFile,
                null,
                templateParameterFileSchema2,
                new[] { "TestPS" });

            Assert.Equal(7, result.Count);

            Assert.Equal("string", result["string"].Name);
            Assert.Equal(typeof(string), result["string"].ParameterType);
            Assert.Equal("myvalue", result["string"].Value);

            Assert.Equal("int", result["int"].Name);
            Assert.Equal(typeof(int), result["int"].ParameterType);
            Assert.Equal("12", result["int"].Value);

            Assert.Equal("bool", result["bool"].Name);
            Assert.Equal(typeof(bool), result["bool"].ParameterType);
            Assert.Equal("True", result["bool"].Value);

            Assert.Equal("object", result["object"].Name);
            Assert.Equal(typeof(Hashtable), result["object"].ParameterType);
            JObject objectValue = result["object"].Value as JObject;

            Assert.Equal(2, objectValue.Count);
            Assert.Equal("F1", objectValue["code"].ToObject <string>());
            Assert.Equal("Free", objectValue["name"].ToObject <string>());

            Assert.Equal("array", result["array"].Name);
            Assert.Equal(typeof(object[]), result["array"].ParameterType);
            var arrayValue = result["array"].Value as JArray;

            Assert.Equal(3, arrayValue.Count);
            Assert.Equal("A", arrayValue[0].ToObject <string>());
            Assert.Equal("F", arrayValue[2].ToObject <string>());
        }
        public object GetDynamicParameters()
        {
            var runtimeParamDictionary = new RuntimeDefinedParameterDictionary();

            var attributes = new Collection <Attribute>();

            attributes.Add(new ParameterAttribute());

            //This parameter has a ParameterAttribute and is considered a dynamic parameter.
            var dynamicParam = new RuntimeDefinedParameter("DynamicParam", typeof(string), attributes);

            //This parameter is missing a ParameterAttribute. While it is technically still a dynamic parameter,
            //it is not considered part of any parameter set and cannot be used.
            var irrelevantParam = new RuntimeDefinedParameter("IrrelevantParam", typeof(string), new Collection <Attribute>());

            runtimeParamDictionary.Add("DynamicParam", dynamicParam);
            runtimeParamDictionary.Add("IrrelevantParam", irrelevantParam);

            return(runtimeParamDictionary);
        }
        object IDynamicParameters.GetDynamicParameters()
        {
            ResolveManager();
            SPModelDescriptor descriptor = SPModelDescriptor.Resolve(this.TypeName);
            RuntimeDefinedParameterDictionary parameters = new RuntimeDefinedParameterDictionary();

            foreach (PropertyInfo property in descriptor.ModelType.GetProperties())
            {
                if (property.CanWrite || property.PropertyType.IsOf(typeof(IList <>)))
                {
                    ParameterAttribute attribute = new ParameterAttribute();
                    attribute.ParameterSetName = "__AllParameterSets";
                    parameters.Add(property.Name, new RuntimeDefinedParameter(property.Name, property.PropertyType, new Collection <Attribute> {
                        attribute
                    }));
                }
            }
            modelParameters = parameters;
            return(parameters);
        }
예제 #33
0
        public object GetDynamicParameters()
        {
            if (_runtimeParamsDict == null)
            {
                ParameterAttribute paramAttribute = new ParameterAttribute();
                paramAttribute.Mandatory = true;

                Collection <Attribute> nameAttributes = new Collection <Attribute>(new Attribute[] {
                    new ValidateSetAttribute(Enum.GetNames(typeof(HistoricalData.HistoricalDataType))),
                    new ValidateNotNullOrEmptyAttribute(),
                    paramAttribute
                });

                _runtimeParamsDict = new RuntimeDefinedParameterDictionary();
                _runtimeParamsDict.Add("HistoricalDataType",
                                       new RuntimeDefinedParameter("HistoricalDataType", typeof(string), nameAttributes));
            }

            return(_runtimeParamsDict);
        }
예제 #34
0
        //https://msdn.microsoft.com/en-us/library/bb336630(v=vs.110).aspx
        /// <summary>
        /// <para type="description">The paper size. Portrate unless otherwise specified.</para>
        /// </summary>
        /// <returns></returns>
        public object GetDynamicParameters()
        {
            IEnumerable <string> pageSizes        = typeof(PageSize).GetFields().Select(x => x.Name);
            var runtimeDefinedParameterDictionary = new RuntimeDefinedParameterDictionary();
            var attrib = new Collection <Attribute>()
            {
                new ParameterAttribute()
                {
                    HelpMessage = "A Slack Emoji to use as the avatar",
                    Mandatory   = true,
                    Position    = 1
                },
                new ValidateSetAttribute(pageSizes.ToArray())
            };
            var parameter = new RuntimeDefinedParameter("PageSize", typeof(String), attrib);

            runtimeDefinedParameterDictionary.Add("PageSize", parameter);
            _staticStorage = runtimeDefinedParameterDictionary;
            return(runtimeDefinedParameterDictionary);
        }
예제 #35
0
        public object GetDynamicParameters()
        {
            var parameters = new RuntimeDefinedParameterDictionary();

            // add `-SubscriptionId` if the cmdlet has [SupportsSubscriptionId] attribute
            if (GetType().IsDefined(typeof(SupportsSubscriptionIdAttribute), true))
            {
                parameters.Add(SubscriptionIdParameter, new RuntimeDefinedParameter(
                                   SubscriptionIdParameter,
                                   typeof(string),
                                   new Collection <Attribute>()
                {
                    new ParameterAttribute {
                        HelpMessage = Resources.SubscriptionIdHelpMessage, Mandatory = false, ValueFromPipelineByPropertyName = true
                    }
                }
                                   ));
            }
            return(parameters);
        }
        object IDynamicParameters.GetDynamicParameters()
        {
            _dict = new RuntimeDefinedParameterDictionary();
            Type access_type = GetNtType()?.AccessRightsType ?? typeof(GenericAccessRights);

            _dict.AddDynamicParameter("Access", access_type, false);

            if (Audit)
            {
                _dict.AddDynamicParameter("SubsystemName", typeof(string), true);
                _dict.AddDynamicParameter("HandleId", typeof(IntPtr), false);
                _dict.AddDynamicParameter("ObjectTypeName", typeof(string), true);
                _dict.AddDynamicParameter("ObjectName", typeof(string), true);
                _dict.AddDynamicParameter("ObjectCreation", typeof(SwitchParameter), false);
                _dict.AddDynamicParameter("AuditType", typeof(AuditEventType), false);
                _dict.AddDynamicParameter("AuditFlags", typeof(AuditAccessCheckFlags), false);
            }

            return(_dict);
        }
예제 #37
0
        /// <summary>
        /// Gets the parameters for a given template file.
        /// </summary>
        /// <param name="templateFilePath">The gallery template path (local or remote)</param>
        /// <param name="templateParameterObject">Existing template parameter object</param>
        /// <param name="templateParameterFilePath">Path to the template parameter file if present</param>
        /// <param name="staticParameters">The existing PowerShell cmdlet parameters</param>
        /// <returns>The template parameters</returns>
        public static RuntimeDefinedParameterDictionary GetTemplateParametersFromFile(string templateFilePath, Hashtable templateParameterObject, string templateParameterFilePath, string[] staticParameters)
        {
            string templateContent = null;

            if (templateFilePath != null)
            {
                if (Uri.IsWellFormedUriString(templateFilePath, UriKind.Absolute))
                {
                    templateContent = GeneralUtilities.DownloadFile(templateFilePath);
                }
                else if (FileUtilities.DataStore.FileExists(templateFilePath))
                {
                    templateContent = FileUtilities.DataStore.ReadFileAsText(templateFilePath);
                }
            }

            RuntimeDefinedParameterDictionary dynamicParameters = ParseTemplateAndExtractParameters(templateContent, templateParameterObject, templateParameterFilePath, staticParameters);

            return(dynamicParameters);
        }
예제 #38
0
        public object GetDynamicParameters()
        {
            if (TemplateParameters == null)
            {
                TemplateParameters = new RuntimeDefinedParameterDictionary();
            }

            var resolvedPaths = SessionState.Path.GetResolvedProviderPathFromPSPath(TemplatePath, out ProviderInfo provider);

            foreach (var resolvedPath in resolvedPaths)
            {
                var templateVariables = Components.TemplateController.GetTemplateVariables(TemplatePath);
                foreach (var variable in templateVariables)
                {
                    TemplateParameters[variable] = new RuntimeDefinedParameter(variable, typeof(string), new Collection <Attribute>());
                }
            }

            return(TemplateParameters);
        }
        protected object CreateVirtualMachineVMImageDeleteDynamicParameters()
        {
            dynamicParameters = new RuntimeDefinedParameterDictionary();
            var pVMImageName = new RuntimeDefinedParameter();
            pVMImageName.Name = "VMImageName";
            pVMImageName.ParameterType = typeof(System.String);
            pVMImageName.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 1,
                Mandatory = true
            });
            pVMImageName.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("VMImageName", pVMImageName);

            var pDeleteFromStorage = new RuntimeDefinedParameter();
            pDeleteFromStorage.Name = "DeleteFromStorage";
            pDeleteFromStorage.ParameterType = typeof(System.Boolean);
            pDeleteFromStorage.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 2,
                Mandatory = true
            });
            pDeleteFromStorage.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("DeleteFromStorage", pDeleteFromStorage);

            var pArgumentList = new RuntimeDefinedParameter();
            pArgumentList.Name = "ArgumentList";
            pArgumentList.ParameterType = typeof(object[]);
            pArgumentList.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByStaticParameters",
                Position = 3,
                Mandatory = true
            });
            pArgumentList.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ArgumentList", pArgumentList);

            return dynamicParameters;
        }
        protected object CreateVirtualMachineExtensionListVersionsDynamicParameters()
        {
            dynamicParameters = new RuntimeDefinedParameterDictionary();
            var pPublisherName = new RuntimeDefinedParameter();
            pPublisherName.Name = "PublisherName";
            pPublisherName.ParameterType = typeof(System.String);
            pPublisherName.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 1,
                Mandatory = true
            });
            pPublisherName.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("PublisherName", pPublisherName);

            var pExtensionName = new RuntimeDefinedParameter();
            pExtensionName.Name = "ExtensionName";
            pExtensionName.ParameterType = typeof(System.String);
            pExtensionName.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 2,
                Mandatory = true
            });
            pExtensionName.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ExtensionName", pExtensionName);

            var pArgumentList = new RuntimeDefinedParameter();
            pArgumentList.Name = "ArgumentList";
            pArgumentList.ParameterType = typeof(object[]);
            pArgumentList.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByStaticParameters",
                Position = 3,
                Mandatory = true
            });
            pArgumentList.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ArgumentList", pArgumentList);

            return dynamicParameters;
        }
예제 #41
0
        public void AddToParamDictionary(RuntimeDefinedParameterDictionary paramDictionary)
        {
            var attributes = new Collection <Attribute>();

            var parameterAttribute = new ParameterAttribute();

            parameterAttribute.Mandatory = true;
            if (null != Position)
            {
                parameterAttribute.Position = 1;
            }
            if (null != HelpMessage)
            {
                parameterAttribute.HelpMessage = HelpMessage;
            }
            if (null != ParameterSetName)
            {
                parameterAttribute.ParameterSetName = ParameterSetName;
            }
            parameterAttribute.Mandatory = Mandatory;
            attributes.Add(parameterAttribute);

            if (null != ValidateSetValues)
            {
                var validateSetAttribute = new ValidateSetAttribute(ValidateSetValues);
                attributes.Add(validateSetAttribute);
            }

            RuntimeDefinedParameter OptionsRuntimeDefinedParam;

            if (AllowMultiple)
            {
                OptionsRuntimeDefinedParam = new RuntimeDefinedParameter(Name, typeof(string[]), attributes);
            }
            else
            {
                OptionsRuntimeDefinedParam = new RuntimeDefinedParameter(Name, typeof(string), attributes);
            }

            paramDictionary.Add(Name, OptionsRuntimeDefinedParam);
        }
예제 #42
0
        public object GetDynamicParameters()
        {
            _lib = new RuntimeDefinedParameterDictionary();
            RuntimeDefinedParameter rtParam = new RuntimeDefinedParameter(PARAM, typeof(long[]), new Collection <Attribute>
            {
                new ParameterAttribute
                {
                    Mandatory = false,
                    Position  = 0
                }
            });

            if (History.IsInitialized() && History.Jobs.Count > 0)
            {
                var set = new ValidateSetAttribute(History.Jobs.Select(x => Convert.ToString(x.Id)).ToArray());
                rtParam.Attributes.Add(set);
            }

            _lib.Add(PARAM, rtParam);
            return(_lib);
        }
        public object GetDynamicParameters()
        {
            _controller = new DeploymentModelHelper(XmlConfigPath);
            _controller.Init();

            IEnumerable<string> paramsForModel = _controller.GetAllParameters();
            _runtimeParamsCollection = new RuntimeDefinedParameterDictionary();

            foreach (string paramForModel in paramsForModel)
            {
                RuntimeDefinedParameter dynamicParam = new RuntimeDefinedParameter()
                {
                    Name = paramForModel,
                    ParameterType = typeof(string),
                };
                dynamicParam.Attributes.Add(new ParameterAttribute() { Mandatory = false });
                _runtimeParamsCollection.Add(paramForModel, dynamicParam);
            }

            return _runtimeParamsCollection;
        }
예제 #44
0
        public object GetDynamicParameters()
        {
            var parameters = new RuntimeDefinedParameterDictionary();
            RuntimeDefinedParameter sourceNameParameter;

            if (TryGetExistingContextNameParameter(SourceParameterName, NameParameterSet, out sourceNameParameter))
            {
                parameters.Add(sourceNameParameter.Name, sourceNameParameter);
                var attributes = new Collection <Attribute>()
                {
                    new ParameterAttribute {
                        Position = 1, Mandatory = true, HelpMessage = "The new name of the context"
                    },
                    new ValidateNotNullOrEmptyAttribute()
                };
                var targetNameParameter = new RuntimeDefinedParameter(TargetParameterName, typeof(string), attributes);
                parameters.Add(targetNameParameter.Name, targetNameParameter);
            }

            return(parameters);
        }
예제 #45
0
        object IDynamicParameters.GetDynamicParameters()
        {
            if (_dynamicParameters == null)
            {
                _dynamicParameters = new RuntimeDefinedParameterDictionary();

                if (this.CmdletDefinitionContext.ExposeCimNamespaceParameter)
                {
                    Collection <Attribute> namespaceAttributes = new Collection <Attribute>();
                    namespaceAttributes.Add(new ValidateNotNullOrEmptyAttribute());
                    namespaceAttributes.Add(new ParameterAttribute());
                    RuntimeDefinedParameter namespaceRuntimeParameter = new RuntimeDefinedParameter(
                        CimNamespaceParameter,
                        typeof(string),
                        namespaceAttributes);
                    _dynamicParameters.Add(CimNamespaceParameter, namespaceRuntimeParameter);
                }
            }

            return(_dynamicParameters);
        }
예제 #46
0
        public object GetDynamicParameters()
        {
            if (_runtimeParamsDict == null)
            {
                ParameterAttribute paramAttribute = new ParameterAttribute();
                paramAttribute.Mandatory = true;
                string[] validNames = IndicatorAndStrategyContainer.Instance.Strategies.Select(strategy => strategy.Name).ToArray();
                Collection <Attribute> nameAttributes = new Collection <Attribute>(new Attribute[] {
                    new ValidateSetAttribute(validNames),
                    new ValidateNotNullOrEmptyAttribute(),
                    paramAttribute
                });

                var nameParam = new RuntimeDefinedParameter("Name", typeof(string), nameAttributes);

                _runtimeParamsDict = new RuntimeDefinedParameterDictionary();
                _runtimeParamsDict.Add("Name", nameParam);
            }

            return(_runtimeParamsDict);
        }
예제 #47
0
        /// <summary>
        /// Add service bus topic error action parameters.
        /// </summary>
        /// <param name="create">true if parameters added for create scenario and false for update scenario.</param>
        /// <returns>PowerShell parameters.</returns>
        internal RuntimeDefinedParameterDictionary AddServiceBusTopicErrorActionParameters(bool create = true)
        {
            var errorActionServiceBusTopicPathAttributes = new Collection <Attribute>
            {
                new ParameterAttribute
                {
                    Mandatory   = create ? true : false,
                    HelpMessage = "Service bus topic path.",
                },
                new ValidateNotNullOrEmptyAttribute()
            };

            this._errorActionServiceBusTopicPath = new RuntimeDefinedParameter("ErrorActionServiceBusTopicPath", typeof(string), errorActionServiceBusTopicPathAttributes);

            var runTimeDefinedParameterDictionary = new RuntimeDefinedParameterDictionary();

            runTimeDefinedParameterDictionary.Add("ErrorActionServiceBusTopicPath", this._errorActionServiceBusTopicPath);
            runTimeDefinedParameterDictionary.AddRange(this.AddServiceBusErrorActionParameters(create));

            return(runTimeDefinedParameterDictionary);
        }
예제 #48
0
        public void GetsDynamicParametersForTemplateFile()
        {
            RuntimeDefinedParameterDictionary result = galleryTemplatesClient.GetTemplateParametersFromFile(
                templateFile,
                null,
                null,
                new[] { "TestPS" });

            Assert.Equal(4, result.Count);

            Assert.Equal("string", result["string"].Name);
            Assert.Equal(typeof(string), result["String"].ParameterType);

            Assert.Equal("int", result["int"].Name);
            Assert.Equal(typeof(int), result["int"].ParameterType);

            Assert.Equal("securestring", result["securestring"].Name);
            Assert.Equal(typeof(SecureString), result["securestring"].ParameterType);

            Assert.Equal("bool", result["bool"].Name);
            Assert.Equal(typeof(bool), result["bool"].ParameterType);
        }
        /// <summary>
        /// Creates a dynamic parameter "Role" based on the Project parameter.
        /// This function will first issue a call to the server to get all the possible roles based on
        /// the Project parameter. It will then create a dynamic parameter that corresponds to:
        /// [Parameter(Mandatory = true, HelpMessage = "Role that is assigned to the specified member.")]
        /// [ValidateSet(The possible roles we get from the server)]
        /// public string Role { get; set; }
        /// </summary>
        public object GetDynamicParameters()
        {
            if (_dynamicParameters == null)
            {
                _dynamicParameters = new RuntimeDefinedParameterDictionary();

                // Try to resolve Project variable to a string, use default value from the SDK if we fail to do so.
                Project = GetCloudSdkSettingValue(CloudSdkSettings.CommonProperties.Project, Project);

                string[] roles = GetGrantableRoles(Project);

                RuntimeDefinedParameter param = GenerateRuntimeParameter(
                    parameterName: "Role",
                    helpMessage: "Role that is assigned to the specified member.",
                    validSet: roles,
                    isMandatory: true);

                _dynamicParameters.Add("Role", param);
            }

            return(_dynamicParameters);
        }
예제 #50
0
        private RuntimeDefinedParameterDictionary ParseTemplateAndExtractParameters(string templateContent, Hashtable templateParameterObject, string templateParameterFilePath, string[] staticParameters)
        {
            RuntimeDefinedParameterDictionary dynamicParameters = new RuntimeDefinedParameterDictionary();

            if (!string.IsNullOrEmpty(templateContent))
            {
                TemplateFile templateFile = null;

                try
                {
                    templateFile = JsonConvert.DeserializeObject <TemplateFile>(templateContent);
                    if (templateFile.Parameters == null)
                    {
                        return(dynamicParameters);
                    }
                }
                catch
                {
                    // Can't parse the template file, do not generate dynamic parameters
                    return(dynamicParameters);
                }

                foreach (KeyValuePair <string, TemplateFileParameterV1> parameter in templateFile.Parameters)
                {
                    RuntimeDefinedParameter dynamicParameter = ConstructDynamicParameter(staticParameters, parameter);
                    dynamicParameters.Add(dynamicParameter.Name, dynamicParameter);
                }
            }
            if (templateParameterObject != null)
            {
                UpdateParametersWithObject(dynamicParameters, templateParameterObject);
            }
            if (templateParameterFilePath != null && FileUtilities.DataStore.FileExists(templateParameterFilePath))
            {
                var parametersFromFile = ParseTemplateParameterFileContents(templateParameterFilePath);
                UpdateParametersWithObject(dynamicParameters, new Hashtable(parametersFromFile));
            }
            return(dynamicParameters);
        }
예제 #51
0
        public object GetDynamicParameters()
        {
            if (_networkProfileList == null)
            {
                _networkProfileList = NetworkProfile.Load();
            }

            _dictionary = new RuntimeDefinedParameterDictionary();
            Collection <Attribute> attributes = new Collection <Attribute>()
            {
                new ParameterAttribute()
                {
                    Mandatory = true, Position = 0
                },
                new ValidateSetAttribute(_networkProfileList.Select(x => x.Name).ToArray()),
            };
            RuntimeDefinedParameter rdParam = new RuntimeDefinedParameter(PARAM_Name, typeof(string), attributes);

            _dictionary.Add(PARAM_Name, rdParam);

            return(_dictionary);
        }
예제 #52
0
        public static void PopulateRuntimeDefinedParameterValues <TCmdlet>(
            [NotNull] this TCmdlet cmdlet,
            [NotNull] RuntimeDefinedParameterDictionary runtimeDefinedParameters)
            where TCmdlet : Cmdlet
        {
            if (cmdlet is null)
            {
                throw new ArgumentNullException(nameof(cmdlet));
            }

            if (runtimeDefinedParameters is null)
            {
                throw new ArgumentNullException(nameof(runtimeDefinedParameters));
            }

            var context = DynamicParameterContext.GetContext(cmdlet);

            foreach (var parameter in runtimeDefinedParameters.Values)
            {
                context.SetParameterValue(parameter.Name, parameter.Value);
            }
        }
예제 #53
0
        public RuntimeDefinedParameterDictionary GetDynamicParameters()
        {
            RuntimeDefinedParameterDictionary dictionary = new RuntimeDefinedParameterDictionary();
            Collection <Attribute>            collection = new Collection <Attribute>();
            ParameterAttribute parameter = new ParameterAttribute();

            parameter.ParameterSetName = "ByName";
            collection.Add(parameter);

            IEnumerable <string> names = RegistryHelper.ShellKeyNames;

            ValidateSetAttribute validateSet = new ValidateSetAttribute(names.ToArray());

            collection.Add(validateSet);

            RuntimeDefinedParameter nameParameter = new RuntimeDefinedParameter("Name", typeof(string), collection);

            dictionary.Add("Name", nameParameter);

            DynamicParameters = dictionary;
            return(dictionary);
        }
예제 #54
0
        public object GetDynamicParameters()
        {
            var            parameters   = new RuntimeDefinedParameterDictionary();
            AzureRmProfile localProfile = DefaultProfile as AzureRmProfile;

            if (localProfile != null && localProfile.Contexts != null && localProfile.Contexts.Count > 0)
            {
                var nameParameter = new RuntimeDefinedParameter(
                    "Name", typeof(string),
                    new Collection <Attribute>()
                {
                    new ParameterAttribute {
                        Position = 0, Mandatory = false, HelpMessage = "The name of the context", ParameterSetName = GetSingleParameterSet
                    },
                    new ValidateSetAttribute((DefaultProfile as AzureRmProfile).Contexts.Keys.ToArray())
                }
                    );
                parameters.Add(nameParameter.Name, nameParameter);
            }

            return(parameters);
        }
예제 #55
0
        public object GetDynamicParameters()
        {
            RuntimeDefinedParameterDictionary dynamicParams = null;

            if (serverTypeSet)
            {
                ServerTypeEnum type = ServerType;
                switch (type)
                {
                case ServerTypeEnum.SQL:
                    this.connCmdlet = new SqlConnectionInfoCmdlet(this.MyInvocation);
                    break;

                default:
                    throw new PSArgumentException();
                }

                dynamicParams = connCmdlet.RuntimeDefinedParams;
            }

            return(dynamicParams);
        }
예제 #56
0
        public object GetDynamicParameters()
        {
            if (_runtimeParamsDict == null)
            {
                ParameterAttribute paramAttribute = new ParameterAttribute();
                paramAttribute.Mandatory = true;
                string[] validNames = IndicatorAndStrategyContainer.Instance.Indicators.Select(indicator => indicator.Name).ToArray();
                Collection<Attribute> nameAttributes = new Collection<Attribute>(new Attribute[] {
                    new ValidateSetAttribute(validNames),
                    new ValidateNotNullOrEmptyAttribute(),
                    paramAttribute
                });

                var nameParam = new RuntimeDefinedParameter("Name", typeof(string), nameAttributes);

                _runtimeParamsDict = new RuntimeDefinedParameterDictionary();
                _runtimeParamsDict.Add("Name", nameParam);

            }

            return _runtimeParamsDict;
        }
        public override object GetDynamicParameters()
        {
            dynamicParameters = new RuntimeDefinedParameterDictionary();
            var pResourceGroupName = new RuntimeDefinedParameter();
            pResourceGroupName.Name = "ResourceGroupName";
            pResourceGroupName.ParameterType = typeof(string);
            pResourceGroupName.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 1,
                Mandatory = true,
                ValueFromPipelineByPropertyName = true,
                ValueFromPipeline = false
            });
            pResourceGroupName.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("ResourceGroupName", pResourceGroupName);

            var pVMScaleSetName = new RuntimeDefinedParameter();
            pVMScaleSetName.Name = "VMScaleSetName";
            pVMScaleSetName.ParameterType = typeof(string);
            pVMScaleSetName.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 2,
                Mandatory = true,
                ValueFromPipelineByPropertyName = true,
                ValueFromPipeline = false
            });
            pVMScaleSetName.Attributes.Add(new AliasAttribute("Name"));
            pVMScaleSetName.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("VMScaleSetName", pVMScaleSetName);

            var pInstanceIds = new RuntimeDefinedParameter();
            pInstanceIds.Name = "InstanceId";
            pInstanceIds.ParameterType = typeof(string[]);
            pInstanceIds.Attributes.Add(new ParameterAttribute
            {
                ParameterSetName = "InvokeByDynamicParameters",
                Position = 3,
                Mandatory = true,
                ValueFromPipelineByPropertyName = true,
                ValueFromPipeline = false
            });
            pInstanceIds.Attributes.Add(new AllowNullAttribute());
            dynamicParameters.Add("InstanceId", pInstanceIds);

            return dynamicParameters;
        }
        /// <summary>
        /// Generate dynamic parameters based on the connection strings in the Web.config.
        /// It will look at 2 Web.config files:
        /// 1. Web.config
        /// 2. Web.&lt;configuration&gt;.config (like Web.Release.config)
        /// This only works when -ProjectFile is used and -ConnectionString is not used.
        /// </summary>
        /// <returns>The dynamic parameters.</returns>
        public object GetDynamicParameters()
        {
            if (!string.IsNullOrEmpty(ProjectFile) && ConnectionString == null)
            {
                // Get the 2 Web.config files.
                PrepareFileFullPaths();

                dynamicParameters = new RuntimeDefinedParameterDictionary();
                if (string.Compare("ProjectFile", ParameterSetName) == 0)
                {
                    // Parse the connection strings from the Web.config files.
                    var names = WebsitesClient.ParseConnectionStringNamesFromWebConfig(fullWebConfigFile, fullWebConfigFileWithConfiguration);

                    // Create a dynmaic parameter for each connection string using the same name.
                    foreach (var name in names)
                    {
                        var parameter = new RuntimeDefinedParameter();
                        parameter.Name = name;
                        parameter.ParameterType = typeof(string);
                        parameter.Attributes.Add(new ParameterAttribute()
                            {
                                ParameterSetName = "ProjectFile",
                                Mandatory = false,
                                ValueFromPipelineByPropertyName = true,
                                HelpMessage = "Connection string from Web.config."
                            }
                        );
                        dynamicParameters.Add(name, parameter);
                    }
                }
            }
            return dynamicParameters;
        }
예제 #59
0
 internal static InternalParameterMetadata Get(RuntimeDefinedParameterDictionary runtimeDefinedParameters, bool processingDynamicParameters, bool checkNames)
 {
     if (runtimeDefinedParameters == null)
     {
         throw PSTraceSource.NewArgumentNullException("runtimeDefinedParameter");
     }
     return new InternalParameterMetadata(runtimeDefinedParameters, processingDynamicParameters, checkNames);
 }
        /// <summary>
        /// Get conditional parameters depending on specified ErrorAction and/or type of http authentication.
        /// </summary>
        /// <returns>List of Powershell dynamic parameters.</returns>
        public object GetDynamicParameters()
        {
            var runtimeDefinedParameterDictionary = new RuntimeDefinedParameterDictionary();

            if (!string.IsNullOrWhiteSpace(this.HttpAuthenticationType))
            {
                if (this.HttpAuthenticationType.Equals(Constants.HttpAuthenticationClientCertificate, StringComparison.InvariantCultureIgnoreCase))
                {
                    runtimeDefinedParameterDictionary.AddRange(this.JobDynamicParameters.AddHttpClientCertificateAuthenticationTypeParameters());
                }
                else if (this.HttpAuthenticationType.Equals(Constants.HttpAuthenticationBasic, StringComparison.InvariantCultureIgnoreCase))
                {
                    runtimeDefinedParameterDictionary.AddRange(this.JobDynamicParameters.AddHttpBasicAuthenticationTypeParameters());
                }
                else if (this.HttpAuthenticationType.Equals(Constants.HttpAuthenticationActiveDirectoryOAuth, StringComparison.InvariantCultureIgnoreCase))
                {
                    runtimeDefinedParameterDictionary.AddRange(this.JobDynamicParameters.AddHttpActiveDirectoryOAuthAuthenticationTypeParameters());
                }
            }

            if (!string.IsNullOrWhiteSpace(this.ErrorActionType))
            {
                runtimeDefinedParameterDictionary.AddRange(this.AddErrorActionParameters(this.ErrorActionType, create: true));
            }

            return runtimeDefinedParameterDictionary;
        }