public OperationAwaiter(OperationBase control)
 {
     _operation = control;
 }
 public static OperationAwaiter GetAwaiter(this OperationBase operation)
 {
     return(new OperationAwaiter(operation));
 }
        private void RaiseLoadCompleted(OperationBase op)
        {
            if (op.HasError)
            {
                op.MarkErrorAsHandled();
            }

            AsyncCompletedEventHandler handler = this.LoadCompleted;
            if (handler != null)
            {
                handler(this, new AsyncCompletedEventArgs(op.Error, op.IsCanceled, op.UserState));
            }
        }
        private void OnInvokeCompleted(object sender, EventArgs e)
        {
            this.Operation = null;

            InvokeOperation op = (InvokeOperation)sender;
            if (!op.HasError && !op.IsCanceled)
            {
                this.Data = (IEnumerable)op.Value;
            }
            this.RaiseLoadCompleted(op);
        }
        private void OnLoadCompleted(LoadOperation op)
        {
            this.Operation = null;

            if (!op.HasError && !op.IsCanceled)
            {
                this.Data = op.Entities;
            }
            this.RaiseLoadCompleted(op);
        }
 public void Refresh()
 {
     if ((this.DomainContext != null) & !string.IsNullOrEmpty(this.OperationName))
     {
         Type domainContextType = this.DomainContext.GetType();
         MethodInfo operationInfo = domainContextType.GetMethods().Where(
             m => (m.Name == this.OperationName) && (m.GetParameters().Count() == this.Parameters.Count)).FirstOrDefault();
         if (operationInfo == null)
         {
             System.Diagnostics.Debug.WriteLine(
                 "Could not find a method named " + this.OperationName +
                 " with the specified parameters (" + string.Join(",", this.Parameters.Select(p => p.ParameterName)) + ").");
         }
         else
         {
             if (typeof(EntityQuery).IsAssignableFrom(operationInfo.ReturnType))
             {
                 // Query
                 if (!DesignerProperties.IsInDesignTool)
                 {
                     EntityQuery query = (EntityQuery)operationInfo.Invoke(this.DomainContext, this.Parameters.Select(p => p.Value).ToArray());
                     this.Operation = this.DomainContext.Load(query, LoadBehavior.KeepCurrent, this.OnLoadCompleted, null);
                 }
             }
             else if (typeof(InvokeOperation).IsAssignableFrom(operationInfo.ReturnType))
             {
                 // Invoke
                 if (!operationInfo.ReturnType.IsGenericType || !typeof(IEnumerable).IsAssignableFrom(operationInfo.ReturnType.GetGenericArguments()[0]))
                 {
                     throw new NotImplementedException("Support non-enumerable InvokeOperation return types is not implemented.");
                 }
                 if (!DesignerProperties.IsInDesignTool)
                 {
                     this.Operation = (InvokeOperation)operationInfo.Invoke(this.DomainContext, this.Parameters.Select(p => p.Value).ToArray());
                     this.Operation.Completed += this.OnInvokeCompleted;
                 }
             }
             else
             {
                 throw new NotImplementedException("Support for return types other than EntityQuery and InvokeOperation is not implemented.");
             }
         }
     }
 }