示例#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);
        }
示例#2
0
        public async Task <bool> ShouldAddInBeEnabledAsync(ProSymbolUtilities.SupportedStandardsType standard)
        {
            if (_schemaExists && (_standard == standard))
            {
                return(true);
            }

            _schemaExists = false;

            //If we can get the database, then enable the add-in
            if (Project.Current == null)
            {
                //No open project
                return(false);
            }

            //Get database with correct schema
            try
            {
                IEnumerable <GDBProjectItem> gdbProjectItems = Project.Current.GetItems <GDBProjectItem>();

                foreach (GDBProjectItem gdbProjectItem in gdbProjectItems)
                {
                    if (gdbProjectItem.Name == "map.gdb") // ignore the project Map GDB
                    {
                        continue;
                    }

                    bool isSchemaComplete = await GDBContainsMilitaryOverlay(gdbProjectItem, standard);

                    // if schema is there/complete then done
                    if (isSchemaComplete)
                    {
                        // If we get here, then schema is found for this standard
                        // Save geodatabase path to use as the selected database
                        _databaseName = gdbProjectItem.Path;
                        _schemaExists = true;
                        _standard     = standard;
                        break;
                    }
                }
            }
            catch (Exception exception)
            {
                System.Diagnostics.Trace.WriteLine(exception.Message);
            }

            return(SchemaExists);
        }
示例#3
0
        public async Task <bool> ShouldAddInBeEnabledAsync(string gdbPath, ProSymbolUtilities.SupportedStandardsType standard)
        {
            bool gdbEnabledWithStanadard = false;

            await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(async() =>
            {
                var currentItem = ItemFactory.Instance.Create(gdbPath);

                if (currentItem is GDBProjectItem)
                {
                    gdbEnabledWithStanadard = await GDBContainsSchema(currentItem as GDBProjectItem, standard);
                }
            });

            return(gdbEnabledWithStanadard);
        }
