예제 #1
0
 private void WriteHeader(TableFormatEntryData tableEntry)
 {
     List<string> values = (from cell in tableEntry.Row select cell.PropertyName).ToList();
     var referenceEntry = new TableFormatEntryData(tableEntry);
     referenceEntry.Wrap = true;
     WriteValuesInRows(values, referenceEntry);
     // now print borders
     StringBuilder line = new StringBuilder(_fullWidth);
     OutputWriter.WriteToErrorStream = referenceEntry.WriteToErrorStream;
     for (int i = 0; i < _currentColumns.Length; i++)
     {
         var cellWidth = _currentColumns[i].Value;
         var curVal = values[i];
         var borderWidth = curVal.Length > cellWidth ? cellWidth : curVal.Length;
         var borderLine = "".PadLeft(borderWidth, '-');
         if (referenceEntry.Row[i].Align.Equals(Alignment.Right))
         {
             borderLine = borderLine.PadLeft(cellWidth);
         }
         else
         {
             borderLine = borderLine.PadRight(cellWidth);
         }
         line.Append(borderLine);
         if (i < values.Count - 1)
         {
             line.Append(" ");
         }
     }
     OutputWriter.WriteLine(line.ToString());
 }
예제 #2
0
        private void WriteHeader(TableFormatEntryData tableEntry)
        {
            List <string> values         = (from cell in tableEntry.Row select cell.PropertyName).ToList();
            var           referenceEntry = new TableFormatEntryData(tableEntry);

            referenceEntry.Wrap = true;
            WriteValuesInRows(values, referenceEntry);
            // now print borders
            StringBuilder line = new StringBuilder(_fullWidth);

            OutputWriter.WriteToErrorStream = referenceEntry.WriteToErrorStream;
            for (int i = 0; i < _currentColumns.Length; i++)
            {
                var cellWidth   = _currentColumns[i].Value;
                var curVal      = values[i];
                var borderWidth = curVal.Length > cellWidth ? cellWidth : curVal.Length;
                var borderLine  = "".PadLeft(borderWidth, '-');
                if (referenceEntry.Row[i].Align.Equals(Alignment.Right))
                {
                    borderLine = borderLine.PadLeft(cellWidth);
                }
                else
                {
                    borderLine = borderLine.PadRight(cellWidth);
                }
                line.Append(borderLine);
                if (i < values.Count - 1)
                {
                    line.Append(" ");
                }
            }
            OutputWriter.WriteLine(line.ToString());
        }
예제 #3
0
        private void WriteValuesInRows(List <string> originalValues, TableFormatEntryData referenceEntry)
        {
            StringBuilder line   = new StringBuilder(_fullWidth);
            var           values = originalValues.ToArray();

            OutputWriter.WriteToErrorStream = referenceEntry.WriteToErrorStream;
            var printOneMoreLine = true;

            while (printOneMoreLine)
            {
                printOneMoreLine = false;
                for (int i = 0; i < _currentColumns.Length; i++)
                {
                    var    alignRight = referenceEntry.Row[i].Align.Equals(Alignment.Right);
                    string rest;
                    line.Append(TrimString(values[i], _currentColumns[i].Value, alignRight,
                                           !referenceEntry.Wrap, out rest));
                    values[i]        = referenceEntry.Wrap ? rest : "";
                    printOneMoreLine = printOneMoreLine || (referenceEntry.Wrap && !String.IsNullOrEmpty(rest));
                    // add space between columns
                    if (i < values.Length - 1)
                    {
                        line.Append(" ");
                    }
                }
                OutputWriter.WriteLine(line.ToString());
                line.Clear();
            }
        }
예제 #4
0
        private void WriteRow(TableFormatEntryData tableEntry)
        {
            var rowEntries = new Dictionary <string, string>();

            foreach (var cell in tableEntry.Row)
            {
                rowEntries[cell.PropertyName] = cell.Value;
            }
            var values = (from column in _currentColumns
                          select rowEntries.ContainsKey(column.Key) ? rowEntries[column.Key] : ""
                          ).ToList();

            WriteValuesInRows(values, tableEntry);
        }
