Exemplo n.º 1
0
 protected AsyncCallback PrepareAsyncCompletion(AsyncCompletion callback)
 {
     this.nextAsyncCompletion = callback;
     if (AsyncResult.asyncCompletionWrapperCallback == null)
     {
         AsyncResult.asyncCompletionWrapperCallback = new AsyncCallback(AsyncCompletionWrapperCallback);
     }
     return(AsyncResult.asyncCompletionWrapperCallback);
 }
Exemplo n.º 2
0
        private AsyncCompletion GetNextCompletion()
        {
            AsyncCompletion result = _nextAsyncCompletion;

#if NET451
            _transactionContext = null;
#endif
            _nextAsyncCompletion = null;
            return(result);
        }
Exemplo n.º 3
0
        AsyncCompletion GetNextCompletion()
        {
            AsyncCompletion result = this.nextAsyncCompletion;

#if NET451
            this.transactionContext = null;
#endif
            this.nextAsyncCompletion = null;
            return(result);
        }
Exemplo n.º 4
0
        AsyncCompletion GetNextCompletion()
        {
            AsyncCompletion result = this.nextAsyncCompletion;

#if !WINDOWS_UWP && !PCL
            this.transactionContext = null;
#endif
            this.nextAsyncCompletion = null;
            return(result);
        }
Exemplo n.º 5
0
        bool TryContinueHelper(IAsyncResult result, out AsyncCompletion callback)
        {
            if (result == null)
            {
                throw Fx.Exception.AsError(new InvalidOperationException(CommonResources.InvalidNullAsyncResult));
            }

            callback = null;


            if (result.CompletedSynchronously)
            {
#if !WINDOWS_UWP && !PCL
                // Once we pass the check, we know that we own forward progress, so transactionContext is correct. Verify its state.
                if (this.transactionContext != null)
                {
                    if (this.transactionContext.State != TransactionSignalState.Completed)
                    {
                        ThrowInvalidAsyncResult("Check/SyncContinue cannot be called from within the PrepareTransactionalCall using block.");
                    }
                    else if (this.transactionContext.IsSignalled)
                    {
                        // This is most likely to happen when result.CompletedSynchronously registers differently here and in the callback, which
                        // is the fault of 'result'.
                        ThrowInvalidAsyncResult(result);
                    }
                }
#endif
            }
#if !WINDOWS_UWP && !PCL
            else if (object.ReferenceEquals(result, this.deferredTransactionalResult))
            {
                // The transactionContext may not be current if forward progress has been made via the callback. Instead,
                // use deferredTransactionalResult to see if we are supposed to execute a post-transaction callback.
                //
                // Once we pass the check, we know that we own forward progress, so transactionContext is correct. Verify its state.
                if (this.transactionContext == null || !this.transactionContext.IsSignalled)
                {
                    ThrowInvalidAsyncResult(result);
                }
                this.deferredTransactionalResult = null;
            }
#endif
            else
            {
                return(false);
            }

            callback = GetNextCompletion();
            if (callback == null)
            {
                ThrowInvalidAsyncResult("Only call Check/SyncContinue once per async operation (once per PrepareAsyncCompletion).");
            }
            return(true);
        }
Exemplo n.º 6
0
        protected AsyncCallback PrepareAsyncCompletion(AsyncCompletion callback)
        {
            this._beforePrepareAsyncCompletionAction?.Invoke();

            this._nextAsyncCompletion = callback;
            if (AsyncResult.s_asyncCompletionWrapperCallback == null)
            {
                AsyncResult.s_asyncCompletionWrapperCallback = Fx.ThunkCallback(new AsyncCallback(AsyncCompletionWrapperCallback));
            }

            return(AsyncResult.s_asyncCompletionWrapperCallback);
        }
Exemplo n.º 7
0
 bool TryContinueHelper(IAsyncResult result, out AsyncCompletion callback)
 {
     if (result.CompletedSynchronously)
     {
         callback = GetNextCompletion();
         return(true);
     }
     else
     {
         callback = null;
         return(false);
     }
 }
