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


C# IObserver.OnCompleted方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: Push

        /// <inheritdoc />
        public IObservable<Unit> Push(IObserver<Tuple<string, int>> observer)
        {
            var branch = _repository.Head;

            var isCancelled = false;
            var options = new PushOptions
            {
                CredentialsProvider = _credentialsHandler,
                OnPushTransferProgress = (current, total, bytes) =>
                {
                    var progress = 0;
                    if (total != 0)
                    {
                        progress = 50 + (50 * current) / total;
                    }

                    observer.OnNext(Tuple.Create("", progress));

                    return !isCancelled;
                }
            };

            return Observable.Create<Unit>(subj =>
            {
                var sub = Observable.Start(() =>
                {
                    _repository.Network.Push(branch, options);

                    observer.OnNext(Tuple.Create("push completed", 100));
                    observer.OnCompleted();
                }, Scheduler.Default).Subscribe(subj);

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

示例11: SendNotificationToObserver

 private void SendNotificationToObserver(IObserver<Unit> observer, SocketAsyncEventArgs socketEvent)
 {
     if (socketEvent.SocketError == SocketError.Success)
     {
         observer.OnNext(Unit.Default);
         observer.OnCompleted();
     }
     else
     {
         observer.OnError(new RedisException(socketEvent.SocketError));
     }
 }
开发者ID:TeamnetGroup,项目名称:Redis.SilverlightClient,代码行数:12,代码来源:SocketTransmitter.cs

示例12: LoadInBackground

		public IEnumerator LoadInBackground(string level, IObserver<IContextView> observer) {
			LoadingLevel = true;
			yield return Application.LoadLevelAsync(level);
			var contextView = default(IContextView);
			yield return StartCoroutine(WaitForContextView(x => contextView = x));
			if(contextView != null) {
				observer.OnNext(contextView);
				yield return StartCoroutine(WaitForReady(contextView));
			}
			LoadingLevel = false;
			observer.OnCompleted();
		}
开发者ID:moto2002,项目名称:Inconspicuous.Framework,代码行数:12,代码来源:LevelManager.cs

示例13: SendNotificationToObserver

 private void SendNotificationToObserver(IObserver<ConnectionToken> observer, ISocketAsyncEventArgs socketEvent, ConnectionToken connectionToken)
 {
     if (socketEvent.SocketError == SocketError.Success)
     {
         observer.OnNext(connectionToken);
         observer.OnCompleted();
     }
     else
     {
         observer.OnError(new RedisException(socketEvent.SocketError));
     }
 }
开发者ID:vgrigoriu,项目名称:Redis.SilverlightClient,代码行数:12,代码来源:RedisConnector.cs

示例14: 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

示例15: CopyTo

        public static void CopyTo(this Stream stream, Stream destination, int bufferSize, IObserver<long> progressChangedWatcher)
        {
            if (progressChangedWatcher == null) throw new ArgumentNullException(nameof(progressChangedWatcher));
            if (bufferSize <= 0) throw new ArgumentOutOfRangeException($"{nameof(bufferSize)} must >= 0.");

            long total = 0;
            byte[] buffer = new byte[bufferSize];
            int read;
            while ((read = stream.Read(buffer, 0, buffer.Length)) != 0)
            {
                destination.Write(buffer, 0, read);
                total += read;
                progressChangedWatcher.OnNext(total);
            }
            progressChangedWatcher.OnCompleted();
        }
开发者ID:nokia6102,项目名称:jasily.cologler,代码行数:16,代码来源:StreamExtensions.cs


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