Пример #1
0
        private static async Task <bool> LoadIndexSilent(string indexFile)
        {
            if (ApplicationView.CurrentIndexFile != null && ApplicationView.CurrentIndexFile.IndexFile == indexFile)
            {
                return(true);
            }

            Guid opId = Guid.Empty;

            if (!ApplicationView.BeginOperation(StatusKind.Loading, out opId))
            {
                return(false);
            }

            try
            {
                ApplicationView.CurrentIndexFile = IndexViewModel.Load(indexFile);
                if (ApplicationView.CurrentIndexFile == null)
                {
                    return(false);
                }

                bool validIndexDirectoryFound = await Task.Run <bool>(() => LuceneHelper.IsValidIndexDirectory(ApplicationView.CurrentIndexFile.IndexDirectory));

                if (!validIndexDirectoryFound)
                {
                    ApplicationView.CurrentIndexFile = null;
                    return(false);
                }

                ApplicationView.UpdateSearchFilter();
                ApplicationView.FileWatcher.WatchDirectories(ApplicationView.CurrentIndexFile.SourceDirectories);
            }
            finally
            {
                ApplicationView.EndOperation(opId);
            }

            RefreshIndexAtStartup(ApplicationView.CurrentIndexFile);
            return(true);
        }
Пример #2
0
        public static async Task <bool> LoadIndex(string indexFile)
        {
            if (ApplicationView.CurrentIndexFile != null && ApplicationView.CurrentIndexFile.IndexFile == indexFile)
            {
                return(true);
            }

            Guid opId = Guid.Empty;

            if (!ApplicationView.BeginOperation(StatusKind.Loading, out opId))
            {
                return(false);
            }

            try
            {
                ApplicationView.CurrentIndexFile = IndexViewModel.Load(indexFile);
                if (ApplicationView.CurrentIndexFile == null)
                {
                    if (MessageBox.Show(indexFile + " not found.\n\nThe index file was not found.\nDo you want to remove it from the recent indices?", "Index file not found",
                                        MessageBoxButton.YesNo,
                                        MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
                    {
                        ApplicationView.UserSettings.RemoveRecentIndex(indexFile);
                    }

                    return(false);
                }

                bool validIndexDirectoryFound = await Task.Run <bool>(() => LuceneHelper.IsValidIndexDirectory(ApplicationView.CurrentIndexFile.IndexDirectory));

                if (!validIndexDirectoryFound &&
                    MessageBox.Show(ApplicationView.CurrentIndexFile.IndexDirectory + " not found.\n\nThe index was moved or deleted.\nDo you want to select a new index directory?", "Index not found",
                                    MessageBoxButton.YesNo,
                                    MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
                {
                    var openFolderDialog = new Ookii.Dialogs.Wpf.VistaFolderBrowserDialog
                    {
                        SelectedPath           = Path.GetDirectoryName(ApplicationView.CurrentIndexFile.IndexDirectory),
                        Description            = "New Index Location",
                        UseDescriptionForTitle = true
                    };

                    if (openFolderDialog.ShowDialog() == true)
                    {
                        ApplicationView.CurrentIndexFile.IndexDirectory = openFolderDialog.SelectedPath;
                        ApplicationView.CurrentIndexFile.SaveIndexFile();
                        validIndexDirectoryFound = await Task.Run <bool>(() => LuceneHelper.IsValidIndexDirectory(openFolderDialog.SelectedPath));
                    }
                }

                if (!validIndexDirectoryFound)
                {
                    ApplicationView.CurrentIndexFile = null;
                    ApplicationView.UserSettings.RemoveRecentIndex(indexFile);
                    return(false);
                }

                ApplicationView.UserSettings.AddRecentIndex(ApplicationView.CurrentIndexFile.Name, ApplicationView.CurrentIndexFile.IndexFile);
                ApplicationView.UpdateSearchFilter();

                ApplicationView.FileWatcher.WatchDirectories(ApplicationView.CurrentIndexFile.SourceDirectories);
            }
            finally
            {
                ApplicationView.EndOperation(opId);
            }

            RefreshIndexAtStartup(ApplicationView.CurrentIndexFile);
            return(true);
        }
Пример #3
0
 public IActionResult Index()
 {
     return(View(IndexViewModel.Load(this.Connection)));
 }