public PostgreServerDataRepositoryItem()
        {
            Icon = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/server.png", UriKind.RelativeOrAbsolute));

            MenuItem editServerMenuItem = new MenuItem();

            editServerMenuItem.Header  = "Configure...";
            editServerMenuItem.Command = new RelayCommand(() =>
            {
                PostgreServerConfigureWindow window = new PostgreServerConfigureWindow(Server, Port, UserName, Password);
                window.Owner = Application.Current.MainWindow;
                window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                if (window.ShowDialog().GetValueOrDefault())
                {
                    PostgreServerDataRepositoryPlugin.SyncToServerItem(window.Result, this);
                }
            });
            editServerMenuItem.Icon = new Image
            {
                Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/server_edit.png", UriKind.RelativeOrAbsolute)),
                Width  = 16,
                Height = 16
            };

            MenuItem deleteServerMenuItem = new MenuItem();

            deleteServerMenuItem.Header  = "Remove";
            deleteServerMenuItem.Command = new RelayCommand(() =>
            {
                if (Parent != null)
                {
                    Parent.Children.Remove(this);
                }

                GisEditor.InfrastructureManager.SaveSettings(GisEditor.DataRepositoryManager.GetPlugins().OfType <PostgreServerDataRepositoryPlugin>());
            });
            deleteServerMenuItem.Command = new RelayCommand(() =>
            {
                if (Parent != null)
                {
                    Parent.Children.Remove(this);
                }

                GisEditor.InfrastructureManager.SaveSettings(GisEditor.DataRepositoryManager.GetPlugins().OfType <PostgreServerDataRepositoryPlugin>());
            });
            deleteServerMenuItem.Icon = new Image
            {
                Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/server_delete.png", UriKind.RelativeOrAbsolute)),
                Width  = 16,
                Height = 16
            };

            ContextMenu = new ContextMenu();
            ContextMenu.Items.Add(editServerMenuItem);
            ContextMenu.Items.Add(deleteServerMenuItem);
        }
        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>());
        }
 protected override void RefreshCore()
 {
     Task.Factory.StartNew(new Action(() =>
     {
         PostgreConfigureInfo postgreInfo = new PostgreConfigureInfo();
         Collection <string> newDbNames   = PostgreSqlFeatureSource.GetDatabaseNames(Server, Port, UserName, Password);
         foreach (var item in newDbNames)
         {
             postgreInfo.DbaseNames.Add(item);
         }
         postgreInfo.Server   = server;
         postgreInfo.Port     = port;
         postgreInfo.UserName = userName;
         postgreInfo.Password = password;
         PostgreServerDataRepositoryPlugin.SyncToServerItem(postgreInfo, this);
     }));
 }