internal async Task <TResult> RunAsync <TResult>(BaseOperation <TResult> operationBase, int timeoutInSeconds = (2 * 60)) { var cancellationTokenSource = new CancellationTokenSource(); if (timeoutInSeconds <= 0) { throw new ArgumentException("Invalid Timeout"); } var timeout = new TimeSpan(0, 0, timeoutInSeconds); cancellationTokenSource.CancelAfter(timeout); await this.ValidateInputAsync(); try { var startTime = DateTimeOffset.UtcNow; var results = await operationBase.RunAsyncWrappper(timeout, cancellationTokenSource.Token).ConfigureAwait(false); return(results); } catch (Exception exception) { FabricEvents.Events.EventStoreFailed(operationBase.GetSupportedEntityType().ToString(), ExtractDetails(exception)); if (exception is ConnectionParsingException) { // This indicates to the caller that the API's are not available as the connection information is not configured. throw new HttpResponseException(HttpStatusCode.ServiceUnavailable); } if (exception is HttpResponseException) { throw; } var fabricException = exception as FabricException; if (fabricException != null) { var fabricError = new FabricError(fabricException); var fabricBackupRestoreError = new FabricErrorError(fabricError); throw new HttpResponseException(fabricBackupRestoreError.ToHttpResponseMessage()); } else if (exception is ArgumentException) { FabricErrorError fabricEventStoreSvcErrorMessage = new FabricErrorError( new FabricError { Code = NativeTypes.FABRIC_ERROR_CODE.E_INVALIDARG, Message = exception.Message }); throw new HttpResponseException(fabricEventStoreSvcErrorMessage.ToHttpResponseMessage()); } else if (exception is OperationCanceledException || exception is TimeoutException) { FabricErrorError fabricEventStoreSvcErrorMessage = new FabricErrorError( new FabricError { Code = NativeTypes.FABRIC_ERROR_CODE.FABRIC_E_TIMEOUT, Message = "Timeout" }); throw new HttpResponseException(fabricEventStoreSvcErrorMessage.ToHttpResponseMessage()); } else { var stringBuilder = new StringBuilder(); if (exception is AggregateException) { var aggregateException = (AggregateException)exception; foreach (var innerException in aggregateException.InnerExceptions) { stringBuilder.AppendFormat("{0} ,", innerException.Message).AppendLine(); } } else { stringBuilder.AppendFormat("{0}", exception.Message); } FabricErrorError fabricEventStoreSvcErrorMessage = new FabricErrorError( new FabricError { Message = stringBuilder.ToString(), Code = NativeTypes.FABRIC_ERROR_CODE.E_UNEXPECTED }); throw new HttpResponseException(fabricEventStoreSvcErrorMessage.ToHttpResponseMessage()); } } throw new HttpResponseException(HttpStatusCode.InternalServerError); }