当前位置: 首页>>代码示例>>C#>>正文


C# Subject.Once方法代码示例

本文整理汇总了C#中Subject.Once方法的典型用法代码示例。如果您正苦于以下问题:C# Subject.Once方法的具体用法?C# Subject.Once怎么用?C# Subject.Once使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Subject的用法示例。


在下文中一共展示了Subject.Once方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NotifiesOfSegmentWhenFileIsCreated

        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);
        }
开发者ID:ItsJustSean,项目名称:TailBlazer,代码行数:35,代码来源:FileSegmentFixture.cs

示例2: CanReadIndiciesBack_SmallFile

        public void CanReadIndiciesBack_SmallFile()
        {
            var pulse = new Subject<Unit>();
            var scheduler = new TestScheduler();

            using (var file = new TestFile())
            {
                file.Append(Enumerable.Range(1, 100).Select(i => $"This is line number {i.ToString("00000000")}").ToArray());

                using (var indexer = new Indexer(file.Info.WatchFile(pulse).WithSegments(), scheduler: scheduler))
                {
                    IndexCollection result = null;
                    using (indexer.Result.Subscribe(indicies => result = indicies))

                    {
                        pulse.Once();

                        var head = result.ReadLines(new ScrollRequest(10, 0));
                        var headText = head.Select(l => l.Text).ToArray();
                        var headExpected = Enumerable.Range(1, 10).Select(i => $"This is line number {i.ToString("00000000")}");
                        headText.ShouldAllBeEquivalentTo(headExpected);

                        var tail = result.ReadLines(new ScrollRequest(10));
                        var tailText = tail.Select(l => l.Text).ToArray();
                        var tailExpected = Enumerable.Range(91, 10).Select(i => $"This is line number {i.ToString("00000000")}").ToArray();
                        tailText.ShouldAllBeEquivalentTo(tailExpected);

                        var mid = result.ReadLines(new ScrollRequest(10, 20));
                        var midText = mid.Select(l => l.Text).ToArray();
                        var midExpected = Enumerable.Range(21, 10).Select(i => $"This is line number {i.ToString("00000000")}").ToArray();
                        midText.ShouldAllBeEquivalentTo(midExpected);
                    }
                }
            }
        }
开发者ID:ItsJustSean,项目名称:TailBlazer,代码行数:35,代码来源:IndexerFixture.cs

示例3: CreateFileLater

        //[Fact]
        //Cannot recreate the file as something is hanging on to it.
        public void CreateFileLater()
        {
            var pulse = new Subject<Unit>();

            using (var file = new TestFile())
            {
                file.Delete();

                FileSearchResult fileSearchResult = null;

                using (file.Info.WatchFile(pulse)
                    .Search(str => str.Contains("9"))
                    .Subscribe(x => fileSearchResult = x))
                {
                    fileSearchResult.Should().Be(FileSearchResult.None);
                    file.Create();
                    pulse.Once();
                    fileSearchResult.Should().NotBe(FileSearchResult.None);
                }
            }
        }
开发者ID:ItsJustSean,项目名称:TailBlazer,代码行数:23,代码来源:FileSearchFixture.cs

示例4: EmptyFile

        public void EmptyFile()
        {
            var pulse = new Subject<Unit>();
            var scheduler = new TestScheduler();
            using (var file = new TestFile())
            {
                FileSearchResult fileSearchResult = null;

                using (file.Info
                    .Search(str => str.Contains("9"), scheduler)
                    .Subscribe(x => fileSearchResult = x))
                {
                    scheduler.AdvanceByMilliSeconds(250);
                    pulse.Once();
                    fileSearchResult.Segments.Should().Be(1);
                    fileSearchResult.SegmentsCompleted.Should().Be(0);
                    fileSearchResult.IsSearching.Should().Be(false);
                    fileSearchResult.Count.Should().Be(0);
                }
            }
        }
开发者ID:ItsJustSean,项目名称:TailBlazer,代码行数:21,代码来源:FileSearchFixture.cs

示例5: SearchOnDataWhenFileIsPopulated

        public void SearchOnDataWhenFileIsPopulated()
        {
            var pulse = new Subject<Unit>();

            using (var file = new TestFile())
            {
                FileSearchResult fileSearchResult = null;


                using (file.Info.WatchFile(pulse)
                    .Search(str => str.Contains("9"))
                    .Subscribe(x => fileSearchResult = x))
                {
                    file.Append(Enumerable.Range(1, 100).Select(i => i.ToString()).ToArray());
                    pulse.Once();
                    pulse.Once();
                    fileSearchResult.Matches.Length.Should().NotBe(0);
                }
            }
        }
