/*
 * Date        Sign  TaskId  Description
 * ----------  ----  ------- -----------
 * 2006-07-31  RMa           Generic version of the AsyncCompletedEventArgs should inherit from the non-generic class with same name.
 * 2006-03-09  MLa           Created
 */

using System;
namespace Wayne.Lib
{
    /// <summary>
    /// Generic event result of an asynchronous command.
    /// </summary>
    public class AsyncCompletedEventArgs : UserTokenEventArgs
    {
        #region Fields

        private bool success;

        #endregion

        #region Construction

        /// <summary>
        /// Construction.
        /// </summary>
        /// <param name="success">The status of the reservation.</param>
        /// <param name="userToken">An optional user token.</param>
        public AsyncCompletedEventArgs(bool success, object userToken)
            : base(userToken)
        {
            this.success = success;
        }

        #endregion

        #region Debug methods

        /// <summary>
        /// Presents the class as a string.
        /// </summary>
        /// <returns></returns>
        public virtual string ToString(string format, IFormatProvider provider)
        {
            return System.String.Format(provider, "AsyncCompletedEventArgs(Success={0})",
                success);
        }

        /// <summary>
        /// Presents the class as a string using the specified culture-specific format information.
        /// </summary>
        /// <returns></returns>
        public virtual string ToString(IFormatProvider provider)
        {
            return ToString("", provider);
        }

        /// <summary>
        /// Presents the class as a string using a format string.
        /// </summary>
        /// <returns></returns>
        public virtual string ToString(string format)
        {
            return ToString(format, System.Globalization.CultureInfo.InvariantCulture);
        }

        /// <summary>
        /// Presents the class as a string using a format string and the specified culture-specific format information.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return ToString("", System.Globalization.CultureInfo.InvariantCulture);
        }

        #endregion

        #region Properties

        /// <summary>
        /// The status of the reservation.
        /// </summary>
        public bool Success
        {
            get { return success; }
        }

        #endregion
    }


    /// <summary>
    /// Generic event result of an asynchronous command with an additional status property.
    /// </summary>
    public class AsyncCompletedEventArgs<TResult> : AsyncCompletedEventArgs
    {
        #region Fields

        private TResult result;

        #endregion

        #region Construction

        /// <summary>
        /// Construction.
        /// </summary>
        /// <param name="success">The basic status of the command.</param>
        /// <param name="result">Refined status of the command.</param>
        /// <param name="userToken">An optional user token.</param>
        public AsyncCompletedEventArgs(bool success, TResult result, object userToken)
            : base(success, userToken)
        {
            this.result = result;
        }

        #endregion

        #region Debug methods

        /// <summary>
        /// Presents the class as a string.
        /// </summary>
        /// <returns></returns>
        public override string ToString(string format, IFormatProvider provider)
        {
            if (result != null)
                return String.Format(provider, "AsyncCompletedEventArgs<{0}>(Success={1}, {2})",
                    typeof(TResult).Name, Success, result);
            else
                return String.Format(provider, "AsyncCompletedEventArgs<{0}>(Success={1}, null)",
                    typeof(TResult).Name, Success);
        }

        #endregion

        #region Properties

        /// <summary>
        /// Refined status of the command.
        /// </summary>
        public TResult Result
        {
            get { return result; }
        }

        #endregion
    }
}