public IServiceCall Call(string appSecret, Guid installId, IList <Log> logs) { var call = new ServiceCall(appSecret, installId, logs); if (!IsEnabled) { call.SetException(new NetworkIngestionException(new Exception("SDK is in offline mode."))); return(call); } CallAsync(appSecret, installId, logs, call.CancellationToken).ContinueWith(task => { // Cancellation token is already shared. if (task.IsCanceled) { return; } // If task is faulted. if (task.IsFaulted) { call.SetException(task.Exception?.InnerException); return; } // If task is succeeded. call.SetResult(task.Result); }); return(call); }
public override IServiceCall Call(string appSecret, Guid installId, IList <Log> logs) { var call = new ServiceCall(appSecret, installId, logs); RetryCall(call, 0); return(call); }
public override IServiceCall Call(string appSecret, Guid installId, IList <Log> logs) { if (_networkStateAdapter.IsConnected) { return(base.Call(appSecret, installId, logs)); } var call = new ServiceCall(appSecret, installId, logs); lock (_calls) { _calls.Add(call); } return(call); }
private void RetryCallContinuation(ServiceCall call, IServiceCall result, int retry) { // Canceled. if (call.IsCanceled) { return; } if (result.IsCanceled) { call.Cancel(); return; } // Faulted. if (result.IsFaulted) { var isRecoverable = result.Exception is IngestionException ingestionException && ingestionException.IsRecoverable; if (!isRecoverable || retry - 1 >= _retryIntervals.Length) { call.SetException(result.Exception); return; } // Shedule next retry. var timer = IntervalCall(retry, () => { lock (_calls) { if (!_calls.Remove(call)) { return; } } RetryCall(call, retry); }); lock (_calls) { _calls.Add(call, timer); } return; } // Succeeded. call.SetResult(result.Result); }
private void RetryCall(ServiceCall call, int retry) { if (call.IsCanceled) { return; } var result = base.Call(call.AppSecret, call.InstallId, call.Logs); // Cancel retry if cancel call. call.ContinueWith(_ => { if (call.IsCanceled && !result.IsCanceled) { result.Cancel(); } }); result.ContinueWith(_ => RetryCallContinuation(call, result, retry + 1)); }
private void RetryCall(ServiceCall call) { if (call.IsCanceled) { return; } var result = base.Call(call.AppSecret, call.InstallId, call.Logs); // Cancel retry if cancel call. call.ContinueWith(_ => { if (call.IsCanceled && !result.IsCanceled) { result.Cancel(); } }); // Pass result. result.ContinueWith(call.CopyState); }