Ejemplo n.º 1
0
 internal List<PacketInfoData> Add(PacketInfoData o)
 {
     FormatStartData data = o as FormatStartData;
     if (data != null)
     {
         this.formatStartData = data;
     }
     this.UpdateObjectCount(o);
     if (!this.processingGroup && (o is GroupStartData))
     {
         this.processingGroup = true;
         this.currentObjectCount = 0;
         this.queue.Enqueue(o);
         return null;
     }
     if (this.processingGroup && ((o is GroupEndData) || ((this.objectCount > 0) && (this.currentObjectCount >= this.objectCount))))
     {
         this.currentObjectCount = 0;
         this.queue.Enqueue(o);
         this.Notify();
         this.processingGroup = false;
         List<PacketInfoData> list = new List<PacketInfoData>();
         while (this.queue.Count > 0)
         {
             list.Add(this.queue.Dequeue());
         }
         return list;
     }
     if (this.processingGroup)
     {
         this.queue.Enqueue(o);
         return null;
     }
     return new List<PacketInfoData> { o };
 }
Ejemplo n.º 2
0
        internal override FormatStartData GenerateStartData(PSObject so)
        {
            FormatStartData data = base.GenerateStartData(so);

            data.shapeInfo = new ListViewHeaderInfo();
            return(data);
        }
Ejemplo n.º 3
0
        private bool ProcessObject(PSObject so)
        {
            object o = this.formatObjectDeserializer.Deserialize(so);

            if (this.NeedsPreprocessing(o))
            {
                return(false);
            }
            if (this.cache == null)
            {
                this.cache = new FormattedObjectsCache(this.LineOutput.RequiresBuffering);
            }
            FormatStartData data = o as FormatStartData;

            if ((data != null) && (data.autosizeInfo != null))
            {
                FormattedObjectsCache.ProcessCachedGroupNotification callBack = new FormattedObjectsCache.ProcessCachedGroupNotification(this.ProcessCachedGroup);
                this.cache.EnableGroupCaching(callBack, data.autosizeInfo.objectCount);
            }
            List <PacketInfoData> list = this.cache.Add((PacketInfoData)o);

            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    this.ctxManager.Process(list[i]);
                }
            }
            return(true);
        }