开发者ID:ItsJustSean,项目名称:TailBlazer,代码行数:20,代码来源:FileSearchFixture.cs

示例6: CanReadLinesBackInLargeFile

        public void CanReadLinesBackInLargeFile()
        {
            var scheduler = new TestScheduler();
            var pulse = new Subject<Unit>();

            using (var file = new TestFile())
            {
                IEnumerable<Line> lines = null;
                file.Append(Enumerable.Range(1, 100000).Select(i => i.ToString()).ToArray());

                using (file.Info.WatchFile(pulse)
                    .Search(str => str.Contains("9"), scheduler)
                    .Select(result => file.Info.ReadLinesByPosition(result.Matches).ToArray())
                    .Subscribe(x => lines=x))
                {
                    pulse.Once();
                   // fileSearchResult.Matches.Length.Should().Be(19);

                    file.Append(new[] { "9", "20" });
                    pulse.Once();
                  //  fileSearchResult.Matches.Length.Should().Be(20);

                    file.Append(new[] { "9999" });
                    pulse.Once();
                 //   fileSearchResult.Matches.Length.Should().Be(21);
                }
            }
        }
开发者ID:ItsJustSean,项目名称:TailBlazer,代码行数:28,代码来源:FileSearchFixture.cs

示例7: WillContinuallyTail

        public void WillContinuallyTail()
        {
            var scheduler = new TestScheduler();
            var pulse = new Subject<Unit>();
            
            using (var file = new TestFile())
            {
                FileSearchResult fileSearchResult = null;
                file.Append(Enumerable.Range(1, 100).Select(i => i.ToString()).ToArray());

                using (file.Info.WatchFile(pulse)
                    .Search(str => str.Contains("9"), scheduler)
                    .Subscribe(x => fileSearchResult = x))
                {
                    pulse.Once();
                    fileSearchResult.Matches.Length.Should().Be(19);

                    file.Append(new [] {"9","20"});
                    pulse.Once();
                    fileSearchResult.Matches.Length.Should().Be(20);

                    file.Append(new[] { "9999" });
                    pulse.Once();
                    fileSearchResult.Matches.Length.Should().Be(21);
                }
            }
        }
开发者ID:ItsJustSean,项目名称:TailBlazer,代码行数:27,代码来源:FileSearchFixture.cs

示例8: CanProduceIndices

        public void CanProduceIndices()
        {
            var pulse = new Subject<Unit>();
            var scheduler = new TestScheduler();
            using (var file = new TestFile())
            {

                using (var indexer = new Indexer(file.Info.WatchFile(pulse).WithSegments(), tailSize: 1000,
                        scheduler: scheduler))
                {
                    var lines = Enumerable.Range(1, 10000)
                        .Select(i => $"This is line number {i.ToString("00000000")}")
                        .ToArray();
                    file.Append(lines);
                   // scheduler.AdvanceBy(1);
                    pulse.Once();
                    IndexCollection result = null;
                    using (indexer.Result.Subscribe(indicies => result = indicies))
                    {
                        //start off the head scanner
                        scheduler.AdvanceBy(1);
                        var totalCount = result.Count;

                        //there could be an overlapping index (the index collection will deal with this)
                        totalCount.Should().Be(10000);
                    }
                }
            }
        }
开发者ID:ItsJustSean,项目名称:TailBlazer,代码行数:29,代码来源:IndexerFixture.cs

示例9: WillAutoTail

        public void WillAutoTail()
        {
            var pulse = new Subject<Unit>();
            var scheduler = new TestScheduler();
            using (var file = new TestFile())
            {

                using (var indexer = new Indexer(file.Info.WatchFile(pulse).WithSegments(), tailSize: 1000,
                        scheduler: scheduler))
                {
                    file.Append(Enumerable.Range(1, 10000)
                            .Select(i => $"This is line number {i.ToString("00000000")}")
                            .ToArray());
                    pulse.Once();
                    IndexCollection result = null;
                    using (indexer.Result.Subscribe(indicies => result = indicies))
                    {
                        scheduler.AdvanceBy(1);
                        result.Count.Should().Be(10000);
                        file.Append(Enumerable.Range(10001, 10).Select(i => $"This is line number {i.ToString("00000000")}").ToArray());
                        pulse.OnNext(Unit.Default);
                        result.Count.Should().Be(10010);
                    }
                }
            }

        }
开发者ID:ItsJustSean,项目名称:TailBlazer,代码行数:27,代码来源:IndexerFixture.cs


注:本文中的Subject.Once方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。