MessageSendResult.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net;
  6. using System.Runtime.Serialization;
  7. namespace WindowsPhone.Recipes.Push.Messasges
  8. {
  9. /// <summary>
  10. /// Push notification message send operation result.
  11. /// </summary>
  12. public class MessageSendResult
  13. {
  14. #region Properties
  15. /// <summary>
  16. /// Gets the original exception or null.
  17. /// </summary>
  18. public Exception Exception { get; private set; }
  19. /// <summary>
  20. /// Gets the response time offset.
  21. /// </summary>
  22. public DateTimeOffset Timestamp { get; private set; }
  23. /// <summary>
  24. /// Gets the associated message.
  25. /// </summary>
  26. public PushNotificationMessage AssociatedMessage { get; private set; }
  27. /// <summary>
  28. /// Gets the channel URI.
  29. /// </summary>
  30. public Uri ChannelUri { get; private set; }
  31. /// <summary>
  32. /// Gets the web request status.
  33. /// </summary>
  34. public HttpStatusCode StatusCode { get; private set; }
  35. /// <summary>
  36. /// Gets the push notification status.
  37. /// </summary>
  38. public NotificationStatus NotificationStatus { get; private set; }
  39. /// <summary>
  40. /// Gets the device connection status.
  41. /// </summary>
  42. public DeviceConnectionStatus DeviceConnectionStatus { get; private set; }
  43. /// <summary>
  44. /// Gets the subscription status.
  45. /// </summary>
  46. public SubscriptionStatus SubscriptionStatus { get; private set; }
  47. #endregion
  48. #region Ctor
  49. /// <summary>
  50. /// Initializes a new instance of this type.
  51. /// </summary>
  52. internal MessageSendResult(PushNotificationMessage associatedMessage, Uri channelUri, WebResponse response)
  53. {
  54. Timestamp = DateTimeOffset.Now;
  55. AssociatedMessage = associatedMessage;
  56. ChannelUri = channelUri;
  57. InitializeStatusCodes(response as HttpWebResponse);
  58. }
  59. /// <summary>
  60. /// Initializes a new instance of this type.
  61. /// </summary>
  62. internal MessageSendResult(PushNotificationMessage associatedMessage, Uri channelUri, WebException exception)
  63. : this(associatedMessage, channelUri, response: exception.Response)
  64. {
  65. Exception = exception;
  66. }
  67. /// <summary>
  68. /// Initializes a new instance of this type.
  69. /// </summary>
  70. internal MessageSendResult(PushNotificationMessage associatedMessage, Uri channelUri, Exception exception)
  71. : this(associatedMessage, channelUri, response: null)
  72. {
  73. Exception = exception;
  74. }
  75. #endregion
  76. #region Privates
  77. private void InitializeStatusCodes(HttpWebResponse response)
  78. {
  79. if (response == null)
  80. {
  81. StatusCode = HttpStatusCode.InternalServerError;
  82. NotificationStatus = NotificationStatus.NotApplicable;
  83. DeviceConnectionStatus = DeviceConnectionStatus.NotApplicable;
  84. SubscriptionStatus = SubscriptionStatus.NotApplicable;
  85. }
  86. else
  87. {
  88. StatusCode = response.StatusCode;
  89. NotificationStatus = response.GetNotificationStatus();
  90. DeviceConnectionStatus = response.GetDeviceConnectionStatus();
  91. SubscriptionStatus = response.GetSubscriptionStatus();
  92. }
  93. }
  94. #endregion
  95. }
  96. }