/// <summary>
        /// inject the start group information
        /// and push group context on stack
        /// </summary>
        /// <param name="firstObjectInGroup">current pipeline object
        /// that is starting the group</param>
        private void PushGroup(PSObject firstObjectInGroup)
        {
            GroupStartData startGroup = _viewManager.ViewGenerator.GenerateGroupStartData(firstObjectInGroup, _enumerationLimit);

            this.WriteObject(startGroup);
            contextManager.Push(FormattingContextState.group);
        }
        private void PushGroup(PSObject firstObjectInGroup)
        {
            GroupStartData o = this.viewManager.ViewGenerator.GenerateGroupStartData(firstObjectInGroup, this.enumerationLimit);

            this.WriteObject(o);
            base.contextManager.Push(new InnerFormatShapeCommandBase.FormattingContext(InnerFormatShapeCommandBase.FormattingContext.State.group));
        }
Example #3
0
        internal GroupStartData GenerateGroupStartData(PSObject firstObjectInGroup, int enumerationLimit)
        {
            GroupStartData data = new GroupStartData();

            if (this.groupingManager != null)
            {
                object currentGroupingKeyPropertyValue = this.groupingManager.CurrentGroupingKeyPropertyValue;
                if (currentGroupingKeyPropertyValue == AutomationNull.Value)
                {
                    return(data);
                }
                PSObject    so      = PSObjectHelper.AsPSObject(currentGroupingKeyPropertyValue);
                ControlBase control = null;
                TextToken   tt      = null;
                if (((this.dataBaseInfo.view != null) && (this.dataBaseInfo.view.groupBy != null)) && (this.dataBaseInfo.view.groupBy.startGroup != null))
                {
                    control = this.dataBaseInfo.view.groupBy.startGroup.control;
                    tt      = this.dataBaseInfo.view.groupBy.startGroup.labelTextToken;
                }
                data.groupingEntry = new GroupingEntry();
                if (control == null)
                {
                    string            textTokenString;
                    StringFormatError formatErrorObject = null;
                    if (this.errorManager.DisplayFormatErrorString)
                    {
                        formatErrorObject = new StringFormatError();
                    }
                    string formatErrorString = PSObjectHelper.SmartToString(so, this.expressionFactory, enumerationLimit, formatErrorObject);
                    if ((formatErrorObject != null) && (formatErrorObject.exception != null))
                    {
                        this.errorManager.LogStringFormatError(formatErrorObject);
                        if (this.errorManager.DisplayFormatErrorString)
                        {
                            formatErrorString = this.errorManager.FormatErrorString;
                        }
                    }
                    FormatEntry item = new FormatEntry();
                    data.groupingEntry.formatValueList.Add(item);
                    FormatTextField field = new FormatTextField();
                    if (tt != null)
                    {
                        textTokenString = this.dataBaseInfo.db.displayResourceManagerCache.GetTextTokenString(tt);
                    }
                    else
                    {
                        textTokenString = this.groupingManager.GroupingKeyDisplayName;
                    }
                    field.text = StringUtil.Format(FormatAndOut_format_xxx.GroupStartDataIndentedAutoGeneratedLabel, textTokenString);
                    item.formatValueList.Add(field);
                    FormatPropertyField field2 = new FormatPropertyField {
                        propertyValue = formatErrorString
                    };
                    item.formatValueList.Add(field2);
                    return(data);
                }
                new ComplexControlGenerator(this.dataBaseInfo.db, this.dataBaseInfo.view.loadingInfo, this.expressionFactory, this.dataBaseInfo.view.formatControlDefinitionHolder.controlDefinitionList, this.ErrorManager, enumerationLimit, this.errorContext).GenerateFormatEntries(50, control, firstObjectInGroup, data.groupingEntry.formatValueList);
            }
            return(data);
        }
