Пример #1
0
        public void ReadXsvObservableTest()
        {
            var csv = new List<IList<string>>();

            using (var reader = new XsvReader(new StringReader(testData01)))
            {
                csv.Add(reader.ReadXsvLine(new[] { "," }).ToArray());
#if net40
                IDisposable disposable = reader.ReadXsvAsObservable(new[] { "," }, System.Reactive.Concurrency.ThreadPoolScheduler.Instance).Subscribe(row =>
#endif
#if net45
                IDisposable disposable = reader.ReadXsvAsObservable(new[] { "," }).Subscribe(row =>
#endif
                {
                    csv.Add(row);
                    Console.WriteLine("OnNext");
                    Console.WriteLine(row.ConcatWith(", "));
                },
                e => Console.WriteLine("OnError " + e.Message),
                () =>
                {
                    Console.WriteLine("OnCompleted.");
                    foreach (var row in csv.Zip(expected01, (l, r) => new { expected = r, actual = l }))
                    {
                        Console.WriteLine(row.actual.ConcatWith("|") + "\\n");
                        CollectionAssert.AreEqual((ICollection)row.expected, (ICollection)row.actual);
                    }
                });
            }
        }
Пример #2
0
        public void ReadAsObservable()
        {
            Cancel();

            var reader = new XsvReader(new System.IO.StreamReader(@".\ModelShips.txt"));
            var header = reader.ReadXsvLine(new[] { "," }).ToList();

            disposable = reader.ReadXsvAsObservable(new[] { "," })
                         .Where(row => !row.First().StartsWith(";"))
                         .Select(row => ModelShip.FromCsvRecord(header, row))
                         //.Where(row => row.Price >= 2500)
                         //.Where(row => row.ClassOfShip == "戦艦")
                         .ObserveOn(System.Threading.SynchronizationContext.Current)
                         .Subscribe(
                row =>
            {
                System.Diagnostics.Debug.WriteLine("OnNext");
                this.Rows.Add(row);
            },
                error =>
            {
                System.Diagnostics.Debug.WriteLine("OnError:" + error);
                reader.Dispose();
            },
                () =>
            {
                System.Diagnostics.Debug.WriteLine("OnCompleted");
                reader.Dispose();
            });
        }
Пример #3
0
        static IDisposable ReadXsvObservable(XsvReader reader)
        {
            var csv = new List <IList <string> >();

            var header = reader.ReadXsvLine(new[] { "," }).ToArray();

            csv.Add(header);

            return(reader.ReadXsvAsObservable(new[] { "," })
                   .Subscribe(row =>
            {
                csv.Add(row);
                Console.WriteLine("OnNext:" + System.Threading.Thread.CurrentThread.ManagedThreadId + " => " + row.ConcatWith(", "));
            },
                              e => Console.WriteLine("OnError " + e.Message),
                              () =>
            {
                Console.WriteLine("OnCompleted:" + System.Threading.Thread.CurrentThread.ManagedThreadId);
                Console.WriteLine("");
                foreach (var row in csv)
                {
                    Console.WriteLine(row.Select(s => s.MakeXsvField(new[] { "," })).ConcatWith(", "));
                }
            }));
        }