public async Task <XResult <T> > OperationWrap <T>(Func <Task <TableResult> > func) { try { var result = await func(); if (result.HttpStatusCode != (int)HttpStatusCode.OK && result.HttpStatusCode != (int)HttpStatusCode.NoContent) { return (XResult <T> .GetBadRequest(String.Format("Table Storage not OK result: {0}", result.HttpStatusCode))); } if (result.Result == null) { return (XResult <T> .GetNotFound(String.Format("Table Storage item not found: {0}", result.HttpStatusCode))); } return(new XResult <T>((T)result.Result)); } catch (Exception ex) { _logService.TrackException(ex); return(XResult <T> .GetException("TableStorage " + ex.ToString(), ex)); } }
public async Task <XResult <T> > OperationWrap <T>(Func <Task <T> > func) { try { var result = await func(); return(new XResult <T>(result)); } catch (Exception ex) { _logService.TrackException(ex); return(XResult <T> .GetException("BlobStorage " + ex.ToString(), ex)); } }
public async Task <XResult <IList <T> > > OperationWrap(Func <Task <FeedResponse <T> > > func) { try { var result = await func(); var docs = result.ToList(); return(new XResult <IList <T> >(docs)); } catch (Exception ex) { _logService.TrackException(ex); return(XResult <IList <T> > .GetException("Document DB " + ex.ToString(), ex)); } }
public async Task <XResult <T> > OperationWrapResourceResponse(Func <Task <ResourceResponse <Document> > > func) { try { var result = await func(); if (result.StatusCode != HttpStatusCode.OK && result.StatusCode != HttpStatusCode.Created && result.StatusCode != HttpStatusCode.NoContent) { return (XResult <T> .GetBadRequest($"Document Database not OK result: {(int)result.StatusCode}")); } dynamic d = result.Resource; T dt = d; return(new XResult <T>(dt)); } catch (Exception ex) { _logService.TrackException(ex); return(XResult <T> .GetException("Document DB " + ex.ToString(), ex)); } }
public async Task <XResult <T> > Run <T>(Func <Task <XResult <T> > > func) { var counter = 0; XResult <T> lastResult = null; while (counter <= Retries || Retries == -1) { try { var result = await func(); result.Retries = counter; if (ExceptionsOnly) { return(result); } if (!result) { if (AllowedResultCodes.HasFlag(result.ResultCode)) { return(result); } lastResult = result; if (counter == Retries) { break; } await Task.Delay(RetryTimeout); counter++; continue; } return(result); } catch (Exception ex) { lastResult = XResult <T> .GetException(); lastResult.Exception = ex; if (counter == Retries) { break; } counter++; } } if (lastResult == null) { lastResult = XResult <T> .GetFailed(); lastResult.ResultCode = OperationResults.RetryTimeout; } lastResult.Retries = counter; return(lastResult); }