コード例 #1
0
        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);
                            }
                        }
                    }
                });
            });
        }
コード例 #2
0
        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>());
        }