本文整理汇总了C#中IObserver.OnError方法的典型用法代码示例。如果您正苦于以下问题:C# IObserver.OnError方法的具体用法?C# IObserver.OnError怎么用?C# IObserver.OnError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IObserver
的用法示例。
在下文中一共展示了IObserver.OnError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
}
示例2: 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);
}
}
}
示例3: 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();
}
示例4: 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;
}
示例5: SuccessTest
/// <summary>
/// This will test if the exception has an error code that is not 0 (0 is success), if it does then it sends the observer an OnError.
/// </summary>
/// <param name="observer">
/// The observer.
/// </param>
public void SuccessTest(IObserver<IUsbDeviceNotification> observer)
{
if (!Win32Error.IsSuccess)
{
observer.OnError(Win32Error.Exception);
}
}
示例6: SendNotificationToObserver
private void SendNotificationToObserver(IObserver<string> observer, SocketAsyncEventArgs socketEvent)
{
if (socketEvent.SocketError == SocketError.Success)
{
if (socketEvent.BytesTransferred == 0)
{
observer.OnError(new InvalidOperationException("Received no bytes from Redis"));
}
else
{
observer.OnNext(Encoding.UTF8.GetString(socketEvent.Buffer, 0, socketEvent.BytesTransferred));
observer.OnCompleted();
}
}
else
{
observer.OnError(new RedisException(socketEvent.SocketError));
}
}
示例7: 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));
}
}
示例8: 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));
}
}
示例9: SendNotificationToObserver
private bool SendNotificationToObserver(IObserver<string> observer, ISocketAsyncEventArgs socketEvent)
{
if (socketEvent.SocketError == SocketError.Success)
{
observer.OnNext(Encoding.UTF8.GetString(socketEvent.Buffer, 0, socketEvent.BytesTransferred));
return true;
}
else
{
observer.OnError(new RedisException(socketEvent.SocketError));
return false;
}
}
示例10: CreateProcessExitSubscription
private IDisposable CreateProcessExitSubscription(Process process, IObservable<EventPattern<object>> processExited, IObserver<string> observer)
{
return processExited.Subscribe(args =>
{
try
{
if (process?.ExitCode > 0)
{
observer.OnError(new Exception(
$"Process '{process.StartInfo.FileName}' terminated with error code {process.ExitCode}"));
}
else observer.OnCompleted();
}
finally
{
this.Started = false;
process?.Close();
}
});
}
示例11: GetWWWCore
// IEnumerator with callback
static IEnumerator GetWWWCore(string url, IObserver<string> observer, CancellationToken cancellationToken)
{
var www = new UnityEngine.WWW(url);
while (!www.isDone && !cancellationToken.IsCancellationRequested)
{
yield return null;
}
if (cancellationToken.IsCancellationRequested) yield break;
if (www.error != null)
{
observer.OnError(new Exception(www.error));
}
else
{
observer.OnNext(www.text);
observer.OnCompleted();
}
}
示例12: RunObservable
private static IDisposable RunObservable(IDbCommand command, IDbConnection connection, IDataReader reader,
IDictionary<string, int> index, IObserver<IDictionary<string, object>> o)
{
try
{
while (reader.Read())
{
o.OnNext(reader.ToDictionary(index));
}
o.OnCompleted();
}
catch (Exception ex)
{
o.OnError(ex);
}
finally
{
DisposeCommandAndReader(connection, command, reader);
}
return ColdObservable.EmptyDisposable;
}
示例13: ReadStreamToEnd
static async Task ReadStreamToEnd(StreamReader stream, IObserver<string> observable) {
try {
var readBuffer = new char[1];
var lineBuffer = new StringBuilder();
while (await stream.ReadAsync(readBuffer, 0, 1).ConfigureAwait(false) > 0) {
var c = readBuffer[0];
lineBuffer.Append(c);
// This does not account for unterminated lines.... like 'verifying download...'
// We would be able to do this by sending the data also byte by byte to the receivers, but for little gain.
if ((c != '\r') && (c != '\n'))
continue;
observable.OnNext(lineBuffer.ToString());
lineBuffer.Clear();
}
if (lineBuffer.Length > 0)
observable.OnNext(lineBuffer.ToString());
observable.OnCompleted();
} catch (Exception ex) {
observable.OnError(ex);
throw;
}
}
示例14: AsObservableCore
static IEnumerator AsObservableCore(AsyncOperation asyncOperation, IObserver<AsyncOperation> observer, IProgress<float> reportProgress, CancellationToken cancel)
{
while (!asyncOperation.isDone && !cancel.IsCancellationRequested)
{
if (reportProgress != null)
{
try
{
reportProgress.Report(asyncOperation.progress);
}
catch (Exception ex)
{
observer.OnError(ex);
yield break;
}
}
yield return null;
}
if (cancel.IsCancellationRequested) yield break;
observer.OnNext(asyncOperation);
observer.OnCompleted();
}
示例15: Producer4
Task Producer4(IObserver<int> results, CancellationToken token, IScheduler scheduler, Exception exception)
{
var tcs = new TaskCompletionSource<object>();
var x = 0;
var d = scheduler.Schedule(TimeSpan.FromTicks(100), self =>
{
if (x == 4)
{
results.OnError(exception);
}
results.OnNext(++x);
self(TimeSpan.FromTicks(100));
});
token.Register(d.Dispose);
return tcs.Task;
}