Пример #1
0
        public async Task DropCollection(CollectionReference collectionReference)
        {
            await _databaseInteractions.DropCollection(collectionReference);

            SelectedCollection = null;
        }
Пример #2
0
        public void DropCollection()
        {
            _databaseInteractions.DropCollection(SelectedCollection);

            SelectedCollection = null;
        }
        public async Task DropCollection()
        {
            await _databaseInteractions.DropCollection(SelectedCollection);

            SelectedCollection = null;
        }
Пример #4
0
        public DefaultCommandsHandler(
            IDatabaseInteractions databaseInteractions,
            IViewInteractionResolver viewInteractionResolver,
            IEventAggregator eventAggregator)
        {
            _databaseInteractions    = databaseInteractions;
            _viewInteractionResolver = viewInteractionResolver;
            _eventAggregator         = eventAggregator;

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

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

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

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

            Add(ApplicationCommands.Close, (sender, args) =>
            {
                GetDatabaseReference(sender, args)
                .OnSuccess(reference =>
                {
                    _databaseInteractions.CloseDatabase(reference);
                    _eventAggregator.PublishOnUIThread(new InteractionEvents.DatabaseClosed(reference));
                });
            }, (sender, args) =>
            {
                args.CanExecute = HasDatabaseReference(sender, args);
            });

            Add(ApplicationCommands.Copy, (sender, args) =>
            {
                GetManyDocumentsReference(sender, args)
                .OnSuccess(references => _databaseInteractions.CopyDocuments(references));
            }, (sender, e) =>
            {
                e.CanExecute = HasAnyDocumentsReference(sender, e, DocumentTypeFilter.BsonDocument);
            });

            Add(ApplicationCommands.Paste, (sender, args) =>
            {
                try
                {
                    GetCollectionReference(sender, args)
                    .OnSuccess(reference =>
                    {
                        var textData = Clipboard.GetText();
                        return(_databaseInteractions.ImportDataFromText(reference, textData));
                    })
                    .OnSuccess(update => _eventAggregator.PublishOnUIThread(update));
                }
                catch (Exception exc)
                {
                    Logger.Warn(exc, "Cannot process clipboard data.");
                    MessageBox.Show("Failed to paste document from clipboard: " + exc.Message, "Import Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }, (sender, e) =>
            {
                e.CanExecute = NotIsFilesCollection(sender, e) && Clipboard.ContainsText();
            });


            Add(Commands.EditDbProperties, (sender, args) =>
            {
                GetDatabaseReference(sender, args)
                .OnSuccess(reference => _viewInteractionResolver.OpenDatabaseProperties(reference.LiteDatabase));
            }, (sender, args) =>
            {
                args.CanExecute = HasDatabaseReference(sender, args);
            });

            Add(Commands.Add, (sender, args) =>
            {
                GetCollectionReference(sender, args)
                .OnSuccess(reference => _databaseInteractions.CreateItem(reference))
                .OnSuccess(reference =>
                {
                    _viewInteractionResolver.ActivateCollection(reference.CollectionReference, reference.NewDocuments);
                    _eventAggregator.PublishOnUIThread(reference);
                });
            }, (sender, args) =>
            {
                args.CanExecute = HasCollectionReference(sender, args);
            });

            Add(Commands.AddFile, (sender, args) =>
            {
                GetDatabaseReference(sender, args)
                .OnSuccess(reference => _databaseInteractions.AddFileToDatabase(reference))
                .OnSuccess(reference =>
                {
                    _viewInteractionResolver.ActivateCollection(reference.CollectionReference, reference.NewDocuments);
                    _eventAggregator.PublishOnUIThread(reference);
                });
            }, (sender, args) =>
            {
                args.CanExecute = HasDatabaseReference(sender, args);
            });

            Add(Commands.Edit, (sender, args) =>
            {
                GetDocumentReference(sender, args)
                .OnSuccess(reference => _databaseInteractions.OpenEditDocument(reference))
                .OnSuccess(maybe =>
                {
                    maybe.Execute(value => _eventAggregator.PublishOnUIThread(new InteractionEvents.DocumentUpdated(value)));
                });
            }, (sender, args) =>
            {
                args.CanExecute = HasDocumentReference(sender, args);
            });

            Add(Commands.AddCollection, (sender, args) =>
            {
                GetDatabaseReference(sender, args)
                .OnSuccess(reference =>
                {
                    var addCollection = _databaseInteractions.AddCollection(reference);
                    if (addCollection.IsSuccess)
                    {
                        _viewInteractionResolver.ActivateCollection(addCollection.Value);
                    }
                });
            }, (sender, args) =>
            {
                args.CanExecute = HasDatabaseReference(sender, args);
            });

            Add(Commands.Remove, (sender, args) =>
            {
                GetManyDocumentsReference(sender, args)
                .OnSuccess(references => _databaseInteractions.RemoveDocuments(references));
            }, (sender, args) =>
            {
                args.CanExecute = HasAnyDocumentsReference(sender, args);
            });

            Add(Commands.Export, (sender, args) =>
            {
                GetManyDocumentsReference(sender, args)
                .OnSuccess(references => _databaseInteractions.ExportDocuments(references.ToList()));
            }, (sender, args) =>
            {
                args.CanExecute = HasAnyDocumentsReference(sender, args);
            });

            Add(Commands.RefreshCollection, (sender, args) =>
            {
                GetCollectionReference(sender, args)
                .OnSuccess(reference => reference.Refresh());
            }, (sender, e) =>
            {
                e.CanExecute = HasCollectionReference(sender, e);
            });

            Add(Commands.RenameCollection, (sender, args) =>
            {
                GetCollectionReference(sender, args)
                .OnSuccess(reference => _databaseInteractions.RenameCollection(reference));
            }, (sender, args) =>
            {
                args.CanExecute = NotIsFilesCollection(sender, args);
            });

            Add(Commands.DropCollection, (sender, args) =>
            {
                GetCollectionReference(sender, args)
                .OnSuccess(reference =>
                {
                    var dropCollection = _databaseInteractions.DropCollection(reference);
                    if (dropCollection.IsSuccess)
                    {
                        _eventAggregator.PublishOnUIThread(new InteractionEvents.CollectionRemoved(reference));
                    }
                });
            }, (sender, args) =>
            {
                args.CanExecute = HasCollectionReference(sender, args);
            });


            Add(Commands.ExportCollection, (sender, args) =>
            {
                GetCollectionReference(sender, args)
                .OnSuccess(reference => _databaseInteractions.ExportCollection(reference));
            }, (sender, args) =>
            {
                args.CanExecute = HasCollectionReference(sender, args);
            });


            Add(Commands.RefreshDatabase, (sender, args) =>
            {
                GetDatabaseReference(sender, args)
                .OnSuccess(reference => reference.Refresh());
            }, (sender, args) =>
            {
                args.CanExecute = HasDatabaseReference(sender, args);
            });

            Add(Commands.RevealInExplorer, (sender, args) =>
            {
                GetDatabaseReference(sender, args)
                .OnSuccess(reference => _databaseInteractions.RevealInExplorer(reference));
            }, (sender, args) =>
            {
                args.CanExecute = HasDatabaseReference(sender, args);
            });
        }