Ejemplo n.º 4
0
        internal override FormatStartData GenerateStartData(PSObject so)
        {
            FormatStartData startFormat = base.GenerateStartData(so);

            startFormat.shapeInfo = new ComplexViewHeaderInfo();
            return(startFormat);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        internal virtual FormatStartData GenerateStartData(PSObject so)
        {
            FormatStartData data = new FormatStartData();

            if (this.autosize)
            {
                data.autosizeInfo = new AutosizeInfo();
            }
            return(data);
        }
Ejemplo n.º 7
0
        internal virtual FormatStartData GenerateStartData(PSObject so)
        {
            FormatStartData startFormat = new FormatStartData();

            if (_autosize)
            {
                startFormat.autosizeInfo = new AutosizeInfo();
            }
            return(startFormat);
        }
Ejemplo n.º 8
0
        private bool ProcessObject(PSObject so)
        {
            object o = _formatObjectDeserializer.Deserialize(so);

            //Console.WriteLine("OutCommandInner.Execute() retrieved object {0}, of type {1}", o.ToString(), o.GetType());
            if (NeedsPreprocessing(o))
            {
                return(false);
            }

            // instantiate the cache if not done yet
            if (_cache == null)
            {
                _cache = new FormattedObjectsCache(this.LineOutput.RequiresBuffering);
            }

            // no need for formatting, just process the object
            FormatStartData formatStart = o as FormatStartData;

            if (formatStart != null)
            {
                // get autosize flag from object
                // turn on group caching
                if (formatStart.autosizeInfo != null)
                {
                    FormattedObjectsCache.ProcessCachedGroupNotification callBack = new FormattedObjectsCache.ProcessCachedGroupNotification(ProcessCachedGroup);
                    _cache.EnableGroupCaching(callBack, formatStart.autosizeInfo.objectCount);
                }
                else
                {
                    // If the format info doesn't define column widths, then auto-size based on the first ten elements
                    TableHeaderInfo headerInfo = formatStart.shapeInfo as TableHeaderInfo;
                    if ((headerInfo != null) &&
                        (headerInfo.tableColumnInfoList.Count > 0) &&
                        (headerInfo.tableColumnInfoList[0].width == 0))
                    {
                        FormattedObjectsCache.ProcessCachedGroupNotification callBack = new FormattedObjectsCache.ProcessCachedGroupNotification(ProcessCachedGroup);
                        _cache.EnableGroupCaching(callBack, TimeSpan.FromMilliseconds(300));
                    }
                }
            }

            //Console.WriteLine("OutCommandInner.Execute() calling ctxManager.Process({0})",o.ToString());
            List <PacketInfoData> info = _cache.Add((PacketInfoData)o);

            if (info != null)
            {
                for (int k = 0; k < info.Count; k++)
                {
                    _ctxManager.Process(info[k]);
                }
            }
            return(true);
        }
Ejemplo n.º 9
0
        internal override FormatStartData GenerateStartData(PSObject so)
        {
            FormatStartData data = base.GenerateStartData(so);

            if (base.dataBaseInfo.view != null)
            {
                data.shapeInfo = this.GenerateTableHeaderInfoFromDataBaseInfo(so);
                return(data);
            }
            data.shapeInfo = this.GenerateTableHeaderInfoFromProperties(so);
            return(data);
        }
Ejemplo n.º 10
0
        internal override FormatStartData GenerateStartData(PSObject so)
        {
            FormatStartData    data = base.GenerateStartData(so);
            WideViewHeaderInfo info = new WideViewHeaderInfo();

            data.shapeInfo = info;
            if (!base.AutoSize)
            {
                info.columns = this.Columns;
                return(data);
            }
            info.columns = 0;
            return(data);
        }
        internal override FormatStartData GenerateStartData(PSObject so)
        {
            FormatStartData startFormat = base.GenerateStartData(so);

            if (this.dataBaseInfo.view != null)
            {
                startFormat.shapeInfo = GenerateTableHeaderInfoFromDataBaseInfo(so);
            }
            else
            {
                startFormat.shapeInfo = GenerateTableHeaderInfoFromProperties(so);
            }
            return(startFormat);
        }
Ejemplo n.º 12
0
        private void ProcessCachedGroup(FormatStartData formatStartData, List <PacketInfoData> objects)
        {
            this.formattingHint = null;
            TableHeaderInfo shapeInfo = formatStartData.shapeInfo as TableHeaderInfo;

            if (shapeInfo != null)
            {
                this.ProcessCachedGroupOnTable(shapeInfo, objects);
            }
            else
            {
                WideViewHeaderInfo wvhi = formatStartData.shapeInfo as WideViewHeaderInfo;
                if (wvhi != null)
                {
                    this.ProcessCachedGroupOnWide(wvhi, objects);
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// handler for processing the caching notification and responsible for
        /// setting the value of the formatting hint
        /// </summary>
        /// <param name="formatStartData"></param>
        /// <param name="objects"></param>
        private void ProcessCachedGroup(FormatStartData formatStartData, List <PacketInfoData> objects)
        {
            _formattingHint = null;

            TableHeaderInfo thi = formatStartData.shapeInfo as TableHeaderInfo;

            if (thi != null)
            {
                ProcessCachedGroupOnTable(thi, objects);
                return;
            }

            WideViewHeaderInfo wvhi = formatStartData.shapeInfo as WideViewHeaderInfo;

            if (wvhi != null)
            {
                ProcessCachedGroupOnWide(wvhi, objects);
                return;
            }
        }
Ejemplo n.º 14
0
        internal override FormatStartData GenerateStartData(PSObject so)
        {
            FormatStartData startFormat = base.GenerateStartData(so);

            WideViewHeaderInfo wideViewHeaderInfo = new WideViewHeaderInfo();

            startFormat.shapeInfo = wideViewHeaderInfo;

            if (!this.AutoSize)
            {
                // autosize overrides columns
                wideViewHeaderInfo.columns = this.Columns;
            }
            else
            {
                wideViewHeaderInfo.columns = 0;
            }

            return(startFormat);
        }
Ejemplo n.º 15
0
        internal List <PacketInfoData> Add(PacketInfoData o)
        {
            FormatStartData data = o as FormatStartData;

            if (data != null)
            {
                this.formatStartData = data;
            }
            this.UpdateObjectCount(o);
            if (!this.processingGroup && (o is GroupStartData))
            {
                this.processingGroup    = true;
                this.currentObjectCount = 0;
                this.queue.Enqueue(o);
                return(null);
            }
            if (this.processingGroup && ((o is GroupEndData) || ((this.objectCount > 0) && (this.currentObjectCount >= this.objectCount))))
            {
                this.currentObjectCount = 0;
                this.queue.Enqueue(o);
                this.Notify();
                this.processingGroup = false;
                List <PacketInfoData> list = new List <PacketInfoData>();
                while (this.queue.Count > 0)
                {
                    list.Add(this.queue.Dequeue());
                }
                return(list);
            }
            if (this.processingGroup)
            {
                this.queue.Enqueue(o);
                return(null);
            }
            return(new List <PacketInfoData> {
                o
            });
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// add an object to the cache.
        /// </summary>
        /// <param name="o">Object to add.</param>
        /// <returns>Objects the cache needs to return. It can be null.</returns>
        internal List <PacketInfoData> Add(PacketInfoData o)
        {
            FormatStartData fsd = o as FormatStartData;

            if (fsd != null)
            {
                // just cache the reference (used during the notification call)
                _formatStartData = fsd;
            }

            UpdateObjectCount(o);

            // STATE TRANSITION: we are not processing and we start
            if (!_processingGroup && (o is GroupStartData))
            {
                // just set the flag and start caching
                _processingGroup    = true;
                _currentObjectCount = 0;

                if (_groupingDuration > TimeSpan.MinValue)
                {
                    _groupingTimer = Stopwatch.StartNew();
                }

                _queue.Enqueue(o);
                return(null);
            }

            // STATE TRANSITION: we are processing and we stop
            if (_processingGroup &&
                ((o is GroupEndData) ||
                 (_objectCount > 0) && (_currentObjectCount >= _objectCount)) ||
                ((_groupingTimer != null) && (_groupingTimer.Elapsed > _groupingDuration))
                )
            {
                // reset the object count
                _currentObjectCount = 0;

                if (_groupingTimer != null)
                {
                    _groupingTimer.Stop();
                    _groupingTimer = null;
                }

                // add object to queue, to be picked up
                _queue.Enqueue(o);

                // we are at the end of a group, drain the queue
                Notify();
                _processingGroup = false;

                List <PacketInfoData> retVal = new List <PacketInfoData>();

                while (_queue.Count > 0)
                {
                    retVal.Add(_queue.Dequeue());
                }

                return(retVal);
            }

            // NO STATE TRANSITION: check the state we are in
            if (_processingGroup)
            {
                // we are in the caching state
                _queue.Enqueue(o);
                return(null);
            }

            // we are not processing, so just return it
            List <PacketInfoData> ret = new List <PacketInfoData>();

            ret.Add(o);
            return(ret);
        }
Ejemplo n.º 18
0
 /// <summary>
 /// construct a context to push on the stack
 /// </summary>
 /// <param name="parentContext">parent context in the stack</param>
 /// <param name="formatData">format data to put in the context</param>
 internal FormatOutputContext(FormatMessagesContextManager.OutputContext parentContext, FormatStartData formatData)
     : base(parentContext)
 {
     Data = formatData;
 }
Ejemplo n.º 19
0
        /// <summary>
        /// handler for processing the caching notification and responsible for 
        /// setting the value of the formatting hint
        /// </summary>
        /// <param name="formatStartData"></param>
        /// <param name="objects"></param>
        private void ProcessCachedGroup(FormatStartData formatStartData, List<PacketInfoData> objects)
        {
            _formattingHint = null;

            TableHeaderInfo thi = formatStartData.shapeInfo as TableHeaderInfo;

            if (thi != null)
            {
                ProcessCachedGroupOnTable(thi, objects);
                return;
            }

            WideViewHeaderInfo wvhi = formatStartData.shapeInfo as WideViewHeaderInfo;

            if (wvhi != null)
            {
                ProcessCachedGroupOnWide(wvhi, objects);
                return;
            }
        }
Ejemplo n.º 20
0
        private void WriteFormatStartData(PSObject so)
        {
            FormatStartData startFormat = _viewManager.ViewGenerator.GenerateStartData(so);

            this.WriteObject(startFormat);
        }
Ejemplo n.º 21
0
 /// <summary>
 /// construct a context to push on the stack
 /// </summary>
 /// <param name="parentContext">parent context in the stack</param>
 /// <param name="formatData">format data to put in the context</param>
 internal FormatOutputContext(FormatMessagesContextManager.OutputContext parentContext, FormatStartData formatData)
     : base(parentContext)
 {
     Data = formatData;
 }
Ejemplo n.º 22
0
 internal virtual FormatStartData GenerateStartData(PSObject so)
 {
     FormatStartData data = new FormatStartData();
     if (this.autosize)
     {
         data.autosizeInfo = new AutosizeInfo();
     }
     return data;
 }
Ejemplo n.º 23
0
 private void ProcessCachedGroup(FormatStartData formatStartData, List<PacketInfoData> objects)
 {
     this.formattingHint = null;
     TableHeaderInfo shapeInfo = formatStartData.shapeInfo as TableHeaderInfo;
     if (shapeInfo != null)
     {
         this.ProcessCachedGroupOnTable(shapeInfo, objects);
     }
     else
     {
         WideViewHeaderInfo wvhi = formatStartData.shapeInfo as WideViewHeaderInfo;
         if (wvhi != null)
         {
             this.ProcessCachedGroupOnWide(wvhi, objects);
         }
     }
 }
Ejemplo n.º 24
0
        internal virtual FormatStartData GenerateStartData(PSObject so)
        {
            FormatStartData startFormat = new FormatStartData();

            if (_autosize)
            {
                startFormat.autosizeInfo = new AutosizeInfo();
            }
            return startFormat;
        }