private int SendWin8(string applicationId, string deviceToken, string alert, string action, NotificationParameters props) { if (props == null) { props = new NotificationParameters(); } ConfigurationProps securityInfo = Certificates.Instance.PropertiesFor(applicationId); return(Win8Notifications.Send(securityInfo.WNSClientSecret, securityInfo.WNSPackageSecurityIdentifier, deviceToken, action, alert, props, out m_customError) ? 0 : 3); }
private int SendIOS(string applicationId, string deviceToken, string alert, string action, NotificationParameters props) { if (props == null) { props = new NotificationParameters(); } ConfigurationProps cert = Certificates.Instance.PropertiesFor(applicationId); string payload = string.Format(PAYLOAD_FORMAT, alert, applicationId, action, Certificates.Instance.TypeFor(applicationId), props.ToJson()); return(IOSNotifications.Send(deviceToken, payload, cert.iOSuseSandboxServer ? IOS_HOST_SANDBOX : IOS_HOST_PROD, cert.iOScertificate, cert.iOScertificatePassword, out m_customError) ? 0 : 3); }
private int SendAndroid(string applicationId, string deviceToken, string alert, string action, NotificationParameters props) { if (props == null) { props = new NotificationParameters(); } ConfigurationProps cert = Certificates.Instance.PropertiesFor(applicationId); // new AndroidUserToken for gcm getting from config file now String AndroidUserToken = cert.androidSenderAPIKey; //TODO: Add parameters to standart call action? return(AndroidNotifications.sendMessage(AndroidUserToken, deviceToken, alert, action, props, out m_customError) ? 0 : 3); }
public int CallAction(string applicationId, short deviceType, string deviceToken, string alertMessage, string action, NotificationParameters props) { return(SendInternal(applicationId, deviceType, deviceToken, alertMessage, action, props)); }
public int CallAction(string applicationId, short deviceType, string deviceToken, string alertMessage, string action, NotificationParameters props) { return(0); }
private int SendInternal(string applicationId, short deviceType, string deviceToken, string alertMessage, string action, NotificationParameters props) { switch (deviceType) { case IOS: m_error = SendIOS(applicationId, deviceToken, alertMessage, action, props); break; case ANDROID: m_error = SendAndroid(applicationId, deviceToken, alertMessage, action, props); break; case WPHONE: m_error = SendWin8(applicationId, deviceToken, alertMessage, action, props); break; default: m_error = -1; break; } return(ErrorCode); }
internal static bool Send(string secret, string sid, string uri, string action, string text, NotificationParameters props, out string log) { WindowsNotification notif = new WindowsNotification { Action = action, Message = text, Parameters = props }; string xml = GetMessage(notif); log = ""; string notificationType = "wns/toast"; string contentType = "text/xml"; string tag = props.ValueOf("tag"); if (action == "toast" || String.IsNullOrEmpty(action)) { notificationType = "wns/toast"; contentType = "text/xml"; } else if (action == "badge") { notificationType = "wns/badge"; } else if (action == "tile") { notificationType = "wns/tile"; } else if (action == "raw") { notificationType = "wns/raw"; contentType = "application/octet-stream"; } return(new Win8Notifications().SendToWns(secret, sid, uri, xml, notificationType, contentType, tag, retries, ref log)); }
public static bool sendMessage(string auth_token, string registrationId, string message, string action, NotificationParameters props, out string log) { StringBuilder postDataBuilder = new StringBuilder(); postDataBuilder.Append(PARAM_REGISTRATION_ID).Append("=") .Append(registrationId); postDataBuilder.Append("&").Append(PARAM_COLLAPSE_KEY).Append("=") .Append("0"); postDataBuilder.Append("&").Append(PARAM_PRIORITY).Append("=") .Append("high"); postDataBuilder.Append("&").Append("data.payload").Append("=") .Append(System.Web.HttpUtility.UrlEncode(message)); postDataBuilder.Append("&").Append("data.action").Append("=") .Append(System.Web.HttpUtility.UrlEncode(action)); //add parameters postDataBuilder.Append("&").Append("data.parameters").Append("=") .Append(System.Web.HttpUtility.UrlEncode(props.ToJson())); String postData = postDataBuilder.ToString(); UTF8Encoding encoding = new UTF8Encoding(); byte[] bytes = encoding.GetBytes(postData); // Hit the dm URL. //Uri uri = new Uri("https://android.clients.google.com/c2dm/send"); // new url for gcm service Uri uri = new Uri("https://android.googleapis.com/gcm/send"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8;"; request.ContentLength = postData.Length; request.Headers["Authorization"] = "key=" + auth_token; // HttpsURLConnection // .setDefaultHostnameVerifier(new CustomizedHostnameVerifier()); //allows for validation of SSL certificates ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate); using (Stream writeStream = request.GetRequestStream()) { writeStream.Write(bytes, 0, bytes.Length); } HttpStatusCode responseCode; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { responseCode = response.StatusCode; } log = ""; if (responseCode != HttpStatusCode.OK) { log = "Cannot send message to device " + responseCode.ToString(); } return(responseCode == HttpStatusCode.OK); }