示例#1
0
        /// <summary>
        /// Provides an enhanced one-time, preprocessing functionality for the cmdlet.
        /// </summary>
        protected override void BeginProcessingEx()
        {
            if (IsNormalParameterSet)
            {
                //Value is not required, but is required in that we need to explicitly say null
                if (!MyInvocation.BoundParameters.ContainsKey("Value"))
                {
                    throw new ParameterBindingException("Value parameter is mandatory, however a value was not specified. If Value should be empty, specify $null.");
                }

                ParseValue();
            }
            else if (IsDynamicParameterSet)
            {
                dynamicParameters = dynamicParams.GetBoundParameters(this, (p, v) => new PropertyParameter(p, PSObjectUtilities.CleanPSObject(v))).ToArray();

                if (dynamicParameters.Length == 0)
                {
                    throw new ParameterBindingException($"At least one dynamic property or -{nameof(Property)} and -{nameof(Value)} must be specified.");
                }
            }
            else if (IsRawPropertyParameterSet)
            {
                WarnSuspiciousPropertyName(RawProperty);
                RawValue = PSObjectUtilities.CleanPSObject(RawValue);
            }
            else if (IsRawParameterSet)
            {
                parameters = RawParameters.Keys.Cast <object>()
                             .Select(k => new CustomParameter(k.ToString(), PSObjectUtilities.CleanPSObject(RawParameters[k]), ParameterType.MultiParameter))
                             .ToArray();
            }

            base.BeginProcessingEx();
        }
示例#2
0
        private IEnumerable <NotificationTrigger> FilterByDynamicParameters(IEnumerable <NotificationTrigger> triggers)
        {
            if (dynamicParameterSet != null)
            {
                //Our NotificationAction parameters are defined as "real" parameters, so we will filter on them elsewhere,
                //not that it matters however, as they too don't support filtering where their values are null
                var boundParameters = dynamicParameterSet.GetBoundParameters(this, Tuple.Create).Where(t => t.Item2 != null);

                foreach (var parameter in boundParameters)
                {
                    //Get the PropertyInfo the filter Property corresponds to.
                    var property = ReflectionCacheManager.Get(typeof(NotificationTrigger)).Properties.First(p => p.GetAttribute <PropertyParameterAttribute>()?.Property.Equals(parameter.Item1) == true);

                    if (property.Property.PropertyType.IsArray)
                    {
                        throw new NotImplementedException("Cannot filter array properties dynamically.");
                    }

                    var items = parameter.Item2.ToIEnumerable().ToList();

                    triggers = triggers.Where(t => items.Any(i => Equals(property.GetValue(t), i)));
                }
            }

            return(triggers);
        }
示例#3
0
        /// <summary>
        /// Provides an enhanced one-time, preprocessing functionality for the cmdlet.
        /// </summary>
        protected override void BeginProcessingEx()
        {
            if (ParameterSetName == ParameterSet.Default)
            {
                //Value is not required, but is required in that we need to explicitly say null
                if (!MyInvocation.BoundParameters.ContainsKey("Value"))
                {
                    throw new ParameterBindingException("Value parameter is mandatory, however a value was not specified. If Value should be empty, specify $null.");
                }

                ParseValue();
            }
            else if (ParameterSetName == ParameterSet.Dynamic)
            {
                dynamicParameters = dynamicParams.GetBoundParameters(this, (p, v) => new PropertyParameter(p, PSObjectUtilities.CleanPSObject(v))).ToArray();
            }
            else if (ParameterSetName == ParameterSet.RawProperty)
            {
                RawValue = PSObjectUtilities.CleanPSObject(RawValue);
            }
            else if (ParameterSetName == ParameterSet.Raw)
            {
                parameters = RawParameters.Keys.Cast <object>()
                             .Select(k => new CustomParameter(k.ToString(), PSObjectUtilities.CleanPSObject(RawParameters[k]), ParameterType.MultiParameter))
                             .ToArray();
            }

            base.BeginProcessingEx();
        }
示例#4
0
        /// <summary>
        /// Provides an enhanced one-time, preprocessing functionality for the cmdlet.
        /// </summary>
        protected override void BeginProcessingEx()
        {
            if (this is IDynamicParameters && dynamicParameterSet != null)
            {
                dynamicParameters = dynamicParameterSet.GetBoundParameters(this, (p, v) =>
                {
                    var cleaned = PSObjectUtilities.CleanPSObject(v);

                    if (cleaned == null)
                    {
                        return(new List <SearchFilter>());
                    }

                    var underlying = cleaned.GetType().GetElementType() ?? cleaned.GetType();

                    if (underlying == typeof(object))
                    {
                        if (cleaned.IsIEnumerable())
                        {
                            var first = cleaned.ToIEnumerable().FirstOrDefault();

                            if (first != null)
                            {
                                underlying = first.GetType();
                            }
                        }
                    }

                    if (underlying == typeof(string))
                    {
                        return(GetWildcardFilters(p, cleaned, val => val.ToString()));
                    }
                    if (typeof(IStringEnum).IsAssignableFrom(underlying))
                    {
                        return(GetWildcardFilters(p, cleaned, val => ((IStringEnum)val).StringValue));
                    }

                    return(new[] { GetPipelineFilter(p, cleaned) });
                });
            }

            base.BeginProcessingEx();
        }
示例#5
0
        internal void BeginProcessing()
        {
            Value = PSObjectUtilities.CleanPSObject(Value);

            if (DynamicSet())
            {
                dynamicParameters = new Lazy <List <TParameter> >(() =>
                {
                    var ret = dynamicParams.GetBoundParameters(cmdlet,
                                                               (p, v) => createParameter(p, PSObjectUtilities.CleanPSObject(v)));

                    if (ret.Count == 0)
                    {
                        throw new ParameterBindingException($"At least one dynamic property or -{nameof(Property)} and -{nameof(Value)} must be specified.");
                    }

                    return(ret);
                });
            }
        }
        private IEnumerable <NotificationTrigger> FilterByDynamicParameters(IEnumerable <NotificationTrigger> triggers)
        {
            if (dynamicParameterSet != null)
            {
                var boundParameters = dynamicParameterSet.GetBoundParameters(this, Tuple.Create);

                foreach (var parameter in boundParameters)
                {
                    //Get the PropertyInfo the filter Property corresponds to.
                    var property = ReflectionCacheManager.Get(typeof(NotificationTrigger)).Properties.First(p => p.GetAttribute <PropertyParameterAttribute>()?.Property.Equals(parameter.Item1) == true);

                    if (property.Property.PropertyType.IsArray)
                    {
                        throw new NotImplementedException("Cannot filter array properties dynamically.");
                    }

                    var items = parameter.Item2.ToIEnumerable().ToList();

                    triggers = triggers.Where(t => items.Any(i => Equals(property.GetValue(t), i)));
                }
            }

            return(triggers);
        }
示例#7
0
        /// <summary>
        /// Provides an enhanced one-time, preprocessing functionality for the cmdlet.
        /// </summary>
        protected override void BeginProcessingEx()
        {
            dynamicParameters = dynamicParams.GetBoundParameters(this, (p, v) => new TriggerParameter(p, PSObjectUtilities.CleanPSObject(v))).ToArray();

            base.BeginProcessingEx();
        }