private static void sendToastMessage(Uri clientURI, string toastTitle) { ToastPushNotificationMessage toastMessage = new ToastPushNotificationMessage(MessageSendPriority.High); toastMessage.Title = toastTitle; toastMessage.SendAsync(clientURI); }
public ActionResult SendMicrosoftToast(string userId, string message) { if (string.IsNullOrWhiteSpace(message)) { return(this.Json("The notification message cannot be null, empty nor white space.", JsonRequestBehavior.AllowGet)); } var resultList = new List <MessageSendResultLight>(); var uris = this.pushUserEndpointsRepository.GetPushUsersByName(userId).Select(u => u.ChannelUri); var pushUserEndpoint = this.pushUserEndpointsRepository.GetPushUsersByName(userId).FirstOrDefault(); var toast = new ToastPushNotificationMessage { SendPriority = MessageSendPriority.High, Title = message }; foreach (var uri in uris) { var messageResult = toast.SendAndHandleErrors(new Uri(uri)); resultList.Add(messageResult); if (messageResult.Status.Equals(MessageSendResultLight.Success)) { this.QueueMessage(pushUserEndpoint, message); } } return(this.Json(resultList, JsonRequestBehavior.AllowGet)); }
public ActionResult SendMicrosoftToast(string userId, string message) { if (string.IsNullOrWhiteSpace(message)) { return this.Json("The notification message cannot be null, empty nor white space.", JsonRequestBehavior.AllowGet); } var resultList = new List<MessageSendResultLight>(); var uris = this.pushUserEndpointsRepository.GetPushUsersByName(userId).Select(u => u.ChannelUri); var pushUserEndpoint = this.pushUserEndpointsRepository.GetPushUsersByName(userId).FirstOrDefault(); var toast = new ToastPushNotificationMessage { SendPriority = MessageSendPriority.High, Title = message }; foreach (var uri in uris) { var messageResult = toast.SendAndHandleErrors(new Uri(uri)); resultList.Add(messageResult); if (messageResult.Status.Equals(MessageSendResultLight.Success)) { this.QueueMessage(pushUserEndpoint, message); } } return this.Json(resultList, JsonRequestBehavior.AllowGet); }
public ActionResult SendToastNotification(MpnsToastViewModel vm) { if (string.IsNullOrEmpty(vm.Title)) { object error = new { Status = "Error sending notification: Field Title cannot be empty" }; return(this.Json(error)); } if (!this.EndpointExists(vm.ApplicationId, vm.TileId, vm.ClientId, vm.ChannelUrl)) { object error = new { Status = "Error sending notification: Endpoint does not exist" }; return(this.Json(error)); } this.Escape(vm.Title); this.Escape(vm.SubTitle); try { var notification = new ToastPushNotificationMessage() { Title = this.Escape(vm.Title), Subtitle = this.Escape(vm.SubTitle), TargetPage = vm.TargetPage, SendPriority = vm.Priority }; var result = notification.Send(new Uri(vm.ChannelUrl)); object response = new { SubscriptionStatus = result.SubscriptionStatus.ToString(), DeviceConnectionStatus = result.DeviceConnectionStatus.ToString(), NotificationStatus = result.NotificationStatus.ToString(), Status = result.LookupDeliveryStatus() }; return(this.Json(response)); } catch (ArgumentOutOfRangeException exception) { object error = new { Status = exception.Message }; return(this.Json(error)); } catch (InvalidOperationException exception) { object error = new { Status = exception.Message }; return(this.Json(error)); } }