Example #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);
        }
Example #2
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;
        }
Example #3
0
 public static FormatGenerator Get(ExecutionContext context, FormatShape shape, FormatGeneratorOptions options)
 {
     if (_lastGenerator != null && _lastGenerator.Shape.Equals(shape) && _lastGenerator.Options.Equals(options))
     {
         return _lastGenerator;
     }
     switch (shape)
     {
         case FormatShape.List:
             _lastGenerator = new ListFormatGenerator(context, options);
             break;
         case FormatShape.Table:
             _lastGenerator = new TableFormatGenerator(context, options);
             break;
         default:
             throw new PSInvalidOperationException("Cannot get a FormatGenerator with undefined shape");
     }
     return _lastGenerator;
 }
Example #4
0
        public static FormatGenerator Get(ExecutionContext context, FormatShape shape, FormatGeneratorOptions options)
        {
            if (_lastGenerator != null && _lastGenerator.Shape.Equals(shape) && _lastGenerator.Options.Equals(options))
            {
                return(_lastGenerator);
            }
            switch (shape)
            {
            case FormatShape.List:
                _lastGenerator = new ListFormatGenerator(context, options);
                break;

            case FormatShape.Table:
                _lastGenerator = new TableFormatGenerator(context, options);
                break;

            default:
                throw new PSInvalidOperationException("Cannot get a FormatGenerator with undefined shape");
            }
            return(_lastGenerator);
        }