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


C# IObserver.OnNext方法代码示例

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


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

示例1: MainAsync

        public static async Task MainAsync(IObserver<string> observer)
        {
            observer.OnNext("start");
            await I.Task.Delay(delay);
            observer.OnNext("1");
            await Observable.Timer(delay);
            observer.OnNext("2");
            await Task.Delay(delay);
            observer.OnNext("3");

            await I.Task.Delay(delay);

            var urls = new[]
            {
                "http://yahoo.co.jp",
                "http://google.co.jp",
                "http://bing.co.jp",
                "http://awsedrftgyhujikol.jp/",
            };

            foreach (var url in urls)
            {
                try
                {
                    var res = await GetAsStringAsync(url);
                    observer.OnNext(res);
                }
                catch (Exception ex)
                {
                    observer.OnError(ex);
                }
            }

            observer.OnCompleted();
        }
开发者ID:ch896,项目名称:MinimumAsyncBridge,代码行数:35,代码来源:Class1.cs

示例2: Subscribe

 public static IDisposable Subscribe(IObserver<int> observer)
 {
     observer.OnNext(0);
     observer.OnNext(1);
     observer.OnNext(2);
     observer.OnCompleted();
     return Disposable.Empty;
 }
开发者ID:snowyunee,项目名称:rx_study,代码行数:8,代码来源:week1.cs

示例3: PostScheduled

        public Task PostScheduled(CommandEnvelope envelope, IObserver<LogEntry> log)
        {
            var req = CreatePostCommandRequest(envelope);
            return _client.PostScheduled(req)
                .ContinueWith(x =>
                {
                    var resp = x.Result;
                    var id = resp.Id;

                    Action<string> traceStatus = m => log.OnNext(new LogEntry
                    {
                        Message = m,
                        Severity = LogEntrySeverity.Trace,
                        Timestamp = DateTime.Now
                    });

                    traceStatus("Start waiting for execution command " + id);

                    var token = DateTime.MinValue;

                    while (true)
                    {
                        var resp2 = _client.GetScheduled(id, token);

                        // Write user log
                        var serverLog = resp2.Log.OrEmpty().ToList();
                        foreach (var entry in serverLog)
                        {
                            log.OnNext(entry);
                        }

                        // Take maximum available timestamp
                        token = serverLog.Select(xx => xx.Timestamp).Union(new[] { token }).Max();

                        switch (resp2.Status)
                        {
                            case ScheduledCommandStatus.Pending:
                                traceStatus("Command(" + id + ") is still pending.");
                                break;

                            case ScheduledCommandStatus.InProgress:
                                traceStatus("Command(" + id + ") is in progress.");
                                break;

                            case ScheduledCommandStatus.Success:
                                traceStatus("Command(" + id + ") completed success.");
                                return;

                            case ScheduledCommandStatus.Failure:
                                traceStatus("Command(" + id + ") failed.");
                                return;
                        }

                        Thread.Sleep(300);
                    }
                });
        }
开发者ID:JustApplications,项目名称:zaz,代码行数:57,代码来源:AdvancedZazClient.cs

示例4: DownloadAudioAsync

        public static async Task DownloadAudioAsync(VideoInfo videoInfo, string downloadPath, IObserver<double> progress)
        {
            string cleanedTitle = RemoveIllegalPathCharacters(videoInfo.Title);
            var downloader = new AudioDownloader(videoInfo, Path.Combine(downloadPath, cleanedTitle + videoInfo.AudioExtension));

            downloader.DownloadProgressChanged += (sender, args) => progress.OnNext(args.ProgressPercentage * 0.95);
            downloader.AudioExtractionProgressChanged += (sender, args) => progress.OnNext(95 + args.ProgressPercentage * 0.05);

            await DownloadFromYoutube(downloader, new[] { typeof(IOException), typeof(WebException), typeof(AudioExtractionException) }, progress);
        }
开发者ID:hur1can3,项目名称:Espera,代码行数:10,代码来源:YoutubeSong.cs

