public NotificationViewModel(NewFileNotification notification, IUnityContainer iocContainer)
 {
     this.Notification   = notification;
     this.iocContainer   = iocContainer;
     this.Dismiss        = new SimpleCommand(() => true, this.DismissNotification);
     this.OpenInExplorer = new SimpleCommand(() => true, this.OpenFileInExplorer);
 }
Пример #2
0
        public void Delete(NewFileNotification notification)
        {
            using (var database = new LiteDatabase(DatabaseName))
            {
                var historyEntries = database.GetCollection <NewFileNotification>(CollectionName);

                historyEntries.Delete(notification.Id);
            }
        }
Пример #3
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");
        }