Exemplo n.º 1
0
        /// <summary>
        ///     Marks a transaction as Failed and provides a <see cref="TimeoutException" /> as the source of failure.
        ///     This also completes the transaction and releases any waiting threads.
        /// </summary>
        /// <param name="transaction">The transaction.</param>
        /// <param name="message">The message.</param>
        public static void TimedOut(this DeviceTransaction transaction, string message = null)
        {
            var exception     = new TimeoutException(message ?? "Timeout");
            var type          = transaction.GetType();
            var onErrorMethod = type.GetMethod("OnError", BindingFlags.Instance | BindingFlags.NonPublic);

            onErrorMethod.Invoke(transaction, BindingFlags.NonPublic | BindingFlags.Instance, Type.DefaultBinder,
                                 new object[] { exception }, null);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Marks a transaction as completed with the supplied response string, which will release any waiting threads.
        /// </summary>
        /// <param name="transaction">The transaction.</param>
        /// <param name="response">The response.</param>
        public static void SimulateCompletionWithResponse(this DeviceTransaction transaction, [NotNull] string response)
        {
            transaction.SetResponse(response);
            var transactionType = transaction.GetType();
            var makeHotMethod   = transactionType.GetMethod("MakeHot",
                                                            BindingFlags.Instance | BindingFlags.NonPublic);

            makeHotMethod.Invoke(transaction, BindingFlags.NonPublic | BindingFlags.Instance, Type.DefaultBinder,
                                 new object[] { }, null);
            var onCompletedMethod = transactionType.GetMethod("OnCompleted",
                                                              BindingFlags.Instance | BindingFlags.NonPublic);

            onCompletedMethod.Invoke(transaction, BindingFlags.NonPublic | BindingFlags.Instance, Type.DefaultBinder,
                                     new object[] { }, null);
        }