Return to Snippet

Revision: 39683
at January 19, 2011 22:19 by RichardCustance


Initial Code
/// <summary>
    /// An Extender to extend the behavior of deleting an Expense Record
    /// </summary>
    public class DeleteExtension : IOperationBehaviorExtender
    {
        #region IOperationBehaviorExtender Members

        /// <summary>
        /// The name of the action being extended
        /// </summary>
        public string Action
        {
            get { return "Expense/Delete"; }
        }

        /// <summary>
        /// Executed before the 'core' implemenation of the method is executed.
        /// </summary>
        /// <param name="action"></param>
        /// <param name="inputs"></param>
        /// <param name="faultMessage"></param>
        /// <returns>returning False will cancel the execution of the Invoke method, otherwise return true</returns>
        public bool BeforeInvoke(string action, object[] inputs, out string faultMessage)
        {
            faultMessage = string.Empty;

            return true;
        }

        /// <summary>
        /// Executed after the 'core' implementation of the method has been executed
        /// </summary>
        /// <param name="action"></param>
        /// <param name="inputs"></param>
        /// <param name="outputs"></param>
        /// <param name="returnValue"></param>
        /// <remarks>
        /// If a fault occurs within this method ensure an Exception is thrown to rollback (if possible) the Invoke and BeforeInvoke implementations
        /// </remarks>
        public void AfterInvoke(string action, object[] inputs, ref object[] outputs, ref object returnValue)
        {
            
        }

        /// <summary>
        /// Very simple validation...don't let an expense be deleted if the id is an odd number
        /// </summary>
        /// <param name="action"></param>
        /// <param name="inputs"></param>
        /// <param name="message"></param>
        /// <returns>bool (false will cancel the method being invoked)</returns>
        /// <remarks>
        /// If a fault occurs within this method ensure an Exception is thrown to rollback (if possible) the Invoke and BeforeInvoke implementations
        /// </remarks>
        public bool ValidateBeforeCall(string action, object[] inputs, out string message)
        {
            bool result = true;
            message = string.Empty;

            // cast the input to the correct type of object
            if (inputs[0] is int)
            {
                int? id = (int?)inputs[0];

                if ((id % 2) > 0)
                {
                    result = false;
                    message = "This Expense is still being processed and cannot be deleted";
                }
            }

            return result;
        }

        /// <summary>
        /// Allows extra processing to occur after the method has been fully processed
        /// </summary>
        /// <param name="action"></param>
        /// <param name="outputs"></param>
        /// <param name="returnValue"></param>
        /// <param name="correlationState"></param>
        public void AfterCall(string action, object[] outputs, object returnValue, object correlationState)
        {
            
        }

        #endregion
    }

Initial URL


Initial Description


Initial Title
Web Extensibility Download Part 2 - Extending Server-side code behavior

Initial Tags


Initial Language
C#