예제 #5
0
        public override FormatEntryData GenerateObjectFormatEntry(PSObject data)
        {
            var rowData = GetSelectedProperties(data);
            var row     = new List <FormatObjectProperty>();

            if (_nextWithHeader)
            {
                _currentAlignments = new Dictionary <string, Alignment>(StringComparer.InvariantCultureIgnoreCase);
            }
            for (int i = 0; i < rowData.Count; i++)
            {
                var    curData = rowData[i];
                object value   = null;
                // getting the value might throw an exception, so we just print nothing for it
                try
                {
                    value = PSObject.Unwrap(curData.Value);
                } catch (GetValueException)
                {
                }
                if (_nextWithHeader)
                {
                    Alignment valAlign = Alignment.Left;
                    if (value != null)
                    {
                        valAlign = (value.GetType().IsNumeric() || value is bool) ? Alignment.Right : Alignment.Left;
                    }
                    _currentAlignments[curData.Name] = valAlign;
                }
                var strValue = value == null ? "" : PSObject.AsPSObject(value).ToString();
                var curAlign = _currentAlignments.ContainsKey(curData.Name) ? _currentAlignments[curData.Name]
                                                                             : Alignment.Left;
                row.Add(new FormatObjectProperty(curData.Name, strValue, curAlign));
            }

            var entry = new TableFormatEntryData(row);

            if (_nextWithHeader)
            {
                entry.ShowHeader = !TableOptions.HideTableHeaders;
                _nextWithHeader  = false;
            }
            entry.Wrap = TableOptions.Wrap;
            return(entry);
        }
예제 #6
0
        public override FormatEntryData GenerateObjectFormatEntry(PSObject data)
        {
            var rowData = GetSelectedProperties(data);
            var row     = new List <FormatObjectProperty>();

            if (_nextWithHeader)
            {
                _currentAlignments = new Alignment[rowData.Count];
            }
            for (int i = 0; i < rowData.Count; i++)
            {
                var    curData = rowData[i];
                object value   = null;
                // getting the value might throw an exception, so we just print nothing for it
                try
                {
                    value = PSObject.Unwrap(curData.Value);
                } catch (GetValueException)
                {
                }
                Alignment align = Alignment.Left;
                if (_nextWithHeader)
                {
                    if (value != null)
                    {
                        align = (value.GetType().IsNumeric() || value is bool) ? Alignment.Right : Alignment.Left;
                    }
                    _currentAlignments[i] = align;
                }
                row.Add(new FormatObjectProperty(curData.Name, PSObject.AsPSObject(value).ToString(),
                                                 _currentAlignments[i]));
            }

            var entry = new TableFormatEntryData(row);

            if (_nextWithHeader)
            {
                entry.ShowHeader = !TableOptions.HideTableHeaders;
                _nextWithHeader  = false;
            }
            entry.Wrap = TableOptions.Wrap;
            return(entry);
        }
예제 #7
0
        public override FormatEntryData GenerateObjectFormatEntry(PSObject data)
        {
            var rowData= GetSelectedProperties(data);
            var row = new List<FormatObjectProperty>();
            if (_nextWithHeader)
            {
                _currentAlignments = new Dictionary<string, Alignment>(StringComparer.InvariantCultureIgnoreCase);
            }
            for (int i = 0; i < rowData.Count; i++)
            {
                var curData = rowData[i];
                object value = null;
                // getting the value might throw an exception, so we just print nothing for it
                try
                {
                    value = PSObject.Unwrap(curData.Value);
                } catch (GetValueException)
                {
                }
                if (_nextWithHeader)
                {
                    Alignment valAlign = Alignment.Left;
                    if (value != null)
                    {
                        valAlign = (value.GetType().IsNumeric() || value is bool) ? Alignment.Right : Alignment.Left;
                    }
                    _currentAlignments[curData.Name] = valAlign;
                }
                var strValue = value == null ? "" : PSObject.AsPSObject(value).ToString();
                var curAlign = _currentAlignments.ContainsKey(curData.Name) ? _currentAlignments[curData.Name]
                                                                             : Alignment.Left;
                row.Add(new FormatObjectProperty(curData.Name, strValue, curAlign));
            }

            var entry = new TableFormatEntryData(row);
            if (_nextWithHeader)
            {
                entry.ShowHeader = !TableOptions.HideTableHeaders;
                _nextWithHeader = false;
            }
            entry.Wrap = TableOptions.Wrap;
            return entry;
        }
