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


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /// <summary>
  2. /// An Extender to extend the behavior of deleting an Expense Record
  3. /// </summary>
  4. public class DeleteExtension : IOperationBehaviorExtender
  5. {
  6. #region IOperationBehaviorExtender Members
  7.  
  8. /// <summary>
  9. /// The name of the action being extended
  10. /// </summary>
  11. public string Action
  12. {
  13. get { return "Expense/Delete"; }
  14. }
  15.  
  16. /// <summary>
  17. /// Executed before the 'core' implemenation of the method is executed.
  18. /// </summary>
  19. /// <param name="action"></param>
  20. /// <param name="inputs"></param>
  21. /// <param name="faultMessage"></param>
  22. /// <returns>returning False will cancel the execution of the Invoke method, otherwise return true</returns>
  23. public bool BeforeInvoke(string action, object[] inputs, out string faultMessage)
  24. {
  25. faultMessage = string.Empty;
  26.  
  27. return true;
  28. }
  29.  
  30. /// <summary>
  31. /// Executed after the 'core' implementation of the method has been executed
  32. /// </summary>
  33. /// <param name="action"></param>
  34. /// <param name="inputs"></param>
  35. /// <param name="outputs"></param>
  36. /// <param name="returnValue"></param>
  37. /// <remarks>
  38. /// If a fault occurs within this method ensure an Exception is thrown to rollback (if possible) the Invoke and BeforeInvoke implementations
  39. /// </remarks>
  40. public void AfterInvoke(string action, object[] inputs, ref object[] outputs, ref object returnValue)
  41. {
  42.  
  43. }
  44.  
  45. /// <summary>
  46. /// Very simple validation...don't let an expense be deleted if the id is an odd number
  47. /// </summary>
  48. /// <param name="action"></param>
  49. /// <param name="inputs"></param>
  50. /// <param name="message"></param>
  51. /// <returns>bool (false will cancel the method being invoked)</returns>
  52. /// <remarks>
  53. /// If a fault occurs within this method ensure an Exception is thrown to rollback (if possible) the Invoke and BeforeInvoke implementations
  54. /// </remarks>
  55. public bool ValidateBeforeCall(string action, object[] inputs, out string message)
  56. {
  57. bool result = true;
  58. message = string.Empty;
  59.  
  60. // cast the input to the correct type of object
  61. if (inputs[0] is int)
  62. {
  63. int? id = (int?)inputs[0];
  64.  
  65. if ((id % 2) > 0)
  66. {
  67. result = false;
  68. message = "This Expense is still being processed and cannot be deleted";
  69. }
  70. }
  71.  
  72. return result;
  73. }
  74.  
  75. /// <summary>
  76. /// Allows extra processing to occur after the method has been fully processed
  77. /// </summary>
  78. /// <param name="action"></param>
  79. /// <param name="outputs"></param>
  80. /// <param name="returnValue"></param>
  81. /// <param name="correlationState"></param>
  82. public void AfterCall(string action, object[] outputs, object returnValue, object correlationState)
  83. {
  84.  
  85. }
  86.  
  87. #endregion
  88. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.