Exemplo n.º 8
0
        protected AsyncCallback PrepareAsyncCompletion(AsyncCompletion callback)
        {
            if (this.beforePrepareAsyncCompletionAction != null)
            {
                this.beforePrepareAsyncCompletionAction();
            }

            this.nextAsyncCompletion = callback;
            if (AsyncResult.asyncCompletionWrapperCallback == null)
            {
                AsyncResult.asyncCompletionWrapperCallback = Fx.ThunkCallback(new AsyncCallback(AsyncCompletionWrapperCallback));
            }
            return(AsyncResult.asyncCompletionWrapperCallback);
        }
Exemplo n.º 9
0
        protected AsyncCallback PrepareAsyncCompletion(AsyncCompletion callback)
        {
            if (_beforePrepareAsyncCompletionAction != null)
            {
                _beforePrepareAsyncCompletionAction();
            }

            _nextAsyncCompletion = callback;
            if (AsyncResult._asyncCompletionWrapperCallback == null)
            {
                AsyncResult._asyncCompletionWrapperCallback = new AsyncCallback(AsyncCompletionWrapperCallback);
            }
            return(AsyncResult._asyncCompletionWrapperCallback);
        }
Exemplo n.º 10
0
        static void AsyncCompletionWrapperCallback(IAsyncResult result)
        {
            if (result == null)
            {
                throw Fx.Exception.AsError(new InvalidOperationException(SRCore.InvalidNullAsyncResult));
            }
            if (result.CompletedSynchronously)
            {
                return;
            }

            AsyncResult thisPtr = (AsyncResult)result.AsyncState;

            if (thisPtr.transactionContext != null && !thisPtr.transactionContext.Signal(result))
            {
                // The TransactionScope isn't cleaned up yet and can't be done on this thread.  Must defer
                // the callback (which is likely to attempt to commit the transaction) until later.
                return;
            }

            AsyncCompletion callback = thisPtr.GetNextCompletion();

            if (callback == null)
            {
                ThrowInvalidAsyncResult(result);
            }

            bool      completeSelf        = false;
            Exception completionException = null;

            try
            {
                completeSelf = callback(result);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                completeSelf        = true;
                completionException = e;
            }

            if (completeSelf)
            {
                thisPtr.Complete(false, completionException);
            }
        }
Exemplo n.º 11
0
        bool ProcessReceiveContext()
        {
            if (this.receiveContext != null)
            {
                if (handleEndProcessReceiveContext == null)
                {
                    handleEndProcessReceiveContext = new AsyncCompletion(HandleEndProcessReceiveContext);
                }

                IAsyncResult nextResult = ReceiveContextAsyncResult.BeginProcessReceiveContext(this, this.receiveContext, PrepareAsyncCompletion(handleEndProcessReceiveContext), this);
                return(SyncContinue(nextResult));
            }

            return(true);
        }
Exemplo n.º 12
0
                public WriteMessageAsyncResult(Message message, Stream stream, WebMessageEncoder webMessageEncoder, AsyncCallback callback, object state)
                    : base(callback, state)
                {
                    this.message           = message;
                    this.stream            = stream;
                    this.webMessageEncoder = webMessageEncoder;

                    WebContentFormat messageFormat = webMessageEncoder.ExtractFormatFromMessage(message);
                    JavascriptCallbackResponseMessageProperty javascriptResponseMessageProperty;

                    switch (messageFormat)
                    {
                    case WebContentFormat.Json:
                        this.encoder = webMessageEncoder.JsonMessageEncoder;
                        this.Schedule();
                        break;

                    case WebContentFormat.Xml:
                        if (message.Properties.TryGetValue <JavascriptCallbackResponseMessageProperty>(JavascriptCallbackResponseMessageProperty.Name, out javascriptResponseMessageProperty) &&
                            javascriptResponseMessageProperty != null &&
                            !String.IsNullOrEmpty(javascriptResponseMessageProperty.CallbackFunctionName))
                        {
                            throw TraceUtility.ThrowHelperError(new InvalidOperationException(SR2.JavascriptCallbackNotsupported), message);
                        }
                        this.encoder = webMessageEncoder.TextMessageEncoder;
                        this.Schedule();
                        break;

                    case WebContentFormat.Raw:
                        if (message.Properties.TryGetValue <JavascriptCallbackResponseMessageProperty>(JavascriptCallbackResponseMessageProperty.Name, out javascriptResponseMessageProperty) &&
                            javascriptResponseMessageProperty != null &&
                            !String.IsNullOrEmpty(javascriptResponseMessageProperty.CallbackFunctionName))
                        {
                            throw TraceUtility.ThrowHelperError(new InvalidOperationException(SR2.JavascriptCallbackNotsupported), message);
                        }

                        handleEndWriteMessage = new AsyncCompletion(HandleEndWriteMessage);
                        IAsyncResult result = webMessageEncoder.RawMessageEncoder.BeginWriteMessage(message, stream, PrepareAsyncCompletion(HandleEndWriteMessage), this);
                        if (SyncContinue(result))
                        {
                            this.Complete(true);
                        }
                        break;

                    default:
                        throw Fx.AssertAndThrow("This should never get hit because GetFormatForContentType shouldn't return a WebContentFormat other than Json, Xml, and Raw");
                    }
                }
