예제 #1
0
 /// <summary>
 /// Concatenate values from a Dictionary to this object.
 /// </summary>
 public Dictionary <string, string> AddHeaders(Dictionary <string, string> HeadersToAdd)
 {
     if (Headers == null)
     {
         Headers = new Dictionary <string, string>(HeadersToAdd);
     }
     else
     {
         Headers = Headers.Concat(HeadersToAdd).ToDictionary(x => x.Key, x => x.Value);
     }
     return(Headers);
 }
예제 #2
0
        public string ToString(string[] additionalHeaders, string[][] additionalData)
        {
            var numberColumns = Headers.Length + additionalHeaders.Length;
            var maxWidth      = new int[numberColumns];

            var rows = new List <string[]>();

            Action <IEnumerable <string> > addRow = cells =>
            {
                var row   = new string[numberColumns];
                var index = 0;

                foreach (var cellText in cells)
                {
                    row[index++] = cellText;
                }

                for (var i = 0; i < numberColumns; i++)
                {
                    var rowValue = row[i];
                    if (rowValue != null && rowValue.Length > maxWidth[i])
                    {
                        maxWidth[i] = rowValue.Length;
                    }
                }

                rows.Add(row);
            };

            addRow(Headers.Concat(additionalHeaders));
            var rowIndex = 0;

            foreach (var row in this)
            {
                var additionalValues = additionalData.Length > rowIndex ? additionalData[rowIndex] : Enumerable.Empty <string>();
                addRow(row.Values.Select(v => v.GetValueAsString()).Concat(additionalValues));
                rowIndex++;
            }

            var stringBuilder = new StringBuilder().AppendLine();

            foreach (var row in rows)
            {
                WriteExampleRow(row, maxWidth, stringBuilder);
            }

            return(stringBuilder.ToString());
        }
예제 #3
0
        public ResultsData Combine(ResultsData newResults)
        {
            if (Headers.Count == 0)
            {
                return(newResults);
            }

            var headers = Headers.Concat(newResults.Headers.GetRange(1, newResults.Headers.Count - 1)).ToList();
            var data    = Data.FullGroupJoin(newResults.Data,
                                             x => x[0],
                                             y => y[0],
                                             (id, x, y) =>
            {
                var cx = x.ToList().Count > 0 ? x.ToList()[0] : null;
                var cy = y.ToList().Count > 0 ? y.ToList()[0] : null;

                return(MergeRows(cx, cy, Headers.Count, newResults.Headers.Count));
            }).ToList();

            return(new ResultsData(data, headers));
        }
예제 #4
0
 /// <summary>
 /// Concatenate values from a Dictionary to this object
 /// </summary>
 public Dictionary <string, string> AddHeaders(Dictionary <string, string> HeadersToAdd)
 {
     Headers = Headers.Concat(HeadersToAdd).ToDictionary(x => x.Key, x => x.Value);
     return(Headers);
 }