Example #4
0
        /// <summary>
        /// class factory for output context
        /// </summary>
        /// <param name="parentContext">parent context in the stack</param>
        /// <param name="formatInfoData"> fromat info data received from the pipeline</param>
        /// <returns></returns>
        private FormatMessagesContextManager.OutputContext CreateOutputContext(
            FormatMessagesContextManager.OutputContext parentContext,
            FormatInfoData formatInfoData)
        {
            FormatStartData formatStartData = formatInfoData as FormatStartData;

            // initialize the format context
            if (formatStartData != null)
            {
                FormatOutputContext foc = new FormatOutputContext(parentContext, formatStartData);

                return(foc);
            }

            GroupStartData gsd = formatInfoData as GroupStartData;

            // we are starting a group, initialize the group context
            if (gsd != null)
            {
                GroupOutputContext goc = null;

                switch (ActiveFormattingShape)
                {
                case FormatShape.Table:
                {
                    goc = new TableOutputContext(this, parentContext, gsd);
                    break;
                }

                case FormatShape.List:
                {
                    goc = new ListOutputContext(this, parentContext, gsd);
                    break;
                }

                case FormatShape.Wide:
                {
                    goc = new WideOutputContext(this, parentContext, gsd);
                    break;
                }

                case FormatShape.Complex:
                {
                    goc = new ComplexOutputContext(this, parentContext, gsd);
                    break;
                }

                default:
                {
                    Diagnostics.Assert(false, "Invalid shape. This should never happen");
                }
                break;
                }
                goc.Initialize();
                return(goc);
            }

            return(null);
        }
Example #5
0
 internal GroupStartData GenerateGroupStartData(PSObject firstObjectInGroup, int enumerationLimit)
 {
     GroupStartData data = new GroupStartData();
     if (this.groupingManager != null)
     {
         object currentGroupingKeyPropertyValue = this.groupingManager.CurrentGroupingKeyPropertyValue;
         if (currentGroupingKeyPropertyValue == AutomationNull.Value)
         {
             return data;
         }
         PSObject so = PSObjectHelper.AsPSObject(currentGroupingKeyPropertyValue);
         ControlBase control = null;
         TextToken tt = null;
         if (((this.dataBaseInfo.view != null) && (this.dataBaseInfo.view.groupBy != null)) && (this.dataBaseInfo.view.groupBy.startGroup != null))
         {
             control = this.dataBaseInfo.view.groupBy.startGroup.control;
             tt = this.dataBaseInfo.view.groupBy.startGroup.labelTextToken;
         }
         data.groupingEntry = new GroupingEntry();
         if (control == null)
         {
             string textTokenString;
             StringFormatError formatErrorObject = null;
             if (this.errorManager.DisplayFormatErrorString)
             {
                 formatErrorObject = new StringFormatError();
             }
             string formatErrorString = PSObjectHelper.SmartToString(so, this.expressionFactory, enumerationLimit, formatErrorObject);
             if ((formatErrorObject != null) && (formatErrorObject.exception != null))
             {
                 this.errorManager.LogStringFormatError(formatErrorObject);
                 if (this.errorManager.DisplayFormatErrorString)
                 {
                     formatErrorString = this.errorManager.FormatErrorString;
                 }
             }
             FormatEntry item = new FormatEntry();
             data.groupingEntry.formatValueList.Add(item);
             FormatTextField field = new FormatTextField();
             if (tt != null)
             {
                 textTokenString = this.dataBaseInfo.db.displayResourceManagerCache.GetTextTokenString(tt);
             }
             else
             {
                 textTokenString = this.groupingManager.GroupingKeyDisplayName;
             }
             field.text = StringUtil.Format(FormatAndOut_format_xxx.GroupStartDataIndentedAutoGeneratedLabel, textTokenString);
             item.formatValueList.Add(field);
             FormatPropertyField field2 = new FormatPropertyField {
                 propertyValue = formatErrorString
             };
             item.formatValueList.Add(field2);
             return data;
         }
         new ComplexControlGenerator(this.dataBaseInfo.db, this.dataBaseInfo.view.loadingInfo, this.expressionFactory, this.dataBaseInfo.view.formatControlDefinitionHolder.controlDefinitionList, this.ErrorManager, enumerationLimit, this.errorContext).GenerateFormatEntries(50, control, firstObjectInGroup, data.groupingEntry.formatValueList);
     }
     return data;
 }
