Пример #1
0
 private void VerifyAndNormalizeParameter(MshParameter parameter, TerminatingErrorContext invocationContext, bool originalParameterWasHashTable)
 {
     for (int i = 0; i < this.paramDef.hashEntries.Count; i++)
     {
         if (parameter.hash.ContainsKey(this.paramDef.hashEntries[i].KeyName))
         {
             object val  = parameter.hash[this.paramDef.hashEntries[i].KeyName];
             object obj3 = this.paramDef.hashEntries[i].Verify(val, invocationContext, originalParameterWasHashTable);
             if (obj3 != null)
             {
                 parameter.hash[this.paramDef.hashEntries[i].KeyName] = obj3;
             }
         }
         else
         {
             object obj4 = this.paramDef.hashEntries[i].ComputeDefaultValue();
             if (obj4 != AutomationNull.Value)
             {
                 parameter.hash[this.paramDef.hashEntries[i].KeyName] = obj4;
             }
             else if (this.paramDef.hashEntries[i].Mandatory)
             {
                 ProcessMissingMandatoryKey(invocationContext, this.paramDef.hashEntries[i].KeyName);
             }
         }
     }
 }
Пример #2
0
        internal List <MshParameter> ProcessParameters(object[] p, TerminatingErrorContext invocationContext)
        {
            if ((p == null) || (p.Length == 0))
            {
                return(null);
            }
            List <MshParameter> list           = new List <MshParameter>();
            bool originalParameterWasHashTable = false;

            for (int i = 0; i < p.Length; i++)
            {
                MshParameter parameter = this.paramDef.CreateInstance();
                object       val       = PSObject.Base(p[i]);
                if (val is IDictionary)
                {
                    originalParameterWasHashTable = true;
                    parameter.hash = this.VerifyHashTable((IDictionary)val, invocationContext);
                }
                else if ((val != null) && MatchesAllowedTypes(val.GetType(), this.paramDef.hashEntries[0].AllowedTypes))
                {
                    parameter.hash = this.paramDef.hashEntries[0].CreateHashtableFromSingleType(val);
                }
                else
                {
                    ProcessUnknownParameterType(invocationContext, val, this.paramDef.hashEntries[0].AllowedTypes);
                }
                this.VerifyAndNormalizeParameter(parameter, invocationContext, originalParameterWasHashTable);
                list.Add(parameter);
            }
            return(list);
        }
 private static void EvaluateSortingExpression(MshParameter p, PSObject inputObject, List<ObjectCommandPropertyValue> orderValues, List<ErrorRecord> errors, out string propertyNotFoundMsg)
 {
     MshExpression entry = p.GetEntry("expression") as MshExpression;
     List<MshExpressionResult> list = entry.GetValues(inputObject, false, true);
     if (list.Count == 0)
     {
         orderValues.Add(ObjectCommandPropertyValue.NonExistingProperty);
         propertyNotFoundMsg = StringUtil.Format(SortObjectStrings.PropertyNotFound, entry.ToString());
     }
     else
     {
         propertyNotFoundMsg = null;
         foreach (MshExpressionResult result in list)
         {
             if (result.Exception == null)
             {
                 orderValues.Add(new ObjectCommandPropertyValue(result.Result));
             }
             else
             {
                 ErrorRecord item = new ErrorRecord(result.Exception, "ExpressionEvaluation", ErrorCategory.InvalidResult, inputObject);
                 errors.Add(item);
                 orderValues.Add(ObjectCommandPropertyValue.ExistingNullProperty);
             }
         }
     }
 }
Пример #4
0
        internal MshResolvedExpressionParameterAssociation(MshParameter parameter, MshExpression expression)
        {
            if (expression == null)
                throw PSTraceSource.NewArgumentNullException("expression");

            OriginatingParameter = parameter;
            ResolvedExpression = expression;
        }
        internal MshResolvedExpressionParameterAssociation(MshParameter parameter, MshExpression expression)
        {
            if (expression == null)
                throw PSTraceSource.NewArgumentNullException("expression");

            OriginatingParameter = parameter;
            ResolvedExpression = expression;
        }
