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


C# AsyncSubject.OnError方法代码示例

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


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

示例1: WriteAsync

        public static IObservable<Unit> WriteAsync(this Stream This, byte[] data, int start, int length)
        {
            var ret = new AsyncSubject<Unit>();

            try
            {
                This.BeginWrite(data, start, length, result =>
                {
                    try
                    {
                        This.EndWrite(result);
                        ret.OnNext(Unit.Default);
                        ret.OnCompleted();
                    }
                    catch (Exception ex)
                    {
                        ret.OnError(ex);
                    }
                }, null);
            }
            catch (Exception ex)
            {
                ret.OnError(ex);
            }

            return ret;
        }
开发者ID:jorik041,项目名称:Akavache,代码行数:27,代码来源:StreamMixins.cs

示例2: detect

        private IObservable<string> detect(string text)
        {
            var subject = new AsyncSubject<string>();
            string detectUri = String.Format(GetDetectUri(text), appId, HttpUtility.HtmlEncode(text));

            var wc = new WebClient();
            wc.OpenReadCompleted += new OpenReadCompletedEventHandler((obj, args) =>
            {
                if (args.Error != null)
                {
                    subject.OnError(args.Error);
                }
                else
                {
                    if (!args.Cancelled)
                    {
                        var xdoc = XDocument.Load(args.Result);
                        subject.OnNext(xdoc.Root.Value);
                    }
                    subject.OnCompleted();
                }
            });
            wc.OpenReadAsync(new Uri(detectUri));
            return subject;
        }
开发者ID:joeldart,项目名称:RX-Example,代码行数:25,代码来源:MainPage.xaml.cs

示例3: Search

 public IObservable<TwitterSearchStatus> Search(string query, int page, int rpp)
 {
     var subject = new AsyncSubject<IEnumerable<TwitterSearchStatus>>();
     this.service.Search(query, page, rpp, (tr, res) =>
     {
         if (res.InnerException == null)
         {
             subject.OnNext(tr.Statuses);
             subject.OnCompleted();
         }
         else
         {
             subject.OnError(res.InnerException);
         }
     });
     return subject.AsObservable().SelectMany(r => r);
 }
开发者ID:runceel,项目名称:WP7Apps,代码行数:17,代码来源:TwitterSearchClient.cs

示例4: LoginAsObservable

        /// <summary>
        /// WebContextのログインを行う。
        /// </summary>
        /// <param name="self"></param>
        /// <param name="userName">ユーザ名</param>
        /// <param name="password">パスワード</param>
        /// <returns>ユーザ情報。ログインできていない場合はnull。</returns>
        public static IObservable<User> LoginAsObservable(this WebContext self, string userName, string password)
        {
            // Subscribeまで処理を遅延させるためDeferでくるむ
            return Observable.Defer(() =>
            {
                var async = new AsyncSubject<User>();
                // ログインを行う
                var op = self.Authentication.Login(userName, password);
                // Completedイベントを購読して
                Observable.FromEvent<EventHandler, EventArgs>(
                    h => (s, e) => h(e),
                    h => op.Completed += h,
                    h => op.Completed -= h)
                    // 1回のイベント発火でイベントハンドラを解除する
                    .Take(1)
                    .Subscribe(_ =>
                    {
                        // キャンセルされてたら何もせず終了
                        if (op.IsCanceled)
                        {
                            async.OnCompleted();
                            return;
                        }

                        // エラーの場合はエラー通知
                        if (op.HasError)
                        {
                            op.MarkErrorAsHandled();
                            async.OnError(op.Error);
                            return;
                        }

                        // ユーザ情報を発行して終了。
                        async.OnNext(op.User as User);
                        async.OnCompleted();
                    });
                return async.AsObservable();
            });
        }
开发者ID:runceel,项目名称:MVVMRxSample,代码行数:46,代码来源:WebContextExtensions.cs

