public void SendNotificationOnWeb() { PushNotification obj = null; AndroidGCMPushNotification objAndroidGCMPushNotification = new AndroidGCMPushNotification(); try { DataTable dt = objAndroidGCMPushNotification.GetUserPushNotification("W"); if (dt != null) { for (int i = 0; i < dt.Rows.Count; i++) { obj = new PushNotification(); obj.Sno = Convert.ToInt32(dt.Rows[i]["Sno"]); obj.MessageType = Convert.ToString(dt.Rows[i]["MessageType"]); obj.MessageText = Convert.ToString(dt.Rows[i]["MessageText"]); obj.DeviceToken = Convert.ToString(dt.Rows[i]["DeviceToken"]); obj.MessageTitle = Convert.ToString(dt.Rows[i]["MessageTitle"]); obj.Data = Convert.ToString(dt.Rows[i]["Data"]); obj.OtherDetails = Convert.ToString(dt.Rows[i]["OtherDetails"]); obj.Data = obj.Data.Trim() + obj.OtherDetails; string val1 = obj.MessageType + "-" + obj.Data; obj.Data = obj.MessageText; obj.MessageText = val1; //end here if (!string.IsNullOrEmpty(obj.DeviceToken)) { WebNotification obj1 = new WebNotification(); obj1.Sno = Convert.ToInt32(dt.Rows[i]["Sno"]); obj1.MessageType = Convert.ToString(dt.Rows[i]["MessageType"]); obj1.MessageText = Convert.ToString(dt.Rows[i]["MessageText"]); obj1.DeviceToken = Convert.ToString(dt.Rows[i]["DeviceToken"]); obj1.MessageTitle = Convert.ToString(dt.Rows[i]["MessageTitle"]); obj1.Data = Convert.ToString(dt.Rows[i]["Data"]); obj1.LoginID = dt.Rows[i]["LoginID"].ToString().Trim(); Console.WriteLine("Sending notification on web for message ID: " + obj1.Sno); string title = obj.MessageType + "-" + obj.Data; string url = WebApiUrl + "GetChallengeNotification?connection=" + obj.DeviceToken + "&msg=" + obj.MessageText + "&title=" + title; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse()) { webResponse.Close(); } } } } } catch (Exception ex) { obj.Messageid = string.Empty; obj.Error = ex.Message; objAndroidGCMPushNotification.UpdateUserPushNotification(obj); } finally { obj = null; } }
public ActionResult Index(MyIndexModel model) { AndroidGCMPushNotification apnGCM = new AndroidGCMPushNotification(); foreach (var zaDevice in MvcApplication.zaDevices) { string strResponse = apnGCM.SendNotification(zaDevice, model); } ViewBag.success = true; return(View(model)); }
public void SendNotificationOnMobile() { PushNotification obj = null; AndroidGCMPushNotification objAndroidGCMPushNotification = new AndroidGCMPushNotification(); try { DataTable dt = objAndroidGCMPushNotification.GetUserPushNotification("M"); if (dt != null) { for (int i = 0; i < dt.Rows.Count; i++) { obj = new PushNotification(); obj.Sno = Convert.ToInt32(dt.Rows[i]["Sno"]); obj.MessageType = Convert.ToString(dt.Rows[i]["MessageType"]); obj.MessageText = Convert.ToString(dt.Rows[i]["MessageText"]); obj.DeviceToken = Convert.ToString(dt.Rows[i]["DeviceToken"]); obj.MessageTitle = Convert.ToString(dt.Rows[i]["MessageTitle"]); obj.Data = Convert.ToString(dt.Rows[i]["Data"]); obj.OtherDetails = Convert.ToString(dt.Rows[i]["OtherDetails"]); obj.Data = obj.Data.Trim() + obj.OtherDetails; string val1 = obj.MessageType + "-" + obj.Data; obj.Data = obj.MessageText; obj.MessageText = val1; //end here if (!string.IsNullOrEmpty(obj.DeviceToken)) { if (dt.Rows[i]["DeviceType"].ToString().Trim().ToLower().Equals("ios")) { Console.WriteLine("Sending notification on Apple device for message ID: " + obj.Sno); List <string> lst_errorText = new List <string>(); try { //AppleNotification push = new AppleNotification(); //push.SendAppleNotificationByPHP(obj.DeviceToken, obj.MessageText, obj.Data, obj.Data); } catch (Exception ex) { lst_errorText.Add(ex.Message); } if (lst_errorText.Count > 0) { //update error obj.Messageid = string.Empty; obj.Error = lst_errorText[0]; objAndroidGCMPushNotification.UpdateUserPushNotification(obj); Console.WriteLine("Error :" + lst_errorText[0]); } else { obj.Messageid = string.Empty; obj.Error = ""; objAndroidGCMPushNotification.UpdateUserPushNotification(obj); Console.WriteLine("Done!"); } //[[end here } else if (dt.Rows[i]["DeviceType"].ToString().Trim().ToLower().Equals("android")) { Console.WriteLine("Sending notification on Android device for message ID: " + obj.Sno); string errorText = objAndroidGCMPushNotification.SendPushNotification(obj); if (!string.IsNullOrEmpty(errorText))// added by Jitendra on 23-05-2017 { //update error obj.Messageid = string.Empty; obj.Error = errorText; objAndroidGCMPushNotification.UpdateUserPushNotification(obj); Console.WriteLine("Error :" + errorText); } else { Console.WriteLine("Done!"); } } } } } } catch (Exception ex) { obj.Messageid = string.Empty; obj.Error = ex.Message; objAndroidGCMPushNotification.UpdateUserPushNotification(obj); } finally { obj = null; } }