/// <summary> /// Extension method to process the result of an asynchronous scalar query operation. /// </summary> /// <typeparam name="T"> The type of entity queried. </typeparam> /// <param name="source"> The EntityScalarQueryOperation returned from an asynchronous query. </param> /// <param name="onSuccess"> A callback to be called if the asynchronous query was successful. </param> /// <param name="onFail"> A callback to be called if the asynchronous query failed. </param> /// <returns> Returns the EntityScalarQueryOperation passed to the method's source parameter. </returns> /// <example> /// <code title="Example" description="" lang="CS">public OperationResult GetCustomerCount(Action<int> onSuccess = null, /// Action<Exception> onFail = null) /// { /// var op = Manager.Customers.AsScalarAsync().Count(); /// return op.OnComplete(onSuccess, onFail).AsOperationResult(); /// }</code> /// </example> public static EntityScalarQueryOperation <T> OnComplete <T>(this EntityScalarQueryOperation <T> source, Action <T> onSuccess, Action <Exception> onFail) { source.Completed += (s, args) => { if (args.CompletedSuccessfully) { if (onSuccess != null) { onSuccess(args.Result); } } if (args.HasError && !args.IsErrorHandled && onFail != null) { args.MarkErrorAsHandled(); onFail(args.Error); } }; return(source); }
/// <summary> /// Gets an awaiter used to await this operation. /// </summary> /// <param name="operation"> The operation to await. </param> public static TaskAwaiter <object> GetAwaiter(this EntityScalarQueryOperation operation) { return(operation.AsOperationResult().GetAwaiter()); }
/// <summary> /// Returns an implementation of <see cref="OperationResult{T}" /> that wraps a DevForce asynchronous function and provides access to the operation's result value. /// </summary> /// <param name="asyncOp"> DevForce asynchronous operation. </param> /// <returns> OperationResult encapsulating the provided DevForce asynchronous operation. </returns> public static OperationResult <T> AsOperationResult <T>(this EntityScalarQueryOperation <T> asyncOp) { return(new EntityScalarQueryOperationResult <T>(asyncOp)); }
/// <summary> /// Returns an implementation of <see cref="OperationResult{T}" /> that wraps a DevForce asynchronous function and provides access to the operation's result value. /// </summary> /// <param name="asyncOp"> DevForce asynchronous operation. </param> /// <returns> OperationResult encapsulating the provided DevForce asynchronous operation. </returns> public static OperationResult <object> AsOperationResult(this EntityScalarQueryOperation asyncOp) { return(new EntityScalarQueryOperationResult <object>(asyncOp)); }
public EntityScalarQueryOperationResult(EntityScalarQueryOperation entityScalarQueryOperation) : base(entityScalarQueryOperation) { _entityScalarQueryOperation = entityScalarQueryOperation; }
public EntityScalarQueryOperationResult(EntityScalarQueryOperation <T> entityScalarQueryOperationT) : base(entityScalarQueryOperationT) { _entityScalarQueryOperationT = entityScalarQueryOperationT; }