コード例 #1
0
        private void ShowCore(MenuNotification notification)
        {
            DialogResult result;
            int          occupiedSlot;

            /*
             * Only <MAX_DISPLAYED_NOTIFICATIONS> notifications are displayed at once.
             * Incoming notifications have to wait until a "notification spot" has become
             * available.
             */
            notificationSema.WaitOne();

            /*
             * Multiple threads can try to obtain an <available slot> simultanenously, so we
             * need to synchronize the multiple thread accesses.
             */
            lock (this.notificationCounterLock)
            {
                occupiedSlot = GetFirstAvailableSlot();
                notificationSpotAvailable[occupiedSlot] = false;
            }

            using (ToastNotificationView notif = new ToastNotificationView(notification, occupiedSlot))
            {
                notif.Shown += OnNotificationShown;
                result       = notif.ShowDialog();
            }

            notificationSpotAvailable[occupiedSlot] = true;
            notificationSema.Release();
        }
コード例 #2
0
        public MenuNotificationViewModel(MenuNotification menuNotification)
        {
            MenuNotification = menuNotification ?? throw new ArgumentNullException(nameof(menuNotification));

            CloseCommand      = new RelayCommand(() => RequestClose?.Invoke(this, EventArgs.Empty));
            OpenSourceCommand = new RelayCommand(() => WebService.OpenWebsite(MenuNotification.Url));
            LostFocusCommand  = new RelayCommand(() => this.IsRead = true);
        }
コード例 #3
0
        public MenuNotification Update(MenuNotification notification)
        {
            if (notification == null)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            throw new NotImplementedException();
        }
コード例 #4
0
        public bool Contains(MenuNotification notification)
        {
            if (notification == null)
            {
                return(false);
            }

            return(db.Notifications.Any(n => n.Id == notification.Id));
        }
コード例 #5
0
        private async void DoJob()
        {
            try
            {
                while (!finishJob)
                {
                    UpdateAvailable status = await CheckForUpdate2();

                    if (status == UpdateAvailable.YES)
                    {
                        //Settings settings = Settings.Instance;
#if DEBUG
                        MenuNotification notification = new MenuNotification()
                        {
                            Title       = "ATG Chapter Update! (DEBUG)",
                            Body        = chapterString,
                            Url         = chapterUrl, /* settings.ChapterUrl */
                            ArrivalTime = DateTime.Now
                        };
#else
                        MenuNotification notification = new MenuNotification()
                        {
                            Title       = "ATG Chapter Update!",
                            Body        = chapterString,
                            Url         = chapterUrl, /* settings.ChapterUrl */
                            ArrivalTime = DateTime.Now
                        };
#endif
                        notificationsController.Add(notification);

                        AppFeedbackManager.FlashApplicationTaskbarButton();

                        jobRoundFinished.Set();

                        if (!Settings.Instance.DoNotDisturb)
                        {
                            notifier.Show(notification);
                        }
                    }

#if DEBUG
                    Thread.Sleep(1 * 10 * 1000);
#else
                    /* Wait for 30 seconds until the next update check. */
                    Thread.Sleep(1 * 30 * 1000);
#endif
                }
            }
            catch (ThreadInterruptedException)
            {
                /* Terminate the worker thread (which is the current thread). */
                workThread.Abort();
            }
        }
コード例 #6
0
        private void Notification_MouseClick(object sender, MouseEventArgs e)
        {
            /*
             * On left-click: Open the obtained chapter URL in the default Internet Browser
             * and close the notification.
             */
            if (e.Button == MouseButtons.Left)
            {
                MenuNotification notification = (MenuNotification)this.DataContext;
                WebService.OpenWebsite(notification.Url);

                this.DialogResult = DialogResult.OK;
            }
        }
コード例 #7
0
        public ToastNotificationView(MenuNotification notification, int slot)
        {
            InitializeComponent();

            slot = (slot < 0) ? 0 : slot;
            Init(slot);

            this.mouseMessageFilter = new MouseMoveMessageFilter
            {
                TargetForm = this
            };
            Application.AddMessageFilter(this.mouseMessageFilter);

            menuNotificationBindingSource.DataSource = notification;
        }
コード例 #8
0
        public void Remove(MenuNotification notification)
        {
            if (notification == null)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            var dbNotif = db.Notifications
                          .Where(u => u.Id == notification.Id)
                          .FirstOrDefault();

            if (dbNotif != null)
            {
                db.Entry(dbNotif).State = EntityState.Deleted;
                db.SaveChanges();

                notification.Id = 0;
            }
        }
コード例 #9
0
        public MenuNotification Add(MenuNotification notification)
        {
            var dbNotif =
                new ATG_Notifier.Data.Entities.MenuNotification()
            {
                Title       = notification.Title,
                Body        = notification.Body,
                Url         = notification.Url,
                ArrivalTime = notification.ArrivalTime,
                IsRead      = notification.IsRead,
            };

            db.Notifications.Add(dbNotif);
            db.SaveChanges();

            notification.Id = dbNotif.Id;

            return(notification);
        }
コード例 #10
0
        public void Add(MenuNotification notification)
        {
            if (notification == null)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            MenuNotificationViewModel notificationVm = new MenuNotificationViewModel(notification);

            notificationVm.RequestClose += (s, e) => Remove(s as MenuNotificationViewModel);
            notificationVm.Notification_ReadStatusChanged += Notification_OnReadStatusChanged;

            Program.MainWindow.Invoke(() =>
            {
                notifications.Add(notificationVm);
            });

            //notification.IsDirty = true;

            NotificationCollectionChanged?.Invoke(this, new NotificationCollectionChangedEventArgs(NotificationCollectionChangedAction.Add, notification));
        }
コード例 #11
0
        public void Show(MenuNotification notification)
        {
            if (notification == null)
            {
                throw new ArgumentNullException(nameof(notification));
            }

            if (!Settings.Instance.DisableOnFullscreen)
            {
                Task.Factory.StartNew(() => ShowCore(notification));
                return;
            }

            int result = NativeMethods.SHQueryUserNotificationState(out QUERY_USER_NOTIFICATION_STATE state);

            if (result == (int)HRESULT.S_OK &&
                state == QUERY_USER_NOTIFICATION_STATE.AcceptsNotifications)
            {
                Task.Factory.StartNew(() => ShowCore(notification));
            }
        }
コード例 #12
0
 public NotificationCollectionChangedEventArgs(NotificationCollectionChangedAction action, MenuNotification notification)
 {
     Action       = action;
     Notification = notification;
 }