private static async Task <string> SendPushNotificationToUser(string uniqueTag, string message) { string[] userTag = new string[1]; userTag[0] = uniqueTag; Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; HttpStatusCode ret = HttpStatusCode.InternalServerError; //We only have android devices as of now. //If other platforms are targeted, update code with switch for other platform var notification = "{ \"data\" : {\"message\":\"" + message + "\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notification, userTag); if (outcome != null) { if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { ret = HttpStatusCode.OK; } } return(ret.ToString()); }
private async Task HandleDeliveryReadyEvent(DeliveryReadyEvent deliverReady) { string[] userTag = new string[2]; userTag[0] = "rider:" + deliverReady.ryderId; Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; switch (deliverReady.pns.ToLower()) { case "apns": // iOS var alert = "{\"aps\":{\"alert\":\"New Delivery is ready\"}}"; outcome = await notificationHubInstance.Hub.SendAppleNativeNotificationAsync(alert, userTag); break; case "fcm": // Android var notif = "{ \"data\" : {\"message\":\"New Delivery is ready\",\"deliveryId\":\"" + deliverReady.deliveryId + "\"}}"; outcome = await notificationHubInstance.Hub.SendFcmNativeNotificationAsync(notif, userTag); break; } if (outcome != null) { if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { } } }
public async Task <HttpResponseMessage> Post(PushMessage model) { Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; HttpStatusCode ret = HttpStatusCode.InternalServerError; switch (model.pns.ToLower()) { case "apns": // iOS var alert = "{\"aps\":{ \"alert\": \"" + model.message + "\" }}"; // var alert = "{"aps":{"alert":"" + "From " + user + ": " + message + ""}}"; outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert); break; case "gcm": // Android var notif = "{ \"data\":{ \"message\": \"" + model.message + "\" }}"; // var notif = "{ "data" : {"message":"" + "From " + user + ": " + message + ""}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif); break; } if (outcome != null) { if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { ret = HttpStatusCode.OK; } } return(Request.CreateResponse(ret)); }
public async Task <HttpResponseMessage> Post() { // var user = HttpContext.Current.User.Identity.Name; //string[] userTag = new string[2]; //userTag[0] = "username:"******"440868453679"; //userTag[1] = "from:" + "TestUser"; // var msg = "hello"; Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; HttpStatusCode ret = HttpStatusCode.InternalServerError; // Android var notif = "{ \"data\" : {\"message\":\"" + "From backend api test notification" + "\"}}"; outcome = await Models.Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif); // outcome = await Models.Notifications.Instance.Hub.SendGcmNativeNotificationAsync("{ \"data\" : {\"msg\":\"" + msg + "\"}}"); // var notificationDetails = await Models.Notifications.Instance.Hub.GetNotificationOutcomeDetailsAsync(outcome.NotificationId); if (outcome != null) { if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { ret = HttpStatusCode.OK; } } return(Request.CreateResponse(ret)); }
public Microsoft.Azure.NotificationHubs.NotificationOutcome DispatchNotification(NotificationType type, string roleNames, string message) { Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; string[] roles = roleNames?.Split(',') ?? new String[] {}; // new String[] { "Admin" }; // switch (type) { case NotificationType.WNS: // Windows 8.1 / Windows Phone 8.1 var toast = $"<toast><visual><binding template=\"ToastText01\"><text id=\"1\">{message}</text></binding></visual></toast>"; outcome = Task.Run(async() => await SealegsNotifications.Instance.Hub.SendWindowsNativeNotificationAsync(toast)).Result; break; case NotificationType.GCM: { // iOS //var alert = $"{{\"aps\":{{\"alert\":\"{ message }\"}}}}"; var badge = 10; var jsonPayload = "{\"aps\" : { \"alert\" : \"" + message + "\", \"badge\" : " + badge + ", \"sound\" : \"default\" }}"; outcome = Task.Run(async() => await SealegsNotifications.Instance.Hub.SendAppleNativeNotificationAsync(jsonPayload, roles)).Result; } break; case NotificationType.APNS: { // Android //var notif = $"{{ \"data\" : {{\"message\":\"{message }\"}}}}"; var badge = 10; var jsonPayload = "{\"data\" : { \"alert\" : \"" + message + "\", \"badge\" : " + badge + ", \"sound\" : \"default\" }}"; outcome = Task.Run(async() => await SealegsNotifications.Instance.Hub.SendGcmNativeNotificationAsync(jsonPayload, roles)).Result; } break; } return(outcome); }
public bool Send(Notification item) { HttpStatusCode ret = HttpStatusCode.InternalServerError; if (string.IsNullOrWhiteSpace(item.Text))//|| password != ConfigurationManager.AppSettings["NotificationsPassword"]) { return(false); } Microsoft.Azure.NotificationHubs.NotificationOutcome outcomeAPNS = DispatchNotification(NotificationType.APNS, item.RoleId, item.Text); Microsoft.Azure.NotificationHubs.NotificationOutcome outcomeGCM = DispatchNotification(NotificationType.GCM, item.RoleId, item.Text); if (outcomeAPNS != null && outcomeGCM != null) { if (!((outcomeAPNS.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcomeAPNS.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown)) && !((outcomeGCM.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcomeGCM.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown)) ) { ret = HttpStatusCode.OK; } } return(ret == HttpStatusCode.OK); }
public async Task <HttpResponseMessage> Post(string pns, [FromBody] string message, string to_tag) { var user = HttpContext.Current.User.Identity.Name; string[] userTag = new string[2]; userTag[0] = "username:"******"from:" + user; Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; HttpStatusCode ret = HttpStatusCode.InternalServerError; switch (pns.ToLower()) { case "wns": // Windows 8.1 / Windows Phone 8.1 var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" + "From " + user + ": " + message + "</text></binding></visual></toast>"; outcome = await Notifications.Instance.Hub.SendWindowsNativeNotificationAsync(toast, userTag); // Windows 10 specific Action Center support toast = @"<toast><visual><binding template=""ToastGeneric""><text id=""1"">" + "From " + user + ": " + message + "</text></binding></visual></toast>"; outcome = await Notifications.Instance.Hub.SendWindowsNativeNotificationAsync(toast, userTag); // Additionally sending Windows Phone Notification MPNS //toast = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + // "<wp:Notification xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1>" + // "From " + user + ": " + message + // "</wp:Text1></wp:Toast></wp:Notification>"; //outcome = await Notifications.Instance.Hub.SendMpnsNativeNotificationAsync(toast, userTag); break; case "apns": // iOS var alert = "{\"aps\":{\"alert\":\"" + "From " + user + ": " + message + "\"}}"; outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, userTag); break; case "gcm": // Android var notif = "{ \"data\" : {\"message\":\"" + "From " + user + ": " + message + "\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, userTag); break; } if (outcome != null) { if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { ret = HttpStatusCode.OK; } } return(Request.CreateResponse(ret)); }
public async Task <HttpResponseMessage> Post([FromBody] FESA.SCM.Notification.Models.Notification notification) //string pns, [FromBody]string message //, string toTag) { var toTag = notification.toTag; var pns = notification.pns; var message = notification.message; var user = Guid.NewGuid().ToString(); var userTag = new string[2]; userTag[0] = "username:"******"from:" + user; Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; var ret = HttpStatusCode.InternalServerError; switch (pns.ToLower()) { case "wns": // Windows 8.1 / Windows Phone 8.1 var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" + "From " + user + ": " + message + "</text></binding></visual></toast>"; outcome = await Notifications.Instance.Hub.SendWindowsNativeNotificationAsync(toast, userTag); break; case "apns": // iOS var alert = "{\"aps\":{\"alert\":\"" + message + "\", \"sound\": \"default\", \"badge\": 1}}"; userTag = new string[1] { toTag }; outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, userTag); break; case "gcm": // Android var notif = "{ \"data\" : {\"message\":\"" + message + "\"}}"; userTag = new string[1] { toTag }; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, userTag); break; } if (outcome == null) { return(Request.CreateResponse(ret)); } if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { ret = HttpStatusCode.OK; } return(Request.CreateResponse(ret)); }
public async Task <HttpResponseMessage> Post(string pns, string password, [FromBody] string message) { Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; if (string.IsNullOrWhiteSpace(message) || password != ConfigurationManager.AppSettings["NotificationsPassword"]) { return(Request.CreateResponse(HttpStatusCode.Forbidden)); } var ret = HttpStatusCode.InternalServerError; try { switch (pns.ToLower()) { case "wns": // Windows 8.1 / Windows Phone 8.1 var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" + message + "</text></binding></visual></toast>"; outcome = await TechdaysNotifications.Instance.Hub.SendWindowsNativeNotificationAsync(toast); break; case "apns": // iOS var alert = "{\"aps\":{\"alert\":\"" + message + "\"}}"; outcome = await TechdaysNotifications.Instance.Hub.SendAppleNativeNotificationAsync(alert); break; case "gcm": // Android var notif = "{ \"data\" : {\"message\":\"" + message + "\"}}"; outcome = await TechdaysNotifications.Instance.Hub.SendGcmNativeNotificationAsync(notif); break; } if (outcome != null) { if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { ret = HttpStatusCode.OK; } } } catch (Exception e) { ret = HttpStatusCode.InternalServerError; } return(Request.CreateResponse(ret)); }
public async Task <HttpResponseMessage> Post(string pns, [FromBody] string message, string to_tag) { var user = User.GetEmail(); if (user == null) { return(new HttpResponseMessage(HttpStatusCode.Unauthorized)); } string[] userTag = new string[2]; userTag[0] = "username:"******"from:" + user; Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; HttpStatusCode ret = HttpStatusCode.InternalServerError; switch (pns.ToLower()) { case "wns": // Windows 8.1 / Windows Phone 8.1 var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" + "From " + user + ": " + message + "</text></binding></visual></toast>"; outcome = await _azureNotifications.Hub.SendWindowsNativeNotificationAsync(toast, userTag); break; case "apns": // iOS var alert = "{\"aps\":{\"alert\":\"" + "From " + user + ": " + message + "\"}}"; outcome = await _azureNotifications.Hub.SendAppleNativeNotificationAsync(alert, userTag); break; case "fcm": // Android var notif = "{ \"data\" : {\"message\":\"" + "From " + user + ": " + message + "\"}}"; outcome = await _azureNotifications.Hub.SendFcmNativeNotificationAsync(notif, userTag); break; } if (outcome != null) { if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { ret = HttpStatusCode.OK; } } return(new HttpResponseMessage(ret)); }
public async Task <HttpResponseMessage> PostUserNotification([FromUri] string pns, [FromUri] string userTag = null) { // var user = HttpContext.Current.User.Identity.Name; //string[] userTag = new string[2]; //userTag[0] = "username:"******"440868453679"; //userTag[1] = "from:" + "TestUser"; // var msg = "hello"; Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; HttpStatusCode ret = HttpStatusCode.InternalServerError; // Android switch (pns.ToLower()) { case "gcm": var notif = "{ \"data\" : {\"message\":\"" + "From backend api test notification" + "\"}}"; if (!string.IsNullOrEmpty(userTag)) { outcome = await Models.Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, userTag); } else { outcome = await Models.Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif); } break; case "apns": var alert = "{\"aps\":{\"alert\":\"" + "From backend api test notification" + "\"}}"; if (!string.IsNullOrEmpty(userTag)) { outcome = await Models.Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, userTag); } else { outcome = await Models.Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert); } break; } // outcome = await Models.Notifications.Instance.Hub.SendGcmNativeNotificationAsync("{ \"data\" : {\"msg\":\"" + msg + "\"}}"); // var notificationDetails = await Models.Notifications.Instance.Hub.GetNotificationOutcomeDetailsAsync(outcome.NotificationId); if (outcome != null) { if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { ret = HttpStatusCode.OK; } } return(Request.CreateResponse(ret)); }
public async Task <IActionResult> Post(string pns, [FromBody] string message, string to_tag) { var user = HttpContext.User.Identity.Name; var userTag = new string[] { "username:"******"from:" + user }; Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; var ret = HttpStatusCode.InternalServerError; switch (pns.ToLower()) { case "wns": // Windows 8.1 / Windows Phone 8.1 var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" + "From " + user + ": " + message + "</text></binding></visual></toast>"; outcome = await Notifications.Instance.Hub.SendWindowsNativeNotificationAsync(toast, userTag); break; case "apns": // iOS var alert = "{\"aps\":{\"alert\":\"" + "From " + user + ": " + message + "\"}}"; outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, userTag); break; case "fcm": // Android var notif = "{ \"data\" : {\"message\":\"" + "From " + user + ": " + message + "\"}}"; outcome = await Notifications.Instance.Hub.SendFcmNativeNotificationAsync(notif, userTag); break; } if (outcome != null) { if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { ret = HttpStatusCode.OK; } } return(StatusCode((int)ret)); }
public async Task <HttpResponseMessage> Post(string pns, string password, [FromBody] string message) { Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; HttpStatusCode ret = HttpStatusCode.InternalServerError; if (string.IsNullOrWhiteSpace(message) || password != ConfigurationManager.AppSettings["NotificationsPassword"]) { return(Request.CreateResponse(ret)); } switch (pns.ToLower()) { case "wns": // Windows 8.1 / Windows Phone 8.1 var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" + message + "</text></binding></visual></toast>"; outcome = await SealegsNotifications.Instance.Hub.SendWindowsNativeNotificationAsync(toast); break; case "apns": // jsonPayload = "{\"aps\" : { \"alert\" : \"" + message + "\", \"badge\" : " + badge + ", \"sound\" : \"default\" }, \"acme1\" : \"bar\", \"acme2\" : 42 }"; // iOS var alert = "{\"aps\":{\"alert\":\"" + message + "\"}}"; outcome = await SealegsNotifications.Instance.Hub.SendAppleNativeNotificationAsync(alert); break; case "gcm": // jsonPayload = "{\"data\" : { \"message\" : \"" + message + "\", \"badge\" : " + badge + ", \"sound\" : \"default\" }, \"acme1\" : \"bar\", \"acme2\" : 42 } // headers.Add("ServiceBusNotification-Tags", recipient); +91-11-24300666 // Android var notif = "{ \"data\" : {\"message\":\"" + message + "\"}}"; outcome = await SealegsNotifications.Instance.Hub.SendGcmNativeNotificationAsync(notif); break; } if (outcome != null) { if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { ret = HttpStatusCode.OK; } } return(Request.CreateResponse(ret)); }
private async Task <bool> SendNotificationAsync(NotificationDto notification) { Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; string pns = notification.Pns; string message = notification.Message; switch (pns.ToLower()) { case "wns": // Windows 8.1 / Windows Phone 8.1 var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" + "From " + ": " + message + "</text></binding></visual></toast>"; outcome = await Notifications.Instance.Hub.SendWindowsNativeNotificationAsync(toast); break; case "apns": // iOS var alert = "{\"aps\":{\"alert\":\"" + "From " + ": " + message + "\"}}"; outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert); break; case "gcm": // Android var notif = "{ \"data\" : {\"message\":\"" + message + "\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif ); break; } if (outcome != null) { if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { return(true); } } return(false); }
public async void PushMessageAsync(PushMsgNotificationModel pushMsgNotificationModel) { JavaScriptSerializer js = new JavaScriptSerializer(); string pushMsgNotificationJson = js.Serialize(new { data = (pushMsgNotificationModel) }); Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; outcome = await CustomNotification.Notifications.Instance.Hub.SendGcmNativeNotificationAsync(pushMsgNotificationJson, pushMsgNotificationModel.CreatedById); outcome = await CustomNotification.Notifications.Instance.Hub.SendAppleNativeNotificationAsync(pushMsgNotificationJson, pushMsgNotificationModel.CreatedById); //CustomNotification.Notifications.Instance.Hub.SendDirectNotificationAsync(new Microsoft.Azure.NotificationHubs.Notification(). //{ //}); }
private async Task <HttpResponseMessage> PostNotification(string pns, [FromBody] string message, string from_tag, string to_tag) { var user = from_tag; string[] userTag = new string[2]; userTag[0] = "username:"******"from:" + user; Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; HttpStatusCode ret = HttpStatusCode.InternalServerError; switch (pns.ToLower()) { //case "wns": // // Windows 8.1 / Windows Phone 8.1 // var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" + // "From " + user + ": " + message + "</text></binding></visual></toast>"; // outcome = await Notifications.Instance.Hub.SendWindowsNativeNotificationAsync(toast, userTag); // break; //case "apns": // // iOS // var alert = "{\"aps\":{\"alert\":\"" + "From " + user + ": " + message + "\"}}"; // outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, userTag); // break; case "gcm": // Android var notif = "{ \"data\" : {\"message\":\"" + message + "\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, to_tag); break; } if (outcome != null) { if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { ret = HttpStatusCode.OK; } } return(Request.CreateResponse(ret)); }
private async static Task <HttpResponseMessage> SendPushAsync(string pns, [FromBody] string message, string to_tag) { Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; HttpStatusCode ret = HttpStatusCode.InternalServerError; var notif = "{ \"data\" : {\"message\":\"" + message + "\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, to_tag); if (outcome != null) { if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { ret = HttpStatusCode.OK; } } return(new HttpResponseMessage(ret)); }
public async Task <HttpStatusCode> SendNotification(string pns, string message, string tag) { Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; HttpStatusCode ret = HttpStatusCode.InternalServerError; List <string> tags = new List <string>(); tags.Add(tag); switch (pns.ToLower()) { //case "wns": // // Windows 8.1 / Windows Phone 8.1 // var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" + // "From " + user + ": " + message + "</text></binding></visual></toast>"; // outcome = await Notifications.Instance.Hub.SendWindowsNativeNotificationAsync(toast, userTag); // break; //case "apns": // // iOS // var alert = "{\"aps\":{\"alert\":\"" + "From " + user + ": " + message + "\"}}"; // outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, userTag); // break; case "fcm": // Android var notif = "{ \"data\" : {\"message\":\"" + "From " + "SergeUser" + ": " + message + "\"}}"; outcome = await Notifications.Instance.Hub.SendFcmNativeNotificationAsync(notif, tags); //outcome = await Notifications.Instance.Hub.SendNotificationAsync(notif, tags); break; } if (outcome != null) { if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { ret = HttpStatusCode.OK; } } return(ret); }
public async Task <HttpResponseMessage> Post(string pns, [FromBody] string message, string to_tag) { var user = HttpContext.Current.User.Identity.Name; user = "******"; string[] userTag = new string[2]; userTag[0] = "username:"******"from:" + user; Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; HttpStatusCode ret = HttpStatusCode.InternalServerError; // Android var notif = "{ \"data\" : {\"message\":\"" + "From " + user + ": " + message + "\"}}"; //outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, userTag); //outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif); Dictionary <string, string> templateParams = new Dictionary <string, string>(); string category = "Music"; templateParams["messageParam"] = "Breaking " + category + " News!"; outcome = await Notifications.Instance.Hub.SendTemplateNotificationAsync(templateParams); if (outcome != null) { if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { ret = HttpStatusCode.OK; } } return(Request.CreateResponse(ret)); }
public async Task <HttpResponseMessage> Post(string pns, [FromBody] string message, string to_tag) { var user = HttpContext.Current.User.Identity.Name; Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; HttpStatusCode ret = HttpStatusCode.InternalServerError; // Android var notif = "{ \"data\" : {\"message\":\"" + message + "\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, to_tag); if (outcome != null) { if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { ret = HttpStatusCode.OK; } } return(Request.CreateResponse(ret)); }
public async System.Threading.Tasks.Task sendpushNotificationAsync() { var user = FBID; string to_tag = FBID + "T"; string[] userTag = new string[2]; userTag[0] = "username:"******"T" FriendsPersistence fp = new FriendsPersistence(); ArrayList friends = fp.getFriends(FBID); string pns = "gcm"; bool firsttime = true; foreach (Friends f in friends) { if (f.Status == 1) { switch (pns.ToLower()) { case "wns": // Windows 8.1 / Windows Phone 8.1 var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">" + "From " + user + ": " + "wns=message" + "</text></binding></visual></toast>"; outcome = await Notifications.Instance.Hub.SendWindowsNativeNotificationAsync(toast, to_tag); break; case "apns": // iOS var alert = "{\"aps\":{\"alert\":\"" + "From " + UserName + " Need Help from you. The User ID =[" + FBID + "] [" + Latitude + "] [" + Longitude + "]\"}}"; outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, f.FriendFBID + "T"); if (firsttime) { var alert1 = "{\"aps\":{\"alert\":\"" + "Your alarm was successfully sent to all your friends ID =[" + FBID + "] [" + Latitude + "] [" + Longitude + "]\"}}"; outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert1, FBID + "T"); firsttime = false; } break; case "gcm": // Android //{"data":{"message":"From Hussi Need Help from you. The User ID =[132569873917640] [56.6642811] [12.8778527]"}} if (f.FriendFBID.Equals(FBID)) { var notif = "{ \"data\" : {\"message\":\"" + "From yourfriend" + " Need Help from you. The User ID =[" + f.UserFBID + "] [" + Latitude + "] [" + Longitude + "]\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, f.UserFBID + "T"); } else { var notif = "{ \"data\" : {\"message\":\"" + "From " + UserName + " Need Help from you. The User ID =[" + FBID + "] [" + Latitude + "] [" + Longitude + "]\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, f.FriendFBID + "T"); } if (firsttime) { System.Threading.Thread.Sleep(500); var notif = "{ \"data\" : {\"message\":\"" + "Your alarm was successfully sent to all your friends ID =[" + FBID + "] [" + Latitude + "] [" + Longitude + "]\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, FBID + "T"); firsttime = false; } break; } if (outcome != null) { if (!((outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Abandoned) || (outcome.State == Microsoft.Azure.NotificationHubs.NotificationOutcomeState.Unknown))) { ret = HttpStatusCode.OK; } } } } }
public async Task <Response <Complaint> > PutComplaint(int id, Complaint complaint) { Response <Complaint> responseComplaint = new Response <Complaint>(); if (!ModelState.IsValid) { responseComplaint.status = "No Complaints"; responseComplaint.model = null; return(responseComplaint); } if (id != complaint.complaintID) { responseComplaint.status = "Failed: ID Did Not Match"; responseComplaint.model = null; return(responseComplaint); } db.Entry(complaint).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ComplaintExists(id)) { responseComplaint.status = "Failed: No Complaint ID Found"; responseComplaint.model = null; return(responseComplaint); } else { throw; } } responseComplaint.status = "Success"; responseComplaint.model = complaint; Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; Response <Notification> responceNotification = new Response <Notification>(); NotificationsController notificationController = new NotificationsController(); responceNotification = await notificationController.GetNotificationbyUserID(complaint.userID); int communityID = complaint.communityID; int complaintID = complaint.complaintID; var ComplaintFromDB = await(from l in db.Complaints where l.communityID == communityID && l.complaintID == complaintID select l).Include(x => x.community).FirstOrDefaultAsync(); if (responceNotification.model.user.Islogout == false) { if (responceNotification.model.Report == true) { // iOS var alert = "{\"aps\":{\"alert\":\"" + ComplaintFromDB.community.name + " : Your iReport has been Received.\",\"id\":\"3\",\"communityid\":\"" + complaint.communityID + "\",\"sound\":\"default\"}}"; outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, Convert.ToString(complaint.userID)); // Android //"{ \"data\" : {\"message\":\"Your iReport has been Received.\",\"id\":\"3\"}}" var notif = "{\"data\":{\"message\":\"" + ComplaintFromDB.community.name + " : Your iReport has been Received.\",\"badge\":\"1\",\"id\":\"3\",\"communityid\":\"" + complaint.communityID + "\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, Convert.ToString(complaint.userID)); } } return(responseComplaint); }
public async Task <IHttpActionResult> PutMember(int id, Member member) { int communityID = member.communityID; int userID = member.userId; var memberFromDB = await(from l in db.Members where l.communityID == communityID && l.userId == userID select l).Include(x => x.user).Include(x => x.community).FirstOrDefaultAsync(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != member.id) { return(BadRequest()); } db.Entry(member).State = EntityState.Modified; try { await db.SaveChangesAsync(); Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; if (memberFromDB.user.Islogout == false) { if (member.isBlocked == true) { // iOS var alert = "{\"aps\":{\"alert\":\"" + memberFromDB.community.name + " : You have been BLOCKED.\",\"id\":\"4\",\"communityid\":\"" + member.communityID + "\",\"sound\":\"default\"}}"; outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, Convert.ToString(member.userId)); // Android //var notif = "{ \"data\" : {\"message\":\"You are blocked\",\"id\":\"4\"}}"; //var notif = "{\"data\":{\"message\":\"" + memberFromDB.community.name + " : You are blocked.\",\"badge\":\"1\",\"id\":\"4\",\"communityid\":\"" + member.communityID + "\"}}"; var notif = "{\"data\":{\"message\":\"" + memberFromDB.community.name + " : You have been BLOCKED.\",\"badge\":\"1\",\"id\":\"4\",\"communityName\":\"" + memberFromDB.community.name + "\",\"communityid\":\"" + member.communityID + "\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, Convert.ToString(member.userId)); } else { // iOS var alert = "{\"aps\":{\"alert\":\"" + memberFromDB.community.name + " : You are now an ACTIVE member.\",\"id\":\"6\",\"communityid\":\"" + member.communityID + "\",\"sound\":\"default\"}}"; outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, Convert.ToString(member.userId)); // Android //var notif = "{ \"data\" : {\"message\":\"You are blocked\",\"id\":\"4\"}}"; //var notif = "{\"data\":{\"message\":\"" + memberFromDB.community.name + " : You are blocked.\",\"badge\":\"1\",\"id\":\"4\",\"communityid\":\"" + member.communityID + "\"}}"; var notif = "{\"data\":{\"message\":\"" + memberFromDB.community.name + " : You are now an ACTIVE member.\",\"badge\":\"1\",\"id\":\"6\",\"communityName\":\"" + memberFromDB.community.name + "\",\"communityid\":\"" + member.communityID + "\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, Convert.ToString(member.userId)); } } } catch (DbUpdateConcurrencyException) { if (!MemberExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <Response <Announcement> > PostAnnouncement(Announcement announcement) { try { Response <Announcement> responseAnnouncement = new Response <Announcement>(); if (!ModelState.IsValid) { responseAnnouncement.status = "Failure"; responseAnnouncement.model = null; return(responseAnnouncement); } if (announcement.image != null) { imageForBlob imageForBlob = new imageForBlob(); string blobImageURL = imageForBlob.ConvertfileForBlob(); announcement.image = blobImageURL; } DateTime ServerDateTime = DateTime.Now; DateTime utcDateTime = ServerDateTime.ToUniversalTime(); // ID from: // "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zone" // See http://msdn.microsoft.com/en-us/library/system.timezoneinfo.id.aspx string malayTimeZoneKey = "Singapore Standard Time"; TimeZoneInfo malayTimeZone = TimeZoneInfo.FindSystemTimeZoneById(malayTimeZoneKey); DateTime malayDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, malayTimeZone); announcement.date = malayDateTime; db.Announcements.Add(announcement); await db.SaveChangesAsync(); responseAnnouncement.status = "Success"; responseAnnouncement.model = announcement; List <Member> member = new List <Member>(); member = db.Members.Where(m => m.communityID == announcement.communityID).Include(x => x.user).ToList(); Community community = new Community(); community = await db.Communities.Where(m => m.communityID == announcement.communityID).FirstOrDefaultAsync(); string communityName = community.name; foreach (var item in member) { Response <Notification> responceNotification = new Response <Notification>(); NotificationsController notificationController = new NotificationsController(); responceNotification = await notificationController.GetNotificationbyUserID(item.userId); if (responceNotification.model != null) { if (responceNotification.model.user.Islogout == false) { if (responceNotification.model.Notices == true) { Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; // iOS var alert = "{\"aps\":{\"alert\":\"" + communityName + " : You have a new Notice.\",\"id\":\"2\",\"communityid\":\"" + item.communityID + "\",\"sound\":\"default\"}}"; outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, Convert.ToString(item.userId)); // Android //var notif = "{ \"data\" : {\"message\":\"You have a new Notice.\",\"id\":\"2\"}}"; var notif = "{\"data\":{\"message\":\"" + communityName + " : You have a new Notice.\",\"badge\":\"1\",\"id\":\"2\",\"communityid\":\"" + item.communityID + "\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, Convert.ToString(item.userId)); } } } //else //{ // responseAnnouncement.status =Convert.ToString(item.userId); // responseAnnouncement.model = null; // return responseAnnouncement; //} } return(responseAnnouncement); } catch (Exception ex) { throw ex; } }
public async Task <Response <Announcement> > PutAnnouncement(int id, Announcement announcement) { Response <Announcement> responseAnnouncement = new Response <Announcement>(); if (!ModelState.IsValid) { responseAnnouncement.status = "Failure"; responseAnnouncement.model = null; return(responseAnnouncement); } if (id != announcement.id) { responseAnnouncement.status = "Failed: ID did not match"; responseAnnouncement.model = null; return(responseAnnouncement); } var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0) { var docfiles = new List <string>(); foreach (string file in httpRequest.Files) { var postedFile = httpRequest.Files[file]; if (postedFile.ContentLength == 0) { Response <Announcement> responseGetAnnouncement = new Response <Announcement>(); AnnouncementsController announcementController = new AnnouncementsController(); responseGetAnnouncement = await announcementController.GetAnnouncement(announcement.id); announcement.image = responseGetAnnouncement.model.image; } else { imageForBlob imageForBlob = new imageForBlob(); string blobImageURL = imageForBlob.ConvertfileForBlob(); announcement.image = blobImageURL; } } } db.Entry(announcement).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AnnouncementExists(id)) { responseAnnouncement.status = "Failed: ID does not exist"; responseAnnouncement.model = null; return(responseAnnouncement); } else { throw; } } responseAnnouncement.status = "Success"; responseAnnouncement.model = announcement; List <Member> member = new List <Member>(); member = db.Members.Where(m => m.communityID == announcement.communityID).Include(x => x.user).ToList(); Community community = new Community(); community = await db.Communities.Where(m => m.communityID == announcement.communityID).FirstOrDefaultAsync(); string communityName = community.name; foreach (var item in member) { Response <Notification> responceNotification = new Response <Notification>(); NotificationsController notificationController = new NotificationsController(); responceNotification = await notificationController.GetNotificationbyUserID(item.userId); if (responceNotification.model != null) { if (responceNotification.model.user.Islogout == false) { if (responceNotification.model.Notices == true) { Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; // iOS var alert = "{\"aps\":{\"alert\":\"" + communityName + " : The Notice has been updated.\",\"id\":\"5\",\"communityid\":\"" + item.communityID + "\",\"sound\":\"default\"}}"; outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, Convert.ToString(item.userId)); // Android //var notif = "{ \"data\" : {\"message\":\"You have a new Notice.\",\"id\":\"2\"}}"; var notif = "{\"data\":{\"message\":\"" + communityName + " : The Notice has been updated.\",\"badge\":\"1\",\"id\":\"5\",\"communityid\":\"" + item.communityID + "\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, Convert.ToString(item.userId)); } } } //else //{ // responseAnnouncement.status =Convert.ToString(item.userId); // responseAnnouncement.model = null; // return responseAnnouncement; //} } return(responseAnnouncement); }
public async Task <Response <Chat> > PostChatForAdmin(string description, int userIdTo, int userIdFrom, int communityID, string image) { Chat chat = new Chat(); chat.desc = description; chat.to = userIdTo; chat.from = userIdFrom; chat.isRead = false; DateTime ServerDateTime = DateTime.Now; DateTime utcDateTime = ServerDateTime.ToUniversalTime(); // ID from: // "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zone" // See http://msdn.microsoft.com/en-us/library/system.timezoneinfo.id.aspx string malayTimeZoneKey = "Singapore Standard Time"; TimeZoneInfo malayTimeZone = TimeZoneInfo.FindSystemTimeZoneById(malayTimeZoneKey); DateTime malayDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, malayTimeZone); chat.Date = malayDateTime; chat.communityID = communityID; chat.image = image; Response <Chat> chatResponse = new Response <Chat>(); chatResponse.model = chat; if (!ModelState.IsValid) { chatResponse.status = "Failure"; chatResponse.model = null; return(chatResponse); } db.Chats.Add(chat); await db.SaveChangesAsync(); chatResponse.status = "Success"; chatResponse.model = chat; Microsoft.Azure.NotificationHubs.NotificationOutcome outcome = null; Response <Notification> responceNotification = new Response <Notification>(); NotificationsController notificationController = new NotificationsController(); responceNotification = await notificationController.GetNotificationbyUserID(userIdTo); var ChatFromDB = await(from l in db.Chats where l.communityID == communityID select l).Include(x => x.community).FirstOrDefaultAsync(); if (responceNotification.model.user.Islogout == false) { if (responceNotification.model.Messages == true) { // iOS var alert = "{\"aps\":{\"alert\":\"" + ChatFromDB.community.name + " : You have a new message.\",\"id\":\"1\",\"communityid\":\"" + chat.communityID + "\",\"Message\":\"" + chat.desc + "\",\"image\":\"" + chat.image + "\",\"sound\":\"default\"}}"; outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, Convert.ToString(userIdTo)); // Android //"{ \"data\" : {\"message\":\"You have a new message.\",\"id\":\"1\"}}" var notif = "{\"data\":{\"message\":\"" + ChatFromDB.community.name + " : You have a new message.\",\"badge\":\"1\",\"id\":\"1\",\"Message\":\"" + chat.desc + "\",\"image\":\"" + chat.image + "\",\"communityid\":\"" + chat.communityID + "\"}}"; outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, Convert.ToString(userIdTo)); } } return(chatResponse); //var alert = "{\"aps\":{\"alert\":\"You have a new message.\",\"badge\":" + msgCount + ",\"id\":\"2\",\"sound\":\"default\"}}"; //var outcome = await Notifications.Instance.Hub.SendAppleNativeNotificationAsync(alert, messages.messageTo); //var notif = "{ \"data\" : {\"message\":\"You have a new message.\",\"badge\":" + msgCount + ",\"id\":\"2\"}}"; //outcome = await Notifications.Instance.Hub.SendGcmNativeNotificationAsync(notif, messages.messageTo); }