Пример #1
0
        public async Task <bool> IsGDBAndFeatureClassInActiveView(string featureClassName)
        {
            string activeGdbPath = DatabaseName;

            IEnumerable <FeatureLayer> mapLayers = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>();

            bool isFeatureClassInActiveView = false;

            await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(async() =>
            {
                foreach (var layer in mapLayers)
                {
                    string fcName = layer.GetFeatureClass().GetName();

                    isFeatureClassInActiveView = false;

                    // GDB and View feature class name match?
                    if (fcName == featureClassName)
                    {
                        Geodatabase geodatabase = await GetGDBFromLayer(layer);
                        if (geodatabase == null)
                        {
                            isFeatureClassInActiveView = false;
                        }
                        else
                        {
                            string gdbPath = ProSymbolUtilities.GetPathFromGeodatabase(geodatabase);

                            if (gdbPath == activeGdbPath)
                            {
                                isFeatureClassInActiveView = true;
                                break;
                            }

                            // last check if it is EGDB
                            if (string.IsNullOrEmpty(gdbPath) && !string.IsNullOrEmpty(_egdbConnectionString) &&
                                (geodatabase != null))
                            {
                                string cs = ((Datastore)geodatabase).GetConnectionString();

                                // TODO: find a full-proof method to see if this layer
                                // is the same data source
                                // Note: different threads may have different connection strings
                                // so this comparison is not a full-proof test
                                // if (cs == _egdbConnectionString)
                                //    isFeatureClassInActiveView = true;
                                // For now just assume the EGDB is the correct one
                                isFeatureClassInActiveView = true;
                            }
                        }
                        break;
                    }
                }

                return(isFeatureClassInActiveView);
            });

            return(isFeatureClassInActiveView);
        }
        public async Task <bool> IsGDBAndFeatureClassInActiveView(string featureClassName)
        {
            string activeGdbPath = DatabaseName;

            IEnumerable <FeatureLayer> mapLayers = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>();

            bool isFeatureClassInActiveView = false;

            await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(async() =>
            {
                foreach (var layer in mapLayers)
                {
                    string fcName = layer.GetFeatureClass().GetName();

                    isFeatureClassInActiveView = false;

                    // GDB and View feature class name match?
                    if (fcName == featureClassName)
                    {
                        Geodatabase geodatabase = await GetGDBFromLayer(layer);
                        if (geodatabase == null)
                        {
                            isFeatureClassInActiveView = false;
                        }
                        else
                        {
                            string gdbPath = ProSymbolUtilities.GetPathFromGeodatabase(geodatabase);

                            if (gdbPath == activeGdbPath)
                            {
                                isFeatureClassInActiveView = true;
                                break;
                            }

                            // last check if it is EGDB
                            if (string.IsNullOrEmpty(gdbPath) && !string.IsNullOrEmpty(_egdbConnectionString) &&
                                (geodatabase != null))
                            {
                                string cs = ((Datastore)geodatabase).GetConnectionString();

                                if (cs == _egdbConnectionString)
                                {
                                    isFeatureClassInActiveView = true;
                                }
                            }
                        }
                        break;
                    }
                }

                return(isFeatureClassInActiveView);
            });

            return(isFeatureClassInActiveView);
        }