/// <summary> /// Pushes the notification. /// </summary> /// <param name="message">The message.</param> /// <param name="title">The title.</param> /// <param name="url">The URL.</param> /// <returns>Task<System.String>.</returns> public static async Task<string> PushNotification(string message, string title = null, string url = null) { try { using (var client = new BetterWebClient()) { var values = new NameValueCollection(); values["apikey"] = MySettings.Instance.NMY_Token; values["application"] = "PushHub"; if (!string.IsNullOrEmpty(title)) values["event"] = title.Truncate(1000); if (!string.IsNullOrEmpty(message)) values["description"] = message.Truncate(10000); if (!string.IsNullOrEmpty(url)) values["url"] = url.Truncate(2000); var priority = MySettings.Instance.NMY_Priority; if ((int)priority != 0) values["priority"] = ((int)priority).ToString(CultureInfo.InvariantCulture); client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; var responseArray = await client.UploadValuesTaskAsync(API_URL, values); return Encoding.ASCII.GetString(responseArray); } } catch (WebException e) { if (e.Status == WebExceptionStatus.NameResolutionFailure) Logger.FailLog("{0}:Bad domain name", ProviderName); if (e.Status == WebExceptionStatus.ProtocolError) Logger.FailLog("{0} Notification failed, Status Code: {1}. Description: {2}", ProviderName, ((HttpWebResponse)e.Response).StatusCode, ((HttpWebResponse)e.Response).StatusDescription); return null; } catch (Exception ex) { Logging.WriteException(LogLevel.Normal, ex); return null; } }
/// <summary> /// Pushes the notification. /// </summary> /// <param name="message">The message.</param> /// <param name="title">The title.</param> /// <returns>Task<System.String>.</returns> public static async Task<string> PushNotification(string message, string title = null) { try { using (var client = new BetterWebClient()) { var values = new NameValueCollection(); if (!string.IsNullOrEmpty(title)) values["title"] = title; if (!string.IsNullOrEmpty(message)) values["notification[long_message]"] = Encoding.UTF8.GetByteCount(message) <= 4000 ? message.Truncate(10000) : "Error: Message bigger then 4KB"; values["sender"] = "PushHub"; client.Headers[HttpRequestHeader.ContentEncoding] = "multipart/form-data"; var responseArray = await client.UploadValuesTaskAsync(new Uri(string.Format(API_URL, MySettings.Instance.Toasty_DeviceID)), values); return Encoding.ASCII.GetString(responseArray); } } catch (WebException e) { if (e.Status == WebExceptionStatus.NameResolutionFailure) Logger.FailLog("{0}:Bad domain name", ProviderName); if (e.Status == WebExceptionStatus.ProtocolError) Logger.FailLog("{0} Notification failed, Status Code: {1}. Description: {2}", ProviderName, ((HttpWebResponse)e.Response).StatusCode, ((HttpWebResponse)e.Response).StatusDescription); return null; } catch (Exception ex) { Logging.WriteException(LogLevel.Normal, ex); return null; } }
/// <summary> /// Pushes the notification. /// </summary> /// <param name="message">The message.</param> /// <param name="title">The title.</param> /// <param name="url">The URL.</param> /// <returns>Task<System.String>.</returns> public static async Task<string> PushNotification(string message, string title = null, string url = null) { string response = string.Empty; try { using (var client = new BetterWebClient()) { var values = new NameValueCollection(); var authEncoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(MySettings.Instance.Pushbullet_Token + ":")); values["AuthorizationToken"] = MySettings.Instance.Pushbullet_Token; values["type"] = Uri.IsWellFormedUriString(url, UriKind.Absolute) ? "link" : "note"; // Title, url and body string device = MySettings.Instance.Pushbullet_Device; if (!string.IsNullOrEmpty(device)) values["device_iden"] = device.Truncate(250); if (!string.IsNullOrEmpty(url) && Uri.IsWellFormedUriString(url, UriKind.Absolute)) values["url"] = url.Truncate(1000); if (!string.IsNullOrEmpty(title)) values["title"] = title.Truncate(250); if (!string.IsNullOrEmpty(message)) values["body"] = message; client.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", authEncoded); client.Headers[HttpRequestHeader.Accept] = "application/json"; client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; byte[] responseArray = await client.UploadValuesTaskAsync(API_URL, values); response = Encoding.ASCII.GetString(responseArray); } return response; } catch (WebException e) { if (e.Status == WebExceptionStatus.NameResolutionFailure) Logger.FailLog("{0}:Bad domain name", ProviderName); if (e.Status == WebExceptionStatus.ProtocolError) Logger.FailLog("{0} Notification failed, Status Code: {1}. Description: {2} - Response:{3}", ProviderName, ((HttpWebResponse)e.Response).StatusCode, ((HttpWebResponse)e.Response).StatusDescription, response); return null; } catch (Exception ex) { Logging.WriteException(LogLevel.Normal, ex); return null; } }
/// <summary> /// Pushes the notification. /// </summary> /// <param name="message">The message.</param> /// <param name="title">The title.</param> /// <param name="url">The URL.</param> /// <returns>Task<System.String>.</returns> public static async Task<string> PushNotification(string message, string title = null, string url = null) { try { using (var client = new BetterWebClient()) { var values = new NameValueCollection(); values["user_credentials"] = MySettings.Instance.BoxCar2_Token; values["notification[source_name]"] = "PushHub"; if (!string.IsNullOrEmpty(title)) values["notification[title]"] = title.Truncate(255); if (!string.IsNullOrEmpty(message)) values["notification[long_message]"] = Encoding.UTF8.GetByteCount(message) <= 4000 ? message.Truncate(10000) : "Error: Message bigger then 4KB"; if (!string.IsNullOrEmpty(url)) values["url"] = url.Truncate(2000); var sound = MySettings.Instance.BoxCar2_Sound; values["notification[sound]"] = sound.ToString().Replace('_', '-').ToLower(); client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; var responseArray = await client.UploadValuesTaskAsync(API_URL, values); return Encoding.ASCII.GetString(responseArray); } } catch (WebException e) { if (e.Status == WebExceptionStatus.NameResolutionFailure) Logger.FailLog("{0}:Bad domain name", ProviderName); if (e.Status == WebExceptionStatus.ProtocolError) Logger.FailLog("{0} Notification failed, Status Code: {1}. Description: {2}", ProviderName, ((HttpWebResponse)e.Response).StatusCode, ((HttpWebResponse)e.Response).StatusDescription); return null; } catch (Exception ex) { Logging.WriteException(LogLevel.Normal, ex); return null; } }
/// <summary> /// Pushes the notification. /// </summary> /// <param name="message">The message.</param> /// <param name="title">The title.</param> /// <param name="url">The URL.</param> /// <param name="urlTitle">The URL title.</param> /// <param name="priority">The priority.</param> /// <param name="IsSilent">if set to <c>true</c> [is silent].</param> /// <param name="IsImportant">if set to <c>true</c> [is important].</param> /// <returns>Task<System.String>.</returns> public static async Task<string> PushNotification(string message, string title = null, string url = null, string urlTitle = null, bool IsSilent = false, bool IsImportant = false) { try { using (var client = new BetterWebClient()) { var values = new NameValueCollection(); values["AuthorizationToken"] = MySettings.Instance.Pushalot_Token; values["Source"] = "PushHub"; if (!string.IsNullOrEmpty(title)) values["Title"] = title.Truncate(250); values["Body"] = message ?? "error"; //Required if (!string.IsNullOrEmpty(url) && Uri.IsWellFormedUriString(url, UriKind.Absolute)) values["Link"] = url.Truncate(1000); if (Uri.IsWellFormedUriString(url, UriKind.Absolute)) values["LinkTitle"] = (urlTitle.Truncate(100)) ?? "notitlespecified"; if (IsSilent) values["IsSilent"] = "True"; if (IsImportant) values["IsImportant"] = "True"; client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; var responseArray = await client.UploadValuesTaskAsync(API_URL, values); return Encoding.ASCII.GetString(responseArray); } } catch (WebException e) { if (e.Status == WebExceptionStatus.NameResolutionFailure) Logger.FailLog("{0}:Bad domain name", ProviderName); if (e.Status == WebExceptionStatus.ProtocolError) Logger.FailLog("{0} Notification failed, Status Code: {1}. Description: {2}", ProviderName, ((HttpWebResponse)e.Response).StatusCode, ((HttpWebResponse)e.Response).StatusDescription); return null; } catch (Exception ex) { Logging.WriteException(LogLevel.Normal, ex); return null; } }
/// <summary> /// Pushes the notification. /// </summary> /// <param name="message">The message.</param> /// <param name="title">The title.</param> /// <param name="url">The URL.</param> /// <param name="urlTitle">The URL title.</param> /// <returns>Task<System.String>.</returns> public static async Task<string> PushNotification(string message, string title = null, string url = null, string urlTitle = null) { string response = string.Empty; try { var editedtitle = string.Format("{0}: {1}", "PushHub", title); using (var wc = new BetterWebClient()) { var parameters = new NameValueCollection { { "token", MySettings.Instance.Pushover_Token }, { "user", MySettings.Instance.Pushover_UserKey }, { "message", message } }; var device = MySettings.Instance.Pushover_Device; if (!string.IsNullOrEmpty(device)) parameters.Add("device", device); if (!string.IsNullOrEmpty(title)) parameters.Add("title", editedtitle); if (!string.IsNullOrEmpty(url) && Uri.IsWellFormedUriString(url, UriKind.Absolute)) parameters.Add("url", url); if (!string.IsNullOrEmpty(urlTitle) && Uri.IsWellFormedUriString(url, UriKind.Absolute)) parameters.Add("urlTitle", urlTitle); var priority = MySettings.Instance.Pushover_Priority; if ((int)priority != 0) parameters.Add("priority", ((int)priority).ToString(CultureInfo.InvariantCulture)); var sound = MySettings.Instance.Pushover_Sound; if (sound != PushoverSound.Pushover) parameters.Add("sound", sound.ToString().ToLower()); var responseArray = await wc.UploadValuesTaskAsync(API_URL, parameters); return Encoding.ASCII.GetString(responseArray); } } catch (WebException e) { if (e.Status == WebExceptionStatus.NameResolutionFailure) Logger.FailLog("{0}:Bad domain name", ProviderName); if (e.Status == WebExceptionStatus.ProtocolError) Logger.FailLog("{0} Notification failed, Status Code: {1}. Description: {2}", ProviderName, ((HttpWebResponse)e.Response).StatusCode, ((HttpWebResponse)e.Response).StatusDescription); return null; } catch (Exception ex) { Logging.WriteException(LogLevel.Normal, ex); return null; } }