示例5: ToIterate_Complete

        IEnumerable<IObservable<Object>> ToIterate_Complete(IObservable<int> xs, IObservable<int> ys, IObservable<int> zs, IObserver<int> observer)
        {
            observer.OnNext(1);
            yield return xs.Select(x => new Object());

            observer.OnNext(2);
            yield return ys.Select(x => new Object());

            observer.OnNext(3);
            observer.OnCompleted();
            yield return zs.Select(x => new Object());

            observer.OnNext(4);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:14,代码来源:ObservableExTest.cs

示例6: Clone

        /// <inheritdoc />
        public static IObservable<IObservableRepository> Clone(
            string sourceUrl,
            string workingDirectory,
            IObserver<Tuple<string, int>> observer,
            CredentialsHandler credentials = null)
        {
            var isCancelled = false;
            var options = new CloneOptions
            {
                Checkout = true,
                CredentialsProvider = credentials,
                OnTransferProgress = progress =>
                {
                    // TODO: how should we signal for the "indexing objects" events
                    var p = (100 * progress.ReceivedObjects) / progress.TotalObjects;
                    var receivingMessage = String.Format("Receiving objects:  {0}% ({1}/{2})", p, progress.ReceivedObjects, progress.TotalObjects);
                    observer.OnNext(Tuple.Create(receivingMessage, p));
                    return !isCancelled;
                },
                IsBare = false,
                OnCheckoutProgress = ProgressFactory.CreateHandlerWithoutMessages(observer)
            };

            var directoryInfo = new DirectoryInfo(workingDirectory);
            var initialMessage = String.Format("Cloning into '{0}'...", directoryInfo.Name);
            observer.OnNext(Tuple.Create(initialMessage, 0));

            return Observable.Create<ObservableRepository>(subj =>
            {
                var sub = Observable.Start(() =>
                {
                    var directory = Repository.Clone(sourceUrl, workingDirectory, options);

                    observer.OnNext(Tuple.Create("clone completed", 100));
                    observer.OnCompleted();

                    return new ObservableRepository(directory, credentials);
                }, Scheduler.Default).Subscribe(subj);

                return new CompositeDisposable(
                    sub,
                    Disposable.Create(() =>
                    {
                        isCancelled = true;
                        observer.OnCompleted();
                    }));
            });
        }
开发者ID:carlosmn,项目名称:ReactiveGit,代码行数:49,代码来源:ObservableRepository.Clone.cs

示例7: Accept

        bool Accept(IObserver<Interactor> observer)
        {
            Log.Info("Accept new connection");

            try
            {
                var newSocket = _listener.Accept();
                var interactor = new Interactor(newSocket, _nextInteractorId++, _bufferManager);
                _interactors.Add(newSocket, interactor);
                Log.DebugFormat("Accepted {0}", interactor);
                observer.OnNext(interactor);
                return true;
            }
            catch (SocketException ex)
            {
                if (ex.SocketErrorCode == SocketError.Interrupted)
                    observer.OnCompleted();
                else
                    observer.OnError(ex);
            }
            catch (Exception ex)
            {
                observer.OnError(ex);
            }

            return false;
        }
开发者ID:rob-blackbourn,项目名称:TopicBus,代码行数:27,代码来源:Acceptor.cs

示例8: FetchBytes

        static IEnumerator FetchBytes(WWW www, IObserver<byte[]> observer, IProgress<float> reportProgress, CancellationToken cancel)
        {
            using (www)
            {
                while (!www.isDone && !cancel.IsCancellationRequested)
                {
                    if (reportProgress != null)
                    {
                        try
                        {
                            reportProgress.Report(www.progress);
                        }
                        catch (Exception ex)
                        {
                            observer.OnError(ex);
                            yield break;
                        }
                    }
                    yield return null;
                }

                if (cancel.IsCancellationRequested) yield break;

                if (!string.IsNullOrEmpty(www.error))
                {
                    observer.OnError(new Exception(www.error));
                }
                else
                {
                    observer.OnNext(www.bytes);
                    observer.OnCompleted();
                }
            }
        }
开发者ID:hoghweed,项目名称:LightNode,代码行数:34,代码来源:ObservableWWW.cs

示例9: ScheduledMethod

        private static IDisposable ScheduledMethod(IObserver<int> o)
        {
            var cancel = new CancellationDisposable();
            // internally creates a new CancellationTokenSource
            NewThreadScheduler.Default.Schedule(() =>
                                                    {
                                                        int i = 0;
                                                        for (;;)
                                                        {
                                                            Thread.Sleep(200);
                                                            // here we do the long lasting background operation
                                                            if (!cancel.Token.IsCancellationRequested)
                                                                // check cancel token periodically
                                                                o.OnNext(i++);
                                                            else
                                                            {
                                                                Console.WriteLine(
                                                                    "Aborting because cancel event was signaled!");
                                                                o.OnCompleted();
                                                                return;
                                                            }
                                                        }
                                                    }
                );

            return cancel;
        }
开发者ID:bFanatic,项目名称:RX-StateMachine,代码行数:27,代码来源:RxWithCancelation.cs

示例10: RunAsync

        public async Task RunAsync(IObserver<string> observer)
        {
            var urls = new[]
            {
                "http://yahoo.co.jp",
                "http://google.co.jp",
                "http://bing.co.jp",
                "http://awsedrftgyhujikol.jp/",
            };

            foreach (var url in urls)
            {
                await Observable.Timer(TimeSpan.FromSeconds(1));

                try
                {
                    var res = await GetAsStringAsync(url);
                    observer.OnNext(res);
                }
                catch(Exception ex)
                {
                    observer.OnError(ex);
                }
            }
        }
开发者ID:ufcpp,项目名称:AwaitableUniRx,代码行数:25,代码来源:Class1.cs

示例11: Pull

        /// <inheritdoc />
        public IObservable<MergeResult> Pull(
            IObserver<Tuple<string, int>> observer)
        {
            var signature = _repository.Config.BuildSignature(DateTimeOffset.Now);
            var isCancelled = false;

            var options = new PullOptions
            {
                FetchOptions = new FetchOptions
                {
                    TagFetchMode = TagFetchMode.None,
                    CredentialsProvider = _credentialsHandler,
                    OnTransferProgress = progress =>
                    {
                        // TODO: how should we signal for the "indexing objects" events
                        var p = (50 * progress.ReceivedObjects) / progress.TotalObjects;
                        observer.OnNext(Tuple.Create("", p));
                        return !isCancelled;
                    }
                },
                MergeOptions = new MergeOptions
                {
                    OnCheckoutProgress = ProgressFactory.CreateHandler(observer, start:50, count:50)
                }
            };

            return Observable.Create<MergeResult>(subj =>
            {
                var sub = Observable.Start(() =>
                {
                    var result = _repository.Network.Pull(signature, options);

                    observer.OnNext(Tuple.Create("pull completed", 100));
                    observer.OnCompleted();

                    return result;
                }, Scheduler.Default).Subscribe(subj);

                return new CompositeDisposable(
                    sub,
                    Disposable.Create(() =>
                    {
                        isCancelled = true;
                        observer.OnCompleted();
                    }));
            });
        }
开发者ID:carlosmn,项目名称:ReactiveGit,代码行数:48,代码来源:ObservableRepository.Pull.cs

示例12: DownloadUrl

            public IObservable<string> DownloadUrl(string url, IObserver<int> progress = null)
            {
                progress = progress ?? new Subject<int>();

                progress.OnNext(100);
                progress.OnCompleted();
                return Observable.Return("");
            }
开发者ID:rzhw,项目名称:Squirrel.Windows,代码行数:8,代码来源:ApplyReleasesTests.cs

示例13: QueueBackgroundDownloads

            public IObservable<Unit> QueueBackgroundDownloads(IEnumerable<string> urls, IEnumerable<string> localPaths, IObserver<int> progress = null)
            {
                progress = progress ?? new Subject<int>();

                progress.OnNext(100);
                progress.OnCompleted();
                return Observable.Return(Unit.Default);
            }
开发者ID:rzhw,项目名称:Squirrel.Windows,代码行数:8,代码来源:ApplyReleasesTests.cs

示例14: EventSourceLoop

 // イベントを飛ばし続けるループ
 static async Task EventSourceLoop(IObserver<int> observer, CancellationToken ct)
 {
     for (var i = 0; !ct.IsCancellationRequested; ++i)
     {
         observer.OnNext(i);
         await Task.Delay(Interval);
     }
 }
开发者ID:ufcpp,项目名称:UfcppSample,代码行数:9,代码来源:Program.cs

示例15: CreateHandlerWithoutMessages

 public static CheckoutProgressHandler CreateHandlerWithoutMessages(
     IObserver<Tuple<string, int>> observer,
     int start = 0,
     int count = 100)
 {
     return (path, completedSteps, totalSteps) =>
     {
         if (totalSteps == 0)
         {
             observer.OnNext(Tuple.Create(path, 0));
         }
         else
         {
             var progress = start + (count * completedSteps) / totalSteps;
             observer.OnNext(Tuple.Create("", progress));
         }
     };
 }
开发者ID:carlosmn,项目名称:ReactiveGit,代码行数:18,代码来源:ProgressFactory.cs


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