示例#4
0
        public async Task <bool> GDBContainsMilitaryOverlay(GDBProjectItem gdbProjectItem,
                                                            ProSymbolUtilities.SupportedStandardsType standard)
        {
            if (gdbProjectItem == null)
            {
                return(false);
            }

            string militaryOverlayFeatureDatasetName =
                ProSymbolUtilities.GetDatasetName(standard);

            bool gdbContainsMilitaryOverlay = await
                                              ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run <bool>(() =>
            {
                using (Datastore datastore = gdbProjectItem.GetDatastore())
                {
                    // Unsupported datastores (non File GDB and non Enterprise GDB) will be of type UnknownDatastore
                    if (datastore is UnknownDatastore)
                    {
                        return(false);
                    }

                    Geodatabase geodatabase = datastore as Geodatabase;
                    if (geodatabase == null)
                    {
                        return(false);
                    }

                    var defs = geodatabase.GetDefinitions <FeatureDatasetDefinition>().Where(fd => fd.GetName().Contains(militaryOverlayFeatureDatasetName)).ToList();;

                    return(defs.Count > 0);
                }
            });

            return(gdbContainsMilitaryOverlay);
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            // or give user the option of selecting workspace:
            string selectedGDB = ProSymbolUtilities.BrowseItem(ArcGIS.Desktop.Catalog.ItemFilters.geodatabases);

            if (string.IsNullOrEmpty(selectedGDB))
            {
                return;
            }

            if (DefaultDatabase != selectedGDB)
            {
                DefaultDatabaseChanged = true;
                DefaultDatabase        = selectedGDB;

                // See if the selected database already contains a standard,
                // if so set the standard, and disable the control

                var selectedGDBasItem = ArcGIS.Desktop.Core.ItemFactory.
                                        Instance.Create(selectedGDB);

                bool hasStandard = false;
                ProSymbolUtilities.SupportedStandardsType standardFound =
                    ProSymbolUtilities.SupportedStandardsType.mil2525d;

                foreach (ProSymbolUtilities.SupportedStandardsType standard in
                         Enum.GetValues(typeof(ProSymbolUtilities.SupportedStandardsType)))
                {
                    bool containsStandard =
                        await ProSymbolEditorModule.Current.MilitaryOverlaySchema.
                        GDBContainsMilitaryOverlay(
                            selectedGDBasItem as ArcGIS.Desktop.Catalog.GDBProjectItem,
                            standard);

                    if (containsStandard)
                    {
                        hasStandard   = true;
                        standardFound = standard;
                        break;
                    }
                }

                if (hasStandard)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(
                        "Database: " + selectedGDB + "\n" +
                        "contains a schema for standard: \n" +
                        ProSymbolUtilities.GetStandardLabel(standardFound) + ".\n" +
                        "Setting standard to this value."
                        , "Database Contains Schema",
                        MessageBoxButton.OK, MessageBoxImage.Information);

                    Standard = standardFound;
                    RaisePropertyChanged("SelectedSymbologyStandard");
                }

                // Disable/enable the standard button if GDB had schema
                IsSettingsReadOnly = hasStandard;
                RaisePropertyChanged("IsSettingsNotReadOnly");

                RaisePropertyChanged("DefaultDatabase");
            }
        }
        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);
        }
        public async Task <bool> ShouldAddInBeEnabledAsync(ProSymbolUtilities.SupportedStandardsType standard)
        {
            _schemaExists = false;

            //If we can get the database, then enable the add-in
            if (Project.Current == null)
            {
                //No open project
                return(false);
            }

            //Get database with correct schema
            try
            {
                IEnumerable <GDBProjectItem> gdbProjectItems = Project.Current.GetItems <GDBProjectItem>();
                await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
                {
                    foreach (GDBProjectItem gdbProjectItem in gdbProjectItems)
                    {
                        if (gdbProjectItem.Name == "map.gdb") // ignore the project Map GDB
                        {
                            continue;
                        }

                        using (Datastore datastore = gdbProjectItem.GetDatastore())
                        {
                            //Unsupported datastores (non File GDB and non Enterprise GDB) will be of type UnknownDatastore
                            if (datastore is UnknownDatastore)
                            {
                                continue;
                            }

                            Geodatabase geodatabase = datastore as Geodatabase;
                            if (geodatabase == null)
                            {
                                continue;
                            }

                            //Set up Fields to check
                            List <string> fieldsToCheck = new List <string>();

                            if (standard == ProSymbolUtilities.SupportedStandardsType.mil2525c_b2)
                            {
                                fieldsToCheck.Add("extendedfunctioncode");
                            }
                            else
                            {   // 2525d
                                fieldsToCheck.Add("symbolset");
                                fieldsToCheck.Add("symbolentity");
                            }

                            // Reset schema data model exists to false for each feature class
                            Dictionary <string, bool> featureClassExists = GetFeatureClassExistsMap(standard, geodatabase);

                            IReadOnlyList <FeatureClassDefinition> featureClassDefinitions = geodatabase.GetDefinitions <FeatureClassDefinition>();

                            bool stopLooking = false;
                            foreach (FeatureClassDefinition featureClassDefinition in featureClassDefinitions)
                            {
                                // stop looking after the first feature class not found
                                if (stopLooking)
                                {
                                    break;
                                }

                                string featureClassName = featureClassDefinition.GetName();

                                if (featureClassExists.ContainsKey(featureClassName))
                                {
                                    //Feature Class Exists!  Check for fields
                                    bool fieldsExist = true;
                                    foreach (string fieldName in fieldsToCheck)
                                    {
                                        IEnumerable <Field> foundFields = featureClassDefinition.GetFields().Where(x => x.Name == fieldName);

                                        if (foundFields.Count() < 1)
                                        {
                                            fieldsExist = false;
                                            stopLooking = true;
                                            break;
                                        }
                                    }

                                    featureClassExists[featureClassName] = fieldsExist;
                                }
                                else
                                {
                                    //Key doesn't exist, so ignore
                                }
                            }

                            bool isSchemaComplete = true;

                            foreach (KeyValuePair <string, bool> pair in featureClassExists)
                            {
                                if (pair.Value == false)
                                {
                                    isSchemaComplete = false;
                                    break;
                                }
                            }

                            //Check if schema is all there
                            if (isSchemaComplete)
                            {
                                //Save geodatabase path to use as the selected database
                                _databaseName = gdbProjectItem.Path;
                                _schemaExists = true;

                                break;
                            }
                        }
                    }
                });
            }
            catch (Exception exception)
            {
                System.Diagnostics.Trace.WriteLine(exception.Message);
            }

            return(SchemaExists);
        }
