Beispiel #1
0
 static void ShowRow(SDict <string, string> r, List <Column> cols)
 {
     for (int j = 0; j < cols.Count; j++)
     {
         Console.Write("|");
         var c = cols[j];
         var v = r.Lookup(c.name) ?? "";
         Console.Write(v);
         for (int k = 0; k < c.width - v.Length; k++)
         {
             Console.Write(" ");
         }
     }
     Console.Write("|");
     Console.WriteLine();
 }
Beispiel #2
0
        static void Show(StrongConnect c, DocArray da)
        {
            List <Column>       cols  = new List <Column>();                                         // of Column
            SDict <string, int> names = SDict <string, int> .Empty;
            SDict <int, SDict <string, string> > rows = SDict <int, SDict <string, string> > .Empty; // of string[]

            for (var b = c.description.First(); b != null; b = b.Next())
            {
                names = names + (b.Value.Item2, b.Value.Item1);
                cols.Add(new Column(b.Value.Item2, b.Value.Item2.Length));
            }
            for (int i = 0; i < da.items.Count; i++)
            {
                var dc  = da[i];
                var row = SDict <string, string> .Empty;
                for (var j = 0; j < dc.fields.Count; j++)
                {
                    var f = dc.fields[j];
                    if (f.Key.StartsWith("_"))
                    {
                        continue;
                    }
                    if (!names.Contains(f.Key))
                    {
                        throw new Exception("Unexpected column " + f.Key);
                    }
                    var k = names.Lookup(f.Key);
                    var s = f.Value.ToString();
                    if (s.Length > cols[k].width)
                    {
                        cols[k].width = s.Length;
                    }
                    row = row + (f.Key, s);
                }
                rows = rows + (rows.Length.Value, row);
            }
            DrawLine(cols);
            ShowHeads(cols);
            DrawLine(cols);
            for (var j = 0; j < rows.Length.Value; j++)
            {
                ShowRow(rows.Lookup(j), cols);
            }
            DrawLine(cols);
        }