Exemplo n.º 1
0
        public static TsvDataSheet Download(AbsoluteUri location)
        {
            if (null == location)
            {
                throw new ArgumentNullException("location");
            }

            TsvDataSheet tsv = null;

            var request = WebRequest.Create((Uri)location);
            using (var response = request.GetResponse())
            {
                using (var stream = response.GetResponseStream())
                {
                    if (null != stream)
                    {
                        using (var reader = new StreamReader(stream))
                        {
#if NET20
                            var file = new FileInfo(StringExtensionMethods.FormatWith("{0}.tsv", AlphaDecimal.Random()));
                            FileInfoExtensionMethods.Create(file, reader.ReadToEnd());
#else
                            var file = new FileInfo("{0}.tsv".FormatWith(AlphaDecimal.Random()));
                            file.Create(reader.ReadToEnd());
#endif

                            tsv = new TsvDataSheet(file);
                        }
                    }
                }
            }

            return tsv;
        }
Exemplo n.º 2
0
        private static void Process(TsvDataSheet sheet)
        {
            Console.WriteLine(Resources.TsvFileInfo, sheet.Info.FullName);
            var count = 0;

            foreach (var entry in sheet)
            {
                if (0 == count)
                {
                    var columns = new StringBuilder();
                    foreach (var key in entry.Keys)
                    {
                        var format = 0 == columns.Length
                            ? "Columns: "
                            : "{0}         ".FormatWith(Environment.NewLine);
                        columns.Append(format + key);
                    }

                    Console.WriteLine(columns);
                }

                count++;
            }

            Console.WriteLine(Resources.TsvEntryCount, count);
        }
Exemplo n.º 3
0
        private static void Process(TsvDataSheet sheet)
        {
            Console.WriteLine(Resources.TsvFileInfo, sheet.Info.FullName);
            var count = 0;
            foreach (var entry in sheet)
            {
                if (0 == count)
                {
                    var columns = new StringBuilder();
                    foreach (var key in entry.Keys)
                    {
                        var format = 0 == columns.Length
                            ? "Columns: "
                            : "{0}         ".FormatWith(Environment.NewLine);
                        columns.Append(format + key);
                    }

                    Console.WriteLine(columns);
                }

                count++;
            }

            Console.WriteLine(Resources.TsvEntryCount, count);
        }
Exemplo n.º 4
0
 public void op_IEnumerable_GetEnumerator()
 {
     using (var file = new TempFile())
     {
         file.Info.AppendLine("name");
         file.Info.AppendLine("Example");
         IEnumerable enumerable = new TsvDataSheet(file.Info);
         foreach (var entry in enumerable.Cast<KeyStringDictionary>())
         {
             Assert.Equal("Example", entry["name"]);
         }
     }
 }
Exemplo n.º 5
0
 public void usage(TsvDataSheet tsv)
 {
     Assert.Equal("A1", tsv.First()["A"]);
     Assert.Equal("B2", tsv.Last()["B"]);
 }
Exemplo n.º 6
0
 public void usage_whenMultipleParameters(TsvDataSheet one,
                                          TsvDataSheet two)
 {
     Assert.Equal("one", one.First()["COLUMN"]);
     Assert.Equal("two", two.First()["COLUMN"]);
 }
Exemplo n.º 7
0
 public void usage(TsvDataSheet sheet)
 {
     Assert.Equal("A1", sheet.First()["A"]);
     Assert.Equal("B2", sheet.Last()["B"]);
 }