RawPushNotificationMessage.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net;
  6. using WindowsPhone.Recipes.Push.Messasges.Properties;
  7. namespace WindowsPhone.Recipes.Push.Messasges
  8. {
  9. /// <summary>
  10. /// Represents a raw push notification message.
  11. /// </summary>
  12. /// <remarks>
  13. /// If you do not wish to update the tile or send a toast notification, you can instead
  14. /// send raw information to your application using a raw notification. If your application
  15. /// is not currently running, the raw notification is discarded on the Microsoft Push
  16. /// Notification Service and is not delivered to the device.
  17. ///
  18. /// This class members are thread safe.
  19. /// </remarks>
  20. public sealed class RawPushNotificationMessage : PushNotificationMessage
  21. {
  22. #region Constants
  23. /// <value>Calculated raw message headers size.</value>
  24. /// <remarks>This should ne updated if changing the protocol.</remarks>
  25. private const int RawMessageHeadersSize = 116;
  26. /// <value>Raw push notification message maximum payload size.</value>
  27. public const int MaxPayloadSize = MaxMessageSize - RawMessageHeadersSize;
  28. #endregion
  29. #region Properties
  30. /// <summary>
  31. /// Gets or sets the message raw data bytes.
  32. /// </summary>
  33. public byte[] RawData
  34. {
  35. get
  36. {
  37. return Payload;
  38. }
  39. set
  40. {
  41. Payload = value;
  42. }
  43. }
  44. /// <summary>
  45. /// Raw push notification message class id.
  46. /// </summary>
  47. protected override int NotificationClassId
  48. {
  49. get { return 3; }
  50. }
  51. #endregion
  52. #region Ctor
  53. /// <summary>
  54. /// Initializes a new instance of this type.
  55. /// </summary>
  56. /// <param name="sendPriority">The send priority of this message in the MPNS.</param>
  57. public RawPushNotificationMessage(MessageSendPriority sendPriority = MessageSendPriority.Normal)
  58. : base(sendPriority)
  59. {
  60. }
  61. #endregion
  62. #region Overrides
  63. protected override void VerifyPayloadSize(byte[] payload)
  64. {
  65. if (payload.Length > MaxPayloadSize)
  66. {
  67. throw new ArgumentOutOfRangeException(string.Format(Resources.PayloadSizeIsTooBig, MaxPayloadSize));
  68. }
  69. }
  70. #endregion
  71. }
  72. }