public void NotifiesOfSegmentWhenFileIsCreated()
        {
            //need to make this test
            var file = Path.GetTempFileName();
            var info = new FileInfo(file);
            var refresher = new Subject<Unit>();

            var segmenter = new FileSegmenter(info.WatchFile(refresher), 1000);
            FileSegmentCollection result = null;

            using (var indexer = segmenter.Segments.Subscribe(segment => result = segment))
            {
                result.Should().NotBeNull();

                File.AppendAllLines(file,
                    Enumerable.Range(1, 10000).Select(i => $"This is line number {i.ToString("00000000")}").ToArray());
                refresher.Once();

                result.Should().NotBeNull();
                result.Count.Should().BeGreaterOrEqualTo(2);
                result.Segments.Select(fs => fs.Type).Should().Contain(FileSegmentType.Head);
                result.Segments.Select(fs => fs.Type).Should().Contain(FileSegmentType.Tail);
                result.FileLength.Should().Be(info.Length);


                File.AppendAllLines(file, Enumerable.Range(101, 10).Select(i => $"{i}"));
                refresher.Once();
                info.Refresh();
                result.FileLength.Should().Be(info.Length);

                File.Delete(file);
            }

            File.Delete(file);
        }
Esempio n. 2
0
        public static IObservable<FileSegmentCollection> WithSegments(this IObservable<FileNotification> source, int initialTail= 100000)
        {
            var shared = source.Replay(1).RefCount();

            return Observable.Create<FileSegmentCollection>(observer =>
            {
                var filtered = source.Where(f=>f.Exists);
                var segmenter = new FileSegmenter(filtered, initialTail);
                return segmenter.Segments.SubscribeSafe(observer);
            })
            .TakeUntil(shared.Where(f => !f.Exists));
        }
Esempio n. 3
0
        public static IObservable <FileSegmentCollection> WithSegments(this IObservable <FileNotification> source, int initialTail = 100000)
        {
            var shared = source.Replay(1).RefCount();

            return(Observable.Create <FileSegmentCollection>(observer =>
            {
                var filtered = source.Where(f => f.Exists);
                var segmenter = new FileSegmenter(filtered, initialTail);
                return segmenter.Segments.SubscribeSafe(observer);
            })
                   .TakeUntil(shared.Where(f => !f.Exists)));
        }
 public static IObservable <FileSegmentCollection> WithSegments(this IObservable <FileNotification> source, int initialTail = 100000)
 {
     return(source.Where(n => (n.NotificationType == FileNotificationType.Changed || n.NotificationType == FileNotificationType.CreatedOrOpened))
            .Publish(shared =>
     {
         return Observable.Create <FileSegmentCollection>(observer =>
         {
             var segmenter = new FileSegmenter(shared, initialTail);
             return segmenter.Segments.SubscribeSafe(observer);
         });
     }));
 }