private void OnRawSent(string userName, MessageSendResult result) { // In case that the device is disconnected, no need to send a tile message. if (result.DeviceConnectionStatus == DeviceConnectionStatus.TempDisconnected) { return; } // Checking these three flags we can know what's the state of both the device and apllication. bool isApplicationRunning = result.SubscriptionStatus == SubscriptionStatus.Active && result.NotificationStatus == NotificationStatus.Received && result.DeviceConnectionStatus == DeviceConnectionStatus.Connected; // In case that the application is not running, send a tile update with counter increase. if (!isApplicationRunning) { var tileMsg = new TilePushNotificationMessage(MessageSendPriority.High) { Count = IncreaseCounter(userName), BackgroundImageUri = BackgroundImageUri, Title = Title }; tileMsg.SendAsync(result.ChannelUri, Log, Log); } }
public ActionResult SendMicrosoftTile(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 pushUserEndpointList = this.pushUserEndpointsRepository.GetPushUsersByName(userId); foreach (var pushUserEndpoint in pushUserEndpointList) { var tile = new TilePushNotificationMessage { SendPriority = MessageSendPriority.High, Count = ++pushUserEndpoint.TileCount }; var messageResult = tile.SendAndHandleErrors(new Uri(pushUserEndpoint.ChannelUri)); resultList.Add(messageResult); if (messageResult.Status.Equals(MessageSendResultLight.Success)) { this.QueueMessage(pushUserEndpoint, message); this.pushUserEndpointsRepository.UpdatePushUserEndpoint(pushUserEndpoint); } } return(this.Json(resultList, JsonRequestBehavior.AllowGet)); }
public void SendLiveTile(string uri, string backgroundImageUrl, string title, int count) { if (count > 99 || !SendRealMessages) {//counter for live tile must be 1-99 number (http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/01/14/windows-push-notification-server-side-helper-library.aspx) return; } var tileMsg = new TilePushNotificationMessage(MessageSendPriority.High) { Count = count, Title = title }; tileMsg.SendAsync(new Uri(uri), delegate(MessageSendResult res) { Log.WriteInfo("DeviceConnectionStatus:" + res.DeviceConnectionStatus); Log.WriteInfo("StatusCode:" + res.StatusCode); Log.WriteInfo("NotificationStatus:" + res.NotificationStatus); Log.WriteInfo("SubscriptionStatus:" + res.SubscriptionStatus); }, delegate(MessageSendResult res) { Log.WriteInfo("DeviceConnectionStatus:" + res.DeviceConnectionStatus); Log.WriteInfo("StatusCode:" + res.StatusCode); Log.WriteInfo("NotificationStatus:" + res.NotificationStatus); Log.WriteInfo("SubscriptionStatus:" + res.SubscriptionStatus); }); }
private void PushService_TileUpdateRequest(object sender, TileUpdateRequestEventArgs e) { // Send a tile notification message to the relevant device. var tileMsg = new TilePushNotificationMessage(MessageSendPriority.High) { BackgroundImageUri = new Uri(string.Format(ImageService.GetTileImageService, e.Parameter)) }; tileMsg.SendAsync(e.ChannelUri, Log, Log); }
public ActionResult SendTileNotification(MpnsTileViewModel vm) { 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)); } var backgroundImageUri = string.IsNullOrEmpty(vm.BackgroundImageUri) ? null : new Uri(vm.BackgroundImageUri); var backBackgroundImageUri = string.IsNullOrEmpty(vm.BackBackgroundImageUri) ? null : new Uri(vm.BackBackgroundImageUri); try { var notification = new TilePushNotificationMessage() { ClearBackBackgroundImageUri = vm.ClearBackBackgroundImageUri, BackBackgroundImageUri = vm.ClearBackBackgroundImageUri ? null : backBackgroundImageUri, ClearBackContent = vm.ClearBackContent, BackContent = vm.ClearBackContent ? null : this.Escape(vm.BackContent), ClearBackTitle = vm.ClearBackTitle, BackTitle = vm.ClearBackTitle ? null : this.Escape(vm.BackTitle), ClearCount = vm.ClearCount, Count = vm.ClearCount ? 0 : vm.Count, ClearTitle = vm.ClearTitle, Title = vm.ClearTitle ? null : this.Escape(vm.Title), BackgroundImageUri = backgroundImageUri, SecondaryTile = vm.TileId, 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)); } }
/// <summary> /// On subscription change, reset the subscriber tile counter if exist. /// </summary> protected override void OnSubscribed(SubscriptionEventArgs e) { // Create a tile message to reset tile count. var tileMsg = new TilePushNotificationMessage(MessageSendPriority.High) { Count = 0, BackgroundImageUri = BackgroundImageUri, Title = Title }; tileMsg.SendAsync(e.Subscription.ChannelUri, Log, Log); ResetCounter(e.Subscription.UserName); }
protected override void OnSend() { // Starts by sending a tile notification to all relvant subscribers. // This tile notification updates the tile with custom image. var tileMsg = new TilePushNotificationMessage(MessageSendPriority.High) { Count = Count, Title = Title }; foreach (var subscriber in PushService.Subscribers) { // Set the tile background image uri with the address of the ImageService.GetTileImage, // REST service, using current subscriber channel uri as a parameter to bo sent to the service. tileMsg.BackgroundImageUri = new Uri(string.Format(ImageService.GetTileImageService, string.Empty)); tileMsg.SendAsync(subscriber.ChannelUri, Log, Log); } }
private void ResetTileNotificationCount(string applicationId, string deviceId) { var pushUserEndpoint = this.pushUserEndpointsRepository.GetPushUserByApplicationAndDevice(applicationId, deviceId); pushUserEndpoint.TileCount = 0; var tile = new TilePushNotificationMessage { SendPriority = MessageSendPriority.High, Count = pushUserEndpoint.TileCount }; // Send a new tile notification message to reset the count in the phone application. tile.SendAndHandleErrors(new Uri(pushUserEndpoint.ChannelUri)); // Save the updated count. this.pushUserEndpointsRepository.UpdatePushUserEndpoint(pushUserEndpoint); }
private TilePushNotificationMessage GetOrCreateMessage(string userName, bool overrideExisting = true) { lock (MessageSync) { TilePushNotificationMessage message; if (!_messages.TryGetValue(userName, out message) || overrideExisting) { message = new TilePushNotificationMessage(MessageSendPriority.High) { BackgroundImageUri = BackgroundImageUri, Count = Count, Title = Title }; _messages[userName] = message; } return(message); } }
public ActionResult SendMicrosoftTile(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 pushUserEndpointList = this.pushUserEndpointsRepository.GetPushUsersByName(userId); foreach (var pushUserEndpoint in pushUserEndpointList) { var tile = new TilePushNotificationMessage { SendPriority = MessageSendPriority.High, Count = ++pushUserEndpoint.TileCount }; var messageResult = tile.SendAndHandleErrors(new Uri(pushUserEndpoint.ChannelUri)); resultList.Add(messageResult); if (messageResult.Status.Equals(MessageSendResultLight.Success)) { this.QueueMessage(pushUserEndpoint, message); this.pushUserEndpointsRepository.UpdatePushUserEndpoint(pushUserEndpoint); } } return this.Json(resultList, JsonRequestBehavior.AllowGet); }
private void ResetTileNotificationCount(Uri channelUri) { var pushUserEndpointList = this.pushUserEndpointsRepository.GetPushUsersByNameAndEndpoint(this.UserId, channelUri); foreach (var pushUserEndpoint in pushUserEndpointList) { pushUserEndpoint.TileCount = 0; var tile = new TilePushNotificationMessage { SendPriority = MessageSendPriority.High, Count = pushUserEndpoint.TileCount }; // Send a new tile notification message to reset the count in the phone application. tile.SendAndHandleErrors(new Uri(pushUserEndpoint.ChannelUri)); // Save the updated count. this.pushUserEndpointsRepository.UpdatePushUserEndpoint(pushUserEndpoint); } }