示例5: HasObservers_OnError

        public void HasObservers_OnError()
        {
            var s = new AsyncSubject<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:Ziriax,项目名称:Rx.NET,代码行数:14,代码来源:AsyncSubjectTest.cs

示例6: GetResult_Blocking_Throw

        private void GetResult_Blocking_Throw(AsyncSubject<int> s)
        {
            Assert.IsFalse(s.IsCompleted);

            var e = new ManualResetEvent(false);

            var ex = new Exception();

            new Thread(() => { e.WaitOne(); s.OnError(ex); }).Start();

            var y = default(Exception);
            var t = new Thread(() =>
            {
                try
                {
                    s.GetResult();
                }
                catch (Exception ex_)
                {
                    y = ex_;
                }
            });
            t.Start();

            while (t.ThreadState != ThreadState.WaitSleepJoin)
                ;

            e.Set();
            t.Join();

            Assert.AreSame(ex, y);
            Assert.IsTrue(s.IsCompleted);
        }
开发者ID:Ziriax,项目名称:Rx.NET,代码行数:33,代码来源:AsyncSubjectTest.cs

示例7: AsyncSubjectTest

        public void AsyncSubjectTest()
        {
            // OnCompletedPattern
            {
                var subject = new AsyncSubject<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.Count.Is(0);

                subject.OnCompleted();
                onNext.IsCollection(1000);
                onCompletedCallCount.Is(1);

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

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

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

            // OnErrorPattern
            {
                var subject = new AsyncSubject<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.Count.Is(0);

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

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

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

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

示例8: sends_no_values_after_error

        public void sends_no_values_after_error()
        {
            AsyncSubject<int> subject = new AsyncSubject<int>();

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

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

            subject.Subscribe(stats);

            Assert.IsFalse(stats.NextCalled);
            Assert.IsFalse(stats.CompletedCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:16,代码来源:AsyncSubjectFixture.cs

示例9: EstablishEncryptionAsync

        public virtual IObservable<bool> EstablishEncryptionAsync()
        {
            ValidateDisposed();

            var future = new AsyncSubject<bool>();
            var watchStatusChanged = new SingleAssignmentDisposable();
            watchStatusChanged.Disposable = this.ObserveStatusChanged().Subscribe(x =>
            {
                if (x == StatusCode.EncryptionFailedToEstablish)
                {
                    watchStatusChanged.Dispose();
                    future.OnError(new EncryptionFailedToEstablishException());
                }

                if (x == StatusCode.EncryptionEstablished)
                {
                    watchStatusChanged.Dispose();

                    future.OnNext(true);
                    future.OnCompleted();
                }
            });

            if (this.EstablishEncryption())
            {
                return future.Timeout(Timeout).Catch((Exception ex) =>
                {
                    watchStatusChanged.Dispose();
                    this.Disconnect();
                    return Observable.Throw<bool>(ex);
                });
            }
            else
            {
                watchStatusChanged.Dispose();
                return Observable.Return(false);
            }
        }
开发者ID:neuecc,项目名称:PhotonWire,代码行数:38,代码来源:ObservablePhotonPeer.cs

示例10: ConnectAsync

        public virtual IObservable<bool> ConnectAsync(string serverAddress, string applicationName)
        {
            ValidateDisposed();

            var future = new AsyncSubject<bool>();
            var watchStatusChanged = new SingleAssignmentDisposable();
            watchStatusChanged.Disposable = this.ObserveStatusChanged().Subscribe(x =>
            {
                if (x == StatusCode.ExceptionOnConnect)
                {
                    watchStatusChanged.Dispose();
                    future.OnError(new ConnectionFailedException(serverAddress, applicationName));
                }

                if (x == StatusCode.Connect)
                {
                    watchStatusChanged.Dispose();

                    future.OnNext(true);
                    future.OnCompleted();
                }
            });

            if (this.Connect(serverAddress, applicationName))
            {
                this.LastConnectServerAddress = serverAddress;
                this.LastConnectApplicationName = applicationName;

                return future.Timeout(Timeout).Catch((Exception ex) =>
                {
                    watchStatusChanged.Dispose();
                    this.Disconnect();
                    return Observable.Throw<bool>(ex);
                });
            }
            else
            {
                watchStatusChanged.Dispose();
                return Observable.Return(false);
            }
        }
开发者ID:neuecc,项目名称:PhotonWire,代码行数:41,代码来源:ObservablePhotonPeer.cs

示例11: QueueBackgroundDownloads

        public IObservable<Unit> QueueBackgroundDownloads(IEnumerable<string> urls, IEnumerable<string> localPaths)
        {
            var ret = new AsyncSubject<Unit>();
            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(Unit.Default);
                        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:iamnilay3,项目名称:Shimmer,代码行数:30,代码来源:BitsManager.cs

示例12: ResolveHostName

    public static IObservable<NameResolutionResult> ResolveHostName(DnsEndPoint endPoint, NetworkInterfaceInfo networkInterface)
    {
      Contract.Requires(endPoint != null);
      Contract.Requires(networkInterface != null);
      Contract.Ensures(Contract.Result<IObservable<NameResolutionResult>>() != null);

      var subject = new AsyncSubject<NameResolutionResult>();

      try
      {
        DeviceNetworkInformation.ResolveHostNameAsync(
          endPoint,
          networkInterface,
          result =>
          {
            var s = (AsyncSubject<NameResolutionResult>) result.AsyncState;

            s.OnNext(result);
            s.OnCompleted();
          },
          subject);
      }
      catch (Exception ex)
      {
        subject.OnError(ex);
      }

      return subject.AsObservable();
    }
开发者ID:ibebbs,项目名称:Rxx,代码行数:29,代码来源:ObservableDns.cs


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