Ejemplo n.º 1
0
 private void DisplayEnumeration(IEnumerable e, TraversalInfo level, List<FormatValue> formatValueList)
 {
     AddPrologue(formatValueList, "[", null);
     this.DisplayEnumerationInner(e, level, this.AddIndentationLevel(formatValueList));
     AddEpilogue(formatValueList, "]");
     formatValueList.Add(new FormatNewLine());
 }
        /// <summary>
        /// given an object, generate a tree-like view
        /// of the object
        /// </summary>
        /// <param name="so">object to process</param>
        /// <param name="inputParameters">parameters from the command line</param>
        /// <returns>complex view entry to send to the output command</returns>
        internal ComplexViewEntry GenerateView(PSObject so, FormattingCommandLineParameters inputParameters)
        {
            _complexSpecificParameters = (ComplexSpecificParameters)inputParameters.shapeParameters;

            int           maxDepth = _complexSpecificParameters.maxDepth;
            TraversalInfo level    = new TraversalInfo(0, maxDepth);

            List <MshParameter> mshParameterList = null;

            mshParameterList = inputParameters.mshParameterList;

            // create a top level entry as root of the tree
            ComplexViewEntry cve = new ComplexViewEntry();
            var typeNames        = so.InternalTypeNames;

            if (TreatAsScalarType(typeNames))
            {
                FormatEntry fe = new FormatEntry();

                cve.formatValueList.Add(fe);
                DisplayRawObject(so, fe.formatValueList);
            }
            else
            {
                // check if the top level object is an enumeration
                IEnumerable e = PSObjectHelper.GetEnumerable(so);

                if (e != null)
                {
                    // let's start the traversal with an enumeration
                    FormatEntry fe = new FormatEntry();

                    cve.formatValueList.Add(fe);
                    DisplayEnumeration(e, level, fe.formatValueList);
                }
                else
                {
                    // let's start the traversal with a traversal on properties
                    DisplayObject(so, level, mshParameterList, cve.formatValueList);
                }
            }

            return(cve);
        }