Exemplo n.º 13
0
        private static void AsyncCompletionWrapperCallback(IAsyncResult result)
        {
            if (result == null)
            {
                throw Fx.Exception.AsError(new InvalidOperationException(InternalSR.InvalidNullAsyncResult));
            }
            if (result.CompletedSynchronously)
            {
                return;
            }

            AsyncResult thisPtr = (AsyncResult)result.AsyncState;

            if (!thisPtr.OnContinueAsyncCompletion(result))
            {
                return;
            }

            AsyncCompletion callback = thisPtr.GetNextCompletion();

            if (callback == null)
            {
                ThrowInvalidAsyncResult(result);
            }

            bool      completeSelf        = false;
            Exception completionException = null;

            try
            {
                completeSelf = callback(result);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                completeSelf        = true;
                completionException = e;
            }

            if (completeSelf)
            {
                thisPtr.Complete(false, completionException);
            }
        }
Exemplo n.º 14
0
        private static void AsyncCompletionWrapperCallback(IAsyncResult result)
        {
            if (result == null)
            {
                throw new ArgumentNullException("null");
            }

            if (result.CompletedSynchronously)
            {
                return;
            }

            AsyncResult thisPtr = (AsyncResult)result.AsyncState;
            if (!thisPtr.OnContinueAsyncCompletion(result))
            {
                return;
            }

            AsyncCompletion callback = thisPtr.GetNextCompletion();
            if (callback == null)
            {
                ThrowInvalidAsyncResult(result);
            }

            bool completeSelf = false;
            Exception completionException = null;
            try
            {
                completeSelf = callback(result);
            }
            catch (Exception e)
            {
                if (Utility.IsFatal(e))
                {
                    throw;
                }

                completeSelf = true;
                completionException = e;
            }

            if (completeSelf)
            {
                thisPtr.Complete(false, completionException);
            }
        }
Exemplo n.º 15
0
 protected AsyncCallback PrepareAsyncCompletion(AsyncCompletion callback)
 {
     if (this.transactionContext != null)
     {
         if (this.transactionContext.IsPotentiallyAbandoned)
         {
             this.transactionContext = null;
         }
         else
         {
             this.transactionContext.Prepared();
         }
     }
     this.nextAsyncCompletion = callback;
     if (asyncCompletionWrapperCallback == null)
     {
         asyncCompletionWrapperCallback = Fx.ThunkCallback(new AsyncCallback(AsyncResult.AsyncCompletionWrapperCallback));
     }
     return(asyncCompletionWrapperCallback);
 }
Exemplo n.º 16
0
        bool TryContinueHelper(IAsyncResult result, out AsyncCompletion callback)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            callback = null;

            if (!result.CompletedSynchronously)
            {
                return(false);
            }

            callback = GetNextCompletion();
            if (callback == null)
            {
                ThrowInvalidAsyncResult("Only call Check/SyncContinue once per async operation (once per PrepareAsyncCompletion).");
            }
            return(true);
        }
