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


C# ReplaySubject.OnError方法代码示例

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


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

示例1: CreateDownloadObservable

 private static IObservable<byte[]> CreateDownloadObservable(Uri uri)
 {
     return Observable.Create<byte[]>(o => {
         var result = new ReplaySubject<byte[]>();
         var inner = Observable.Using(() => new WebClient(), wc => {
             var obs = Observable
                 .FromEventPattern<
                     DownloadDataCompletedEventHandler,
                     DownloadDataCompletedEventArgs>(
                         h => wc.DownloadDataCompleted += h,
                         h => wc.DownloadDataCompleted -= h)
                 .Take(1);
             wc.DownloadDataAsync(uri);
             return obs;
         }).Subscribe(ep => {
             if (ep.EventArgs.Cancelled) {
                 result.OnCompleted();
             } else {
                 if (ep.EventArgs.Error != null) {
                     result.OnError(ep.EventArgs.Error);
                 } else {
                     result.OnNext(ep.EventArgs.Result);
                     result.OnCompleted();
                 }
             }
         }, ex => {
             result.OnError(ex);
         });
         return new CompositeDisposable(inner, result.Subscribe(o));
     }).Retry(5);
 }
开发者ID:huoxudong125,项目名称:il-repack,代码行数:31,代码来源:NuGetHelpers.cs

示例2: errors_are_sent_through_scheduler

        public void errors_are_sent_through_scheduler()
        {
            ManualScheduler scheduler = new ManualScheduler();

            ReplaySubject<int> subject = new ReplaySubject<int>(scheduler);

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.OnError(new Exception());

            subject.Subscribe(stats);

            Assert.IsFalse(stats.ErrorCalled);

            scheduler.RunNext();
            Assert.IsTrue(stats.ErrorCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:17,代码来源:ReplaySubjectFixture.cs

示例3: buffer_size_includes_onerror

        public void buffer_size_includes_onerror()
        {
            ReplaySubject<int> subject = new ReplaySubject<int>(2);

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);
            subject.OnError(new Exception());

            subject.Subscribe(stats);

            Assert.AreEqual(1, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 3 }));
            Assert.IsTrue(stats.ErrorCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:17,代码来源:ReplaySubjectFixture.cs

示例4: CallOperationOnService

        private static IObservable<ServiceState> CallOperationOnService(ServiceBase serviceBase, Operation operation)
        {
            ReplaySubject<ServiceState> result = new ReplaySubject<ServiceState>();
            result.OnNext(operation.InitialState);

            var methodObs = Observable.Start(() =>
                {
                    Type serviceBaseType = serviceBase.GetType();
                    object[] parameters = null;
                    if (operation == Operations.Start)
                    {
                        parameters = new object[] { null };
                    }

                    try
                    {
                        serviceBaseType.InvokeMember(operation.MethodCall, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, serviceBase, parameters);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(string.Format("An exception was thrown while trying to call the {0} of the {1} service.  Examine the inner exception for more information.", operation, serviceBase.ServiceName), ex.InnerException);
                    }
                });

            methodObs.Subscribe
                (
                    _ =>
                    {
                        result.OnNext(operation.FinishedState);
                        result.OnCompleted();
                    },

                    ex =>
                    {
                        result.OnNext(operation.ErrorState);
                        result.OnError(ex);
                    }
                );

            return result;
        }
开发者ID:Behzadkhosravifar,项目名称:SignalR,代码行数:41,代码来源:ServiceBaseHelpers.cs

示例5: Errored_to_late_subscriber_ReplayByTime

        public void Errored_to_late_subscriber_ReplayByTime()
        {
            var expectedException = new Exception("Test");
            var s = new ReplaySubject<int>(TimeSpan.FromMinutes(1));
            s.OnNext(1);
            s.OnNext(2);
            s.OnNext(3);
            s.OnError(expectedException);

            var scheduler = new TestScheduler();
            var observer = scheduler.CreateObserver<int>();
            s.Subscribe(observer);

            Assert.Equal(4, observer.Messages.Count);

            Assert.Equal(1, observer.Messages[0].Value.Value);
            Assert.Equal(2, observer.Messages[1].Value.Value);
            Assert.Equal(3, observer.Messages[2].Value.Value);
            Assert.Equal(NotificationKind.OnError, observer.Messages[3].Value.Kind);
            Assert.Equal(expectedException, observer.Messages[3].Value.Exception);
        }
开发者ID:RolandPheasant,项目名称:Rx.NET,代码行数:21,代码来源:ReplaySubjectTest.cs

示例6: HasObservers_OnError

        private static void HasObservers_OnError(ReplaySubject<int> s)
        {
            Assert.False(s.HasObservers);

            var d = s.Subscribe(_ => { }, ex => { });
            Assert.True(s.HasObservers);

            s.OnNext(42);
            Assert.True(s.HasObservers);

            s.OnError(new Exception());
            Assert.False(s.HasObservers);
        }
开发者ID:RolandPheasant,项目名称:Rx.NET,代码行数:13,代码来源:ReplaySubjectTest.cs

示例7: ReplaySubject

        public void ReplaySubject()
        {
            // OnCompletedPattern
            {
                var subject = new ReplaySubject<int>();

                var onNext = new List<int>();
                var exception = new List<Exception>();
                int onCompletedCallCount = 0;
                var _ = subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);

                subject.OnNext(1);
                subject.OnNext(10);
                subject.OnNext(100);
                subject.OnNext(1000);
                onNext.IsCollection(1, 10, 100, 1000);

                // replay subscription
                onNext.Clear();
                _.Dispose();
                subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
                onNext.IsCollection(1, 10, 100, 1000);

                subject.OnCompleted();
                onCompletedCallCount.Is(1);

                subject.OnNext(1);
                subject.OnNext(10);
                subject.OnNext(100);
                onNext.Count.Is(4);

                subject.OnCompleted();
                subject.OnError(new Exception());
                exception.Count.Is(0);
                onCompletedCallCount.Is(1);

                // ++subscription
                onNext.Clear();
                onCompletedCallCount = 0;
                subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
                onNext.IsCollection(1, 10, 100, 1000);
                exception.Count.Is(0);
                onCompletedCallCount.Is(1);
            }

            // OnErrorPattern
            {
                var subject = new ReplaySubject<int>();

                var onNext = new List<int>();
                var exception = new List<Exception>();
                int onCompletedCallCount = 0;
                subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);

                subject.OnNext(1);
                subject.OnNext(10);
                subject.OnNext(100);
                subject.OnNext(1000);
                onNext.IsCollection(1, 10, 100, 1000);

                subject.OnError(new Exception());
                exception.Count.Is(1);

                subject.OnNext(1);
                subject.OnNext(10);
                subject.OnNext(100);
                onNext.Count.Is(4);

                subject.OnCompleted();
                subject.OnError(new Exception());
                exception.Count.Is(1);
                onCompletedCallCount.Is(0);

                // ++subscription
                onNext.Clear();
                exception.Clear();
                onCompletedCallCount = 0;
                subject.Subscribe(x => onNext.Add(x), x => exception.Add(x), () => onCompletedCallCount++);
                onNext.IsCollection(1, 10, 100, 1000);
                exception.Count.Is(1);
                onCompletedCallCount.Is(0);
            }
        }
