Esempio n. 1
0
        /// <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&lt;int&gt; onSuccess = null,
        ///     Action&lt;Exception&gt; 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);
        }
Esempio n. 2
0
 /// <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());
 }
Esempio n. 3
0
 /// <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));
 }
Esempio n. 4
0
 /// <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));
 }
Esempio n. 5
0
 public EntityScalarQueryOperationResult(EntityScalarQueryOperation entityScalarQueryOperation)
     : base(entityScalarQueryOperation)
 {
     _entityScalarQueryOperation = entityScalarQueryOperation;
 }
Esempio n. 6
0
 public EntityScalarQueryOperationResult(EntityScalarQueryOperation <T> entityScalarQueryOperationT)
     : base(entityScalarQueryOperationT)
 {
     _entityScalarQueryOperationT = entityScalarQueryOperationT;
 }