Exemplo n.º 17
0
        bool TryContinueHelper(IAsyncResult result, out AsyncCompletion continueCallback)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            continueCallback = null;

            if (!result.CompletedSynchronously)
            {
                return(false);
            }

            continueCallback = GetNextCompletion();
            if (continueCallback == null)
            {
                ThrowInvalidAsyncResult(string.Format(CultureInfo.CurrentCulture, Resources.Error_OnlyOnceChecOrSyncPerOperation));
            }
            return(true);
        }
Exemplo n.º 18
0
 private bool TryContinueHelper(IAsyncResult result, out AsyncCompletion callback)
 {
     if (result == null)
     {
         throw Fx.Exception.AsError(new InvalidOperationException(SRCore.InvalidNullAsyncResult));
     }
     callback = null;
     if (result.CompletedSynchronously)
     {
         if (this.transactionContext != null)
         {
             if (this.transactionContext.State != TransactionSignalState.Completed)
             {
                 ThrowInvalidAsyncResult("Check/SyncContinue cannot be called from within the PrepareTransactionalCall using block.");
             }
             else if (this.transactionContext.IsSignalled)
             {
                 ThrowInvalidAsyncResult(result);
             }
         }
     }
     else
     {
         if (!object.ReferenceEquals(result, this.deferredTransactionalResult))
         {
             return(false);
         }
         if ((this.transactionContext == null) || !this.transactionContext.IsSignalled)
         {
             ThrowInvalidAsyncResult(result);
         }
         this.deferredTransactionalResult = null;
     }
     callback = this.GetNextCompletion();
     if (callback == null)
     {
         ThrowInvalidAsyncResult("Only call Check/SyncContinue once per async operation (once per PrepareAsyncCompletion).");
     }
     return(true);
 }
Exemplo n.º 19
0
        private static void AsyncCompletionWrapperCallback(IAsyncResult result)
        {
            if (result == null)
            {
                throw Fx.Exception.AsError(new InvalidOperationException(CommonResources.InvalidNullAsyncResult));
            }

            if (result.CompletedSynchronously)
            {
                return;
            }

            var thisPtr = (AsyncResult)result.AsyncState;

            AsyncCompletion callback = thisPtr.GetNextCompletion();

            if (callback == null)
            {
                ThrowInvalidAsyncResult(result);
            }

            bool      completeSelf        = false;
            Exception completionException = null;

            try
            {
                completeSelf = callback(result);
            }
            catch (Exception e)
            {
                completeSelf        = true;
                completionException = e;
            }

            if (completeSelf)
            {
                thisPtr.Complete(false, completionException);
            }
        }
Exemplo n.º 20
0
        protected AsyncCallback PrepareAsyncCompletion(AsyncCompletion callback)
        {
            if (this.transactionContext != null)
            {
                // It might be an old, leftover one, if an exception was thrown within the last using (PrepareTransactionalCall()) block.
                if (this.transactionContext.IsPotentiallyAbandoned)
                {
                    this.transactionContext = null;
                }
                else
                {
                    this.transactionContext.Prepared();
                }
            }

            this.nextAsyncCompletion = callback;
            if (AsyncResult.asyncCompletionWrapperCallback == null)
            {
                AsyncResult.asyncCompletionWrapperCallback = new AsyncCallback(AsyncCompletionWrapperCallback);
            }
            return(AsyncResult.asyncCompletionWrapperCallback);
        }
Exemplo n.º 21
0
        static void AsyncCompletionWrapperCallback(IAsyncResult result)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }
            if (result.CompletedSynchronously)
            {
                return;
            }

            AsyncResult thisPtr = (AsyncResult)result.AsyncState;

            AsyncCompletion callback = thisPtr.GetNextCompletion();

            if (callback == null)
            {
                ThrowInvalidAsyncResult(result);
            }

            bool      completeSelf;
            Exception completionException = null;

            try
            {
                completeSelf = callback(result);
            }
            catch (Exception e)
            {
                completeSelf        = true;
                completionException = e;
            }

            if (completeSelf)
            {
                thisPtr.Complete(false, completionException);
            }
        }