开发者ID:ragcat,项目名称:UniRx,代码行数:83,代码来源:UnitTests.cs

示例8: QueueBackgroundDownloads

        public IObservable<int> QueueBackgroundDownloads(IEnumerable<string> urls, IEnumerable<string> localPaths)
        {
            var ret = new ReplaySubject<int>();
            var jobFiles = urls.Zip(localPaths, (url, path) => new {url, path});

            var job = manager.CreateJob(applicationName + "_" + Guid.NewGuid() , JobType.Download);
            job.OnJobError += (o, e) => ret.OnError(new BitsException(e.Error));
            job.OnJobTransferred += (o, e) => {
                try {
                    job.Complete();

                    if (job.ErrorCount != 0) {
                        ret.OnError(new BitsException(job.Error));
                    } else {
                        ret.OnNext(100);
                        ret.OnCompleted();
                    }
                } catch (Exception ex) {
                    ret.OnError(ex);
                }
            };

            jobFiles
                .Where(x => !File.Exists(x.path))
                .ForEach(x => job.AddFile(x.url, x.path));

            job.Resume();

            return ret;
        }
开发者ID:erwinchan,项目名称:Shimmer,代码行数:30,代码来源:BitsManager.cs

示例9: HasObservers_OnError

        public void HasObservers_OnError()
        {
            var s = new ReplaySubject<int>();
            Assert.IsFalse(s.HasObservers);

            var d = s.Subscribe(_ => { }, ex => { });
            Assert.IsTrue(s.HasObservers);

            s.OnNext(42);
            Assert.IsTrue(s.HasObservers);

            s.OnError(new Exception());
            Assert.IsFalse(s.HasObservers);
        }
开发者ID:TonyDoumanis,项目名称:Rx,代码行数:14,代码来源:ReplaySubjectTest.cs

