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>());
        }
Пример #2
0
        private Collection <MsSqlFeatureLayer> GetMsSql2008FeatureLayers()
        {
            if (LayerInfo != null)
            {
                MsSqlServerDataRepositoryItem serverItem = Parent.Parent.Parent.Parent.Parent as MsSqlServerDataRepositoryItem;
                if (serverItem != null)
                {
                    LayerInfo.TableName    = TableName;
                    LayerInfo.DatabaseName = DatabaseName;
                    LayerInfo.SchemaName   = SchemaName;
                    Collection <string>   newColumnNames        = LayerInfo.CollectColumnsFromTable();
                    FeatureIdColumnWindow featureIdColumnWindow = new FeatureIdColumnWindow(newColumnNames);
                    featureIdColumnWindow.Owner = Application.Current.MainWindow;
                    featureIdColumnWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    if (featureIdColumnWindow.ShowDialog().GetValueOrDefault())
                    {
                        GetLayersParameters layerParameters = new GetLayersParameters();
                        layerParameters.CustomData["TableName"]    = TableName;
                        layerParameters.CustomData["SchemaName"]   = SchemaName;
                        layerParameters.CustomData["DatabaseName"] = DatabaseName;
                        layerParameters.CustomData["IdColumn"]     = featureIdColumnWindow.FeatureIdColumn;
                        layerParameters.CustomData["ServerName"]   = serverItem.Name;
                        layerParameters.CustomData["UserName"]     = serverItem.UserName;
                        layerParameters.CustomData["Password"]     = serverItem.Password;

                        Collection <MsSqlFeatureLayer> newLayers = new Collection <MsSqlFeatureLayer>();
                        try
                        {
                            newLayers = GisEditor.LayerManager.GetLayers <MsSqlFeatureLayer>(layerParameters);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Unable to Load Layer(s)", MessageBoxButton.OK, MessageBoxImage.Error);
                        }

                        if (newLayers != null && newLayers.Count > 0)
                        {
                            return(newLayers);
                        }
                    }
                }
            }
            return(new Collection <MsSqlFeatureLayer>());
        }