Esempio n. 1
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;
 }
Esempio n. 2
0
 internal static string GetControlShapeName(ControlBase control)
 {
     if (control is TableControlBody)
     {
         return FormatShape.Table.ToString();
     }
     if (control is ListControlBody)
     {
         return FormatShape.List.ToString();
     }
     if (control is WideControlBody)
     {
         return FormatShape.Wide.ToString();
     }
     if (control is ComplexControlBody)
     {
         return FormatShape.Complex.ToString();
     }
     return "";
 }
Esempio n. 3
0
 internal void GenerateFormatEntries(int maxTreeDepth, ControlBase control, PSObject so, List<FormatValue> formatValueList)
 {
     if (control == null)
     {
         throw PSTraceSource.NewArgumentNullException("control");
     }
     this.ExecuteFormatControl(new TraversalInfo(0, maxTreeDepth), control, so, formatValueList);
 }
Esempio n. 4
0
 internal bool ProcessNode(System.Xml.XmlNode n)
 {
     if (this._loader.MatchNodeName(n, "CustomControl"))
     {
         this._control = this._loader.LoadComplexControl(n);
         return true;
     }
     if (this._loader.MatchNodeName(n, "CustomControlName"))
     {
         string mandatoryInnerText = this._loader.GetMandatoryInnerText(n);
         if (mandatoryInnerText == null)
         {
             return false;
         }
         ControlReference reference = new ControlReference {
             name = mandatoryInnerText,
             controlType = typeof(ComplexControlBody)
         };
         this._control = reference;
         return true;
     }
     PSTraceSource.NewInvalidOperationException();
     return false;
 }
        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;
        }
Esempio n. 6
0
        private static ViewDefinition GetView(PSPropertyExpressionFactory expressionFactory, TypeInfoDataBase db, System.Type mainControlType, Collection <string> typeNames, string viewName)
        {
            TypeMatch match = new TypeMatch(expressionFactory, db, typeNames);

            foreach (ViewDefinition vd in db.viewDefinitionsSection.viewDefinitionList)
            {
                if (vd == null || mainControlType != vd.mainControl.GetType())
                {
                    ActiveTracer.WriteLine(
                        "NOT MATCH {0}  NAME: {1}",
                        ControlBase.GetControlShapeName(vd.mainControl), (vd != null ? vd.name : string.Empty));
                    continue;
                }

                if (IsOutOfBandView(vd))
                {
                    ActiveTracer.WriteLine(
                        "NOT MATCH OutOfBand {0}  NAME: {1}",
                        ControlBase.GetControlShapeName(vd.mainControl), vd.name);
                    continue;
                }

                if (vd.appliesTo == null)
                {
                    ActiveTracer.WriteLine(
                        "NOT MATCH {0}  NAME: {1}  No applicable types",
                        ControlBase.GetControlShapeName(vd.mainControl), vd.name);
                    continue;
                }
                // first make sure we match on name:
                // if not, we do not try a match at all
                if (viewName != null && !string.Equals(vd.name, viewName, StringComparison.OrdinalIgnoreCase))
                {
                    ActiveTracer.WriteLine(
                        "NOT MATCH {0}  NAME: {1}",
                        ControlBase.GetControlShapeName(vd.mainControl), vd.name);
                    continue;
                }

                // check if we have a perfect match
                // if so, we are done
                try
                {
                    TypeMatch.SetTracer(ActiveTracer);
                    if (match.PerfectMatch(new TypeMatchItem(vd, vd.appliesTo)))
                    {
                        TraceHelper(vd, true);
                        return(vd);
                    }
                }
                finally
                {
                    TypeMatch.ResetTracer();
                }

                TraceHelper(vd, false);
            }

            // this is the best match we had
            ViewDefinition result = GetBestMatch(match);

            // we were unable to find a best match so far..try
            // to get rid of Deserialization prefix and see if a
            // match can be found.
            if (result == null)
            {
                Collection <string> typesWithoutPrefix = Deserializer.MaskDeserializationPrefix(typeNames);
                if (typesWithoutPrefix != null)
                {
                    result = GetView(expressionFactory, db, mainControlType, typesWithoutPrefix, viewName);
                }
            }

            return(result);
        }
