Ejemplo n.º 1
0
        private void OnDragDrop(DragDropMessage message)
        {
            var epubFolder = FileUtils.GetEpubFolder();

            if (!FileUtils.DirectoryIsWritable(epubFolder))
            {
                message.DragEventArgs.Handled = true;
                _snackbarService.EnqueueWithOk(string.Format(Properties.Resources.NO_WRITE_ACCESS, epubFolder));
                return;
            }

            var busyCursor = _userInterfaceService.GetBusy();

            var origEpubPath = _bibleVersesService.EpubPath;

            Task.Run(() =>
            {
                var files = GetDroppedFiles(message.DragEventArgs);

                var validFileCount = 0;

                // close reader so that we can overwrite the current epub (if necessary)
                _bibleVersesService.CloseReader();

                Parallel.ForEach(files, file =>
                {
                    try
                    {
                        if (_bibleVersesService.IsValidBibleEpub(file))
                        {
                            File.Copy(file, GetDestinationFileName(file), overwrite: true);
                            Interlocked.Increment(ref validFileCount);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Logger.Error(ex, $@"Could not copy epub file {file}");
                    }
                });

                _snackbarService.EnqueueWithOk(GetDoneMessage(files.Count, validFileCount));
                message.DragEventArgs.Handled = true;
            }).ContinueWith(t =>
            {
                _bibleVersesService.EpubPath = origEpubPath;

                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    EpubFileListChanged?.Invoke(this, EventArgs.Empty);
                    busyCursor.Dispose();
                });
            });
        }
Ejemplo n.º 2
0
        public void Refresh()
        {
            if (_currentBookNumber > 0 && !string.IsNullOrEmpty(_currentChapterAndVerses))
            {
                using (_userInterfaceService.GetBusy())
                {
                    var bibleTextImage = new BibleTextImage();

                    ApplyFormatting(bibleTextImage, _optionsService.ThemePath);

                    _images = _optionsService.EpubPath != null
                        ? bibleTextImage.Generate(
                        _optionsService.EpubPath,
                        _currentBookNumber,
                        _currentChapterAndVerses).ToArray()
                        : null;
                }
            }
        }