private static RemoteNotificationResult FromWindowsNotification(WindowsNotification notification) { RemoteNotificationResult result = new RemoteNotificationResult(); result.DeviceType = Notifications.WPHONE; result.DeviceToken = notification.ChannelUri; return(result); }
private static RemoteNotificationResult FromGoogleNotification(GcmNotification googleNotification) { RemoteNotificationResult result = new RemoteNotificationResult(); result.DeviceType = Notifications.ANDROID; result.DeviceToken = googleNotification.RegistrationIds[0]; return(result); }
private static RemoteNotificationResult FromAppleNotification(AppleNotification appleNotification) { RemoteNotificationResult result = new RemoteNotificationResult(); result.DeviceType = Notifications.IOS; result.DeviceToken = appleNotification.DeviceToken; return(result); }
private void SetResult(int errorCode, PushSharp.Common.Notification notification, Exception ex) { RemoteNotificationResult result = RemoteNotificationResult.FromNotification(notification); result.ErrorCode = errorCode; result.ErrorDescription = GetErrorDescription(errorCode); if (ex != null && String.IsNullOrEmpty(result.ErrorDescription)) { if (ex is NotificationFailureException) { result.ErrorDescription = ((NotificationFailureException)ex).ErrorStatusDescription; } else { result.ErrorDescription = ex.Message; } log.Error(String.Format("SetResult - ErrCode {0} - {1}", errorCode, result.ErrorDescription), ex); } SetResult(result); }
public List <RemoteNotificationResult> Send() { foreach (RemoteNotification notif in m_notifications) { PlatformType platformType = PlatformConverter.FromDeviceType(notif.DeviceType); switch (platformType) { case PlatformType.Apple: EnsureiOS(); AppleNotification n = NotificationFactory.Apple(); n.DeviceToken = notif.DeviceToken; n.Payload = new AppleNotificationPayload(); if (!string.IsNullOrEmpty(notif.Message)) { n.Payload.Alert = new AppleNotificationAlert() { Body = notif.Message } } ; if (!string.IsNullOrEmpty(notif.Sound)) { n.Payload.Sound = notif.Sound; } if (!string.IsNullOrEmpty(notif.Action) && notif.Action.Trim().Length > 0) { n.Payload.AddCustom("a", notif.Action); if (notif.Parameters != null && notif.Parameters.Names.Count > 0) { n.Payload.AddCustom("p", notif.Parameters.ToJObject()); } } if (!string.IsNullOrEmpty(notif.Badge)) { int badgeInt; if (int.TryParse(notif.Badge, out badgeInt)) { n.Payload.Badge = badgeInt; } else if (notif.Badge == "!") { n.Payload.Badge = -1; } } if (notif.ExecutionTime != 0) { n.Payload.ContentAvailable = 1; } Service.QueueNotification(n); break; case PlatformType.AndroidGcm: EnsureAndroid(); GcmNotification g = NotificationFactory.Google(); g.RegistrationIds.Add(notif.DeviceToken); g.JsonData = string.Format("{{ \"payload\":\"{0}\",\"action\":\"{1}\",\"parameters\": {2} ,\"executiontime\": {3} ,\"priority\": {4} }}" , notif.Message, notif.Action, notif.Parameters.ToJson(), notif.ExecutionTime.ToString(), notif.Delivery.Priority); g.CollapseKey = "NONE"; Service.QueueNotification(g); break; case PlatformType.WindowsPhone: EnsureWindows(); WindowsNotification w = NotificationFactory.Windows(); w.ChannelUri = notif.DeviceToken; w.Message = notif.Message; w.Title = notif.Title; w.ImageUri = notif.Icon; w.Badge = notif.Badge; w.Sound = notif.Sound; w.Action = notif.Action; w.Parameters = notif.Parameters; w.ExecutionTime = notif.ExecutionTime; Service.QueueNotification(w); break; default: RemoteNotificationResult result = RemoteNotificationResult.ForDevice(notif.DeviceType, notif.DeviceToken); result.ErrorCode = INVALID_DEVICE_TYPE; result.ErrorDescription = GetErrorDescription(INVALID_DEVICE_TYPE); SetResult(result); break; } } Service.StopAllServices(true); return(m_results); }
private void SetResult(RemoteNotificationResult result) { lock (m_results) m_results.Add(result); }