Example #1
0
        public MainViewModel(
            IDragDropService dragDropService,
            IBackupFileService backupFileService,
            IWindowService windowService,
            IFileOpenSaveService fileOpenSaveService,
            IDialogService dialogService)
        {
            _dragDropService     = dragDropService;
            _backupFileService   = backupFileService;
            _windowService       = windowService;
            _fileOpenSaveService = fileOpenSaveService;
            _dialogService       = dialogService;

            Files.CollectionChanged += FilesCollectionChanged;

            SetTitle();

            // subscriptions...
            Messenger.Default.Register <DragOverMessage>(this, OnDragOver);
            Messenger.Default.Register <DragDropMessage>(this, OnDragDrop);
            Messenger.Default.Register <MainWindowClosingMessage>(this, OnMainWindowClosing);
            Messenger.Default.Register <NotesRedactedMessage>(this, OnNotesRedacted);

            AddDesignTimeItems();

            InitCommands();

            GetVersionData();
        }
Example #2
0
        public static int ApplyMergeParameters(
            IBackupFileService backupFileService,
            Database database,
            MergeParameters fileMergeParameters)
        {
            int changeCount = 0;

            if (!fileMergeParameters.IncludeTags)
            {
                changeCount += backupFileService.RemoveTags(database);
            }

            if (!fileMergeParameters.IncludeBookmarks)
            {
                changeCount += backupFileService.RemoveBookmarks(database);
            }

            // NB - notes must be removed before underlining
            // since if notes are retained, some of the underlining
            // must also be!
            if (!fileMergeParameters.IncludeNotes)
            {
                changeCount += backupFileService.RemoveNotes(database);
            }

            if (!fileMergeParameters.IncludeUnderlining)
            {
                changeCount += backupFileService.RemoveUnderlining(database);
            }

            return(changeCount);
        }
 public static Task ExecuteAsync(BackupFile backupFile, IBackupFileService backupFileService, string filePath)
 {
     return(Task.Run(() =>
     {
         backupFile?.Database.TagMaps.RemoveAll(x => x.TagId == 1);
         backupFileService.WriteNewDatabase(backupFile, filePath, filePath);
     }));
 }
Example #4
0
        private DetailWindow CreateDetailWindow(IBackupFileService backupFileService, string filePath)
        {
            var window    = new DetailWindow();
            var viewModel = (DetailViewModel)window.DataContext;

            viewModel.FilePath   = filePath;
            viewModel.BackupFile = backupFileService.Load(filePath);

            window.Closed += DetailWindowClosed;
            _detailWindows.Add(window);
            return(window);
        }
 public static Task ExecuteAsync(
     BackupFile backupFile,
     IBackupFileService backupFileService,
     string bibleNotesExportFilePath,
     IExcelService excelService)
 {
     return(Task.Run(() =>
     {
         backupFileService.ExportBibleNotesToExcel(
             backupFile,
             bibleNotesExportFilePath,
             excelService);
     }));
 }
Example #6
0
        public static async Task <int> ExecuteAsync(
            BackupFile backupFile, IBackupFileService backupFileService, string filePath, int[] tagIds)
        {
            if (backupFile == null)
            {
                return(0);
            }

            var tagIdsHash = tagIds.ToHashSet();

            var result = await Task.Run(() =>
            {
                var tagMapIdsToRemove = new HashSet <int>();
                var noteIdsToRemove   = new HashSet <int>();
                var userMarksToRemove = new HashSet <int>();

                foreach (var tagMap in backupFile.Database.TagMaps)
                {
                    if (tagIdsHash.Contains(tagMap.TagId) && tagMap.NoteId != null && tagMap.NoteId > 0)
                    {
                        tagMapIdsToRemove.Add(tagMap.TagMapId);
                        noteIdsToRemove.Add(tagMap.NoteId.Value);

                        var note = backupFile.Database.FindNote(tagMap.NoteId.Value);
                        if (note?.UserMarkId != null)
                        {
                            userMarksToRemove.Add(note.UserMarkId.Value);
                        }
                    }
                }

                backupFile.Database.TagMaps.RemoveAll(x => tagMapIdsToRemove.Contains(x.TagMapId));
                backupFile.Database.Notes.RemoveAll(x => noteIdsToRemove.Contains(x.NoteId));
                backupFile.Database.UserMarks.RemoveAll(x => userMarksToRemove.Contains(x.UserMarkId));

                // Note that redundant block ranges are cleaned automatically by Cleaner.

                if (noteIdsToRemove.Count > 0 || tagMapIdsToRemove.Count > 0)
                {
                    backupFileService.WriteNewDatabaseWithClean(backupFile, filePath, filePath);
                }

                return(noteIdsToRemove.Count);
            });

            return(result);
        }
