Пример #1
0
        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);
            });
        }
        private Collection <PostgreSqlFeatureLayer> GetPostgreSqlFeatureLayers()
        {
            PostgreSchemaDataRepositoryItem schemaItem = Parent.Parent as PostgreSchemaDataRepositoryItem;

            if (schemaItem != null)
            {
                DatabaseDataRepositoryItem databaseItem = schemaItem.Parent.Parent as DatabaseDataRepositoryItem;
                if (databaseItem != null)
                {
                    PostgreServerDataRepositoryItem serverItem = databaseItem.Parent as PostgreServerDataRepositoryItem;
                    if (serverItem != null)
                    {
                        string connectionString = PostgreServerDataRepositoryPlugin.GetConnectionString(serverItem, databaseItem.Name);
                        if (string.IsNullOrEmpty(idColumnName))
                        {
                            try
                            {
                                PostgreSqlFeatureSource featureSource = new PostgreSqlFeatureSource(connectionString, Name, "oid");
                                featureSource.SchemaName = schemaItem.SchemaName;
                                featureSource.Open();
                                List <string> newColumnNames = featureSource.GetColumns().Select(c => c.ColumnName).ToList();
                                featureSource.Close();
                                FeatureIdColumnWindow featureIdColumnWindow = new FeatureIdColumnWindow(newColumnNames);
                                featureIdColumnWindow.Owner = Application.Current.MainWindow;
                                featureIdColumnWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                                if (featureIdColumnWindow.ShowDialog().GetValueOrDefault())
                                {
                                    IdColumnName = featureIdColumnWindow.FeatureIdColumn;
                                }
                            }
                            catch { }
                        }

                        if (string.IsNullOrEmpty(IdColumnName))
                        {
                            return(new Collection <PostgreSqlFeatureLayer>());
                        }

                        string[] tableInfo = tableName.Split(':');
                        string   url       = "postgreSqlFeatureLayer:{0}|{1}|{2}|{3}";
                        url = String.Format(CultureInfo.InvariantCulture, url, tableInfo[1], tableInfo[0], connectionString, idColumnName);
                        Uri layerUri = new Uri(url);

                        GetLayersParameters layerParameters = new GetLayersParameters();
                        layerParameters.LayerUris.Add(layerUri);
                        Collection <PostgreSqlFeatureLayer> newLayers = GisEditor.LayerManager.GetLayers <PostgreSqlFeatureLayer>(layerParameters);
                        if (newLayers.Count > 0)
                        {
                            return(newLayers);
                        }
                    }
                }
            }
            return(new Collection <PostgreSqlFeatureLayer>());
        }
Пример #3
0
        public Uri GetResultLayerUri()
        {
            string connectionString = viewModel.GetConnectionString();
            //string[] tableNameSegs = viewModel.CurrentItem.Name.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
            PostgreSchemaDataRepositoryItem schemaItem = (PostgreSchemaDataRepositoryItem)viewModel.CurrentItem.Parent.Parent;
            string schemaName = schemaItem.Name;
            string tableName  = viewModel.CurrentItem.Name;
            string columnName = viewModel.FeatureIdColumnName;

            string url = "postgreSqlFeatureLayer:{0}|{1}|{2}|{3}";

            url = String.Format(CultureInfo.InvariantCulture, url, tableName, schemaName, connectionString, columnName);
            return(new Uri(url));
        }