Пример #6
0
        internal MshResolvedExpressionParameterAssociation(MshParameter parameter, PSPropertyExpression expression)
        {
            if (expression == null)
            {
                throw PSTraceSource.NewArgumentNullException(nameof(expression));
            }

            OriginatingParameter = parameter;
            ResolvedExpression   = expression;
        }
Пример #7
0
        /// <exception cref="ArgumentException"></exception>
        private void VerifyAndNormalizeParameter(MshParameter parameter,
                                                 TerminatingErrorContext invocationContext,
                                                 bool originalParameterWasHashTable)
        {
            for (int k = 0; k < _paramDef.hashEntries.Count; k++)
            {
                if (parameter.hash.ContainsKey(_paramDef.hashEntries[k].KeyName))
                {
                    // we have a key, just do some post processing normalization
                    // retrieve the value
                    object val    = parameter.hash[_paramDef.hashEntries[k].KeyName];
                    object newVal = _paramDef.hashEntries[k].Verify(val, invocationContext, originalParameterWasHashTable);

                    if (newVal != null)
                    {
                        // if a new value is provided, we need to update the hash entry
                        parameter.hash[_paramDef.hashEntries[k].KeyName] = newVal;
                    }
                }
                else
                {
                    // we do not have the key, we might want to have a default value
                    object defaultValue = _paramDef.hashEntries[k].ComputeDefaultValue();

                    if (defaultValue != AutomationNull.Value)
                    {
                        // we have a default value, add it
                        parameter.hash[_paramDef.hashEntries[k].KeyName] = defaultValue;
                    }
                    else if (_paramDef.hashEntries[k].Mandatory)
                    {
                        // no default value and mandatory: we cannot proceed
                        ProcessMissingMandatoryKey(invocationContext, _paramDef.hashEntries[k].KeyName);
                    }
                }
            }
        }
Пример #8
0
        /// <exception cref="ArgumentException"></exception>
        private void VerifyAndNormalizeParameter(MshParameter parameter,
                                                    TerminatingErrorContext invocationContext,
                                                    bool originalParameterWasHashTable)
        {
            for (int k = 0; k < _paramDef.hashEntries.Count; k++)
            {
                if (parameter.hash.ContainsKey(_paramDef.hashEntries[k].KeyName))
                {
                    // we have a key, just do some post processing normalization
                    // retrieve the value
                    object val = parameter.hash[_paramDef.hashEntries[k].KeyName];
                    object newVal = _paramDef.hashEntries[k].Verify(val, invocationContext, originalParameterWasHashTable);

                    if (newVal != null)
                    {
                        // if a new value is provided, we need to update the hash entry
                        parameter.hash[_paramDef.hashEntries[k].KeyName] = newVal;
                    }
                }
                else
                {
                    // we do not have the key, we might want to have a default value
                    object defaultValue = _paramDef.hashEntries[k].ComputeDefaultValue();

                    if (defaultValue != AutomationNull.Value)
                    {
                        // we have a default value, add it
                        parameter.hash[_paramDef.hashEntries[k].KeyName] = defaultValue;
                    }
                    else if (_paramDef.hashEntries[k].Mandatory)
                    {
                        // no default value and mandatory: we cannot proceed
                        ProcessMissingMandatoryKey(invocationContext, _paramDef.hashEntries[k].KeyName);
                    }
                }
            }
        }
Пример #9
0
 private void WritePropertyValue(StringBuilder Listtag, MshParameter p)
 {
     MshExpression entry = p.GetEntry("expression") as MshExpression;
     foreach (MshExpressionResult result in entry.GetValues(this.inputObject))
     {
         if (result.Result != null)
         {
             string str = WebUtility.HtmlEncode(SafeToString(result.Result));
             Listtag.Append(str);
         }
         Listtag.Append(", ");
     }
     if (Listtag.ToString().EndsWith(", ", StringComparison.Ordinal))
     {
         Listtag.Remove(Listtag.Length - 2, 2);
     }
 }