Example #7
0
        public DetailViewModel(
            IBackupFileService backupFileService,
            IFileOpenSaveService fileOpenSaveService,
            IDialogService dialogService,
            IRedactService redactService)
        {
            _backupFileService   = backupFileService;
            _fileOpenSaveService = fileOpenSaveService;
            _dialogService       = dialogService;
            _redactService       = redactService;

            ListItems = CreateListItems();

            ImportBibleNotesCommand = new RelayCommand(ImportBibleNotes);
            RedactNotesCommand      = new RelayCommand(RedactNotes);
            DeleteFavouritesCommand = new RelayCommand(DeleteFavourites);
        }
Example #8
0
        public DetailViewModel(
            IBackupFileService backupFileService,
            IFileOpenSaveService fileOpenSaveService,
            IDialogService dialogService,
            IRedactService redactService)
        {
            _backupFileService   = backupFileService;
            _fileOpenSaveService = fileOpenSaveService;
            _dialogService       = dialogService;
            _redactService       = redactService;

            ListItems = CreateListItems();

            ImportBibleNotesCommand = new RelayCommand(async() => await ImportBibleNotes().ConfigureAwait(true));
            RedactNotesCommand      = new RelayCommand(async() => await RedactNotes().ConfigureAwait(true));
            DeleteFavouritesCommand = new RelayCommand(async() => await DeleteFavourites().ConfigureAwait(true));
        }
Example #9
0
        public void ShowDetailWindow(IBackupFileService backupFileService, string filePath)
        {
            var existingWindow = GetDetailWindow(filePath);

            if (existingWindow != null)
            {
                existingWindow.Activate();
            }
            else
            {
                var window = CreateDetailWindow(backupFileService, filePath);

                var viewModel = (DetailViewModel)window.DataContext;
                viewModel.SelectedDataType = viewModel.ListItems.FirstOrDefault();

                window.Show();
            }
        }
        public static JwLibraryFile CreateMockJwLibraryFile(
            IBackupFileService backupFileService,
            int fileIndex)
        {
            var file = backupFileService.CreateBlank();

            file.Manifest.Name           = $"File {fileIndex + 1}";
            file.Manifest.CreationDate   = GenerateDateString(DateTime.Now.AddDays(-fileIndex));
            file.Manifest.UserDataBackup = new UserDataBackup
            {
                DeviceName = "MYPC",
            };

#pragma warning disable S1075 // URIs should not be hardcoded
            return(new JwLibraryFile("c:\\temp\\myfile.jwlibrary", file));

#pragma warning restore S1075 // URIs should not be hardcoded
        }
        public static JwLibraryFile CreateMockJwLibraryFile(
            IBackupFileService backupFileService,
            int fileIndex)
        {
            var file = backupFileService.CreateBlank();

            file.Manifest.Name           = $"File {fileIndex + 1}";
            file.Manifest.CreationDate   = GenerateDateString(DateTime.Now.AddDays(-fileIndex));
            file.Manifest.UserDataBackup = new UserDataBackup
            {
                DeviceName = "MYPC"
            };

            return(new JwLibraryFile
            {
                FilePath = "c:\\temp\\myfile.jwlibrary",
                BackupFile = file
            });
        }
        public static async Task ExecuteAsync(
            BackupFile backupFile,
            IBackupFileService backupFileService,
            string backupFilePath,
            string importFilePath,
            ImportBibleNotesParams options)
        {
            await Task.Run(() =>
            {
                var file = new BibleNotesFile(importFilePath);

                backupFileService.ImportBibleNotes(
                    backupFile,
                    file.GetNotes(),
                    file.GetBibleKeySymbol(),
                    file.GetMepsLanguageId(),
                    options);

                backupFileService.WriteNewDatabase(backupFile, backupFilePath, backupFilePath);
            });
        }
Example #13
0
        public static Task ExecuteAsync(
            List<Note> notes, IRedactService redactService, BackupFile backupFile, IBackupFileService backupFileService, string filePath)
        {
            return Task.Run(() =>
            {
                foreach (var note in notes)
                {
                    if (!string.IsNullOrEmpty(note.Title))
                    {
                        note.Title = redactService.GetNoteTitle(note.Title.Length);
                    }

                    if (!string.IsNullOrEmpty(note.Content))
                    {
                        note.Content = redactService.GenerateNoteContent(note.Content.Length);
                    }
                }

                backupFileService.WriteNewDatabase(backupFile, filePath, filePath);
            });
        }