Example #1
0
 /// <summary>
 ///     Called when the response sequence produces an error, or by a custom transaction to indicate an
 ///     error condition. This indicates a failed transaction.
 /// </summary>
 /// <param name="except">The exception.</param>
 /// <remarks>
 ///     Overriding <c>OnError</c> is discouraged but it you do, you should call <c>base.OnError</c>
 ///     before returning from your override method, to ensure correct thread synchronization and that
 ///     the internal state remains consistent. <see cref="OnError" /> and <see cref="OnCompleted" />
 ///     are mutually exclusive, therefore do not call <c>base.OnCompleted</c> after calling this
 ///     method.
 /// </remarks>
 protected virtual void OnError(Exception except)
 {
     Contract.Requires(except != null);
     Contract.Ensures(Response != null);
     Contract.Ensures(ErrorMessage != null);
     Response     = Maybe <string> .Empty;
     ErrorMessage = except.Message.AsMaybe();
     State        = TransactionLifecycle.Failed;
     SignalCompletion();
 }
Example #2
0
        internal bool WaitUntilHotOrTimeout()
        {
            var wasHot = hot.WaitOne(HotTimeout);

            if (!wasHot)
            {
                State        = TransactionLifecycle.Failed;
                ErrorMessage = Maybe <string> .From("Transaction was never executed");
            }
            return(wasHot);
        }
Example #3
0
        /// <summary>
        ///     Waits (blocks) until the transaction is completed or a timeout occurs. The timeout duration
        ///     comes from the <see cref="Timeout" /> property.
        /// </summary>
        /// <returns><c>true</c> if the transaction completed successfully, <c>false</c> otherwise.</returns>
        public bool WaitForCompletionOrTimeout()
        {
            var hot = WaitUntilHotOrTimeout();

            if (!hot)
            {
                return(false);
            }
            var signalled = completion.WaitOne(Timeout);

            if (!signalled)
            {
                Response     = Maybe <string> .Empty;
                State        = TransactionLifecycle.Failed;
                ErrorMessage = Maybe <string> .From("Timed out");
            }
            return(signalled);
        }
Example #4
0
 /// <summary>Called when the response sequence completes. This indicates a successful transaction.</summary>
 /// <remarks>
 ///     This method is normally overridden in a derived type, where you can perform additional parsing
 ///     and type conversion of any received response. The recommended pattern is for the derived type
 ///     to add a <c>Value</c> property of an appropriate type, then in the OnCompleted method, set the
 ///     <c>Value</c> property before calling <c>base.OnCompleted</c>. You MUST call
 ///     <c>base.OnCompleted</c> before returning from your override method, to ensure correct thread
 ///     synchronization and internal state consistency.
 /// </remarks>
 protected virtual void OnCompleted()
 {
     State = TransactionLifecycle.Completed;
     SignalCompletion();
 }
Example #5
0
 internal void MakeHot()
 {
     State = TransactionLifecycle.InProgress;
     hot.Set();
 }