/// <summary> /// Send a Raw notification to all WP7 devices subscribed to a given subscription. /// </summary> /// <param name="subId">Id of the subscription to send the message to.</param> /// <param name="message">The message text.</param> /// <returns>Returns "success" if successful otherwise an error.</returns> public string SendRawNotification(string subId, string message) { // Make sure user is authenticated, if (!AuthManager.AuthenticateUser()) { AuthManager.ConstructAuthResponse(); return null; } // Make sure subscription name is created bool subExists = this.subscriptionInfoMgr.IsSubscriptionRegistered(subId); if (!subExists) { throw new WebFaultException<string>(Utils.GetErrorString(PushMessageError.ErrorSubscriptionNameNotFound), System.Net.HttpStatusCode.BadRequest); } try { RawMessage rawMsg = new RawMessage(subId, message); this.msgQueue.Enque(rawMsg); return "success"; } catch (Exception e) { Trace.TraceError(string.Format(CultureInfo.InvariantCulture, "Internal Error: SendRaw subscription: {0} message: {1}, Error: {2}", subId, message, e.Message)); throw new WebFaultException<string>(e.Message, System.Net.HttpStatusCode.InternalServerError); } }
/// <summary> /// Initializes a new instance of the NotificationFormatException class. /// </summary> /// This is needed for ISerializable interface /// <param name="serializationInfo">SerializationInfo provides the class where the class is serialized.</param> /// <param name="streamingContext">Additional StreamingContext class.</param> protected NotificationFormatException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext) { if (serializationInfo != null) { PushMessageType messageType = (PushMessageType)serializationInfo.GetInt16("MessageType"); string subscriptionName = serializationInfo.GetString("SubscriptionName"); if ((PushMessageType)this.NotificationMessage.MessageType == PushMessageType.Raw) { string rawMessageText = serializationInfo.GetString("rawMessageText"); RawMessage rawMessage = new RawMessage(subscriptionName, rawMessageText); this.NotificationMessage = rawMessage; } else if ((PushMessageType)this.NotificationMessage.MessageType == PushMessageType.Toast) { string tileMessageText = serializationInfo.GetString("toastMessageText"); ToastMessage toastMessage = new ToastMessage(subscriptionName, tileMessageText); this.NotificationMessage = toastMessage; } else if ((PushMessageType)this.NotificationMessage.MessageType == PushMessageType.Tile) { string tileMessageTitle = serializationInfo.GetString("tileMessageTitle"); string tileMessageCount = serializationInfo.GetString("tileMessageCount"); string tileMessageUrl = serializationInfo.GetString("tileMessageUrl"); TileMessage tileMessage = new TileMessage(subscriptionName, tileMessageTitle, tileMessageCount, tileMessageUrl); this.NotificationMessage = tileMessage; } else if ((PushMessageType)this.NotificationMessage.MessageType == PushMessageType.Iphone) { string messageAlert = serializationInfo.GetString("iPhoneMessageAlert"); string messageBadge = serializationInfo.GetString("iPhoneMessageBadge"); string messageSound = serializationInfo.GetString("iPhoneMessageSound"); iPhoneMessage iphoneMessage = new iPhoneMessage(subscriptionName, messageAlert, messageBadge, messageSound); this.NotificationMessage = iphoneMessage; } else if ((PushMessageType)this.NotificationMessage.MessageType == PushMessageType.Common) { string messageTitle = serializationInfo.GetString("commmonMessageTitle"); int messageCount = serializationInfo.GetInt32("commonMessageCount"); string messageImage = serializationInfo.GetString("commonMessageImage"); string messageSound = serializationInfo.GetString("commonMessageSound"); CommonMessage commonMessage = new CommonMessage(subscriptionName, messageTitle, messageCount, messageImage, messageSound); this.NotificationMessage = commonMessage; } } }