public void Notify(string source, string description, NotificationPriority priority)
        {
            foreach (MailAddress address in Global.mail_to)
            {
                MailMessage mail = new MailMessage();
                mail.From = Global.mail_from;
                mail.To.Add(address);
                mail.Subject = "OmniLinkBridge - " + source;
                mail.Body    = source + ": " + description;

                using (SmtpClient smtp = new SmtpClient(Global.mail_server, Global.mail_port))
                {
                    if (!string.IsNullOrEmpty(Global.mail_username))
                    {
                        smtp.UseDefaultCredentials = false;
                        smtp.Credentials           = new NetworkCredential(Global.mail_username, Global.mail_password);
                    }

                    try
                    {
                        smtp.Send(mail);
                    }
                    catch (Exception ex)
                    {
                        log.Error("An error occurred sending notification", ex);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void SendNotification(string title, string message, string apiKey, NotificationPriority priority = NotificationPriority.Normal, string url = null)
        {
            try
            {
                var notification = new Prowlin.Notification
                {
                    Application = BuildInfo.AppName,
                    Description = message,
                    Event       = title,
                    Priority    = priority,
                    Url         = url
                };

                notification.AddApiKey(apiKey.Trim());

                var client = new ProwlClient();

                _logger.Debug("Sending Prowl Notification");

                var notificationResult = client.SendNotification(notification);

                if (!string.IsNullOrWhiteSpace(notificationResult.ErrorMessage))
                {
                    throw new InvalidApiKeyException("API Key: " + apiKey + " is invalid");
                }
            }

            catch (Exception ex)
            {
                _logger.Debug(ex, ex.Message);
                _logger.Warn("Invalid API Key: {0}", apiKey);
            }
        }
Exemplo n.º 3
0
        public void SendNotification(string title, string message, string apiKey, NotificationPriority priority = NotificationPriority.Normal, string url = null)
        {
            try
            {
                var notification = new Prowlin.Notification
                                   {
                                       Application = "Sonarr",
                                       Description = message,
                                       Event = title,
                                       Priority = priority,
                                       Url = url
                                   };

                notification.AddApiKey(apiKey.Trim());

                var client = new ProwlClient();

                _logger.Debug("Sending Prowl Notification");

                var notificationResult = client.SendNotification(notification);

                if (!string.IsNullOrWhiteSpace(notificationResult.ErrorMessage))
                {
                    throw new InvalidApiKeyException("API Key: " + apiKey + " is invalid");
                }
            }

            catch (Exception ex)
            {
                _logger.DebugException(ex.Message, ex);
                _logger.Warn("Invalid API Key: {0}", apiKey);
            }
        }
Exemplo n.º 4
0
        public virtual bool SendNotification(string title, string message, string apiKeys, NotificationPriority priority = NotificationPriority.Normal, string url = null)
        {
            try
            {
                var notification = new Notification
                                   {
                                       Application = "NzbDrone",
                                       Description = message,
                                       Event = title,
                                       Priority = priority,
                                       Url = url
                                   };

                foreach (var apiKey in apiKeys.Split(','))
                    notification.AddApiKey(apiKey.Trim());

                var client = new ProwlClient();

                Logger.Trace("Sending Prowl Notification");

                var notificationResult = client.SendNotification(notification);

                if (String.IsNullOrWhiteSpace(notificationResult.ErrorMessage))
                    return true;
            }

            catch (Exception ex)
            {
                Logger.TraceException(ex.Message, ex);
                Logger.Warn("Invalid API Key(s): {0}", apiKeys);
            }

            return false;
        }
Exemplo n.º 5
0
 public static void Notify(string source, string description, NotificationPriority priority = NotificationPriority.Normal)
 {
     Parallel.ForEach(providers, (provider) =>
     {
         provider.Notify(source, description, priority);
     });
 }
        /// <summary>
        /// Converts <see cref="EmailNotificationItemTableEntity"/> to a <see cref="EmailNotificationItemEntity"/>.
        /// </summary>
        /// <param name="emailNotificationItemTableEntity"> EmailNotificationItemTableEntity. </param>
        /// <returns><see cref="EmailNotificationItemEntity"/>.</returns>
        public static EmailNotificationItemEntity ConvertToEmailNotificationItemEntity(this EmailNotificationItemTableEntity emailNotificationItemTableEntity)
        {
            if (emailNotificationItemTableEntity is null)
            {
                return(null);
            }

            EmailNotificationItemEntity emailNotificationItemEntity = new EmailNotificationItemEntity();
            NotificationPriority        notificationPriority        = Enum.TryParse <NotificationPriority>(emailNotificationItemTableEntity.Priority, out notificationPriority) ? notificationPriority : NotificationPriority.Low;
            NotificationItemStatus      notificationItemStatus      = Enum.TryParse <NotificationItemStatus>(emailNotificationItemTableEntity.Status, out notificationItemStatus) ? notificationItemStatus : NotificationItemStatus.Queued;

            emailNotificationItemEntity.Priority         = notificationPriority;
            emailNotificationItemEntity.Status           = notificationItemStatus;
            emailNotificationItemEntity.PartitionKey     = emailNotificationItemTableEntity.Application;
            emailNotificationItemEntity.RowKey           = emailNotificationItemTableEntity.NotificationId;
            emailNotificationItemEntity.Application      = emailNotificationItemTableEntity.Application;
            emailNotificationItemEntity.BCC              = emailNotificationItemTableEntity.BCC;
            emailNotificationItemEntity.CC               = emailNotificationItemTableEntity.CC;
            emailNotificationItemEntity.EmailAccountUsed = emailNotificationItemTableEntity.EmailAccountUsed;
            emailNotificationItemEntity.ErrorMessage     = emailNotificationItemTableEntity.ErrorMessage;
            emailNotificationItemEntity.From             = emailNotificationItemTableEntity.From;
            emailNotificationItemEntity.NotificationId   = emailNotificationItemTableEntity.NotificationId;
            emailNotificationItemEntity.ReplyTo          = emailNotificationItemTableEntity.ReplyTo;
            emailNotificationItemEntity.Sensitivity      = emailNotificationItemTableEntity.Sensitivity;
            emailNotificationItemEntity.Subject          = emailNotificationItemTableEntity.Subject;
            emailNotificationItemEntity.TemplateId       = emailNotificationItemTableEntity.TemplateId;
            //emailNotificationItemEntity.TemplateData = emailNotificationItemTableEntity.TemplateData;
            emailNotificationItemEntity.Timestamp     = emailNotificationItemTableEntity.Timestamp;
            emailNotificationItemEntity.To            = emailNotificationItemTableEntity.To;
            emailNotificationItemEntity.TrackingId    = emailNotificationItemTableEntity.TrackingId;
            emailNotificationItemEntity.TryCount      = emailNotificationItemTableEntity.TryCount;
            emailNotificationItemEntity.ETag          = emailNotificationItemTableEntity.ETag;
            emailNotificationItemEntity.SendOnUtcDate = emailNotificationItemTableEntity.SendOnUtcDate;
            return(emailNotificationItemEntity);
        }
Exemplo n.º 7
0
 public Notification(GameObject sender, GameObject receiver, NotificationType type, NotificationPriority priority, object data)
 {
     this.sender   = sender;
     this.receiver = receiver;
     this.type     = type;
     this.priority = priority;
     this.data     = data;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Notifies an account is to expire within a week.
        /// </summary>
        /// <param name="character"></param>
        /// <param name="result"></param>
        internal void NotifyAccountExpiration(Account account, DateTime expireDate, NotificationPriority priority)
        {
            var notification = new Notification(NotificationCategory.AccountExpiration, account)
            {
                Description = String.Format("This account expires in {0}: {1}.",
                                            expireDate.ToRemainingTimeShortDescription(DateTimeKind.Utc), account),
                Behaviour = NotificationBehaviour.Overwrite,
                Priority  = priority
            };

            Notify(notification);
        }
Exemplo n.º 9
0
 public static void Notify(string source, string description, NotificationPriority priority = NotificationPriority.Normal)
 {
     Parallel.ForEach(providers, (provider) =>
     {
         try
         {
             provider.Notify(source, description, priority);
         }
         catch (Exception ex)
         {
             log.Error("Failed to send notification", ex);
         }
     });
 }
Exemplo n.º 10
0
        public void Notify(NotificationPriority priority, NotificationEventType eventType, string logMessage)
        {
            switch (eventType)
            {
            case NotificationEventType.FileSystem:
                SystemSounds.Asterisk.Play();
                break;

            case NotificationEventType.Update:
                SystemSounds.Hand.Play();
                break;

            case NotificationEventType.Error:
                SystemSounds.Exclamation.Play();
                break;
            }
        }
Exemplo n.º 11
0
        public void Notify(string source, string description, NotificationPriority priority)
        {
            foreach (string key in Global.pushover_user)
            {
                var parameters = new NameValueCollection {
                    { "token", Global.pushover_token },
                    { "user", key },
                    { "priority", ((int)priority).ToString() },
                    { "title", $"{Global.controller_name} - {source}" },
                    { "message", description }
                };

                using (WebClient client = new WebClient())
                {
                    client.UploadValues(URI, parameters);
                    client.UploadStringCompleted += Client_UploadStringCompleted;
                }
            }
        }
Exemplo n.º 12
0
        public void Notify(string source, string description, NotificationPriority priority)
        {
            foreach (string key in Global.prowl_key)
            {
                List <string> parameters = new List <string>();

                parameters.Add("apikey=" + key);
                parameters.Add("priority= " + (int)priority);
                parameters.Add("application=OmniLinkBridge");
                parameters.Add("event=" + source);
                parameters.Add("description=" + description);

                using (WebClient client = new WebClient())
                {
                    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                    client.UploadStringAsync(URI, string.Join("&", parameters.ToArray()));
                    client.UploadStringCompleted += client_UploadStringCompleted;
                }
            }
        }
Exemplo n.º 13
0
        public void Show(string message, NotificationPriority priority, NotificationTime time, NotificationType type)
        {
            if (currentPriority > priority)
            {
                return;
            }
            currentPriority = priority;

            this.MessageBlock.Text = message;
            PreviewShowNotification?.Invoke(this, new EventArgs());
            this.Visibility = Visibility.Visible;
            this.type       = type;

            hideTimer.Stop();
            if (!(time == NotificationTime.Eternally))
            {
                hideCount = (int)time;
                hideTimer.Start();
            }
        }
Exemplo n.º 14
0
 /// <summary>
 /// Sets notification messages on status strip of a form. It takes a message and priority as parameters
 /// </summary>
 /// <param name="message"></param>
 /// <param name="notify"></param>
 public void SetNotification(string message, NotificationPriority notify)
 {
     if (notify == NotificationPriority.Success)
     {
         statusStrip.BackColor = Color.DodgerBlue;
     }
     else if (notify == NotificationPriority.Failure)
     {
         statusStrip.BackColor = Color.Red;
     }
     else if (notify == NotificationPriority.Ready)
     {
         statusStrip.BackColor = Color.Green;
     }
     else if (notify == NotificationPriority.Waiting)
     {
         statusStrip.BackColor = Color.Orange;
     }
     toolStripStatusLabel.Text = message;
 }
        public ActionResult SendNotification(
            [ModelBinder(typeof(NotificationTemplateModelBinder))] INotificationContent notification,
            string channelUrl,
            NotificationPriority priority = NotificationPriority.Normal)
        {
            var options = new NotificationSendOptions()
            {
                Priority = priority
            };

            NotificationSendResult result = notification.Send(new Uri(channelUrl), this.tokenProvider, options);

            object response = new
            {
                DeviceConnectionStatus = result.DeviceConnectionStatus.ToString(),
                NotificationStatus     = result.NotificationStatus.ToString(),
                Status = result.LookupHttpStatusCode()
            };

            return(this.Json(response));
        }
        private static int GetMeetingPriority(NotificationPriority priority)
        {
            int meetingPriority = 0;

            switch (priority)
            {
            case NotificationPriority.High:
                meetingPriority = 1;
                break;

            case NotificationPriority.Low:
                meetingPriority = 9;
                break;

            default:
                meetingPriority = 0;
                break;
            }

            return(meetingPriority);
        }
        public ActionResult SendNotification(
            [ModelBinder(typeof(NotificationTemplateModelBinder))] INotificationContent notification,
            string channelUrl,
            NotificationPriority priority = NotificationPriority.Normal)
        {
            var options = new NotificationSendOptions()
                {
                    Priority = priority
                };

            NotificationSendResult result = notification.Send(new Uri(channelUrl), this.tokenProvider, options);

            object response = new
            {
                DeviceConnectionStatus = result.DeviceConnectionStatus.ToString(),
                NotificationStatus = result.NotificationStatus.ToString(),
                Status = result.LookupHttpStatusCode()
            };

            return this.Json(response);
        }
Exemplo n.º 18
0
        private string GetIconUrl(NotificationPriority notificationPriority, string userName)
        {
            var iconUrl = "";

            if (_user.HasClaim(c => c.Type == "client_logo"))
            {
                iconUrl = _user.Claims.Where(x => x.Type == "client_logo").FirstOrDefault().Value;
            }
            else if (notificationPriority == NotificationPriority.System)
            {
                iconUrl = _configuration["Notifications:SystemIconUrl"];
            }
            else if (_user.HasClaim(ClaimTypes.Role, PlayerClaimTypes.HelpDeskAgent.ToString()))
            {
                iconUrl = _context.Applications.FirstOrDefault(x => x.Name == _configuration["Notifications:HelpDeskApplicationName"]).Icon;
            }
            else
            {
                iconUrl = _configuration["Notifications:UserIconUrl"];
            }
            return(iconUrl);
        }
Exemplo n.º 19
0
        public void Notify(string source, string description, NotificationPriority priority)
        {
            if (string.IsNullOrEmpty(Global.mail_server))
            {
                return;
            }

            foreach (MailAddress address in Global.mail_to)
            {
                MailMessage mail = new MailMessage
                {
                    From    = Global.mail_from,
                    Subject = $"{Global.controller_name} - {source}",
                    Body    = $"{source}: {description}"
                };
                mail.To.Add(address);

                using (SmtpClient smtp = new SmtpClient(Global.mail_server, Global.mail_port))
                {
                    smtp.EnableSsl = Global.mail_tls;
                    if (!string.IsNullOrEmpty(Global.mail_username))
                    {
                        smtp.UseDefaultCredentials = false;
                        smtp.Credentials           = new NetworkCredential(Global.mail_username, Global.mail_password);
                    }

                    try
                    {
                        smtp.Send(mail);
                    }
                    catch (Exception ex)
                    {
                        log.Error("An error occurred sending email notification", ex);
                    }
                }
            }
        }
Exemplo n.º 20
0
        public void Notify(NotificationPriority priority, NotificationEventType eventType, string logMessage)
        {
            const int scaleInterval = 131;
            var       duration      = priority switch
            {
                NotificationPriority.High => 500,
                NotificationPriority.Medium => 200,
                NotificationPriority.Low => 0,
                _ => 0,
            };
            var frequency = eventType switch
            {
                NotificationEventType.Error => scaleInterval * 1,
                NotificationEventType.FileSystem => scaleInterval * 2,
                NotificationEventType.JournalEntry => scaleInterval * 3,
                NotificationEventType.Update => scaleInterval * 5,
                _ => 0,
            };

            if (frequency > 0 && duration > 0)
            {
                System.Console.Beep(frequency, duration);
            }
        }
Exemplo n.º 21
0
        private static void SetHeaders(string accessToken, NotificationType type, int? secondsTTL, bool? cache, bool? requestForStatus, string tag, NotificationPriority priority, HttpWebRequest request)
        {
            SetCustomHeaders(request, type);
            request.Headers.Add("Authorization", string.Format("Bearer {0}", accessToken));

            if (priority != NotificationPriority.Normal)
            {
                request.Headers.Add(WnsHeaders.Priority, ((int)priority).ToString());
            }

            // Cache policy
            if (cache.HasValue)
            {
                request.Headers.Add(WnsHeaders.CachePolicy, cache.Value ? Constants.Cache : Constants.NoCache);
            }

            // Request for Device Status and Notification Status to be returned in the response
            if (requestForStatus.HasValue)
            {
                request.Headers.Add(WnsHeaders.RequestForStatus, requestForStatus.Value.ToString().ToLower());
            }

            // Assign a tag label for a notification - used by device to detect dups - note 16chars in length
            if (!string.IsNullOrWhiteSpace(tag))
            {
                request.Headers.Add(WnsHeaders.Tag, tag);
            }

            // if null default behaviour is to not expire
            if (secondsTTL.HasValue)
            {
                request.Headers.Add(WnsHeaders.TTL, secondsTTL.Value.ToString());
            }
        }
Exemplo n.º 22
0
        public static NotificationSendResult Send(Uri channelUri, IAccessTokenProvider accessTokenProvider, string payload, NotificationType type, int? secondsTTL = null, bool? cache = null, bool? requestForStatus = null, string tag = null, NotificationPriority priority = NotificationPriority.Normal, int tokenRetry = 0)
        {
            NotificationSendResult result;
            byte[] payloadBytes;
            HttpWebRequest request = null;

            try
            {
                WnsDiagnostics.TraceVerbose(
                       DiagnosticsConstants.SendingWNSNotificationID,
                       "Sending WNS notification.\r\n\r\n{0}",
                       NotificationRequestStatus(channelUri.ToString(), payload, secondsTTL, cache, requestForStatus, tag, priority, tokenRetry));

                var accessToken = string.Empty;

                try
                {
                    accessToken = accessTokenProvider.GetAccessToken(true);
                }
                catch (WebException e)
                {
                    if (e.Response != null)
                    {
                        var accessTokenError = GetAccessTokenError(e.Response);
                        WnsDiagnostics.TraceError(DiagnosticsConstants.WnsAccessTokenSendResultErrorID, AccessTokenLogMessage(e.Response, accessTokenError));
                        return new WnsAccessTokenSendResult(channelUri, e, accessTokenError);
                    }
                    else
                    {
                        WnsDiagnostics.TraceError(DiagnosticsConstants.ServiceUnavailableErrorID, e.Message);
                        return new NotificationSendResult(channelUri, e.Message, HttpStatusCode.ServiceUnavailable);
                    }
                }

                request = CreateWebRequest(channelUri, accessToken, payload, type, secondsTTL, cache, requestForStatus, tag, priority, out payloadBytes);

                using (Stream requestStream = request.GetRequestStream())
                {
                    requestStream.Write(payloadBytes, 0, payloadBytes.Length);
                }

                var response = (HttpWebResponse)request.GetResponse();
                result = new NotificationSendResult(channelUri, response);

                WnsDiagnostics.TraceInformation(DiagnosticsConstants.SentWNSNotificationID, NotificationLogMessage("Sent WNS notification", result.NotificationStatus.ToString(), result, payload, request, response));
            }
            catch (WebException e)
            {
                if (e.Response != null)
                {
                    string exceptionDetails = e.Response.Headers[WnsHeaders.WWWAuthenticate];
                    if (!string.IsNullOrWhiteSpace(exceptionDetails) && exceptionDetails.Contains("Token expired"))
                    {
                        accessTokenProvider.ResetCachedToken();

                        tokenRetry++;
                        if (tokenRetry <= MaxSendRetries)
                        {
                            result = Send(channelUri, accessTokenProvider, payload, type, secondsTTL, cache, requestForStatus, tag, priority, tokenRetry);
                        }
                        else
                        {
                            result = new NotificationSendResult(channelUri, e);
                        }
                    }
                    else
                    {
                        result = new NotificationSendResult(channelUri, e);
                    }

                    WnsDiagnostics.TraceError(DiagnosticsConstants.WNSNotificationFailureID, NotificationLogMessage("WNS notification failure", e.Message, result, payload, request, e.Response));
                }
                else
                {
                    WnsDiagnostics.TraceError(DiagnosticsConstants.ServiceUnavailableErrorID, e.Message);
                    return new NotificationSendResult(channelUri, e.Message, HttpStatusCode.ServiceUnavailable);
                }
            }
            catch (Exception e)
            {
                result = new NotificationSendResult(channelUri, e);

                WnsDiagnostics.TraceException(DiagnosticsConstants.WNSNotificationFailureID, e, "WNS notification failure: {0}\r\n\r\n{1}", e.Message, result);
            }

            return result;
        }
Exemplo n.º 23
0
        private static string NotificationRequestStatus(string channelId, string payload, int? secondsTTL, bool? cache, bool? requestForStatus, string tag, NotificationPriority priority, int tokenRetry)
        {
            var sb = new StringBuilder();
            sb.AppendFormat("Channel URI:              {0}\r\n", channelId);
            sb.AppendFormat("TTL:                      {0}\r\n", secondsTTL.HasValue ? secondsTTL.Value.ToString() : "-");
            sb.AppendFormat("Cache:                    {0}\r\n", cache.HasValue && cache.Value ? "yes" : "no");
            sb.AppendFormat("Request for status:       {0}\r\n", requestForStatus.HasValue && requestForStatus.Value ? "yes" : "no");
            sb.AppendFormat("Tag:                      {0}\r\n", tag);
            sb.AppendFormat("Priority:                 {0}\r\n", priority);
            sb.AppendFormat("Token retry count:        {0}\r\n", tokenRetry);
            sb.AppendLine();
            sb.AppendLine(payload);

            return sb.ToString();
        }
Exemplo n.º 24
0
 internal AndroidOptionsBuilder()
 {
     Priority   = NotificationPriority.Default;
     ChannelId  = "Plugin.LocalNotification.GENERAL";
     AutoCancel = true;
 }
Exemplo n.º 25
0
        /// <summary>
        /// Sends a notification using Pushover service
        /// </summary>
        /// <param name="token">Application Token/Key</param>
        /// <param name="apikey"></param>
        /// <param name="description">Message to send</param>
        /// <param name="ev">Title</param>
        /// <param name="p">Notification Priority</param>
        /// <returns></returns>
        public static Results.NotificationResult Pushover(string token, string apikey, string description, string ev, NotificationPriority p)
        {
            if (!CheckApiToken(token))
            {
                return(Results.NotificationResult.TokenError);
            }

            if (!CheckApiToken(apikey))
            {
                return(Results.NotificationResult.ApiKeyError);
            }

            string url = "https://api.pushover.net/1/messages.json";

            url += "?token=" + HttpUtility.UrlEncode(token.Trim()) +
                   "&user="******"&message=" + HttpUtility.UrlEncode(description) +
                   "&title=" + HttpUtility.UrlEncode(ev) +
                   "&priority=" + HttpUtility.UrlEncode(p.ToString());

            return(Send(url));
        }
Exemplo n.º 26
0
        public Int32 GetNumberOfSentPrioritiesThreshold(NotificationPriority myPriority)
        {
            if (!_NumberOfSentPrioritiesThresholds.ContainsKey((Byte)myPriority))
                return DefaultNumberOfSentPrioritiesThreshold;

            return _NumberOfSentPrioritiesThresholds[(Byte)myPriority];
        }
Exemplo n.º 27
0
        public virtual bool SendNotification(string title, string message, string apiKeys, NotificationPriority priority = NotificationPriority.Normal, string url = null)
        {
            try
            {
                var notification = new Notification
                {
                    Application = "NzbDrone",
                    Description = message,
                    Event       = title,
                    Priority    = priority,
                    Url         = url
                };

                foreach (var apiKey in apiKeys.Split(','))
                {
                    notification.AddApiKey(apiKey.Trim());
                }

                var client = new ProwlClient();

                Logger.Trace("Sending Prowl Notification");

                var notificationResult = client.SendNotification(notification);

                if (String.IsNullOrWhiteSpace(notificationResult.ErrorMessage))
                {
                    return(true);
                }
            }

            catch (Exception ex)
            {
                Logger.TraceException(ex.Message, ex);
                Logger.Warn("Invalid API Key(s): {0}", apiKeys);
            }

            return(false);
        }
Exemplo n.º 28
0
 public Notification(NotificationPriority priority, string text)
 {
     this.priority = priority;
     this.text     = text;
 }
Exemplo n.º 29
0
 /// <summary>
 /// Set the relative priority for this notification.
 /// In Android, Only used if Android Api below 26.
 /// Use NotificationCenter.CreateNotificationChannel when Android Api equal or above 26
 /// </summary>
 public AndroidOptionsBuilder WithPriority(NotificationPriority priority)
 {
     Priority = priority;
     return(this);
 }
Exemplo n.º 30
0
        public void PostNotification(string title, string text, bool autoCancellable, NotificationPriority notificationPriority)
        {
#pragma warning disable CS0618 // 'Notification.Builder(Context) está obsoleto
            Notification.Builder builder = new Notification.Builder(Application.Context);
#pragma warning restore
            builder.SetContentTitle(title);
            builder.SetContentText(text);
            builder.SetAutoCancel(autoCancellable);
#pragma warning disable CS0618 // 'Notification.Builder.SetPriority(int)' está obsoleto: 'deprecated'
            builder.SetPriority(Convert.ToInt32(NotificationPriority.Low));
#pragma warning restore CS0618 // 'Notification.Builder.SetPriority(int)' está obsoleto: 'deprecated'

            builder.SetSmallIcon(Resource.Drawable.ic_stat_default_appicon);
            notificationManager.Notify(1, builder.Build());
        }
Exemplo n.º 31
0
    public void CreateNotification(GameObject sender, GameObject receiver, NotificationType type, NotificationPriority priority, object data)
    {
        Notification notification = new Notification(sender, receiver, type, priority, data);

        notification.Send();
    }
Exemplo n.º 32
0
        /// <summary>
        /// Sends a notification using Prowl service (iPhone)
        /// </summary>
        /// <param name="apikey"></param>
        /// <param name="pluginName">Name of the Plugin</param>
        /// <param name="ev">Event name</param>
        /// <param name="description">Event description</param>
        /// <param name="priority">Notification Priority</param>
        /// <returns>NotificationResult enum entry</returns>
        public static Results.NotificationResult Prowl(string apikey, string pluginName, string ev, string description, NotificationPriority priority)
        {
            if (!CheckApiToken(apikey))
            {
                return(Results.NotificationResult.ApiKeyError);
            }

            string url = "https://prowl.weks.net/publicapi/add";

            url += "?apikey=" + HttpUtility.UrlEncode(apikey.Trim()) +
                   "&application=" + HttpUtility.UrlEncode(pluginName) +
                   "&description=" + HttpUtility.UrlEncode(description) +
                   "&event=" + HttpUtility.UrlEncode(ev) +
                   "&priority=" + HttpUtility.UrlEncode(priority.ToString());

            return(Send(url));
        }
Exemplo n.º 33
0
 private Priority(NotificationPriority p)
 {
     priority = p;
 }
			private Priority(NotificationPriority p)
			{
				priority = p;
			}
Exemplo n.º 35
0
 public void Hide()
 {
     currentPriority = NotificationPriority.Lowest;
     this.Visibility = Visibility.Collapsed;
 }
Exemplo n.º 36
0
        public static void SendAsynchronously(Uri channelUri, IAccessTokenProvider accessTokenProvider, string payload, Action<NotificationSendResult> sent, Action<NotificationSendResult> error, NotificationType type, int? secondsTTL = null, bool? cache = null, bool? requestForStatus = null, string tag = null, NotificationPriority priority = NotificationPriority.Normal, int tokenRetry = 0)
        {
            byte[] payloadBytes;

            try
            {
                WnsDiagnostics.TraceVerbose(
                    DiagnosticsConstants.SendingWNSNotificationID,
                    "Sending WNS notification.\r\n\r\n{0}",
                    NotificationRequestStatus(channelUri.ToString(), payload, secondsTTL, cache, requestForStatus, tag, priority, tokenRetry));

                var accessToken = string.Empty;

                try
                {
                    accessToken = accessTokenProvider.GetAccessToken(true);
                }
                catch (WebException e)
                {
                    if (e.Response != null)
                    {
                        var accessTokenError = GetAccessTokenError(e.Response);
                        WnsDiagnostics.TraceError(DiagnosticsConstants.WnsAccessTokenSendResultErrorID, AccessTokenLogMessage(e.Response, accessTokenError));
                        error(new WnsAccessTokenSendResult(channelUri, e, accessTokenError));
                    }
                    else
                    {
                        WnsDiagnostics.TraceError(DiagnosticsConstants.ServiceUnavailableErrorID, e.Message);
                        error(new NotificationSendResult(channelUri, e.Message, HttpStatusCode.ServiceUnavailable));
                    }
                }

                if (!string.IsNullOrEmpty(accessToken))
                {
                    var request = CreateWebRequest(channelUri, accessToken, payload, type, secondsTTL, cache, requestForStatus, tag, priority, out payloadBytes);

                    // Get the request stream asynchronously.
                    request.BeginGetRequestStream(
                        requestAsyncResult =>
                        {
                            try
                            {
                                using (Stream requestStream = request.EndGetRequestStream(requestAsyncResult))
                                {
                                    // Start writing the payload to the stream.
                                    requestStream.Write(payloadBytes, 0, payloadBytes.Length);
                                }

                                // Switch to receiving the response from WNS asynchronously.
                                request.BeginGetResponse(
                                    responseAsyncResult =>
                                    {
                                        try
                                        {
                                            using (
                                                var response =
                                                    (HttpWebResponse)request.EndGetResponse(responseAsyncResult))
                                            {
                                                var result = new NotificationSendResult(channelUri, response);
                                                if (result.StatusCode == HttpStatusCode.OK)
                                                {
                                                    WnsDiagnostics.TraceInformation(DiagnosticsConstants.SentWNSNotificationID, NotificationLogMessage("Sent WNS notification", result.NotificationStatus.ToString(), result, payload, request, response));
                                                    sent(result);
                                                }
                                                else
                                                {
                                                    error(result);
                                                    WnsDiagnostics.TraceError(DiagnosticsConstants.WNSNotificationFailureID, "WNS notification failure:\r\n\r\n{0}", result);
                                                }
                                            }
                                        }
                                        catch (WebException e)
                                        {
                                            if (e.Response != null)
                                            {
                                                var result = new NotificationSendResult(channelUri, e);

                                                string exceptionDetails = e.Response.Headers[WnsHeaders.WWWAuthenticate];
                                                if (!string.IsNullOrWhiteSpace(exceptionDetails) &&
                                                    exceptionDetails.Contains("Token expired"))
                                                {
                                                    accessTokenProvider.ResetCachedToken();

                                                    tokenRetry++;
                                                    if (tokenRetry <= MaxSendRetries)
                                                    {
                                                        SendAsynchronously(channelUri, accessTokenProvider, payload, sent, error, type, secondsTTL, cache, requestForStatus, tag, priority, tokenRetry);
                                                    }
                                                    else
                                                    {
                                                        WnsDiagnostics.TraceError(DiagnosticsConstants.WNSNotificationFailureID, NotificationLogMessage("WNS notification failure", e.Message, result, payload, request, e.Response));
                                                        error(result);
                                                    }
                                                }
                                                else
                                                {
                                                    WnsDiagnostics.TraceError(DiagnosticsConstants.WNSNotificationFailureID, NotificationLogMessage("WNS notification failure", e.Message, result, payload, request, e.Response));
                                                    error(result);
                                                }
                                            }
                                            else
                                            {
                                                WnsDiagnostics.TraceError(DiagnosticsConstants.ServiceUnavailableErrorID, e.Message);
                                                error(new NotificationSendResult(channelUri, e.Message, HttpStatusCode.ServiceUnavailable));
                                            }
                                        }
                                        catch (Exception ex3)
                                        {
                                            var result = new NotificationSendResult(channelUri, ex3);
                                            WnsDiagnostics.TraceException(DiagnosticsConstants.GeneralNotificationFailureID, ex3, "WNS notification failure: {0}\r\n\r\n{1}", ex3.Message, result);
                                            error(result);
                                        }
                                    },
                                    null);
                            }
                            catch (Exception ex2)
                            {
                                var result = new NotificationSendResult(channelUri, ex2);
                                WnsDiagnostics.TraceException(DiagnosticsConstants.GeneralNotificationFailureID, ex2, "WNS notification failure: {0}\r\n\r\n{1}", ex2.Message, result);
                                error(result);
                            }
                        },
                        null);
                }
            }
            catch (Exception ex1)
            {
                var result = new NotificationSendResult(channelUri, ex1);
                WnsDiagnostics.TraceException(DiagnosticsConstants.GeneralNotificationFailureID, ex1, "WNS notification failure: {0}\r\n\r\n{1}", ex1.Message, result);
                error(result);
            }
        }
Exemplo n.º 37
0
        private static HttpWebRequest CreateWebRequest(Uri channelId, string accessToken, string payload, NotificationType type, int? secondsTTL, bool? cache, bool? requestForStatus, string tag, NotificationPriority priority, out byte[] payloadBytes)
        {
            var request = (HttpWebRequest) HttpWebRequest.Create(channelId);
            request.Method = Constants.Post;

            request.ServicePoint.Expect100Continue = false;

            SetHeaders(accessToken, type, secondsTTL, cache, requestForStatus, tag, priority, request);

            payloadBytes = Encoding.UTF8.GetBytes(payload);
            request.ContentLength = payloadBytes.Length;

            return request;
        }
 public void Notify(NotificationPriority priority, NotificationEventType eventType, string logMessage)
 {
     Log.Info($"{priority} {eventType}: {logMessage}");
 }
Exemplo n.º 39
0
    public static void CreateNotification(NotificationPriority priority, string text)
    {
        Notification notification = new Notification(priority, text);

        NotificationMagazine.AddNotification(notification);
    }
Exemplo n.º 40
0
        public void ChangeNumberOfSentPrioritiesThreshold(NotificationPriority myPriority, Int32 myThreshold)
        {
            if (!_NumberOfSentPrioritiesThresholds.ContainsKey((Byte)myPriority))
                throw new ArgumentOutOfRangeException("myPriority");

            _NumberOfSentPrioritiesThresholds[(Byte)myPriority] = myThreshold;
        }