Exemplo n.º 22
0
 private static void AsyncCompletionWrapperCallback(IAsyncResult result)
 {
     if (result == null)
     {
         throw Fx.Exception.AsError(new InvalidOperationException(SRCore.InvalidNullAsyncResult));
     }
     if (!result.CompletedSynchronously)
     {
         AsyncResult asyncState = (AsyncResult)result.AsyncState;
         if ((asyncState.transactionContext == null) || asyncState.transactionContext.Signal(result))
         {
             AsyncCompletion nextCompletion = asyncState.GetNextCompletion();
             if (nextCompletion == null)
             {
                 ThrowInvalidAsyncResult(result);
             }
             bool      flag      = false;
             Exception exception = null;
             try
             {
                 flag = nextCompletion(result);
             }
             catch (Exception exception2)
             {
                 if (Fx.IsFatal(exception2))
                 {
                     throw;
                 }
                 flag      = true;
                 exception = exception2;
             }
             if (flag)
             {
                 asyncState.Complete(false, exception);
             }
         }
     }
 }
Exemplo n.º 23
0
        protected AsyncCallback PrepareAsyncCompletion(AsyncCompletion callback)
        {
#if NET451
            if (_transactionContext != null)
            {
                // It might be an old, leftover one, if an exception was thrown within the last using (PrepareTransactionalCall()) block.
                if (_transactionContext.IsPotentiallyAbandoned)
                {
                    _transactionContext = null;
                }
                else
                {
                    _transactionContext.Prepared();
                }
            }
#endif
            _nextAsyncCompletion = callback;
            if (s_asyncCompletionWrapperCallback == null)
            {
                s_asyncCompletionWrapperCallback = new AsyncCallback(AsyncCompletionWrapperCallback);
            }
            return(s_asyncCompletionWrapperCallback);
        }
            bool ReleaseInstance()
            {
                if (handleEndUnload == null)
                {
                    handleEndUnload = new AsyncCompletion(HandleEndUnload);
                }

                IAsyncResult result = null;
                try
                {
                    if (this.isTryUnload)
                    {
                        result = this.BeginTryUnload(timeoutHelper.RemainingTime(),
                            this.PrepareAsyncCompletion(handleEndUnload), this);
                    }
                    else
                    {
                        result = this.BeginUnload(timeoutHelper.RemainingTime(),
                            this.PrepareAsyncCompletion(handleEndUnload), this);
                    }
                }
                catch (FaultException exception)
                {
                    if (OperationExecutionFault.IsAbortedFaultException(exception))
                    {
                        FxTrace.Exception.AsWarning(exception);
                        return true;
                    }
                    else
                    {
                        throw;
                    }
                }

                if (result.CompletedSynchronously)
                {
                    return HandleEndUnload(result);
                }
                else
                {
                    return false;
                }
            }
                bool HandleEndAcquireReference()
                {
                    this.referenceAcquired = true;

                    if (this.instance.TryReleaseLastReference())
                    {
                        if (handleEndAbandon == null)
                        {
                            handleEndAbandon = new AsyncCompletion(HandleEndAbandon);
                        }

                        IAsyncResult result = this.instance.BeginAbandon(new FaultException(OperationExecutionFault.CreateAbortedFault(SR.DefaultAbortReason)), false,
                            this.timeoutHelper.RemainingTime(), PrepareAsyncCompletion(handleEndAbandon), this);
                        return SyncContinue(result);
                    }
                    else
                    {
                        return true;
                    }
                }
            bool Track()
            {
                // For aborted, the AbortInstance will handle tracking.
                if (this.instance.state != State.Aborted && this.instance.Controller.HasPendingTrackingRecords)
                {
                    if (handleEndTrack == null)
                    {
                        handleEndTrack = new AsyncCompletion(HandleEndTrack);
                    }

                    IAsyncResult result = this.instance.Controller.BeginFlushTrackingRecords(this.instance.trackTimeout, PrepareAsyncCompletion(handleEndTrack), this);
                    if (result.CompletedSynchronously)
                    {
                        return HandleEndTrack(result);
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return ReleaseLock();
                }
            }
            bool AttachTransaction()
            {
                if (this.OperationTransaction != null && this.Instance.transactionContext == null)
                {
                    this.Instance.transactionContext = new TransactionContext(this.Instance, this.OperationTransaction);
                    this.Instance.isInTransaction = true;
                    this.Instance.isRunnable = false;
                }

                if (this.IsSynchronousOperation)
                {
                    PerformOperation();
                    return Track();
                }
                else
                {
                    if (handleEndPerformOperation == null)
                    {
                        handleEndPerformOperation = new AsyncCompletion(HandleEndPerformOperation);
                    }

                    IAsyncResult result = BeginPerformOperation(PrepareAsyncCompletion(handleEndPerformOperation), this);
                    if (result.CompletedSynchronously)
                    {
                        return HandleEndPerformOperation(result);
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            AsyncCallback PrepareInnerAsyncCompletion(AsyncCompletion innerCallback)
            {
                this.nextInnerAsyncCompletion = innerCallback;

                return PrepareAsyncCompletion(outermostCallback);
            }
            AsyncCompletion GetNextInnerAsyncCompletion()
            {
                AsyncCompletion next = this.nextInnerAsyncCompletion;

                Fx.Assert(this.nextInnerAsyncCompletion != null, "Must have had one if we are calling GetNext");
                this.nextInnerAsyncCompletion = null;

                return next;
            }
            static bool OnReleasePersistenceContext(IAsyncResult result)
            {
                ReleaseInstanceAsyncResult thisPtr = (ReleaseInstanceAsyncResult)result.AsyncState;
                thisPtr.workflowInstance.persistenceContext.EndRelease(result);
                if (onClosePersistenceContext == null)
                {
                    onClosePersistenceContext = new AsyncCompletion(OnClosePersistenceContext);
                }

                IAsyncResult closeResult = thisPtr.workflowInstance.persistenceContext.BeginClose(thisPtr.timeoutHelper.RemainingTime(),
                    thisPtr.PrepareAsyncCompletion(onClosePersistenceContext), thisPtr);
                return thisPtr.SyncContinue(closeResult);
            }
            bool AbandonReceiveContext(Exception operationException)
            {
                Fx.Assert(ShouldAbandonReceiveContext(), "ShouldAbandonReceiveContext() is false!");
                if (handleEndAbandonReceiveContext == null)
                {
                    handleEndAbandonReceiveContext = new AsyncCompletion(HandleEndAbandonReceiveContext);
                }

                Fx.Assert(operationException != null, "operationException must not be null!");
                Fx.Assert(this.operationException == null, "AbandonReceiveContext must not be called twice!");
                this.operationException = operationException;
                IAsyncResult result = this.receiveContext.BeginAbandon(TimeSpan.MaxValue, this.PrepareAsyncCompletion(handleEndAbandonReceiveContext), this);
                return SyncContinue(result);
            }
            bool ReleasePersistenceContext()
            {
                if (this.workflowInstance.persistenceContext.State != CommunicationState.Opened)
                {
                    return true;
                }

                if (onReleasePersistenceContext == null)
                {
                    onReleasePersistenceContext = new AsyncCompletion(OnReleasePersistenceContext);
                }

                IAsyncResult result = this.workflowInstance.persistenceContext.BeginRelease(this.workflowInstance.persistTimeout,
                    PrepareAsyncCompletion(onReleasePersistenceContext), this);

                return SyncContinue(result);
            }
Exemplo n.º 33
0
        bool ProcessReceiveContext()
        {
            if (this.receiveContext != null)
            {
                if (handleEndProcessReceiveContext == null)
                {
                    handleEndProcessReceiveContext = new AsyncCompletion(HandleEndProcessReceiveContext);
                }

                IAsyncResult nextResult = ReceiveContextAsyncResult.BeginProcessReceiveContext(this, this.receiveContext, PrepareAsyncCompletion(handleEndProcessReceiveContext), this);
                return SyncContinue(nextResult);
            }

            return true;
        }
                public WriteMessageAsyncResult(Message message, Stream stream, WebMessageEncoder webMessageEncoder, AsyncCallback callback, object state)
                    : base(callback, state)
                {
                    this.message = message;
                    this.stream = stream;
                    this.webMessageEncoder = webMessageEncoder;

                    WebContentFormat messageFormat = webMessageEncoder.ExtractFormatFromMessage(message);
                    JavascriptCallbackResponseMessageProperty javascriptResponseMessageProperty;

                    switch (messageFormat)
                    {
                        case WebContentFormat.Json:
                            this.encoder = webMessageEncoder.JsonMessageEncoder;
                            this.Schedule();
                            break;

                        case WebContentFormat.Xml:
                            if (message.Properties.TryGetValue<JavascriptCallbackResponseMessageProperty>(JavascriptCallbackResponseMessageProperty.Name, out javascriptResponseMessageProperty) &&
                                javascriptResponseMessageProperty != null &&
                                !String.IsNullOrEmpty(javascriptResponseMessageProperty.CallbackFunctionName))
                            {
                                throw TraceUtility.ThrowHelperError(new InvalidOperationException(SR2.JavascriptCallbackNotsupported), message);
                            }
                            this.encoder = webMessageEncoder.TextMessageEncoder;
                            this.Schedule();
                            break;

                        case WebContentFormat.Raw:
                            if (message.Properties.TryGetValue<JavascriptCallbackResponseMessageProperty>(JavascriptCallbackResponseMessageProperty.Name, out javascriptResponseMessageProperty) &&
                                javascriptResponseMessageProperty != null &&
                                !String.IsNullOrEmpty(javascriptResponseMessageProperty.CallbackFunctionName))
                            {
                                throw TraceUtility.ThrowHelperError(new InvalidOperationException(SR2.JavascriptCallbackNotsupported), message);
                            }

                            handleEndWriteMessage = new AsyncCompletion(HandleEndWriteMessage);
                            IAsyncResult result = webMessageEncoder.RawMessageEncoder.BeginWriteMessage(message, stream, PrepareAsyncCompletion(HandleEndWriteMessage), this);
                            if (SyncContinue(result))
                            {
                                this.Complete(true);
                            }
                            break;

                        default:
                            throw Fx.AssertAndThrow("This should never get hit because GetFormatForContentType shouldn't return a WebContentFormat other than Json, Xml, and Raw");
                    }
                }
Exemplo n.º 35
0
 protected AsyncCallback PrepareAsyncCompletion(AsyncCompletion callback)
 {
     this._nextAsyncCompletion = callback;
     return(AsyncResult._asyncCompletionWrapperCallback ??
            (AsyncResult._asyncCompletionWrapperCallback = new AsyncCallback(AsyncCompletionWrapperCallback)));
 }
Exemplo n.º 36
0
 private AsyncCompletion GetNextCompletion()
 {
     AsyncCompletion result = this.nextAsyncCompletion;
     this.nextAsyncCompletion = null;
     return result;
 }
            public SaveAsyncResult(Guid id, string workflowInstanceStatus, WorkflowDefinitionInfo definitionInfo, string connectionString, TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.definitionInfo = definitionInfo;

                if (handleEndExecuteNonQuery == null)
                {
                    handleEndExecuteNonQuery = new AsyncCompletion(HandleEndExecuteNonQuery);
                }

                this.connection = new SqlConnection(connectionString);
                if (!StatusIsComplete(workflowInstanceStatus))
                {
                    this.command = BuildAssociateDefinitionCommand(this.connection, id, this.definitionInfo.Path);
                }
                else
                {
                    this.command = BuildDeleteDefinitionCommand(this.connection, id);
                }
                this.connection.Open();

                IAsyncResult result = command.BeginExecuteNonQuery(PrepareAsyncCompletion(handleEndExecuteNonQuery), this);

                if (result.CompletedSynchronously)
                {
                    if (HandleEndExecuteNonQuery(result))
                    {
                        Complete(true);
                    }
                }
            }