示例10: window_includes_onerror

        public void window_includes_onerror()
        {
            ManualScheduler scheduler = new ManualScheduler();

            ReplaySubject<int> subject =
                new ReplaySubject<int>(TimeSpan.FromMilliseconds(10), scheduler);

            StatsObserver<int> stats = new StatsObserver<int>();

            DateTime start = DateTime.UtcNow;

            scheduler.Now = start;
            subject.OnNext(1);

            scheduler.Now = start.AddMilliseconds(5);
            subject.OnNext(2);

            scheduler.Now = start.AddMilliseconds(10);
            subject.OnError(new Exception());

            scheduler.Now = start.AddMilliseconds(11);
            subject.Subscribe(stats);

            scheduler.RunAll();

            Assert.AreEqual(1, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 2 }));
            Assert.IsTrue(stats.ErrorCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:29,代码来源:ReplaySubjectFixture.cs

示例11: window_can_pass_error

        public void window_can_pass_error()
        {
            ManualScheduler scheduler = new ManualScheduler();

            ReplaySubject<int> subject =
                new ReplaySubject<int>(TimeSpan.FromMilliseconds(10), scheduler);

            StatsObserver<int> stats = new StatsObserver<int>();

            DateTime start = DateTime.UtcNow;

            scheduler.Now = start;
            subject.OnError(new Exception());

            scheduler.Now = start.AddMilliseconds(11);
            subject.Subscribe(stats);

            scheduler.RunAll();

            Assert.IsFalse(stats.ErrorCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:21,代码来源:ReplaySubjectFixture.cs

示例12: replays_values_when_errored

        public void replays_values_when_errored()
        {
            ReplaySubject<int> subject = new ReplaySubject<int>();

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);
            subject.OnError(new Exception());

            subject.Subscribe(stats);

            Assert.AreEqual(3, stats.NextCount);
            Assert.IsTrue(stats.NextValues.SequenceEqual(new int[] { 1, 2, 3 }));
            Assert.IsTrue(stats.ErrorCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:17,代码来源:ReplaySubjectFixture.cs

示例13: replays_error_sequence

        public void replays_error_sequence()
        {
            ReplaySubject<int> subject = new ReplaySubject<int>();

            StatsObserver<int> stats = new StatsObserver<int>();

            subject.OnError(new Exception());

            subject.Subscribe(stats);

            Assert.IsTrue(stats.ErrorCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:12,代码来源:ReplaySubjectFixture.cs

示例14: DoAsyncSend

        private IObservable<string> DoAsyncSend(string cmd)
        {
            if (this.scheduler == null)
                throw new Exception("Connection closed.");

            var subject = new ReplaySubject<string>();

            this.scheduler.Schedule(() =>
            {
                try
                {
                    if (!this.Connect())
                        return;

                    var writer = new StreamWriter(client.GetStream()) { AutoFlush = true };
                    var reader = new StreamReader(client.GetStream());

                    writer.WriteLine(cmd);
                    var response = ReadLine(reader);

                    subject.OnNext(response);
                    
                    if (Regex.IsMatch(response, "201.*"))
                        subject.OnNext(ReadLine(reader));
                    else if (Regex.IsMatch(response, "200.*"))
                    {
                        while (response != string.Empty)
                        {
                            response = ReadLine(reader);
                            subject.OnNext(response);
                        }
                    }
                    else if (Regex.IsMatch(response, "400.*"))
                        throw new Exception("Command not understood.");
                    else if (Regex.IsMatch(response, "401.*"))
                        throw new Exception("Illegal Command.");
                    else if (Regex.IsMatch(response, "402.*"))
                        throw new Exception("Parameter missing.");
                    else if (Regex.IsMatch(response, "403.*"))
                        throw new Exception("Illegal parameter.");
                    else if (Regex.IsMatch(response, "404.*"))
                        throw new Exception("Media file not found.");
                    else if (Regex.IsMatch(response, "500.*"))
                        throw new Exception("Internal server error.");
                    else if (Regex.IsMatch(response, "501.*"))
                        throw new Exception("Internal server error.");
                    else if (Regex.IsMatch(response, "502.*"))
                        throw new Exception("Media file unreadable.");
                }
                catch (IOException ex)
                {
                    this.Reset();
                    subject.OnError(ex);
                }
                catch(ObjectDisposedException ex)
                {
                    this.Reset();
                    subject.OnError(ex);
                }
                catch (Exception ex)
                {
                    subject.OnError(ex);
                }

                subject.OnCompleted();
            });
            
            return subject;
        }
开发者ID:erwinmnl,项目名称:Tools,代码行数:69,代码来源:Connection.cs


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