示例#8
0
        // TODO: we may be able to deprecate this method (GDBContainsSchema) and use the method above (GDBContainsMilitaryOverlay)
        public async Task <bool> GDBContainsSchema(GDBProjectItem gdbProjectItem,
                                                   ProSymbolUtilities.SupportedStandardsType standard)
        {
            bool isSchemaComplete = await
                                    ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run <bool>(() =>
            {
                if (gdbProjectItem == null)
                {
                    return(false);
                }

                using (Datastore datastore = gdbProjectItem.GetDatastore())
                {
                    // Unsupported datastores (non File GDB and non Enterprise GDB) will be of type UnknownDatastore
                    if (datastore is UnknownDatastore)
                    {
                        return(false);
                    }

                    Geodatabase geodatabase = datastore as Geodatabase;
                    if (geodatabase == null)
                    {
                        return(false);
                    }

                    // Set up Fields to check
                    List <string> fieldsToCheck = new List <string>();

                    if (ProSymbolUtilities.IsLegacyStandard(standard))
                    {
                        fieldsToCheck.Add("extendedfunctioncode");
                    }
                    else
                    {   // 2525d / app6d
                        fieldsToCheck.Add("symbolset");
                        fieldsToCheck.Add("symbolentity");
                    }

                    // Reset schema data model exists to false for each feature class
                    Dictionary <string, bool> featureClassExists = GetFeatureClassExistsMap(standard, geodatabase);

                    IReadOnlyList <FeatureClassDefinition> featureClassDefinitions = geodatabase.GetDefinitions <FeatureClassDefinition>();

                    bool stopLooking = false;
                    foreach (FeatureClassDefinition featureClassDefinition in featureClassDefinitions)
                    {
                        // Stop looking after the first feature class not found
                        if (stopLooking)
                        {
                            return(false);
                        }

                        string featureClassName = featureClassDefinition.GetName();

                        if (featureClassExists.ContainsKey(featureClassName))
                        {
                            // Feature Class Exists. Check for fields
                            bool fieldsExist = true;

                            // Don't do this for remote databases (too slow)
                            if (geodatabase.GetGeodatabaseType() != GeodatabaseType.RemoteDatabase)
                            {
                                foreach (string fieldName in fieldsToCheck)
                                {
                                    IEnumerable <Field> foundFields = featureClassDefinition.GetFields().Where(x => x.Name == fieldName);

                                    if (foundFields.Count() < 1)
                                    {
                                        fieldsExist = false;
                                        return(false);
                                    }
                                }
                            }

                            featureClassExists[featureClassName] = fieldsExist;
                        }
                        else
                        {
                            // Key doesn't exist, so ignore
                        }
                    }

                    foreach (KeyValuePair <string, bool> pair in featureClassExists)
                    {
                        if (pair.Value == false)
                        {
                            return(false);
                        }
                    }

                    // If here, schema is complete
                    // Save geodatabase path to use as the selected database
                    _databaseName = gdbProjectItem.Path;
                    _schemaExists = true;
                    _standard     = standard;

                    return(true);
                }
            });

            return(isSchemaComplete);
        }