Esempio n. 1
0
        public Collection <FormatData> Process(PSObject psobj)
        {
            var formatData = new Collection <FormatData>();

            if (psobj.BaseObject is FormatData)
            {
                formatData.Add((FormatData)psobj.BaseObject);
                return(formatData);
            }
            if (_generator == null)
            {
                if (Shape.Equals(FormatShape.Undefined))
                {
                    Shape = FormatShapeHelper.SelectByData(psobj);
                }
                _generator = FormatGenerator.Get(_executionContext, Shape, Options);
            }
            // check if we have a simple type or an error type. if yes, then we don't need a document structure
            if (psobj.BaseObject == null || psobj.BaseObject.GetType().IsSimple())
            {
                formatData.Add(_generator.GenerateSimpleFormatEntry(psobj));
                return(formatData);
            }
            if (psobj.BaseObject is ErrorRecord || psobj.BaseObject is Exception)
            {
                formatData.Add(_generator.GenerateErrorFormatEntry(psobj));
                return(formatData);
            }

            // object to be printed get a complete document structure
            if (_state.Equals(FormattingState.FormatEnd))
            {
                formatData.Add(_generator.GenerateFormatStart());
                _state = FormattingState.FormatStart;
            }
            if (_state.Equals(FormattingState.GroupStart) && ShouldChangeGroup(psobj))
            {
                formatData.Add(_generator.GenerateGroupEnd());
                _state = FormattingState.GroupEnd;
            }
            if (_state.Equals(FormattingState.GroupEnd) || _state.Equals(FormattingState.FormatStart))
            {
                formatData.Add(_generator.GenerateGroupStart(psobj));
                _state = FormattingState.GroupStart;
            }
            // we have to be in the state GroupStart where we can write the data itself
            formatData.Add(_generator.GenerateObjectFormatEntry(psobj));
            return(formatData);
        }
Esempio n. 2
0
        public Collection <FormatData> End()
        {
            var formatData = new Collection <FormatData>();

            if (_state.Equals(FormattingState.GroupStart))
            {
                // generator cannot be null
                formatData.Add(_generator.GenerateGroupEnd());
                _state = FormattingState.GroupEnd;
            }
            if (_state.Equals(FormattingState.GroupEnd) || _state.Equals(FormattingState.FormatStart))
            {
                formatData.Add(_generator.GenerateFormatEnd());
                _state = FormattingState.FormatEnd;
            }
            return(formatData);
        }