private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { DataRepositoryItem[] selectedItems = ChildrenList.SelectedItems.OfType <DataRepositoryItem>().ToArray(); if (selectedItems.Length > 1) { DataRepositoryContentViewModel.Current.PlaceOnMapCommand = DataRepositoryHelper.GetPlaceMultipleFilesCommand(selectedItems); } else if (selectedItems.Length == 1) { DataRepositoryItem dataRepositoryItem = selectedItems[0]; if (dataRepositoryItem != null && dataRepositoryItem.ContextMenu != null) { DataRepositoryContentViewModel.Current.ContextMenuStackPanel = DataRepositoryContentUserControl.ConvertContextMenuToButton(dataRepositoryItem.ContextMenu); } if (dataRepositoryItem != null && dataRepositoryItem.IsLoadable) { DataRepositoryContentViewModel.Current.PlaceOnMapCommand = ((MenuItem)selectedItems.First().ContextMenu.Items[0]).Command; } else { DataRepositoryContentViewModel.Current.PlaceOnMapCommand = null; } } }
private static void AddChildrens(DataRepositoryItem dbItem, List <string> itemNames, string iconUri, string name, Func <string, DataRepositoryItem> newItemFunc) { if (itemNames.Count == 0) { return; } DataRepositoryItem tablesItem = new DataRepositoryItem(); tablesItem.Name = String.Format(CultureInfo.InvariantCulture, "{0} ({1})", name, itemNames.Count); tablesItem.Icon = new BitmapImage(new Uri(iconUri, UriKind.RelativeOrAbsolute)); dbItem.Children.Add(tablesItem); foreach (var itemName in itemNames) { DataRepositoryItem tableItem = newItemFunc(itemName); tableItem.Name = itemName; int index = itemName.IndexOf(":", StringComparison.Ordinal); if (index != -1) { tableItem.Name = itemName.Substring(index + 1); } tablesItem.Children.Add(tableItem); } }
private static void AddSchemaChildrens(DataRepositoryItem dbItem, IEnumerable <string> tableNames, IEnumerable <string> viewNames, string iconUri, string name, string databaseName) { if (!tableNames.Any() && !viewNames.Any()) { return; } PostgreSchemaDataRepositoryItem schemaItem = new PostgreSchemaDataRepositoryItem(); schemaItem.Name = String.Format(CultureInfo.InvariantCulture, "{0}", name); schemaItem.SchemaName = schemaItem.Name; schemaItem.Icon = new BitmapImage(new Uri(iconUri, UriKind.RelativeOrAbsolute)); dbItem.Children.Add(schemaItem); AddChildrens(schemaItem, tableNames.ToList(), "/GisEditorPluginCore;component/Images/tables.png", "Tables", tmpName => { PostgreTableDataRepositoryItem tableItem = new PostgreTableDataRepositoryItem(); tableItem.TableName = tmpName; tableItem.SchemaName = schemaItem.Name; tableItem.DatabaseName = databaseName; return(tableItem); }); AddChildrens(schemaItem, viewNames.ToList(), "/GisEditorPluginCore;component/Images/dataviews.png", "Views", tmpName => { PostgreViewDataRepositoryItem viewItem = new PostgreViewDataRepositoryItem(); viewItem.ViewName = tmpName; viewItem.SchemaName = schemaItem.Name; viewItem.DatabaseName = databaseName; return(viewItem); }); }
public static DataRepositoryItem CreateRootDataRepositoryItem(DataRepositoryPlugin dataRepositoryPlugin) { DataRepositoryItem dataRepositoryItem = new DataRepositoryItem(); dataRepositoryItem.SourcePlugin = dataRepositoryPlugin; dataRepositoryItem.Name = dataRepositoryPlugin.Name; dataRepositoryItem.Icon = dataRepositoryPlugin.SmallIcon; var addDataCommand = new RelayCommand(() => { var dataItem = dataRepositoryPlugin.CreateDataRepositoryItem(); if (dataItem != null) { dataRepositoryItem.Children.Add(dataItem); GisEditor.InfrastructureManager.SaveSettings(GisEditor.DataRepositoryManager.GetPlugins()); } }); if (dataRepositoryPlugin.ContextMenu != null && dataRepositoryPlugin.ContextMenu.HasItems) { ((MenuItem)dataRepositoryPlugin.ContextMenu.Items[0]).Command = addDataCommand; } dataRepositoryItem.ContextMenu = dataRepositoryPlugin.ContextMenu; dataRepositoryItem.Content = dataRepositoryPlugin.Content; return(dataRepositoryItem); }
private static void AddChildrens(DataRepositoryItem dbItem, List <string> itemNames, string iconUri, string name, MsSql2008FeatureLayerInfo layerInfo, string databaseName) { if (itemNames.Count == 0) { return; } DataRepositoryItem tablesItem = new DataRepositoryItem(); tablesItem.Name = String.Format(CultureInfo.InvariantCulture, "{0} ({1})", name, itemNames.Count); tablesItem.Icon = new BitmapImage(new Uri(iconUri, UriKind.RelativeOrAbsolute)); dbItem.Children.Add(tablesItem); foreach (var itemName in itemNames) { MsSqlTableDataRepositoryItem tableItem = new MsSqlTableDataRepositoryItem(); tableItem.LayerInfo = layerInfo; tableItem.TableName = itemName; tableItem.SchemaName = dbItem.Name; tableItem.DatabaseName = databaseName; tableItem.Name = itemName; int index = itemName.IndexOf(".", StringComparison.Ordinal); if (index != -1) { tableItem.Name = itemName.Substring(index + 1); tableItem.TableName = tableItem.Name; } tablesItem.Children.Add(tableItem); } }
private void ListBoxItem_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { ListBoxItem listBoxItem = (ListBoxItem)sender; DataRepositoryItem dataRepositoryItem = (DataRepositoryItem)listBoxItem.DataContext; dataRepositoryItem.Load(); }
internal static void SyncToServerItem(PostgreConfigureInfo configureInfo, PostgreServerDataRepositoryItem serverItem, bool resetDatabases = false) { serverItem.Name = configureInfo.Server; serverItem.Server = configureInfo.Server; serverItem.Port = configureInfo.Port; serverItem.UserName = configureInfo.UserName; serverItem.Password = configureInfo.Password; GetDatabasesParameter parameter = new GetDatabasesParameter(); parameter.ServerItem = serverItem; parameter.ResetDatabases = resetDatabases; foreach (var item in configureInfo.DbaseNames) { parameter.DatabaseNames.Add(item); } Task <Collection <DatabaseModel> > task = new Task <Collection <DatabaseModel> >(GetDatabaseItems, parameter); task.Start(); task.ContinueWith(t => { Application.Current.Dispatcher.BeginInvoke(() => { if (t.Result.Count > 0) { serverItem.Children.Clear(); foreach (var databaseItem in t.Result) { if (databaseItem.TableModels.Count > 0) { DatabaseDataRepositoryItem dbItem = new DatabaseDataRepositoryItem(); dbItem.Name = databaseItem.Name; var groupItems = databaseItem.TableModels.GroupBy(g => g.SchemaName); DataRepositoryItem schemaItem = new DataRepositoryItem(); schemaItem.Name = String.Format(CultureInfo.InvariantCulture, "{0} ({1})", "Schemas", groupItems.Count()); schemaItem.Icon = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/schemas.png", UriKind.RelativeOrAbsolute)); dbItem.Children.Add(schemaItem); foreach (var group in groupItems) { IEnumerable <string> tableGroup = group.Where(v => !v.IsView).Select(g => g.Name); IEnumerable <string> viewGroup = group.Where(v => v.IsView).Select(g => g.Name); AddSchemaChildrens(schemaItem, tableGroup, viewGroup, "/GisEditorPluginCore;component/Images/tablefolder.png", group.Key, databaseItem.Name); } serverItem.Children.Add(dbItem); DataRepositoryContentViewModel.RestoreChildrenExpandStatus(new ObservableCollection <DataRepositoryItem> { serverItem }, GisEditor.DataRepositoryManager.ExpandedFolders); } } } }); }); }
private void TreeViewItem_MouseDoubleClick(object sender, MouseButtonEventArgs e) { DataRepositoryItem currentItem = sender.GetDataContext <DataRepositoryItem>(); if (currentItem != null && currentItem.IsLoadable) { currentItem.Load(); } }
private void TreeViewItem_MouseDoubleClick(object sender, MouseButtonEventArgs e) { DataRepositoryItem currentItem = sender.GetDataContext <DataRepositoryItem>(); if (currentItem != null && currentItem.IsLeaf) { viewModel.CurrentItem = currentItem; DropdownButton.IsChecked = false; } }
internal void RestoreExpandStatus(DataRepositoryItem viewModel, Collection <string> expandStatus) { if (viewModel == null) { return; } viewModel.IsExpanded = expandStatus.Contains(viewModel.Id); if (viewModel.Id.Equals(selectedItem)) { viewModel.IsSelected = true; } RestoreChildrenExpandStatus(viewModel.Children, expandStatus); }
private void TreeViewItem_MouseDoubleClick(object sender, MouseButtonEventArgs e) { MsSqlTableDataRepositoryItem currentItem = sender.GetDataContext <MsSqlTableDataRepositoryItem>(); if (currentItem != null && currentItem.IsLeaf) { DataRepositoryItem databaseItem = currentItem.Parent.Parent.Parent.Parent as DataRepositoryItem; DatabaseLayerInfoViewModel <MsSqlFeatureLayer> viewModel = DataContext as DatabaseLayerInfoViewModel <MsSqlFeatureLayer>; viewModel.Model.DatabaseName = databaseItem.Name; viewModel.CurrentItem = currentItem; DropdownButton.IsChecked = false; } }
public static RelayCommand GetPlaceMultipleFilesCommand(IEnumerable <DataRepositoryItem> selectedItems) { var newCommand = new RelayCommand(() => { DataRepositoryItem dataRepositoryItem = selectedItems.FirstOrDefault(); if (dataRepositoryItem != null) { DataRepositoryItem rootItem = dataRepositoryItem.GetRootDataRepositoryItem(); rootItem.SourcePlugin.DropOnMap(selectedItems); } }); return(newCommand); }
private long GetSize(DataRepositoryItem dataRepositoryItem) { long size = 0; if (dataRepositoryItem != null && dataRepositoryItem.CustomData.ContainsKey("Size")) { try { size = (long)dataRepositoryItem.CustomData["Size"]; } catch (Exception) { size = 0; } } return(size); }
private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { DataRepositoryContentViewModel.Current.SearchResultVisibility = Visibility.Collapsed; if (e.NewValue != null && (selectedTreeViewItem = e.NewValue as DataRepositoryItem) != null) { FolderDataRepositoryItem folderItem = selectedTreeViewItem as FolderDataRepositoryItem; if (folderItem != null && !Directory.Exists(folderItem.FolderInfo.FullName)) { System.Windows.Forms.MessageBox.Show(string.Format(CultureInfo.InvariantCulture, alertMessage, folderItem.FolderInfo.FullName), "Warning", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); return; } DataRepositoryContentViewModel.SelectedDataRepositoryItem = selectedTreeViewItem; if (selectedTreeViewItem.ContextMenu != null) { DataRepositoryContentViewModel.Current.ContextMenuStackPanel = DataRepositoryContentUserControl.ConvertContextMenuToButton(selectedTreeViewItem.ContextMenu); } else { DataRepositoryContentViewModel.Current.ContextMenuStackPanel = null; } if (!selectedTreeViewItem.IsLeaf) { var viewModelContainingContent = selectedTreeViewItem.GetRootDataRepositoryItem(); DataRepositoryContentViewModel.Current.CurrentPluginItemViewModel = viewModelContainingContent; if (viewModelContainingContent.ContextMenu != null && viewModelContainingContent.ContextMenu.HasItems) { DataRepositoryContentViewModel.Current.AddDataCommand = ((MenuItem)viewModelContainingContent.ContextMenu.Items[0]).Command; } if (DataRepositoryContentViewModel.Current.CurrentPluginItemViewModel.Content != null) { if (!DataRepositoryContentViewModel.SelectedDataRepositoryItem.Id.Equals("Data Folders", System.StringComparison.InvariantCultureIgnoreCase)) { var sourcePlugin = DataRepositoryContentViewModel.SelectedDataRepositoryItem.GetSourcePlugin(); if (sourcePlugin != null && sourcePlugin.CanRefreshDynamically) { DataRepositoryContentViewModel.SelectedDataRepositoryItem.Refresh(); } } DataRepositoryContentViewModel.Current.CurrentPluginItemViewModel.Content.DataContext = DataRepositoryContentViewModel.SelectedDataRepositoryItem; } } } }
private DataRepositoryItem GetSelectedTreeView(DataRepositoryItem treeViewParent) { DataRepositoryItem selectedTreeView = null; foreach (var child in treeViewParent.Children) { if (child.IsSelected) { selectedTreeView = child; break; } if (child.Children.Count > 0) { return(GetSelectedTreeView(child)); } } return(selectedTreeView); }
private string GetToServerConnectionString(MsSqlTableDataRepositoryItem msSqlTableDataRepositoryItem) { DataRepositoryItem item = msSqlTableDataRepositoryItem.Parent; while (!(item is MsSqlServerDataRepositoryItem)) { item = item.Parent; } MsSqlServerDataRepositoryItem serverItem = (MsSqlServerDataRepositoryItem)item; StringBuilder connectionBuilder = new StringBuilder(); connectionBuilder.AppendFormat(CultureInfo.InvariantCulture, "Data Source={0};Persist Security Info=True;", serverItem.Server); if (string.IsNullOrEmpty(serverItem.UserName) && string.IsNullOrEmpty(serverItem.Password)) { connectionBuilder.Append("Trusted_Connection=Yes;"); } else { connectionBuilder.AppendFormat(CultureInfo.InvariantCulture, "User ID={0};Password={1};", serverItem.UserName, serverItem.Password); } return(connectionBuilder.ToString()); }
public string GetConnectionString() { DataRepositoryItem databaseItem = currentItem.Parent.Parent.Parent.Parent; return(String.Format(CultureInfo.InvariantCulture, "Server={0};Database={1};Port={2};User Id={3};Password={4};", serverName, databaseItem.Name, portName, userName, password)); }
public static DataRepositoryPlugin GetSourcePlugin(this DataRepositoryItem dataRepositoryItem) { var rootDataRepsitory = dataRepositoryItem.GetRootDataRepositoryItem(); return(rootDataRepsitory.SourcePlugin); }