Ejemplo n.º 3
0
        private void DisplayEnumerationInner(IEnumerable e, TraversalInfo level, List <FormatValue> formatValueList)
        {
            int enumCount = 0;

            foreach (object x in e)
            {
                if (LocalPipeline.GetExecutionContextFromTLS().CurrentPipelineStopping)
                {
                    throw new PipelineStoppedException();
                }

                if (_enumerationLimit >= 0)
                {
                    if (_enumerationLimit == enumCount)
                    {
                        DisplayLeaf(PSObjectHelper.Ellipsis, formatValueList);
                        break;
                    }

                    enumCount++;
                }

                if (TreatAsLeafNode(x, level))
                {
                    DisplayLeaf(x, formatValueList);
                }
                else
                {
                    // check if the top level object is an enumeration
                    IEnumerable e1 = PSObjectHelper.GetEnumerable(x);

                    if (e1 != null)
                    {
                        formatValueList.Add(new FormatNewLine());
                        DisplayEnumeration(e1, level.NextLevel, AddIndentationLevel(formatValueList));
                    }
                    else
                    {
                        DisplayObject(PSObjectHelper.AsPSObject(x), level.NextLevel, null, formatValueList);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 private bool ExecuteFormatControl(TraversalInfo level, ControlBase control, PSObject so, List<FormatValue> formatValueList)
 {
     ComplexControlBody complexBody = null;
     ControlReference controlReference = control as ControlReference;
     if ((controlReference != null) && (controlReference.controlType == typeof(ComplexControlBody)))
     {
         complexBody = DisplayDataQuery.ResolveControlReference(this.db, this.controlDefinitionList, controlReference) as ComplexControlBody;
     }
     else
     {
         complexBody = control as ComplexControlBody;
     }
     if (complexBody != null)
     {
         this.ExecuteFormatControlBody(level, so, complexBody, formatValueList);
         return true;
     }
     return false;
 }
        /// <summary>
        /// Recursive call to display an object.
        /// </summary>
        /// <param name="so">Object to display.</param>
        /// <param name="currentLevel">Current level in the traversal.</param>
        /// <param name="parameterList">List of parameters from the command line.</param>
        /// <param name="formatValueList">List of format tokens to add to.</param>
        private void DisplayObject(PSObject so, TraversalInfo currentLevel, List<MshParameter> parameterList,
            List<FormatValue> formatValueList)
        {
            // resolve the names of the properties
            List<MshResolvedExpressionParameterAssociation> activeAssociationList =
                        AssociationManager.SetupActiveProperties(parameterList, so, _expressionFactory);

            // create a format entry
            FormatEntry fe = new FormatEntry();
            formatValueList.Add(fe);

            // add the display name of the object
            string objectDisplayName = GetObjectDisplayName(so);
            if (objectDisplayName != null)
                objectDisplayName = "class " + objectDisplayName;

            AddPrologue(fe.formatValueList, "{", objectDisplayName);
            ProcessActiveAssociationList(so, currentLevel, activeAssociationList, AddIndentationLevel(fe.formatValueList));
            AddEpilogue(fe.formatValueList, "}");
        }
Ejemplo n.º 6
0
        private bool ExecuteFormatControl(TraversalInfo level, ControlBase control, PSObject so, List <FormatValue> formatValueList)
        {
            ComplexControlBody complexBody      = null;
            ControlReference   controlReference = control as ControlReference;

            if ((controlReference != null) && (controlReference.controlType == typeof(ComplexControlBody)))
            {
                complexBody = DisplayDataQuery.ResolveControlReference(this.db, this.controlDefinitionList, controlReference) as ComplexControlBody;
            }
            else
            {
                complexBody = control as ComplexControlBody;
            }
            if (complexBody != null)
            {
                this.ExecuteFormatControlBody(level, so, complexBody, formatValueList);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 7
0
        private void DisplayEnumerationInner(IEnumerable e, TraversalInfo level, List <FormatValue> formatValueList)
        {
            int num = 0;

            foreach (object obj2 in e)
            {
                if (LocalPipeline.GetExecutionContextFromTLS().CurrentPipelineStopping)
                {
                    throw new PipelineStoppedException();
                }
                if (this.enumerationLimit >= 0)
                {
                    if (this.enumerationLimit == num)
                    {
                        this.DisplayLeaf("...", formatValueList);
                        break;
                    }
                    num++;
                }
                if (TreatAsLeafNode(obj2, level))
                {
                    this.DisplayLeaf(obj2, formatValueList);
                }
                else
                {
                    IEnumerable enumerable = PSObjectHelper.GetEnumerable(obj2);
                    if (enumerable != null)
                    {
                        formatValueList.Add(new FormatNewLine());
                        this.DisplayEnumeration(enumerable, level.NextLevel, this.AddIndentationLevel(formatValueList));
                    }
                    else
                    {
                        this.DisplayObject(PSObjectHelper.AsPSObject(obj2), level.NextLevel, null, formatValueList);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 private void DisplayEnumerationInner(IEnumerable e, TraversalInfo level, List<FormatValue> formatValueList)
 {
     int num = 0;
     foreach (object obj2 in e)
     {
         if (LocalPipeline.GetExecutionContextFromTLS().CurrentPipelineStopping)
         {
             throw new PipelineStoppedException();
         }
         if (this.enumerationLimit >= 0)
         {
             if (this.enumerationLimit == num)
             {
                 this.DisplayLeaf("...", formatValueList);
                 break;
             }
             num++;
         }
         if (TreatAsLeafNode(obj2, level))
         {
             this.DisplayLeaf(obj2, formatValueList);
         }
         else
         {
             IEnumerable enumerable = PSObjectHelper.GetEnumerable(obj2);
             if (enumerable != null)
             {
                 formatValueList.Add(new FormatNewLine());
                 this.DisplayEnumeration(enumerable, level.NextLevel, this.AddIndentationLevel(formatValueList));
             }
             else
             {
                 this.DisplayObject(PSObjectHelper.AsPSObject(obj2), level.NextLevel, null, formatValueList);
             }
         }
     }
 }
Ejemplo n.º 9
0
 private void DisplayObject(PSObject so, TraversalInfo currentLevel, List<MshParameter> parameterList, List<FormatValue> formatValueList)
 {
     List<MshResolvedExpressionParameterAssociation> activeAssociationList = AssociationManager.SetupActiveProperties(parameterList, so, this.expressionFactory);
     FormatEntry item = new FormatEntry();
     formatValueList.Add(item);
     string objectDisplayName = this.GetObjectDisplayName(so);
     if (objectDisplayName != null)
     {
         objectDisplayName = "class " + objectDisplayName;
     }
     AddPrologue(item.formatValueList, "{", objectDisplayName);
     this.ProcessActiveAssociationList(so, currentLevel, activeAssociationList, this.AddIndentationLevel(item.formatValueList));
     AddEpilogue(item.formatValueList, "}");
 }
Ejemplo n.º 10
0
        /// <summary>
        /// determine if we have to stop the expansion
        /// </summary>
        /// <param name="val">object to verify</param>
        /// <param name="level">current level of recursion</param>
        /// <returns></returns>
        private static bool TreatAsLeafNode(object val, TraversalInfo level)
        {
            if (level.Level >= level.MaxDepth || val == null)
                return true;

            return TreatAsScalarType(PSObject.GetTypeNames(val));
        }
Ejemplo n.º 11
0
        private void DisplayEnumerationInner(IEnumerable e, TraversalInfo level, List<FormatValue> formatValueList)
        {
            int enumCount = 0;
            foreach (object x in e)
            {
                if (LocalPipeline.GetExecutionContextFromTLS().CurrentPipelineStopping)
                {
                    throw new PipelineStoppedException();
                }
                if (_enumerationLimit >= 0)
                {
                    if (_enumerationLimit == enumCount)
                    {
                        DisplayLeaf(PSObjectHelper.ellipses, formatValueList);
                        break;
                    }
                    enumCount++;
                }
                if (TreatAsLeafNode(x, level))
                {
                    DisplayLeaf(x, formatValueList);
                }
                else
                {
                    // check if the top level object is an enumeration
                    IEnumerable e1 = PSObjectHelper.GetEnumerable(x);

                    if (e1 != null)
                    {
                        formatValueList.Add(new FormatNewLine());
                        DisplayEnumeration(e1, level.NextLevel, AddIndentationLevel(formatValueList));
                    }
                    else
                    {
                        DisplayObject(PSObjectHelper.AsPSObject(x), level.NextLevel, null, formatValueList);
                    }
                }
            }
        }
Ejemplo n.º 12
0
        private void ProcessActiveAssociationList(PSObject so,
                                TraversalInfo currentLevel,
                                List<MshResolvedExpressionParameterAssociation> activeAssociationList,
                                                    List<FormatValue> formatValueList)
        {
            foreach (MshResolvedExpressionParameterAssociation a in activeAssociationList)
            {
                FormatTextField ftf = new FormatTextField();

                ftf.text = a.ResolvedExpression.ToString() + " = ";
                formatValueList.Add(ftf);

                // compute the value of the entry
                List<MshExpressionResult> resList = a.ResolvedExpression.GetValues(so);
                object val = null;
                if (resList.Count >= 1)
                {
                    MshExpressionResult result = resList[0];
                    if (result.Exception != null)
                    {
                        _errorManager.LogMshExpressionFailedResult(result, so);
                        if (_errorManager.DisplayErrorStrings)
                        {
                            val = _errorManager.ErrorString;
                        }
                        else
                        {
                            val = "";
                        }
                    }
                    else
                    {
                        val = result.Result;
                    }
                }


                // extract the optional max depth
                TraversalInfo level = currentLevel;
                if (a.OriginatingParameter != null)
                {
                    object maxDepthKey = a.OriginatingParameter.GetEntry(FormatParameterDefinitionKeys.DepthEntryKey);
                    if (maxDepthKey != AutomationNull.Value)
                    {
                        int parameterMaxDept = (int)maxDepthKey;
                        level = new TraversalInfo(currentLevel.Level, parameterMaxDept);
                    }
                }

                IEnumerable e = null;
                if (val != null || (level.Level >= level.MaxDepth))
                    e = PSObjectHelper.GetEnumerable(val);

                if (e != null)
                {
                    formatValueList.Add(new FormatNewLine());
                    DisplayEnumeration(e, level.NextLevel, AddIndentationLevel(formatValueList));
                }
                else if (val == null || TreatAsLeafNode(val, level))
                {
                    DisplayLeaf(val, formatValueList);
                }
                else
                {
                    formatValueList.Add(new FormatNewLine());

                    // we need to go one more level down
                    DisplayObject(PSObject.AsPSObject(val), level.NextLevel, null,
                        AddIndentationLevel(formatValueList));
                }
            } // for each
        }
Ejemplo n.º 13
0
        /// <summary>
        /// recursive call to display an object
        /// </summary>
        /// <param name="so">object to display</param>
        /// <param name="currentLevel">current level in the traversal</param>
        /// <param name="parameterList"> list of parameters from the command line</param>
        /// <param name="formatValueList">list of format tokens to add to</param>
        private void DisplayObject(PSObject so, TraversalInfo currentLevel, List<MshParameter> parameterList,
                                        List<FormatValue> formatValueList)
        {
            // resolve the names of the properties
            List<MshResolvedExpressionParameterAssociation> activeAssociationList =
                        AssociationManager.SetupActiveProperties(parameterList, so, _expressionFactory);

            // create a format entry
            FormatEntry fe = new FormatEntry();
            formatValueList.Add(fe);

            // add the display name of the object
            string objectDisplayName = GetObjectDisplayName(so);
            if (objectDisplayName != null)
                objectDisplayName = "class " + objectDisplayName;

            AddPrologue(fe.formatValueList, "{", objectDisplayName);
            ProcessActiveAssociationList(so, currentLevel, activeAssociationList, AddIndentationLevel(fe.formatValueList));
            AddEpilogue(fe.formatValueList, "}");
        }
Ejemplo n.º 14
0
 private static bool TreatAsLeafNode(object val, TraversalInfo level)
 {
     if ((level.Level < level.MaxDepth) && (val != null))
     {
         return TreatAsScalarType(PSObject.GetTypeNames(val));
     }
     return true;
 }
Ejemplo n.º 15
0
        private void ProcessActiveAssociationList(PSObject so,
                                                  TraversalInfo currentLevel,
                                                  List <MshResolvedExpressionParameterAssociation> activeAssociationList,
                                                  List <FormatValue> formatValueList)
        {
            foreach (MshResolvedExpressionParameterAssociation a in activeAssociationList)
            {
                FormatTextField ftf = new FormatTextField();

                ftf.text = a.ResolvedExpression.ToString() + " = ";
                formatValueList.Add(ftf);

                // compute the value of the entry
                List <PSPropertyExpressionResult> resList = a.ResolvedExpression.GetValues(so);
                object val = null;
                if (resList.Count >= 1)
                {
                    PSPropertyExpressionResult result = resList[0];
                    if (result.Exception != null)
                    {
                        _errorManager.LogPSPropertyExpressionFailedResult(result, so);
                        if (_errorManager.DisplayErrorStrings)
                        {
                            val = _errorManager.ErrorString;
                        }
                        else
                        {
                            val = string.Empty;
                        }
                    }
                    else
                    {
                        val = result.Result;
                    }
                }

                // extract the optional max depth
                TraversalInfo level = currentLevel;
                if (a.OriginatingParameter != null)
                {
                    object maxDepthKey = a.OriginatingParameter.GetEntry(FormatParameterDefinitionKeys.DepthEntryKey);
                    if (maxDepthKey != AutomationNull.Value)
                    {
                        int parameterMaxDept = (int)maxDepthKey;
                        level = new TraversalInfo(currentLevel.Level, parameterMaxDept);
                    }
                }

                IEnumerable e = null;
                if (val != null || (level.Level >= level.MaxDepth))
                {
                    e = PSObjectHelper.GetEnumerable(val);
                }

                if (e != null)
                {
                    formatValueList.Add(new FormatNewLine());
                    DisplayEnumeration(e, level.NextLevel, AddIndentationLevel(formatValueList));
                }
                else if (val == null || TreatAsLeafNode(val, level))
                {
                    DisplayLeaf(val, formatValueList);
                }
                else
                {
                    formatValueList.Add(new FormatNewLine());

                    // we need to go one more level down
                    DisplayObject(PSObject.AsPSObject(val), level.NextLevel, null,
                                  AddIndentationLevel(formatValueList));
                }
            } // for each
        }
Ejemplo n.º 16
0
 private void ExecuteFormatControlBody(TraversalInfo level, PSObject so, ComplexControlBody complexBody, List<FormatValue> formatValueList)
 {
     ComplexControlEntryDefinition activeComplexControlEntryDefinition = this.GetActiveComplexControlEntryDefinition(complexBody, so);
     this.ExecuteFormatTokenList(level, so, activeComplexControlEntryDefinition.itemDefinition.formatTokenList, formatValueList);
 }
Ejemplo n.º 17
0
 private void ExecuteFormatTokenList(TraversalInfo level, PSObject so, List <FormatToken> formatTokenList, List <FormatValue> formatValueList)
 {
     if (so == null)
     {
         throw PSTraceSource.NewArgumentNullException("so");
     }
     if (level.Level != level.MaxDepth)
     {
         FormatEntry item = new FormatEntry();
         formatValueList.Add(item);
         foreach (FormatToken token in formatTokenList)
         {
             TextToken tt = token as TextToken;
             if (tt != null)
             {
                 FormatTextField field = new FormatTextField {
                     text = this.db.displayResourceManagerCache.GetTextTokenString(tt)
                 };
                 item.formatValueList.Add(field);
             }
             else if (token is NewLineToken)
             {
                 item.formatValueList.Add(new FormatNewLine());
             }
             else
             {
                 FrameToken token3 = token as FrameToken;
                 if (token3 != null)
                 {
                     FormatEntry entry2 = new FormatEntry {
                         frameInfo = new FrameInfo()
                     };
                     entry2.frameInfo.firstLine        = token3.frameInfoDefinition.firstLine;
                     entry2.frameInfo.leftIndentation  = token3.frameInfoDefinition.leftIndentation;
                     entry2.frameInfo.rightIndentation = token3.frameInfoDefinition.rightIndentation;
                     this.ExecuteFormatTokenList(level, so, token3.itemDefinition.formatTokenList, entry2.formatValueList);
                     item.formatValueList.Add(entry2);
                 }
                 else
                 {
                     CompoundPropertyToken token4 = token as CompoundPropertyToken;
                     if ((token4 != null) && this.EvaluateDisplayCondition(so, token4.conditionToken))
                     {
                         object result = null;
                         if ((token4.expression == null) || string.IsNullOrEmpty(token4.expression.expressionValue))
                         {
                             result = so;
                         }
                         else
                         {
                             List <MshExpressionResult> values = this.expressionFactory.CreateFromExpressionToken(token4.expression, this.loadingInfo).GetValues(so);
                             if (values.Count > 0)
                             {
                                 result = values[0].Result;
                                 if (values[0].Exception != null)
                                 {
                                     this.errorManager.LogMshExpressionFailedResult(values[0], so);
                                 }
                             }
                         }
                         if ((token4.control == null) || (token4.control is FieldControlBody))
                         {
                             if (result == null)
                             {
                                 result = "";
                             }
                             FieldFormattingDirective fieldFormattingDirective = null;
                             StringFormatError        formatErrorObject        = null;
                             if (token4.control != null)
                             {
                                 fieldFormattingDirective = ((FieldControlBody)token4.control).fieldFormattingDirective;
                                 if ((fieldFormattingDirective != null) && this.errorManager.DisplayFormatErrorString)
                                 {
                                     formatErrorObject = new StringFormatError();
                                 }
                             }
                             IEnumerable         enumerable = PSObjectHelper.GetEnumerable(result);
                             FormatPropertyField field2     = new FormatPropertyField();
                             if (token4.enumerateCollection && (enumerable != null))
                             {
                                 foreach (object obj3 in enumerable)
                                 {
                                     if (obj3 != null)
                                     {
                                         field2 = new FormatPropertyField {
                                             propertyValue = PSObjectHelper.FormatField(fieldFormattingDirective, obj3, this.enumerationLimit, formatErrorObject, this.expressionFactory)
                                         };
                                         item.formatValueList.Add(field2);
                                     }
                                 }
                             }
                             else
                             {
                                 field2 = new FormatPropertyField {
                                     propertyValue = PSObjectHelper.FormatField(fieldFormattingDirective, result, this.enumerationLimit, formatErrorObject, this.expressionFactory)
                                 };
                                 item.formatValueList.Add(field2);
                             }
                             if ((formatErrorObject != null) && (formatErrorObject.exception != null))
                             {
                                 this.errorManager.LogStringFormatError(formatErrorObject);
                                 field2.propertyValue = this.errorManager.FormatErrorString;
                             }
                         }
                         else if (result != null)
                         {
                             IEnumerable enumerable2 = PSObjectHelper.GetEnumerable(result);
                             if (token4.enumerateCollection && (enumerable2 != null))
                             {
                                 foreach (object obj4 in enumerable2)
                                 {
                                     if (obj4 != null)
                                     {
                                         this.ExecuteFormatControl(level.NextLevel, token4.control, PSObject.AsPSObject(obj4), item.formatValueList);
                                     }
                                 }
                             }
                             else
                             {
                                 this.ExecuteFormatControl(level.NextLevel, token4.control, PSObjectHelper.AsPSObject(result), item.formatValueList);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 18
0
        private void ExecuteFormatControlBody(TraversalInfo level, PSObject so, ComplexControlBody complexBody, List <FormatValue> formatValueList)
        {
            ComplexControlEntryDefinition activeComplexControlEntryDefinition = this.GetActiveComplexControlEntryDefinition(complexBody, so);

            this.ExecuteFormatTokenList(level, so, activeComplexControlEntryDefinition.itemDefinition.formatTokenList, formatValueList);
        }
Ejemplo n.º 19
0
 internal ComplexViewEntry GenerateView(PSObject so, FormattingCommandLineParameters inputParameters)
 {
     this.complexSpecificParameters = (ComplexSpecificParameters) inputParameters.shapeParameters;
     int maxDepth = this.complexSpecificParameters.maxDepth;
     TraversalInfo level = new TraversalInfo(0, maxDepth);
     List<MshParameter> parameterList = null;
     if (inputParameters != null)
     {
         parameterList = inputParameters.mshParameterList;
     }
     ComplexViewEntry entry = new ComplexViewEntry();
     if (TreatAsScalarType(so.InternalTypeNames))
     {
         FormatEntry item = new FormatEntry();
         entry.formatValueList.Add(item);
         this.DisplayRawObject(so, item.formatValueList);
         return entry;
     }
     IEnumerable e = PSObjectHelper.GetEnumerable(so);
     if (e != null)
     {
         FormatEntry entry3 = new FormatEntry();
         entry.formatValueList.Add(entry3);
         this.DisplayEnumeration(e, level, entry3.formatValueList);
         return entry;
     }
     this.DisplayObject(so, level, parameterList, entry.formatValueList);
     return entry;
 }
Ejemplo n.º 20
0
 private void ProcessActiveAssociationList(PSObject so, TraversalInfo currentLevel, List <MshResolvedExpressionParameterAssociation> activeAssociationList, List <FormatValue> formatValueList)
 {
     foreach (MshResolvedExpressionParameterAssociation association in activeAssociationList)
     {
         FormatTextField item = new FormatTextField {
             text = association.ResolvedExpression.ToString() + " = "
         };
         formatValueList.Add(item);
         List <MshExpressionResult> values = association.ResolvedExpression.GetValues(so);
         object errorString = null;
         if (values.Count >= 1)
         {
             MshExpressionResult result = values[0];
             if (result.Exception != null)
             {
                 this.errorManager.LogMshExpressionFailedResult(result, so);
                 if (this.errorManager.DisplayErrorStrings)
                 {
                     errorString = this.errorManager.ErrorString;
                 }
                 else
                 {
                     errorString = "";
                 }
             }
             else
             {
                 errorString = result.Result;
             }
         }
         TraversalInfo level = currentLevel;
         if (association.OriginatingParameter != null)
         {
             object entry = association.OriginatingParameter.GetEntry("depth");
             if (entry != AutomationNull.Value)
             {
                 int maxDepth = (int)entry;
                 level = new TraversalInfo(currentLevel.Level, maxDepth);
             }
         }
         IEnumerable e = null;
         if ((errorString != null) || (level.Level >= level.MaxDepth))
         {
             e = PSObjectHelper.GetEnumerable(errorString);
         }
         if (e != null)
         {
             formatValueList.Add(new FormatNewLine());
             this.DisplayEnumeration(e, level.NextLevel, this.AddIndentationLevel(formatValueList));
         }
         else if ((errorString == null) || TreatAsLeafNode(errorString, level))
         {
             this.DisplayLeaf(errorString, formatValueList);
         }
         else
         {
             formatValueList.Add(new FormatNewLine());
             this.DisplayObject(PSObject.AsPSObject(errorString), level.NextLevel, null, this.AddIndentationLevel(formatValueList));
         }
     }
 }
Ejemplo n.º 21
0
        private void ExecuteFormatTokenList(TraversalInfo level,
                                            PSObject so, List <FormatToken> formatTokenList, List <FormatValue> formatValueList)
        {
            if (so == null)
            {
                throw PSTraceSource.NewArgumentNullException("so");
            }

            // guard against infinite loop
            if (level.Level == level.MaxDepth)
            {
                return;
            }

            FormatEntry fe = new FormatEntry();

            formatValueList.Add(fe);
            #region foreach loop
            foreach (FormatToken t in formatTokenList)
            {
                TextToken tt = t as TextToken;
                if (tt != null)
                {
                    FormatTextField ftf = new FormatTextField();
                    ftf.text = _db.displayResourceManagerCache.GetTextTokenString(tt);
                    fe.formatValueList.Add(ftf);
                    continue;
                }
                var newline = t as NewLineToken;
                if (newline != null)
                {
                    for (int i = 0; i < newline.count; i++)
                    {
                        fe.formatValueList.Add(new FormatNewLine());
                    }
                    continue;
                }
                FrameToken ft = t as FrameToken;
                if (ft != null)
                {
                    // instantiate a new entry and attach a frame info object
                    FormatEntry feFrame = new FormatEntry();
                    feFrame.frameInfo = new FrameInfo();

                    // add the frame info
                    feFrame.frameInfo.firstLine        = ft.frameInfoDefinition.firstLine;
                    feFrame.frameInfo.leftIndentation  = ft.frameInfoDefinition.leftIndentation;
                    feFrame.frameInfo.rightIndentation = ft.frameInfoDefinition.rightIndentation;

                    // execute the list inside the frame
                    ExecuteFormatTokenList(level, so, ft.itemDefinition.formatTokenList, feFrame.formatValueList);

                    // add the frame computation results to the current format entry
                    fe.formatValueList.Add(feFrame);
                    continue;
                }
                #region CompoundPropertyToken
                CompoundPropertyToken cpt = t as CompoundPropertyToken;
                if (cpt != null)
                {
                    if (!EvaluateDisplayCondition(so, cpt.conditionToken))
                    {
                        // token not active, skip it
                        continue;
                    }

                    // get the property from the object
                    object val = null;

                    // if no expression was specified, just use the
                    // object itself
                    if (cpt.expression == null || string.IsNullOrEmpty(cpt.expression.expressionValue))
                    {
                        val = so;
                    }
                    else
                    {
                        PSPropertyExpression ex = _expressionFactory.CreateFromExpressionToken(cpt.expression, _loadingInfo);
                        List <PSPropertyExpressionResult> resultList = ex.GetValues(so);
                        if (resultList.Count > 0)
                        {
                            val = resultList[0].Result;
                            if (resultList[0].Exception != null)
                            {
                                _errorManager.LogPSPropertyExpressionFailedResult(resultList[0], so);
                            }
                        }
                    }

                    // if the token is has a formatting string, it's a leaf node,
                    // do the formatting and we will be done
                    if (cpt.control == null || cpt.control is FieldControlBody)
                    {
                        // Since it is a leaf node we just consider it an empty string and go
                        // on with formatting
                        if (val == null)
                        {
                            val = string.Empty;
                        }
                        FieldFormattingDirective fieldFormattingDirective = null;
                        StringFormatError        formatErrorObject        = null;
                        if (cpt.control != null)
                        {
                            fieldFormattingDirective = ((FieldControlBody)cpt.control).fieldFormattingDirective;
                            if (fieldFormattingDirective != null && _errorManager.DisplayFormatErrorString)
                            {
                                formatErrorObject = new StringFormatError();
                            }
                        }

                        IEnumerable         e   = PSObjectHelper.GetEnumerable(val);
                        FormatPropertyField fpf = new FormatPropertyField();
                        if (cpt.enumerateCollection && e != null)
                        {
                            foreach (object x in e)
                            {
                                if (x == null)
                                {
                                    // nothing to process
                                    continue;
                                }
                                fpf = new FormatPropertyField();

                                fpf.propertyValue = PSObjectHelper.FormatField(fieldFormattingDirective, x, _enumerationLimit, formatErrorObject, _expressionFactory);
                                fe.formatValueList.Add(fpf);
                            }
                        }
                        else
                        {
                            fpf = new FormatPropertyField();

                            fpf.propertyValue = PSObjectHelper.FormatField(fieldFormattingDirective, val, _enumerationLimit, formatErrorObject, _expressionFactory);
                            fe.formatValueList.Add(fpf);
                        }
                        if (formatErrorObject != null && formatErrorObject.exception != null)
                        {
                            _errorManager.LogStringFormatError(formatErrorObject);
                            fpf.propertyValue = _errorManager.FormatErrorString;
                        }
                    }
                    else
                    {
                        // An empty result that is not a leaf node should not be expanded
                        if (val == null)
                        {
                            continue;
                        }
                        IEnumerable e = PSObjectHelper.GetEnumerable(val);
                        if (cpt.enumerateCollection && e != null)
                        {
                            foreach (object x in e)
                            {
                                if (x == null)
                                {
                                    // nothing to process
                                    continue;
                                }

                                // proceed with the recursion
                                ExecuteFormatControl(level.NextLevel, cpt.control, PSObject.AsPSObject(x), fe.formatValueList);
                            }
                        }
                        else
                        {
                            // proceed with the recursion
                            ExecuteFormatControl(level.NextLevel, cpt.control, PSObjectHelper.AsPSObject(val), fe.formatValueList);
                        }
                    }
                }
                #endregion CompoundPropertyToken
            }
            #endregion foreach loop
        }
Ejemplo n.º 22
0
        /// <summary>
        /// given an object, generate a tree-like view
        /// of the object
        /// </summary>
        /// <param name="so">object to process</param>
        /// <param name="inputParameters">parameters from the command line</param>
        /// <returns>complex view entry to send to the output command</returns>
        internal ComplexViewEntry GenerateView(PSObject so, FormattingCommandLineParameters inputParameters)
        {
            _complexSpecificParameters = (ComplexSpecificParameters)inputParameters.shapeParameters;

            int maxDepth = _complexSpecificParameters.maxDepth;
            TraversalInfo level = new TraversalInfo(0, maxDepth);

            List<MshParameter> mshParameterList = null;
            if (inputParameters != null)
                mshParameterList = inputParameters.mshParameterList;

            // create a top level entry as root of the tree
            ComplexViewEntry cve = new ComplexViewEntry();
            var typeNames = so.InternalTypeNames;
            if (TreatAsScalarType(typeNames))
            {
                FormatEntry fe = new FormatEntry();

                cve.formatValueList.Add(fe);
                DisplayRawObject(so, fe.formatValueList);
            }
            else
            {
                // check if the top level object is an enumeration
                IEnumerable e = PSObjectHelper.GetEnumerable(so);

                if (e != null)
                {
                    // let's start the traversal with an enumeration
                    FormatEntry fe = new FormatEntry();

                    cve.formatValueList.Add(fe);
                    DisplayEnumeration(e, level, fe.formatValueList);
                }
                else
                {
                    // let's start the traversal with a traversal on properties
                    DisplayObject(so, level, mshParameterList, cve.formatValueList);
                }
            }

            return cve;
        }
Ejemplo n.º 23
0
        private bool ExecuteFormatControl(TraversalInfo level, ControlBase control,
        PSObject so, List<FormatValue> formatValueList)
        {
            // we are looking for a complex control to execute
            ComplexControlBody complexBody = null;

            // we might have a reference
            ControlReference controlReference = control as ControlReference;
            if (controlReference != null && controlReference.controlType == typeof(ComplexControlBody))
            {
                // retrieve the reference
                complexBody = DisplayDataQuery.ResolveControlReference(
                                        _db,
                                        _controlDefinitionList,
                                        controlReference) as ComplexControlBody;
            }
            else
            {
                // try as an in line control
                complexBody = control as ComplexControlBody;
            }

            // finally, execute the control body
            if (complexBody != null)
            {
                // we have an inline control, just execute it
                ExecuteFormatControlBody(level, so, complexBody, formatValueList);
                return true;
            }
            return false;
        }
Ejemplo n.º 24
0
 private void ProcessActiveAssociationList(PSObject so, TraversalInfo currentLevel, List<MshResolvedExpressionParameterAssociation> activeAssociationList, List<FormatValue> formatValueList)
 {
     foreach (MshResolvedExpressionParameterAssociation association in activeAssociationList)
     {
         FormatTextField item = new FormatTextField {
             text = association.ResolvedExpression.ToString() + " = "
         };
         formatValueList.Add(item);
         List<MshExpressionResult> values = association.ResolvedExpression.GetValues(so);
         object errorString = null;
         if (values.Count >= 1)
         {
             MshExpressionResult result = values[0];
             if (result.Exception != null)
             {
                 this.errorManager.LogMshExpressionFailedResult(result, so);
                 if (this.errorManager.DisplayErrorStrings)
                 {
                     errorString = this.errorManager.ErrorString;
                 }
                 else
                 {
                     errorString = "";
                 }
             }
             else
             {
                 errorString = result.Result;
             }
         }
         TraversalInfo level = currentLevel;
         if (association.OriginatingParameter != null)
         {
             object entry = association.OriginatingParameter.GetEntry("depth");
             if (entry != AutomationNull.Value)
             {
                 int maxDepth = (int) entry;
                 level = new TraversalInfo(currentLevel.Level, maxDepth);
             }
         }
         IEnumerable e = null;
         if ((errorString != null) || (level.Level >= level.MaxDepth))
         {
             e = PSObjectHelper.GetEnumerable(errorString);
         }
         if (e != null)
         {
             formatValueList.Add(new FormatNewLine());
             this.DisplayEnumeration(e, level.NextLevel, this.AddIndentationLevel(formatValueList));
         }
         else if ((errorString == null) || TreatAsLeafNode(errorString, level))
         {
             this.DisplayLeaf(errorString, formatValueList);
         }
         else
         {
             formatValueList.Add(new FormatNewLine());
             this.DisplayObject(PSObject.AsPSObject(errorString), level.NextLevel, null, this.AddIndentationLevel(formatValueList));
         }
     }
 }
Ejemplo n.º 25
0
 private void ExecuteFormatTokenList(TraversalInfo level, PSObject so, List<FormatToken> formatTokenList, List<FormatValue> formatValueList)
 {
     if (so == null)
     {
         throw PSTraceSource.NewArgumentNullException("so");
     }
     if (level.Level != level.MaxDepth)
     {
         FormatEntry item = new FormatEntry();
         formatValueList.Add(item);
         foreach (FormatToken token in formatTokenList)
         {
             TextToken tt = token as TextToken;
             if (tt != null)
             {
                 FormatTextField field = new FormatTextField {
                     text = this.db.displayResourceManagerCache.GetTextTokenString(tt)
                 };
                 item.formatValueList.Add(field);
             }
             else if (token is NewLineToken)
             {
                 item.formatValueList.Add(new FormatNewLine());
             }
             else
             {
                 FrameToken token3 = token as FrameToken;
                 if (token3 != null)
                 {
                     FormatEntry entry2 = new FormatEntry {
                         frameInfo = new FrameInfo()
                     };
                     entry2.frameInfo.firstLine = token3.frameInfoDefinition.firstLine;
                     entry2.frameInfo.leftIndentation = token3.frameInfoDefinition.leftIndentation;
                     entry2.frameInfo.rightIndentation = token3.frameInfoDefinition.rightIndentation;
                     this.ExecuteFormatTokenList(level, so, token3.itemDefinition.formatTokenList, entry2.formatValueList);
                     item.formatValueList.Add(entry2);
                 }
                 else
                 {
                     CompoundPropertyToken token4 = token as CompoundPropertyToken;
                     if ((token4 != null) && this.EvaluateDisplayCondition(so, token4.conditionToken))
                     {
                         object result = null;
                         if ((token4.expression == null) || string.IsNullOrEmpty(token4.expression.expressionValue))
                         {
                             result = so;
                         }
                         else
                         {
                             List<MshExpressionResult> values = this.expressionFactory.CreateFromExpressionToken(token4.expression, this.loadingInfo).GetValues(so);
                             if (values.Count > 0)
                             {
                                 result = values[0].Result;
                                 if (values[0].Exception != null)
                                 {
                                     this.errorManager.LogMshExpressionFailedResult(values[0], so);
                                 }
                             }
                         }
                         if ((token4.control == null) || (token4.control is FieldControlBody))
                         {
                             if (result == null)
                             {
                                 result = "";
                             }
                             FieldFormattingDirective fieldFormattingDirective = null;
                             StringFormatError formatErrorObject = null;
                             if (token4.control != null)
                             {
                                 fieldFormattingDirective = ((FieldControlBody) token4.control).fieldFormattingDirective;
                                 if ((fieldFormattingDirective != null) && this.errorManager.DisplayFormatErrorString)
                                 {
                                     formatErrorObject = new StringFormatError();
                                 }
                             }
                             IEnumerable enumerable = PSObjectHelper.GetEnumerable(result);
                             FormatPropertyField field2 = new FormatPropertyField();
                             if (token4.enumerateCollection && (enumerable != null))
                             {
                                 foreach (object obj3 in enumerable)
                                 {
                                     if (obj3 != null)
                                     {
                                         field2 = new FormatPropertyField {
                                             propertyValue = PSObjectHelper.FormatField(fieldFormattingDirective, obj3, this.enumerationLimit, formatErrorObject, this.expressionFactory)
                                         };
                                         item.formatValueList.Add(field2);
                                     }
                                 }
                             }
                             else
                             {
                                 field2 = new FormatPropertyField {
                                     propertyValue = PSObjectHelper.FormatField(fieldFormattingDirective, result, this.enumerationLimit, formatErrorObject, this.expressionFactory)
                                 };
                                 item.formatValueList.Add(field2);
                             }
                             if ((formatErrorObject != null) && (formatErrorObject.exception != null))
                             {
                                 this.errorManager.LogStringFormatError(formatErrorObject);
                                 field2.propertyValue = this.errorManager.FormatErrorString;
                             }
                         }
                         else if (result != null)
                         {
                             IEnumerable enumerable2 = PSObjectHelper.GetEnumerable(result);
                             if (token4.enumerateCollection && (enumerable2 != null))
                             {
                                 foreach (object obj4 in enumerable2)
                                 {
                                     if (obj4 != null)
                                     {
                                         this.ExecuteFormatControl(level.NextLevel, token4.control, PSObject.AsPSObject(obj4), item.formatValueList);
                                     }
                                 }
                             }
                             else
                             {
                                 this.ExecuteFormatControl(level.NextLevel, token4.control, PSObjectHelper.AsPSObject(result), item.formatValueList);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 26
0
        private void ExecuteFormatTokenList(TraversalInfo level,
                PSObject so, List<FormatToken> formatTokenList, List<FormatValue> formatValueList)
        {
            if (so == null)
            {
                throw PSTraceSource.NewArgumentNullException("so");
            }

            // guard against infinite loop
            if (level.Level == level.MaxDepth)
            {
                return;
            }

            FormatEntry fe = new FormatEntry();

            formatValueList.Add(fe);
            #region foreach loop
            foreach (FormatToken t in formatTokenList)
            {
                TextToken tt = t as TextToken;
                if (tt != null)
                {
                    FormatTextField ftf = new FormatTextField();
                    ftf.text = _db.displayResourceManagerCache.GetTextTokenString(tt);
                    fe.formatValueList.Add(ftf);
                    continue;
                }
                var newline = t as NewLineToken;
                if (newline != null)
                {
                    for (int i = 0; i < newline.count; i++)
                    {
                        fe.formatValueList.Add(new FormatNewLine());
                    }
                    continue;
                }
                FrameToken ft = t as FrameToken;
                if (ft != null)
                {
                    // instantiate a new entry and attach a frame info object
                    FormatEntry feFrame = new FormatEntry();
                    feFrame.frameInfo = new FrameInfo();

                    // add the frame info 
                    feFrame.frameInfo.firstLine = ft.frameInfoDefinition.firstLine;
                    feFrame.frameInfo.leftIndentation = ft.frameInfoDefinition.leftIndentation;
                    feFrame.frameInfo.rightIndentation = ft.frameInfoDefinition.rightIndentation;

                    // execute the list inside the frame
                    ExecuteFormatTokenList(level, so, ft.itemDefinition.formatTokenList, feFrame.formatValueList);

                    // add the frame computation results to the current format entry
                    fe.formatValueList.Add(feFrame);
                    continue;
                }
                #region CompoundPropertyToken
                CompoundPropertyToken cpt = t as CompoundPropertyToken;
                if (cpt != null)
                {
                    if (!EvaluateDisplayCondition(so, cpt.conditionToken))
                    {
                        // token not active, skip it
                        continue;
                    }

                    // get the property from the object
                    object val = null;

                    // if no expression was specified, just use the 
                    // object itself
                    if (cpt.expression == null || string.IsNullOrEmpty(cpt.expression.expressionValue))
                    {
                        val = so;
                    }
                    else
                    {
                        MshExpression ex = _expressionFactory.CreateFromExpressionToken(cpt.expression, _loadingInfo);
                        List<MshExpressionResult> resultList = ex.GetValues(so);
                        if (resultList.Count > 0)
                        {
                            val = resultList[0].Result;
                            if (resultList[0].Exception != null)
                            {
                                _errorManager.LogMshExpressionFailedResult(resultList[0], so);
                            }
                        }
                    }


                    // if the token is has a formatting string, it's a leaf node,
                    // do the formatting and we will be done
                    if (cpt.control == null || cpt.control is FieldControlBody)
                    {
                        // Since it is a leaf node we just consider it an empty string and go
                        // on with formatting
                        if (val == null)
                        {
                            val = "";
                        }
                        FieldFormattingDirective fieldFormattingDirective = null;
                        StringFormatError formatErrorObject = null;
                        if (cpt.control != null)
                        {
                            fieldFormattingDirective = ((FieldControlBody)cpt.control).fieldFormattingDirective;
                            if (fieldFormattingDirective != null && _errorManager.DisplayFormatErrorString)
                            {
                                formatErrorObject = new StringFormatError();
                            }
                        }

                        IEnumerable e = PSObjectHelper.GetEnumerable(val);
                        FormatPropertyField fpf = new FormatPropertyField();
                        if (cpt.enumerateCollection && e != null)
                        {
                            foreach (object x in e)
                            {
                                if (x == null)
                                {
                                    // nothing to process
                                    continue;
                                }
                                fpf = new FormatPropertyField();

                                fpf.propertyValue = PSObjectHelper.FormatField(fieldFormattingDirective, x, _enumerationLimit, formatErrorObject, _expressionFactory);
                                fe.formatValueList.Add(fpf);
                            }
                        }
                        else
                        {
                            fpf = new FormatPropertyField();

                            fpf.propertyValue = PSObjectHelper.FormatField(fieldFormattingDirective, val, _enumerationLimit, formatErrorObject, _expressionFactory);
                            fe.formatValueList.Add(fpf);
                        }
                        if (formatErrorObject != null && formatErrorObject.exception != null)
                        {
                            _errorManager.LogStringFormatError(formatErrorObject);
                            fpf.propertyValue = _errorManager.FormatErrorString;
                        }
                    }
                    else
                    {
                        // An empty result that is not a leaf node should not be expanded
                        if (val == null)
                        {
                            continue;
                        }
                        IEnumerable e = PSObjectHelper.GetEnumerable(val);
                        if (cpt.enumerateCollection && e != null)
                        {
                            foreach (object x in e)
                            {
                                if (x == null)
                                {
                                    // nothing to process
                                    continue;
                                }

                                // proceed with the recursion
                                ExecuteFormatControl(level.NextLevel, cpt.control, PSObject.AsPSObject(x), fe.formatValueList);
                            }
                        }
                        else
                        {
                            // proceed with the recursion
                            ExecuteFormatControl(level.NextLevel, cpt.control, PSObjectHelper.AsPSObject(val), fe.formatValueList);
                        }
                    }
                }
                #endregion CompoundPropertyToken
            }
            #endregion foreach loop
        }