Ejemplo n.º 1
0
        private void FolderContentChanged(object sender, FolderContentChangedEventArgs args)
        {
            logger.Info("Folder content changed. Files have been added: {0}", string.Join(", ", args.CreatedFiles.Select(x => x.FileName)));
            foreach (var file in args.CreatedFiles)
            {
                App.Current.Dispatcher.Invoke((Action) delegate
                {
                    var notification = new NewFileNotification
                    {
                        ChangeDate = file.ChangeDate,
                        Folder     = settings.Folders.Single(x => x.FolderId == file.FolderId).FolderName,
                        File       = file.FileName.Substring(file.FileName.LastIndexOf('\\') + 1)
                    };

                    var vm        = new NotificationViewModel(notification, this.iocContainer);
                    vm.OnDismiss += this.NotificationDismissed;
                    this.notificationHistoryService.Create(notification);
                    this.Notifications.Add(vm);
                });
            }

            if (args.CreatedFiles != null && args.CreatedFiles.Any())
            {
                this.windowManager.ShowBalloon(Resources.NewFilesDetected_Title, string.Join(Environment.NewLine, args.CreatedFiles.Select(x => x.FileName)));
            }

            // remove notifications for removed files if this is desired
            if (!this.settings.KeepNotificationsForDeletedFiles)
            {
                foreach (var deletedFile in args.DeletedFiles)
                {
                    logger.Info("Removing notification for deleted file: {0}", deletedFile.FileName);

                    var notification = this.Notifications.SingleOrDefault(x => (x.Notification.Folder + "\\" + x.Notification.File).ToLower() == deletedFile.FileName.ToLower());

                    if (notification != null)
                    {
                        App.Current.Dispatcher.Invoke((Action) delegate
                        {
                            notification.DismissNotification();
                        });
                    }
                }
            }

            this.NotifyOfPropertyChanges("ToolTip");
            this.NotifyOfPropertyChanges("Icon");
            this.NotifyOfPropertyChanges("IsIconVisible");
        }
Ejemplo n.º 2
0
        private void ReapplySettings()
        {
            logger.Info("Reapplying settings ...");
            // clear everything that has been wired up so far
            this.StopWatching();

            this.settings = this.iocContainer.Resolve <ISettingsService>().GetSettings();

            // add watchers
            var watchers = new List <IFolderWatcher>();

            foreach (var folder in this.settings.Folders)
            {
                var watcher = this.iocContainer.Resolve <IFolderWatcher>();
                watcher.FolderContentChanged += FolderContentChanged;
                watcher.Watch(folder);

                watchers.Add(watcher);
            }

            this.watchers = watchers;

            // load unread notifications
            var notifications = this.notificationHistoryService.ReadAll();

            foreach (var notification in notifications)
            {
                var vm = new NotificationViewModel(notification, this.iocContainer);
                vm.OnDismiss += this.NotificationDismissed;
                this.Notifications.Add(vm);
            }

            this.NotifyOfPropertyChanges("Icon");
            this.NotifyOfPropertyChanges("ToolTip");
            this.NotifyOfPropertyChanges("IsIconVisible");
        }