Пример #1
0
        /// <summary>
        /// If NetworkDiagram exists, fill the lists of DiagramElements, with the selection
        /// If there is no selection and GetSelection is true, get all DiagramElements in diagram
        /// </summary>
        /// <param name="GetAllElements">Get all DiagramElements in diagram</param>
        /// <param name="GetSelection">Get only DiagramElements in selection, if exist, if not get all</param>
        /// <returns>NetworkDiagram exists</returns>
        internal static bool IsDiagramUsable(bool GetAllElements = false, bool GetSelection = false)
        {
            if (GlobalDiagram == null)
            {
                GetParameters(MapView.Active.Map);
            }

            if (GlobalDiagram == null)
            {
                return(false);
            }

            if (GlobalGeodatabase.HasEdits())
            {
                return(false);
            }

            if (GetAllElements == false && GetSelection == false)
            {
                return(true);
            }

            if (GetSelection)
            {
                GlobalSelectedJunctionIDs  = new List <long>();
                GlobalSelectedContainerIDs = new List <long>();
                GlobalSelectedEdgeIDs      = new List <long>();

                GlobalMapSelection = MapView.Active.Map.GetSelection();
                foreach (var v in GlobalMapSelection)
                {
                    FeatureLayer layer = v.Key as FeatureLayer;
                    if (layer.ShapeType == esriGeometryType.esriGeometryPoint)
                    {
                        foreach (var id in v.Value)
                        {
                            GlobalSelectedJunctionIDs.Add(id);
                        }
                    }
                    else if (layer.ShapeType == esriGeometryType.esriGeometryPolygon)
                    {
                        foreach (var id in v.Value)
                        {
                            GlobalSelectedContainerIDs.Add(id);
                        }
                    }
                    else
                    {
                        foreach (var id in v.Value)
                        {
                            GlobalSelectedEdgeIDs.Add(id);
                        }
                    }
                }
            }
            else
            {
                GlobalMapSelection = null;
            }

            DiagramElementQueryResult deqr;

            try
            {
                if (GetAllElements || (GlobalSelectedContainerIDs.Count + GlobalSelectedEdgeIDs.Count + GlobalSelectedJunctionIDs.Count == 0))
                {
                    DiagramElementQueryByElementTypes query = new DiagramElementQueryByElementTypes
                    {
                        QueryDiagramContainerElement = true,
                        QueryDiagramEdgeElement      = true,
                        QueryDiagramJunctionElement  = true
                    };
                    deqr = GlobalDiagram.QueryDiagramElements(query);
                }
                else
                {
                    DiagramElementQueryByObjectIDs query1 = new DiagramElementQueryByObjectIDs
                    {
                        AddConnected       = true,
                        AddContents        = true,
                        ContainerObjectIDs = GlobalSelectedContainerIDs,
                        JunctionObjectIDs  = GlobalSelectedJunctionIDs,
                        EdgeObjectIDs      = GlobalSelectedEdgeIDs
                    };

                    deqr = GlobalDiagram.QueryDiagramElements(query1);
                }
            }


            catch (Exception ex)
            {
                ShowException(exception: ex);
                return(false);
            }

            GlobalDiagramJunctionElements  = deqr.DiagramJunctionElements.ToList();
            GlobalDiagramEdgeElements      = deqr.DiagramEdgeElements.ToList();
            GlobalDiagramContainerElements = deqr.DiagramContainerElements.ToList();

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Open a dataset
        /// </summary>
        /// <typeparam name="T">Dataset type</typeparam>
        /// <param name="name">Dataset name</param>
        /// <returns>Dataset</returns>
        private static T OpenDataset <T>(string name) where T : Dataset
        {
            if (GlobalGeodatabase == null)
            {
                GlobalGeodatabase = GetGeodatabaseFromActiveMap();
            }

            if (GlobalGeodatabase.GetGeodatabaseType() == GeodatabaseType.Service)
            {
                Type t = typeof(T);

                if (t == typeof(Table))
                {
                    IReadOnlyList <TableDefinition> allTables = GlobalGeodatabase.GetDefinitions <TableDefinition>();
                    foreach (TableDefinition tableDef in allTables)
                    {
                        string aliasName = tableDef.GetAliasName();
                        if (aliasName.Replace(" ", "").Equals(name, StringComparison.OrdinalIgnoreCase))
                        {
                            return(GlobalGeodatabase.OpenDataset <T>(tableDef.GetName()));
                        }
                    }
                }
                else if (t == typeof(FeatureClass))
                {
                    IReadOnlyList <FeatureClassDefinition> allFeatureClasses = GlobalGeodatabase.GetDefinitions <FeatureClassDefinition>();
                    foreach (FeatureClassDefinition fcDef in allFeatureClasses)
                    {
                        string aliasName = fcDef.GetAliasName();
                        if (!String.IsNullOrEmpty(aliasName))
                        {
                            if (aliasName.Replace(" ", "").Equals(name, StringComparison.OrdinalIgnoreCase))
                            {
                                return(GlobalGeodatabase.OpenDataset <T>(fcDef.GetName()));
                            }
                        }
                        else
                        {
                            //Weird case, where the alias name is empty (Error Tables, Dirty Areas)
                            string fullName = fcDef.GetName();
                            if (fullName.Replace("_", "").Contains(name)) //the Point errors, line errors, polygon errors and dirty areas come back as  Dirty_Areas (want to compare to DirtyAreas).
                            {
                                return(GlobalGeodatabase.OpenDataset <T>(fullName));
                            }
                        }
                    }
                }
                else if (t == typeof(RelationshipClass))
                {
                    IReadOnlyList <RelationshipClassDefinition> allRelationshipClasses = GlobalGeodatabase.GetDefinitions <RelationshipClassDefinition>();
                    foreach (RelationshipClassDefinition rcDef in allRelationshipClasses)
                    {
                        string aliasName = rcDef.GetAliasName();
                        if (aliasName.Replace(" ", "").Equals(name, StringComparison.OrdinalIgnoreCase))
                        {
                            return(GlobalGeodatabase.OpenDataset <T>(rcDef.GetName()));
                        }
                    }
                }
                else if (t == typeof(UtilityNetwork))
                {
                    IReadOnlyList <UtilityNetworkDefinition> unDefinition = GlobalGeodatabase.GetDefinitions <UtilityNetworkDefinition>();
                    foreach (UtilityNetworkDefinition unDef in unDefinition)
                    {
                        return(GlobalGeodatabase.OpenDataset <T>(unDef.GetName()));
                    }
                }
                else
                {
                    //There is no type supported in the Feature Service DB, have to return null
                    return(null);
                }
            }
            else
            {
                return(GlobalGeodatabase.OpenDataset <T>(name));
            }
            return(null);
        }
Пример #3
0
        /// <summary>
        /// Set Global fields
        /// </summary>
        /// <param name="map">Diagram Layer</param>
        internal static void GetParameters(Map map)
        {
            if (map == null)
            {
                CleanModule();
                return;
            }

            if (GlobalActiveMapName != map.Name || GlobalDiagram == null || GlobalDiagramLayer == null)
            {
                GlobalActiveMap     = map;
                GlobalActiveMapName = GlobalActiveMap.Name;
                GlobalDiagramLayer  = GetDiagramLayerFromMap(map);
                if (GlobalDiagramLayer == null)
                {
                    CleanModule();
                }
                else
                {
                    QueuedTask.Run(() =>
                    {
                        try
                        {
                            GlobalDiagram = GlobalDiagramLayer.GetNetworkDiagram();
                        }
                        catch
                        {
                            GlobalDiagram = null;
                        }

                        try
                        {
                            if (GlobalDiagram != null)
                            {
                                GlobalDiagramManager = GlobalDiagram.DiagramManager;

                                GlobalUtilityNetwork = GlobalDiagramManager.GetNetwork <UtilityNetwork>();

                                GlobalGeodatabase = GlobalUtilityNetwork.GetDatastore() as Geodatabase;

                                NetworkDiagramInfo networkDiagramInfo = GlobalDiagram.GetDiagramInfo();
                                if (networkDiagramInfo == null)
                                {
                                    GlobalIsSystem        = false;
                                    GlobalEnvelope        = null;
                                    GlobalIsStored        = false;
                                    GlobalContainerMargin = 0.5;
                                }
                                else
                                {
                                    GlobalIsSystem        = networkDiagramInfo.IsSystem;
                                    GlobalEnvelope        = networkDiagramInfo.DiagramExtent;
                                    GlobalIsStored        = networkDiagramInfo.IsStored;
                                    GlobalContainerMargin = networkDiagramInfo.ContainerMargin;
                                }

                                GlobalTypeGeo = GlobalGeodatabase.GetGeodatabaseType();

                                if (GlobalTypeGeo == GeodatabaseType.Service)
                                {
                                    VersionManager vm = GlobalGeodatabase.GetVersionManager();
                                    if (vm != null)
                                    {
                                        GlobalIsVersioned = (vm.GetCurrentVersion() != null);
                                    }
                                    else
                                    {
                                        GlobalIsVersioned = false;
                                    }
                                }
                                else
                                {
                                    GlobalIsVersioned = false;
                                }
                            }
                            else
                            {
                                GlobalDiagramLayer = null;
                            }

                            CleanSelections();
                        }
                        catch (Exception ex)
                        {
                            ShowException(exception: ex);

                            CleanModule();
                        }
                    });
                }
            }
        }