Beispiel #1
0
        public Result <InteractionEvents.CollectionDocumentChange> AddFileToDatabase(DatabaseReference database)
        {
            var dialog = new OpenFileDialog
            {
                Filter      = "All files|*.*",
                Multiselect = false
            };

            if (dialog.ShowDialog() != true)
            {
                return(Result.Fail <InteractionEvents.CollectionDocumentChange>("FILE_OPEN_CANCELED"));
            }

            try
            {
                if (InputBoxWindow.ShowDialog("New file id:", "Enter new file id", Path.GetFileName(dialog.FileName),
                                              out string id) == true)
                {
                    var file = database.AddFile(id, dialog.FileName);

                    var documentsCreated = new InteractionEvents.CollectionDocumentChange(ReferenceNodeChangeAction.Add, new [] { file }, file.Collection);

                    _eventAggregator.PublishOnUIThread(documentsCreated);

                    return(Result.Ok(documentsCreated));
                }
            }
            catch (Exception exc)
            {
                _viewInteractionResolver.ShowError(exc, "Failed to upload file:" + Environment.NewLine + exc.Message, "Database error");
            }


            return(Result.Fail <InteractionEvents.CollectionDocumentChange>("FILE_OPEN_FAIL"));
        }
Beispiel #2
0
        public Result <InteractionEvents.CollectionDocumentChange> CreateItem(CollectionReference collection)
        {
            if (collection is FileCollectionReference)
            {
                return(AddFileToDatabase(collection.Database));
            }

            var newDoc = new BsonDocument
            {
                ["_id"] = ObjectId.NewObjectId()
            };

            var documentReference = collection.AddItem(newDoc);

            var documentsCreated = new InteractionEvents.CollectionDocumentChange(ReferenceNodeChangeAction.Add, documentReference, collection);

            return(Result.Ok(documentsCreated));
        }
Beispiel #3
0
        public Result <InteractionEvents.CollectionDocumentChange> ImportDataFromText(CollectionReference collection, string textData)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(textData))
                {
                    return(Result.Ok(InteractionEvents.CollectionDocumentChange.Nome));
                }

                var newValue = JsonSerializer.Deserialize(textData);
                var newDocs  = new List <DocumentReference>();
                if (newValue.IsArray)
                {
                    foreach (var value in newValue.AsArray)
                    {
                        var doc = value.AsDocument;
                        var documentReference = collection.AddItem(doc);
                        newDocs.Add(documentReference);
                    }
                }
                else
                {
                    var doc = newValue.AsDocument;
                    var documentReference = collection.AddItem(doc);
                    newDocs.Add(documentReference);
                }

                var documentsUpdate = new InteractionEvents.CollectionDocumentChange(ReferenceNodeChangeAction.Add, newDocs, collection);

                return(Result.Ok(documentsUpdate));
            }
            catch (Exception e)
            {
                var message = "Failed to import document from text content: " + e.Message;
                Logger.Warn(e, "Cannot process clipboard data.");
                _viewInteractionResolver.ShowError(e, message, "Import Error");
                return(Result.Fail <InteractionEvents.CollectionDocumentChange>(message));
            }
        }