Example #6
0
 /// <summary>
 /// construct a context to push on the stack
 /// </summary>
 internal GroupOutputContext(OutCommandInner cmd,
                             FormatMessagesContextManager.OutputContext parentContext,
                             GroupStartData formatData)
     : base(parentContext)
 {
     InnerCommand = cmd;
     Data         = formatData;
 }
Example #7
0
        private FormatMessagesContextManager.OutputContext CreateOutputContext(FormatMessagesContextManager.OutputContext parentContext, FormatInfoData formatInfoData)
        {
            FormatStartData formatData = formatInfoData as FormatStartData;

            if (formatData != null)
            {
                return(new FormatOutputContext(parentContext, formatData));
            }
            GroupStartData data2 = formatInfoData as GroupStartData;

            if (data2 == null)
            {
                return(null);
            }
            GroupOutputContext context2 = null;

            switch (this.ActiveFormattingShape)
            {
            case FormatShape.Table:
                context2 = new TableOutputContext(this, parentContext, data2);
                break;

            case FormatShape.List:
                context2 = new ListOutputContext(this, parentContext, data2);
                break;

            case FormatShape.Wide:
                context2 = new WideOutputContext(this, parentContext, data2);
                break;

            case FormatShape.Complex:
                context2 = new ComplexOutputContext(this, parentContext, data2);
                break;
            }
            context2.Initialize();
            return(context2);
        }
 /// <summary>
 /// construct a context to push on the stack
 /// </summary>
 /// <param name="cmd">reference to the OutCommandInner instance who owns this instance</param>
 /// <param name="parentContext">parent context in the stack</param>
 /// <param name="formatData">format data to put in the context</param>
 internal TableOutputContext(OutCommandInner cmd,
     FormatMessagesContextManager.OutputContext parentContext,
     GroupStartData formatData)
     : base(cmd, parentContext, formatData)
 {
 }
 /// <summary>
 /// construct a context to push on the stack
 /// </summary>
 internal GroupOutputContext(OutCommandInner cmd,
                         FormatMessagesContextManager.OutputContext parentContext,
                         GroupStartData formatData)
     : base(parentContext)
 {
     InnerCommand = cmd;
     Data = formatData;
 }
Example #10
0
 /// <summary>
 /// construct a context to push on the stack
 /// </summary>
 /// <param name="cmd">reference to the OutCommandInner instance who owns this instance</param>
 /// <param name="parentContext">parent context in the stack</param>
 /// <param name="formatData">format data to put in the context</param>
 internal TableOutputContext(OutCommandInner cmd,
                             FormatMessagesContextManager.OutputContext parentContext,
                             GroupStartData formatData)
     : base(cmd, parentContext, formatData)
 {
 }
        internal GroupStartData GenerateGroupStartData(PSObject firstObjectInGroup, int enumerationLimit)
        {
            GroupStartData startGroup = new GroupStartData();

            if (_groupingManager is 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 is 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);
        }
Example #12
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;
        }
Example #13
0
 internal TableOutputContextBase(OutCommandInner cmd, FormatMessagesContextManager.OutputContext parentContext, GroupStartData formatData) : base(cmd, parentContext, formatData)
 {
     this.tableWriter = new TableWriter();
 }
Example #14
0
 internal ListOutputContext(OutCommandInner cmd, FormatMessagesContextManager.OutputContext parentContext, GroupStartData formatData) : base(cmd, parentContext, formatData)
 {
     this.listWriter = new ListWriter();
 }
Example #15
0
 internal TableOutputContextBase(OutCommandInner cmd, FormatMessagesContextManager.OutputContext parentContext, GroupStartData formatData) : base(cmd, parentContext, formatData)
 {
     this.tableWriter = new TableWriter();
 }
Example #16
0
 internal ListOutputContext(OutCommandInner cmd, FormatMessagesContextManager.OutputContext parentContext, GroupStartData formatData) : base(cmd, parentContext, formatData)
 {
     this.listWriter = new ListWriter();
 }