Beispiel #1
0
        Dictionary <string, bool> GetFeatureClassExistsMap(ProSymbolUtilities.SupportedStandardsType standard,
                                                           Geodatabase gdb = null)
        {
            EGDBPrefixName        = string.Empty;
            _egdbConnectionString = string.Empty;

            if (gdb != null)
            {
                GeodatabaseType gdbType = gdb.GetGeodatabaseType();
                if (gdbType == GeodatabaseType.RemoteDatabase)
                {
                    // if an SDE/EGDB, then feature class name format will differ:
                    // Database + User + Feature Class Name
                    DatabaseConnectionProperties dbcps = gdb.GetConnector() as DatabaseConnectionProperties;

                    if (dbcps != null)
                    {
                        EGDBPrefixName = dbcps.Database + "." + dbcps.User + ".";

                        // Also save this connection string to identify this EGDB later
                        _egdbConnectionString = ((Datastore)gdb).GetConnectionString();
                    }
                }
            }

            Dictionary <string, bool> featureClassExists = new Dictionary <string, bool>();

            List <SymbolSetMapping> symbolSetMapping = null;

            switch (standard)
            {
            case ProSymbolUtilities.SupportedStandardsType.app6b: symbolSetMapping = _symbolSetMappingAPP6B; break;

            case ProSymbolUtilities.SupportedStandardsType.app6d: symbolSetMapping = _symbolSetMappingAPP6D; break;

            case ProSymbolUtilities.SupportedStandardsType.mil2525b: symbolSetMapping = _symbolSetMapping2525B; break;

            case ProSymbolUtilities.SupportedStandardsType.mil2525c: symbolSetMapping = _symbolSetMapping2525C; break;

            default:
                symbolSetMapping = _symbolSetMapping2525D;
                break;
            }

            foreach (SymbolSetMapping mapping in symbolSetMapping)
            {
                string featureClassName = EGDBPrefixName + mapping.FeatureClassName;

                if (!featureClassExists.ContainsKey(featureClassName))
                {
                    featureClassExists.Add(featureClassName, false);
                }
            }

            return(featureClassExists);
        }
        /// <summary>
        /// This method will
        /// 1. Make sure if a Feature Layer is selected.
        /// 2. The Workspace is not null
        /// 3. Make sure that the workspace is an Enterprise SQL Server Geodatabase Workspace
        ///
        /// and then create a new version (In a Queued Task)
        /// and Connect to the newly created version and delete all the features for the selected subtype (In a separate QueuedTask)
        /// </summary>
        /// <param name="item">The newly selected combo box item</param>
        protected override async void OnSelectionChange(ComboBoxItem item)
        {
            await QueuedTask.Run(async() =>
            {
                if (item == null)
                {
                    return;
                }

                if (string.IsNullOrEmpty(item.Text))
                {
                    return;
                }

                Layer layer = MapView.Active.GetSelectedLayers()[0];
                if (layer is FeatureLayer featureLayer)
                {
                    using (Geodatabase geodatabase = featureLayer.GetTable().GetDatastore() as Geodatabase)
                        using (Table table = featureLayer.GetTable())
                        {
                            if (geodatabase == null)
                            {
                                return;
                            }
                            EnterpriseDatabaseType enterpriseDatabaseType = ((DatabaseConnectionProperties)geodatabase.GetConnector()).DBMS;


                            if (enterpriseDatabaseType != EnterpriseDatabaseType.SQLServer)
                            {
                                Enabled = false;
                                return;
                            }

                            if (table.GetRegistrationType().Equals(RegistrationType.Nonversioned))
                            {
                                return;
                            }


                            using (Version newVersion = await CreateVersionAsync(table))
                                using (Geodatabase newVersionGeodatabase = newVersion.Connect())
                                    using (Table newVersionTable = newVersionGeodatabase.OpenDataset <Table>(table.GetName()))
                                    {
                                        string subtypeField     = table.GetDefinition().GetSubtypeField();
                                        int code                = table.GetDefinition().GetSubtypes().First(subtype => subtype.GetName().Equals(item.Text)).GetCode();
                                        QueryFilter queryFilter = new QueryFilter {
                                            WhereClause = string.Format("{0}={1}", subtypeField, code)
                                        };

                                        using (var rowCursor = newVersionTable.Search(queryFilter, false))
                                        {
                                            EditOperation editOperation = new EditOperation
                                            {
                                                EditOperationType = EditOperationType.Long,
                                                Name = "Delete Based On Subtype"
                                            };

                                            editOperation.Callback(context =>
                                            {
                                                while (rowCursor.MoveNext())
                                                {
                                                    using (Row row = rowCursor.Current)
                                                    {
                                                        context.Invalidate(row);
                                                        row.Delete();
                                                    }
                                                }
                                            }, newVersionTable);

                                            bool result = await editOperation.ExecuteAsync();
                                            if (!result)
                                            {
                                                MessageBox.Show(String.Format("Could not delete features for subtype {0} : {1}", item.Text, editOperation.ErrorMessage));
                                            }

                                            await Project.Current.SaveEditsAsync();
                                        }
                                    }
                        }
                }
            });
        }
        Dictionary <string, bool> GetFeatureClassExistsMap(ProSymbolUtilities.SupportedStandardsType standard,
                                                           Geodatabase gdb = null)
        {
            string prefixName = string.Empty;

            _egdbConnectionString = string.Empty;

            if (gdb != null)
            {
                GeodatabaseType gdbType = gdb.GetGeodatabaseType();
                if (gdbType == GeodatabaseType.RemoteDatabase)
                {
                    // if an SDE/EGDB, then feature class name format will differ:
                    // Database + User + Feature Class Name
                    DatabaseConnectionProperties dbcps = gdb.GetConnector() as DatabaseConnectionProperties;

                    if (dbcps != null)
                    {
                        prefixName = dbcps.Database + "." + dbcps.User + ".";

                        // Also save this connection string to identify this EGDB later
                        _egdbConnectionString = ((Datastore)gdb).GetConnectionString();
                    }
                }
            }

            Dictionary <string, bool> featureClassExists = new Dictionary <string, bool>();

            if (standard == ProSymbolUtilities.SupportedStandardsType.mil2525c_b2)
            {
                // 2525c_b2
                featureClassExists.Add(prefixName + "Activities", false);
                featureClassExists.Add(prefixName + "Air", false);
                featureClassExists.Add(prefixName + "ControlMeasuresAreas", false);
                featureClassExists.Add(prefixName + "ControlMeasuresLines", false);
                featureClassExists.Add(prefixName + "ControlMeasuresPoints", false);
                featureClassExists.Add(prefixName + "Installations", false);
                featureClassExists.Add(prefixName + "LandEquipment", false);
                featureClassExists.Add(prefixName + "METOCAreas", false);
                featureClassExists.Add(prefixName + "METOCLines", false);
                featureClassExists.Add(prefixName + "METOCPoints", false);
                featureClassExists.Add(prefixName + "SeaSubsurface", false);
                featureClassExists.Add(prefixName + "SeaSurface", false);
                featureClassExists.Add(prefixName + "SIGINT", false);
                featureClassExists.Add(prefixName + "Space", false);
                featureClassExists.Add(prefixName + "Units", false);
            }
            else
            {
                // 2525d
                featureClassExists.Add(prefixName + "Activities", false);
                featureClassExists.Add(prefixName + "Air", false);
                featureClassExists.Add(prefixName + "AirMissile", false);
                featureClassExists.Add(prefixName + "Civilian", false);
                featureClassExists.Add(prefixName + "ControlMeasuresAreas", false);
                featureClassExists.Add(prefixName + "ControlMeasuresLines", false);
                featureClassExists.Add(prefixName + "ControlMeasuresPoints", false);
                featureClassExists.Add(prefixName + "Cyberspace", false);
                featureClassExists.Add(prefixName + "Installations", false);
                featureClassExists.Add(prefixName + "LandEquipment", false);
                featureClassExists.Add(prefixName + "METOCAreasAtmospheric", false);
                featureClassExists.Add(prefixName + "METOCAreasOceanographic", false);
                featureClassExists.Add(prefixName + "METOCLinesAtmospheric", false);
                featureClassExists.Add(prefixName + "METOCLinesOceanographic", false);
                featureClassExists.Add(prefixName + "METOCPointsAtmospheric", false);
                featureClassExists.Add(prefixName + "METOCPointsOceanographic", false);
                featureClassExists.Add(prefixName + "MineWarfare", false);
                featureClassExists.Add(prefixName + "SeaSubsurface", false);
                featureClassExists.Add(prefixName + "SeaSurface", false);
                featureClassExists.Add(prefixName + "SIGINT", false);
                featureClassExists.Add(prefixName + "Space", false);
                featureClassExists.Add(prefixName + "SpaceMissile", false);
                featureClassExists.Add(prefixName + "Units", false);
            }

            return(featureClassExists);
        }