Пример #10
0
 private void WritePropertyName(StringBuilder Listtag, MshParameter p)
 {
     string entry = p.GetEntry("label") as string;
     if (entry != null)
     {
         Listtag.Append(entry);
     }
     else
     {
         Listtag.Append((p.GetEntry("expression") as MshExpression).ToString());
     }
 }
Пример #11
0
 private static List<MshParameter> ExpandExpressions(List<PSObject> inputObjects, List<MshParameter> unexpandedParameterList)
 {
     List<MshParameter> list = new List<MshParameter>();
     if (unexpandedParameterList != null)
     {
         foreach (MshParameter parameter in unexpandedParameterList)
         {
             MshExpression entry = (MshExpression) parameter.GetEntry("expression");
             if (!entry.HasWildCardCharacters)
             {
                 list.Add(parameter);
             }
             else
             {
                 SortedDictionary<string, MshExpression> dictionary = new SortedDictionary<string, MshExpression>(StringComparer.OrdinalIgnoreCase);
                 if (inputObjects != null)
                 {
                     foreach (object obj2 in inputObjects)
                     {
                         if (obj2 != null)
                         {
                             foreach (MshExpression expression2 in entry.ResolveNames(PSObject.AsPSObject(obj2)))
                             {
                                 dictionary[expression2.ToString()] = expression2;
                             }
                         }
                     }
                 }
                 foreach (MshExpression expression3 in dictionary.Values)
                 {
                     MshParameter item = new MshParameter {
                         hash = (Hashtable) parameter.hash.Clone()
                     };
                     item.hash["expression"] = expression3;
                     list.Add(item);
                 }
             }
         }
     }
     return list;
 }
Пример #12
0
 private void VerifyAndNormalizeParameter(MshParameter parameter, TerminatingErrorContext invocationContext, bool originalParameterWasHashTable)
 {
     for (int i = 0; i < this.paramDef.hashEntries.Count; i++)
     {
         if (parameter.hash.ContainsKey(this.paramDef.hashEntries[i].KeyName))
         {
             object val = parameter.hash[this.paramDef.hashEntries[i].KeyName];
             object obj3 = this.paramDef.hashEntries[i].Verify(val, invocationContext, originalParameterWasHashTable);
             if (obj3 != null)
             {
                 parameter.hash[this.paramDef.hashEntries[i].KeyName] = obj3;
             }
         }
         else
         {
             object obj4 = this.paramDef.hashEntries[i].ComputeDefaultValue();
             if (obj4 != AutomationNull.Value)
             {
                 parameter.hash[this.paramDef.hashEntries[i].KeyName] = obj4;
             }
             else if (this.paramDef.hashEntries[i].Mandatory)
             {
                 ProcessMissingMandatoryKey(invocationContext, this.paramDef.hashEntries[i].KeyName);
             }
         }
     }
 }
Пример #13
0
        /// <summary>
        /// To write the Property value
        /// </summary>
        private void WritePropertyValue(StringBuilder Listtag, MshParameter p)
        {
            MshExpression exValue = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as MshExpression;

            // get the value of the property
            List<MshExpressionResult> resultList = exValue.GetValues(_inputObject);
            foreach (MshExpressionResult result in resultList)
            {
                // create comma sep list for multiple results
                if (result.Result != null)
                {
                    string htmlEncodedResult = WebUtility.HtmlEncode(SafeToString(result.Result));
                    Listtag.Append(htmlEncodedResult);
                }
                Listtag.Append(", ");
            }
            if (Listtag.ToString().EndsWith(", ", StringComparison.Ordinal))
            {
                Listtag.Remove(Listtag.Length - 2, 2);
            }
        }
Пример #14
0
 /// <summary>
 /// To write the Property name
 /// </summary>
 private void WritePropertyName(StringBuilder Listtag, MshParameter p)
 {
     //for writing the property name
     string label = p.GetEntry(ConvertHTMLParameterDefinitionKeys.LabelEntryKey) as string;
     if (label != null)
     {
         Listtag.Append(label);
     }
     else
     {
         MshExpression ex = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as MshExpression;
         Listtag.Append(ex.ToString());
     }
 }