コード例 #1
0
        public void ExecuteNotification(string sender, IEnumerable <string> messages)
        {
            if (string.IsNullOrWhiteSpace(sender))
            {
                return;
            }

            foreach (var message in messages)
            {
                if (string.IsNullOrEmpty(message))
                {
                    continue;
                }

                Notifications.Insert(0, new NotificationItem(sender, message));
                NewNotification?.Invoke(this, new EventArgs <string, string>(sender, message));
            }
        }
コード例 #2
0
        public CustomerService()
        {
            SqlDependency.Start(ConfigurationManager.ConnectionStrings["NotificationCenterContext"].ConnectionString);

            var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["NotificationCenterContext"].ConnectionString);

            var command = new SqlCommand
            {
                Connection   = connection,
                CommandType  = CommandType.Text,
                CommandText  = "SELECT * FROM [dbo].[Notifications]",
                Notification = null
            };

            command.Connection.Open();

            SqlDependency dependency = new SqlDependency(command);

            dependency.OnChange += (sender, args) => { NewNotification?.Invoke(); };
            command.ExecuteReader();
        }
コード例 #3
0
ファイル: General.cs プロジェクト: JuanDouglas/WSClass
        private void ThreadNotifications(object @object)
        {
            if (!(@object is NotificationThreadStart))
            {
                throw new ArgumentException("Could not start this thread");
            }
            NotificationThreadStart notificationThreadStart = (NotificationThreadStart)@object;
            NotificationsController controller = new NotificationsController();

            do
            {
                Thread.Sleep(notificationThreadStart.UpdateDelay);
                var requestThread = controller.GetNotificationsAsync(notificationThreadStart.LoginToken, notificationThreadStart.ValidKey);
                requestThread.Wait();
                Notification[] notifications = requestThread.Result;
                if (notifications != null)
                {
                    foreach (var notification in notifications)
                    {
                        NewNotification.Invoke(null, new NewNotificationArgs(notification, DateTime.Now));
                    }
                }
            } while (Thread.CurrentThread.ThreadState == ThreadState.Running);
        }
コード例 #4
0
 protected void triggerNewNotification(NotificationEventArgs e)
 {
     NewNotification?.Invoke(this, e);
 }
コード例 #5
0
 /// <summary>
 /// Fires a new notification, returning the id of the returned notification.
 /// </summary>
 /// <param name="title"></param>
 /// <param name="line"></param>
 /// <param name="type"></param>
 /// <param name="duration"></param>
 /// <param name="template"></param>
 /// <param name="forcedId"></param>
 /// <returns></returns>
 public static int N(string title, string line, NotificationType type, int duration = -1, NotificationTemplate template = NotificationTemplate.Default, int forcedId = -1)
 {
     return(NewNotification?.Invoke(title, line, type, duration, template, forcedId) ?? -1);
 }
コード例 #6
0
        /// <summary>
        /// Отправить уведомление.
        /// </summary>
        /// <param name="notification">Данные уведомления.</param>
        public void SendNotification(AppNotification notification)
        {
            if (notification == null)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            if (!_settingsService.GetNoCache(ENABLE_IN_APP_POPUPS, true) && !notification.IsImportant)
            {
                return;
            }

            Task.Run(async() =>
            {
                try
                {
                    if (!notification.NoSound && _settingsService.GetNoCache(ENABLE_IN_APP_SOUND, true))
                    {
                        await PlaySound(notification.Type);
                    }
                }
                catch (Exception)
                {
                    _settingsService.Set(ENABLE_IN_APP_SOUND, false);
                    var error = new AppNotification
                    {
                        Type        = AppNotificationType.Error,
                        NoSound     = true,
                        Title       = _locService["AppNotifications_SoundNotWorking_Title"],
                        Content     = _locService["AppNotifications_SoundNotWorking_Content"],
                        IsImportant = true
                    };
                    SendNotification(error);
                }
            });

            _presenter.ShowNotification(notification);

            Task.Run(async() =>
            {
                try
                {
                    if (!notification.NoVibration && _settingsService.GetNoCache(ENABLE_IN_APP_VIBRATION, true))
                    {
                        await StartVibration(notification.Type);
                    }
                }
                catch (Exception)
                {
                    _settingsService.Set(ENABLE_IN_APP_VIBRATION, false);
                    var error = new AppNotification
                    {
                        Type        = AppNotificationType.Error,
                        NoVibration = true,
                        Title       = _locService["AppNotifications_VibrationNotWorking_Title"],
                        Content     = _locService["AppNotifications_VibrationNotWorking_Content"],
                        IsImportant = true
                    };
                    SendNotification(error);
                }
            });

            NewNotification?.Invoke(this, notification);
        }
コード例 #7
0
 public void RaiseNewNotification(Notification notification)
 {
     NewNotification?.Invoke(this, notification);
 }