Esempio n. 7
0
        internal GroupStartData GenerateGroupStartData(PSObject firstObjectInGroup, int enumerationLimit)
        {
            GroupStartData startGroup = new GroupStartData();

            if (_groupingManager == null)
            {
                return(startGroup);
            }

            object currentGroupingValue = _groupingManager.CurrentGroupingKeyPropertyValue;

            if (currentGroupingValue == AutomationNull.Value)
            {
                return(startGroup);
            }

            PSObject so = PSObjectHelper.AsPSObject(currentGroupingValue);

            // we need to determine how to display the group header
            ControlBase control        = null;
            TextToken   labelTextToken = null;

            if (this.dataBaseInfo.view != null && this.dataBaseInfo.view.groupBy != null)
            {
                if (this.dataBaseInfo.view.groupBy.startGroup != null)
                {
                    // NOTE: from the database constraints, only one of the
                    // two will be non null
                    control        = this.dataBaseInfo.view.groupBy.startGroup.control;
                    labelTextToken = this.dataBaseInfo.view.groupBy.startGroup.labelTextToken;
                }
            }

            startGroup.groupingEntry = new GroupingEntry();

            if (control == null)
            {
                // we do not have a control, we auto generate a
                // snippet of complex display using a label

                StringFormatError formatErrorObject = null;
                if (_errorManager.DisplayFormatErrorString)
                {
                    // we send a format error object down to the formatting calls
                    // only if we want to show the formatting error strings
                    formatErrorObject = new StringFormatError();
                }

                string currentGroupingValueDisplay = PSObjectHelper.SmartToString(so, this.expressionFactory, enumerationLimit, formatErrorObject);

                if (formatErrorObject != null && formatErrorObject.exception != null)
                {
                    // if we did no thave any errors in the expression evaluation
                    // we might have errors in the formatting, if present
                    _errorManager.LogStringFormatError(formatErrorObject);
                    if (_errorManager.DisplayFormatErrorString)
                    {
                        currentGroupingValueDisplay = _errorManager.FormatErrorString;
                    }
                }

                FormatEntry fe = new FormatEntry();
                startGroup.groupingEntry.formatValueList.Add(fe);

                FormatTextField ftf = new FormatTextField();

                // determine what the label should be. If we have a label from the
                // database, let's use it, else fall back to the string provided
                // by the grouping manager
                string label;
                if (labelTextToken != null)
                {
                    label = this.dataBaseInfo.db.displayResourceManagerCache.GetTextTokenString(labelTextToken);
                }
                else
                {
                    label = _groupingManager.GroupingKeyDisplayName;
                }

                ftf.text = StringUtil.Format(FormatAndOut_format_xxx.GroupStartDataIndentedAutoGeneratedLabel, label);

                fe.formatValueList.Add(ftf);

                FormatPropertyField fpf = new FormatPropertyField();

                fpf.propertyValue = currentGroupingValueDisplay;
                fe.formatValueList.Add(fpf);
            }
            else
            {
                // NOTE: we set a max depth to protect ourselves from infinite loops
                const int maxTreeDepth = 50;
                ComplexControlGenerator controlGenerator =
                    new ComplexControlGenerator(this.dataBaseInfo.db,
                                                this.dataBaseInfo.view.loadingInfo,
                                                this.expressionFactory,
                                                this.dataBaseInfo.view.formatControlDefinitionHolder.controlDefinitionList,
                                                this.ErrorManager,
                                                enumerationLimit,
                                                this.errorContext);

                controlGenerator.GenerateFormatEntries(maxTreeDepth,
                                                       control, firstObjectInGroup, startGroup.groupingEntry.formatValueList);
            }

            return(startGroup);
        }