예제 #1
0
        public DefaultCommandsHandler(
            IDatabaseInteractions databaseInteractions,
            IApplicationInteraction applicationInteraction)
        {
            _databaseInteractions   = databaseInteractions;
            _applicationInteraction = applicationInteraction;

            Add(Commands.Exit, (sender, args) =>
            {
                Store.Current.CloseDatabases();

                if (Application.Current.MainWindow != null)
                {
                    Application.Current.MainWindow.Close();
                }
            });

            Add(ApplicationCommands.Open, async(sender, args) =>
            {
                await _databaseInteractions.OpenDatabase();
            });

            Add(ApplicationCommands.New, async(sender, args) =>
            {
                await _databaseInteractions.CreateAndOpenDatabase();
            });

            Add(Commands.FileDropped, async(sender, args) =>
            {
                if (!(args.Parameter is IDataObject dataObject))
                {
                    return;
                }

                try
                {
                    if (dataObject.GetDataPresent(DataFormats.FileDrop) && dataObject.GetData(DataFormats.FileDrop, false) is string[] paths)
                    {
                        await _databaseInteractions.OpenDatabases(paths);
                    }
                }
                catch (Exception exc)
                {
                    _applicationInteraction.ShowError("Failed to open database: " + exc.Message, "Database Error");
                }
            });

            Add(Commands.Import, (sender, args) =>
            {
                _applicationInteraction.ShowImportWizard();
            }, (sender, args) =>
            {
                var hasDatabaseOpen = Store.Current.Databases.Any();
                args.CanExecute     = hasDatabaseOpen;
            });
        }
예제 #2
0
        public void ImportData()
        {
            var options = new ImportDataOptions();

            if (SelectedCollection != null)
            {
                options.DatabaseReference   = SelectedCollection.Database;
                options.CollectionReference = SelectedCollection;
            }
            else if (SelectedDatabase != null)
            {
                options.DatabaseReference = SelectedDatabase;
            }

            _applicationInteraction.ShowImportWizard(options);
        }