本文整理汇总了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();
}));
});
}
示例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;
}
示例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();
}
}
}
示例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();
}
示例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;
}
示例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();
}));
});
}
示例7: Subscribe
public static IDisposable Subscribe(IObserver<int> observer)
{
observer.OnNext(0);
observer.OnNext(1);
observer.OnNext(2);
observer.OnCompleted();
return Disposable.Empty;
}
示例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);
}
示例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("");
}
示例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();
}));
});
}
示例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));
}
}
示例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();
}
示例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));
}
}
示例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);
}
示例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();
}