Exemplo n.º 1
0
        private void ListCollectionData_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (DbSelectedItems.Count() > 1 || DbSelectedItems.Count() == 0)
            {
                ItemsDocPreview.ItemsSource  = null;
                BorderDocPreview.Visibility  = Visibility.Collapsed;
                BorderFilePreview.Visibility = Visibility.Collapsed;
                return;
            }


            BorderDocPreview.Visibility = Visibility.Visible;
            var document = DbSelectedItems.First();
            var controls = new List <DocumentFieldData>();

            for (int i = 0; i < document.LiteDocument.Keys.Count; i++)
            {
                var key       = document.LiteDocument.Keys.ElementAt(i);
                var valueEdit = BsonValueEditor.GetBsonValueEditor(string.Format("[{0}]", key), document.LiteDocument[key], document.LiteDocument, true);
                controls.Add(new DocumentFieldData(key, valueEdit));
            }

            ItemsDocPreview.ItemsSource = controls;

            if (document.Collection is FileCollectionReference)
            {
                var fileInfo = (document.Collection as FileCollectionReference).GetFileObject(document);
                FilePreview.LoadFile(fileInfo);
                BorderFilePreview.Visibility = Visibility.Visible;
            }
            else
            {
                BorderFilePreview.Visibility = Visibility.Collapsed;
            }
        }
Exemplo n.º 2
0
        private void EditCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            var item = DbSelectedItems.First();

            var window = new Windows.DocumentViewer(item)
            {
                Owner = this
            };

            if (window.ShowDialog() == true)
            {
                UpdateGridColumns(item.LiteDocument);
            }
        }
Exemplo n.º 3
0
        private void ListCollectionData_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (DbSelectedItems.Count() > 1 || !DbSelectedItems.Any())
            {
                // ItemsDocPreview.ItemsSource = null;
                BorderDocPreview.Visibility  = Visibility.Collapsed;
                BorderFilePreview.Visibility = Visibility.Collapsed;
                return;
            }


            BorderDocPreview.Visibility = Visibility.Visible;
            var document = DbSelectedItems.First();

            /*var controls = new List<DocumentFieldData>();
             *
             * for (int i = 0; i < document.LiteDocument.Keys.Count; i++)
             * {
             *  var key = document.LiteDocument.Keys.ElementAt(i);
             *  var valueEdit = BsonValueEditor.GetBsonValueEditor(
             *      expandMode: BsonEditorExpandMode.Inline,
             *      bindingPath: $"[{key}]",
             *      bindingValue: document.LiteDocument[key],
             *      bindingSource: document.LiteDocument,
             *      readOnly: true,
             *      keyName: key
             *  );
             *  controls.Add(new DocumentFieldData(key, valueEdit));
             * }
             *
             * ItemsDocPreview.ItemsSource = controls;*/

            DocumentTreeView.ItemsSource = new DocumentTreeItemsSource(document);

            if (document.Collection is FileCollectionReference reference)
            {
                var fileInfo = reference.GetFileObject(document);
                FilePreview.LoadFile(fileInfo);
                BorderFilePreview.Visibility = Visibility.Visible;
            }
            else
            {
                BorderFilePreview.Visibility = Visibility.Collapsed;
            }
        }
Exemplo n.º 4
0
        private void EditCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            var item = DbSelectedItems.First();

            var windowController = new WindowController {
                Title = "Document Editor"
            };
            var control = new DocumentViewerControl(item, windowController);
            var window  = new DialogWindow(control, windowController)
            {
                Owner  = Application.Current.MainWindow,
                Height = 600
            };

            /*var window = new Windows.DocumentViewer(item)
             * {
             *  Owner = this
             * };*/

            if (window.ShowDialog() == true)
            {
                UpdateGridColumns(item.LiteDocument);
            }
        }
Exemplo n.º 5
0
        private void ExportCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (SelectedCollection is FileCollectionReference)
            {
                if (DbSelectedItems.Count() == 1)
                {
                    var file = DbSelectedItems.First();

                    var dialog = new SaveFileDialog()
                    {
                        Filter          = "All files|*.*",
                        FileName        = file.LiteDocument["filename"],
                        OverwritePrompt = true
                    };

                    if (dialog.ShowDialog() == true)
                    {
                        (file.Collection as FileCollectionReference).SaveFile(file, dialog.FileName);
                    }
                }
                else
                {
                    var dialog = new CommonOpenFileDialog()
                    {
                        IsFolderPicker = true,
                        Title          = "Select folder to export files to..."
                    };

                    if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
                    {
                        foreach (var file in DbSelectedItems)
                        {
                            var path = Path.Combine(dialog.FileName, file.LiteDocument["_id"].AsString + "-" + file.LiteDocument["filename"].AsString);
                            var dir  = Path.GetDirectoryName(path);
                            if (!Directory.Exists(dir))
                            {
                                Directory.CreateDirectory(dir);
                            }

                            (file.Collection as FileCollectionReference).SaveFile(file, path);
                        }
                    }
                }
            }
            else
            {
                var dialog = new SaveFileDialog()
                {
                    Filter          = "Json File|*.json",
                    FileName        = "export.json",
                    OverwritePrompt = true
                };

                if (dialog.ShowDialog() == true)
                {
                    if (DbSelectedItems.Count() == 1)
                    {
                        File.WriteAllText(dialog.FileName, JsonSerializer.Serialize(DbSelectedItems.First().LiteDocument, true, false));
                    }
                    else
                    {
                        var data = new BsonArray(DbSelectedItems.Select(a => a.LiteDocument));
                        File.WriteAllText(dialog.FileName, JsonSerializer.Serialize(data, true, false));
                    }
                }
            }
        }