public IAsyncResult BeginExecute(InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
 {
     IAsyncResult result;
     if (command == null)
     {
         throw Fx.Exception.ArgumentNull("command");
     }
     this.ThrowIfNotActive("BeginExecute");
     try
     {
         this.ReconcileTransaction();
         result = new ExecuteAsyncResult(this, command, timeout, callback, state);
     }
     catch (TimeoutException)
     {
         this.InstanceHandle.Free();
         throw;
     }
     catch (OperationCanceledException)
     {
         this.InstanceHandle.Free();
         throw;
     }
     return result;
 }
Exemple #2
0
        private static JObject getJsonResultOrThrow(ExecuteAsyncResult result)
        {
            var jsonResult = JObject.Parse(
                JsonConvert.SerializeObject(
                    new { data = result.Result.Data }
                    )
                );

            if (result.Result.Errors != null)
            {
                Exception error   = result.Result.Errors[0];
                var       message = "";
                while (error != null)
                {
                    message = error.Message;
                    error   = error.InnerException;
                }

                var errorMessage = string.Join(
                    Environment.NewLine,
                    "",
                    "Query:", result.Query,
                    "Variable:", result.Variable,
                    "Result:", jsonResult.ToString(),
                    "Error Messages:", message
                    );
                throw new Exception(errorMessage, new Exception(message));
            }

            return(jsonResult);
        }
 protected override void EndMakeMethodCall(AsyncCodeActivityContext context, IAsyncResult result)
 {
     MethodResolver.InvokeMethodInstanceData data = ExecuteAsyncResult.End(result);
     if (data.ExceptionWasThrown)
     {
         throw FxTrace.Exception.AsError(data.Exception);
     }
     base.SetOutArgumentAndReturnValue(context, data.ReturnValue, data.ActualParameters);
 }
            protected override void EndMakeMethodCall(AsyncCodeActivityContext context, IAsyncResult result)
            {
                InvokeMethodInstanceData instance = ExecuteAsyncResult.End(result);

                if (instance.ExceptionWasThrown)
                {
                    throw FxTrace.Exception.AsError(instance.Exception);
                }
                else
                {
                    this.SetOutArgumentAndReturnValue(context, instance.ReturnValue, instance.ActualParameters);
                }
            }
                private static void AsyncExecute(object state)
                {
                    ExecuteAsyncResult thisPtr = (ExecuteAsyncResult)state;

                    thisPtr.AsyncExecuteCore();
                }
                public static InvokeMethodInstanceData End(IAsyncResult result)
                {
                    ExecuteAsyncResult thisPtr = AsyncResult.End <ExecuteAsyncResult>(result);

                    return(thisPtr.instance);
                }
            public ExecuteAsyncResult(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
                : this(command, timeout, callback, state)
            {
                this.context = context;

                this.priorAsyncResult = this.context.LastAsyncResult;
                Fx.Assert(this.priorAsyncResult != null, "The LastAsyncResult should already have been checked.");
                this.priorAsyncResult.executeCalledByCurrentCommand = true;

                OnCompleting = new Action<AsyncResult, Exception>(SimpleCleanup);

                bool completeSelf = false;
                bool success = false;
                try
                {
                    this.context.LastAsyncResult = this;
                    if (RunLoop())
                    {
                        completeSelf = true;
                    }
                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        this.context.LastAsyncResult = this.priorAsyncResult;
                    }
                }
                if (completeSelf)
                {
                    Complete(true);
                }
            }
            public ExecuteAsyncResult(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout)
                : this(command, timeout, null, null)
            {
                this.context = context;

                this.priorAsyncResult = this.context.LastAsyncResult;
                Fx.Assert(this.priorAsyncResult != null, "The LastAsyncResult should already have been checked.");
                this.priorAsyncResult.executeCalledByCurrentCommand = true;

                bool success = false;
                try
                {
                    this.context.LastAsyncResult = this;
                    RunLoopCore(true);
                    success = true;
                }
                finally
                {
                    this.context.LastAsyncResult = this.priorAsyncResult;
                    if (!success && this.context.IsHandleDoomedByRollback)
                    {
                        this.context.InstanceHandle.Free();
                    }
                }
                Complete(true);
            }
        public virtual IAsyncResult BeginExecute(string command, AsyncCallback callback, object state)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(this.GetType().ToString());
            }
            if (!IsConnected)
            {
                throw new InvalidOperationException(Resources.NotConnectedMessage);
            }
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }
            if (command.Length > Ddeml.MAX_STRING_SIZE)
            {
                throw new ArgumentException(Resources.StringParameterInvalidMessage, "command");
            }

            // Convert the command to a byte array with a null terminating character.
            byte[] data = _Context.Encoding.GetBytes(command + "\0");

            // Send the command to the server.
            int transactionId = 0;
            IntPtr result = Ddeml.DdeClientTransaction(
                data,
                data.Length,
                _ConversationHandle,
                IntPtr.Zero,
                Ddeml.CF_TEXT,
                Ddeml.XTYP_EXECUTE,
                Ddeml.TIMEOUT_ASYNC,
                ref transactionId);

            // If the result is null then the asynchronous operation could not begin.
            if (result == IntPtr.Zero)
            {
                int error = Ddeml.DdeGetLastError(_InstanceId);
                string message = Resources.ExecuteFailedMessage;
                message = message.Replace("${command}", command);
                throw new DdemlException(message, error);
            }

            // Create an IAsyncResult for this asynchronous operation and add it to the asynchronous transaction table.
            ExecuteAsyncResult ar = new ExecuteAsyncResult(this);
            ar.Command = command;
            ar.Callback = callback;
            ar.AsyncState = state;
            ar.TransactionId = transactionId;
            _AsynchronousTransactionTable.Add(transactionId, ar);

            return ar;
        }
 internal static IAsyncResult BeginOuterExecute(System.Runtime.DurableInstancing.InstanceHandle initialInstanceHandle, InstancePersistenceCommand command, System.Transactions.Transaction transaction, TimeSpan timeout, AsyncCallback callback, object state)
 {
     IAsyncResult result;
     try
     {
         result = new ExecuteAsyncResult(initialInstanceHandle, command, transaction, timeout, callback, state);
     }
     catch (TimeoutException)
     {
         initialInstanceHandle.Free();
         throw;
     }
     catch (OperationCanceledException)
     {
         initialInstanceHandle.Free();
         throw;
     }
     return result;
 }