예제 #8
0
 private void WriteValuesInRows(List<string> originalValues, TableFormatEntryData referenceEntry)
 {
     StringBuilder line = new StringBuilder(_fullWidth);
     var values = originalValues.ToArray();
     OutputWriter.WriteToErrorStream = referenceEntry.WriteToErrorStream;
     var printOneMoreLine = true;
     while (printOneMoreLine)
     {
         printOneMoreLine = false;
         for (int i = 0; i < _currentColumns.Length; i++)
         {
             var alignRight = referenceEntry.Row[i].Align.Equals(Alignment.Right);
             string rest;
             line.Append(TrimString(values[i], _currentColumns[i].Value, alignRight,
                                    !referenceEntry.Wrap, out rest));
             values[i] = referenceEntry.Wrap ? rest : "";
             printOneMoreLine = printOneMoreLine || (referenceEntry.Wrap && !String.IsNullOrEmpty(rest));
             // add space between columns
             if (i < values.Length - 1)
             {
                 line.Append(" ");
             }
         }
         OutputWriter.WriteLine(line.ToString());
         line.Clear();
     }
 }
예제 #9
0
 private void WriteRow(TableFormatEntryData tableEntry)
 {
     var rowEntries = new Dictionary<string, string>();
     foreach (var cell in tableEntry.Row)
     {
         rowEntries[cell.PropertyName] = cell.Value;
     }
     var values = (from column in _currentColumns
                   select rowEntries.ContainsKey(column.Key) ? rowEntries[column.Key] : ""
                   ).ToList();
     WriteValuesInRows(values, tableEntry);
 }
예제 #10
0
 internal TableFormatEntryData(TableFormatEntryData entry) : base(entry)
 {
     Row = entry.Row;
     Wrap = entry.Wrap;
     ShowHeader = entry.ShowHeader;
 }
예제 #11
0
        public override FormatEntryData GenerateObjectFormatEntry(PSObject data)
        {
            var rowData= GetSelectedProperties(data);
            var row = new List<FormatObjectProperty>();
            if (_nextWithHeader)
            {
                _currentAlignments = new Alignment[rowData.Count];
            }
            for (int i = 0; i < rowData.Count; i++)
            {
                var curData = rowData[i];
                object value = null;
                // getting the value might throw an exception, so we just print nothing for it
                try
                {
                    value = PSObject.Unwrap(curData.Value);
                } catch (GetValueException)
                {
                }
                Alignment align = Alignment.Left;
                if (_nextWithHeader)
                {
                    if (value != null)
                    {
                        align = (value.GetType().IsNumeric() || value is bool) ? Alignment.Right : Alignment.Left;
                    }
                    _currentAlignments[i] = align;
                }
                row.Add(new FormatObjectProperty(curData.Name, PSObject.AsPSObject(value).ToString(),
                                                 _currentAlignments[i]));
            }

            var entry = new TableFormatEntryData(row);
            if (_nextWithHeader)
            {
                entry.ShowHeader = !TableOptions.HideTableHeaders;
                _nextWithHeader = false;
            }
            entry.Wrap = TableOptions.Wrap;
            return entry;
        }
예제 #12
0
 internal TableFormatEntryData(TableFormatEntryData entry) : base(entry)
 {
     Row        = entry.Row;
     Wrap       = entry.Wrap;
     ShowHeader = entry.ShowHeader;
 }