private void Model_ElementInvalid(object sender, ElementEventArgs e) {
            // Exit if GeometricNetwork Does not Exist
            if (this._geometricNetwork == null) { return; }

            // Get Element
            Element element = e.Value;
            if (element == null) { return; }
            EsriLine<GeometricNetworkControllerMembership> line = element as EsriLine<GeometricNetworkControllerMembership>;
            if (line == null) { return; }

            // Get Controller
            GeometricNetworkControllerMembership controller = line.Parent;

            // Suspend Rule Events
            controller.Suspend();

            // Get Start and End Elements
            Element elementStart = line.Start.Shape;
            Element elementEnd = line.End.Shape;

            // Update GeometricNetwork Name Property
            if (elementStart == null) {
                controller.GeometricNetworkName = string.Empty;
            }
            else if (elementStart is EsriShape<GeometricNetwork>) {
                EsriShape<GeometricNetwork> shape = (EsriShape<GeometricNetwork>)elementStart;
                GeometricNetwork geometricNetwork = shape.Parent;
                controller.GeometricNetworkName = geometricNetwork.Name;
            }

            //
            DiagrammerEnvironment diagrammerEnvironment = DiagrammerEnvironment.Default;
            SchemaModel schemaModel = diagrammerEnvironment.SchemaModel;
            ObjectClass objectClass = schemaModel.FindParent(controller);
            if (objectClass != null) {
                objectClass.ControllerMemberships.Remove(controller);
            }

            if (elementEnd == null) {
                controller.AncillaryRoleFieldName = string.Empty;
                controller.EnabledFieldName = string.Empty;
            }
            else if (elementEnd is EsriShape<FeatureClass>) {
                EsriShape<FeatureClass> es = (EsriShape<FeatureClass>)elementEnd;
                FeatureClass featureClass = es.Parent;
                featureClass.ControllerMemberships.Add(controller);
            }

            // Resume Controller Events
            controller.Resume();
        }
        private void Model_ElementInvalid(object sender, ElementEventArgs e) {
            // Exit if Topology Does not Exist
            if (this._topology == null) { return; }

            // Get Element
            Element element = e.Value;
            if (element == null) { return; }
            EsriLine<TopologyRule> line = element as EsriLine<TopologyRule>;
            if (line == null) { return; }

            // Get TopologyRule
            TopologyRule rule = line.Parent;

            // Suspend Rule Events
            rule.Suspend();

            // Get Start and End Elements
            Element elementStart = line.Start.Shape;
            Element elementEnd = line.End.Shape;

            // Update Start Class/Subtype
            if (elementStart == null) {
                rule.AllOriginSubtypes = false;
                rule.OriginClassId = -1;
                rule.OriginSubtype = -1;
            }
            else if (elementStart is EsriShape<FeatureClass>) {
                EsriShape<FeatureClass> shape = (EsriShape<FeatureClass>)elementStart;
                ObjectClass objectClass = shape.Parent;
                rule.AllOriginSubtypes = true;
                rule.OriginClassId = objectClass.DSID;
                rule.OriginSubtype = 0;
            }
            else if (elementStart is EsriShape<Subtype>) {
                EsriShape<Subtype> shape = (EsriShape<Subtype>)elementStart;
                Subtype subtype = shape.Parent;
                ObjectClass objectClass = subtype.GetParent();
                rule.AllOriginSubtypes = false;
                if (objectClass == null) {
                    rule.OriginClassId = -1;
                    rule.OriginSubtype = -1;
                }
                else {
                    rule.OriginClassId = objectClass.DSID;
                    rule.OriginSubtype = subtype.SubtypeCode;
                }
            }

            // Update End Class/Subtype
            if (elementEnd == null) {
                rule.AllDestinationSubtypes = false;
                rule.DestinationClassId = -1;
                rule.DestinationSubtype = -1;
            }
            else if (elementEnd is EsriShape<FeatureClass>) {
                EsriShape<FeatureClass> shape = (EsriShape<FeatureClass>)elementEnd;
                ObjectClass objectClass = shape.Parent;
                rule.AllDestinationSubtypes = true;
                rule.DestinationClassId = objectClass.DSID;
                rule.DestinationSubtype = 0;
            }
            else if (elementEnd is EsriShape<Subtype>) {
                EsriShape<Subtype> shape = (EsriShape<Subtype>)elementEnd;
                Subtype subtype = shape.Parent;
                ObjectClass objectClass = subtype.GetParent();
                rule.AllDestinationSubtypes = false;
                if (objectClass == null) {
                    rule.DestinationClassId = -1;
                    rule.DestinationSubtype = -1;
                }
                else {
                    rule.DestinationClassId = objectClass.DSID;
                    rule.DestinationSubtype = subtype.SubtypeCode;
                }
            }

            // Resume Rule Events
            rule.Resume();
        }
        private void Model_ElementInvalid(object sender, ElementEventArgs e) {
            // Check Relationship
            if (this._relationshipClass == null) { return; }

            // Get Element
            Element element = e.Value;
            if (element == null) { return; }
            EsriLine<RelationshipRule> line = element as EsriLine<RelationshipRule>;
            if (line == null) { return; }

            // Get Rule
            RelationshipRule rule = line.Parent;

            // Suspend Rule Events
            rule.Suspend();

            //
            Element elementStart = line.Start.Shape;
            Element elementEnd = line.End.Shape;

            // Update Origin Class/Subtype
            if (elementStart == null) {
                rule.OriginClass = -1;
                rule.OriginSubtype = -1;
            }
            else if (elementStart is EsriShape<ObjectClass>) {
                EsriShape<ObjectClass> shape = (EsriShape<ObjectClass>)elementStart;
                ObjectClass objectClass = shape.Parent;
                rule.OriginClass = objectClass.DSID;
                rule.OriginSubtype = 0;
            }
            else if (elementStart is EsriShape<FeatureClass>) {
                EsriShape<FeatureClass> shape = (EsriShape<FeatureClass>)elementStart;
                FeatureClass featureClass = shape.Parent;
                rule.OriginClass = featureClass.DSID;
                rule.OriginSubtype = 0;
            }
            else if (elementStart is EsriShape<Subtype>) {
                EsriShape<Subtype> shape = (EsriShape<Subtype>)elementStart;
                Subtype subtype = shape.Parent;
                ObjectClass objectClass = subtype.GetParent();
                if (objectClass != null) {
                    rule.OriginClass = objectClass.DSID;
                    rule.OriginSubtype = subtype.SubtypeCode;
                }
            }

            // Update Destination Class/Subtype
            if (elementEnd == null) {
                rule.DestinationClass = -1;
                rule.DestinationSubtype = -1;
            }
            else if (elementEnd is EsriShape<ObjectClass>) {
                EsriShape<ObjectClass> shape = (EsriShape<ObjectClass>)elementEnd;
                ObjectClass objectClass = shape.Parent;
                rule.DestinationClass = objectClass.DSID;
                rule.DestinationSubtype = 0;
            }
            else if (elementEnd is EsriShape<FeatureClass>) {
                EsriShape<FeatureClass> shape = (EsriShape<FeatureClass>)elementEnd;
                FeatureClass featureClass = shape.Parent;
                rule.DestinationClass = featureClass.DSID;
                rule.DestinationSubtype = 0;
            }
            else if (elementEnd is EsriShape<Subtype>) {
                EsriShape<Subtype> shape = (EsriShape<Subtype>)elementEnd;
                Subtype subtype = shape.Parent;
                ObjectClass objectClass = subtype.GetParent();
                if (objectClass != null) {
                    rule.DestinationClass = objectClass.DSID;
                    rule.DestinationSubtype = subtype.SubtypeCode;
                }
            }

            // Resume Rule Events
            rule.Resume();
        }
        private void Model_ElementInvalid(object sender, ElementEventArgs e) {
            // Exit if GeometricNetwork Does not Exist
            if (this._terrain == null) { return; }

            // Get Element
            Element element = e.Value;
            if (element == null) { return; }
            EsriLine<TerrainDataSource> line = element as EsriLine<TerrainDataSource>;
            if (line == null) { return; }

            // Get Controller
            TerrainDataSource terrainDataSource = line.Parent;

            // Suspend Rule Events
            terrainDataSource.Suspend();

            // Get Start and End Elements
            Element elementStart = line.Start.Shape;
            Element elementEnd = line.End.Shape;

            // Update FeatureClass Name Property
            if (elementEnd == null) {
                terrainDataSource.FeatureClassName = string.Empty;
            }
            else if (elementEnd is EsriShape<FeatureClass>) {
                EsriShape<FeatureClass> shape = (EsriShape<FeatureClass>)elementEnd;
                FeatureClass featureClass = shape.Parent;
                terrainDataSource.FeatureClassName = featureClass.Name;
            }

            // Add if missing
            if (!this._terrain.TerrainDataSources.Contains(terrainDataSource)) {
                this._terrain.TerrainDataSources.Add(terrainDataSource);
            }

            // Resume Controller Events
            terrainDataSource.Resume();
        }
        private void Model_ElementInvalid(object sender, ElementEventArgs e) {
            // Exit if GeometricNetwork Does not Exist
            if (this._geometricNetwork == null) { return; }

            // Get Element
            Element element = e.Value;
            if (element == null) { return; }
            EsriLine<EdgeConnectivityRule> line = element as EsriLine<EdgeConnectivityRule>;
            if (line == null) { return; }

            // Get EdgeConnectivityRule
            EdgeConnectivityRule rule = line.Parent;

            // Suspend Rule Events
            rule.Suspend();

            // Get Start and End Elements
            Element elementStart = line.Start.Shape;
            Element elementEnd = line.End.Shape;

            // Update Start Class/Subtype
            if (elementStart == null) {
                rule.FromClassID = -1;
                rule.FromEdgeSubtypeCode = -1;
            }
            else if (elementStart is EsriShape<FeatureClass>) {
                EsriShape<FeatureClass> shape = (EsriShape<FeatureClass>)elementStart;
                ObjectClass objectClass = shape.Parent;
                rule.FromClassID = objectClass.DSID;
                rule.FromEdgeSubtypeCode = 0;
            }
            else if (elementStart is EsriShape<Subtype>) {
                EsriShape<Subtype> shape = (EsriShape<Subtype>)elementStart;
                Subtype subtype = shape.Parent;
                ObjectClass objectClass = subtype.GetParent();
                if (objectClass == null) {
                    rule.FromClassID = -1;
                    rule.FromEdgeSubtypeCode = -1;
                }
                else {
                    rule.FromClassID = objectClass.DSID;
                    rule.FromEdgeSubtypeCode = subtype.SubtypeCode;
                }
            }

            // Update End Class/Subtype
            if (elementEnd == null) {
                rule.ToClassID = -1;
                rule.ToEdgeSubtypeCode = -1;
            }
            else if (elementEnd is EsriShape<FeatureClass>) {
                EsriShape<FeatureClass> shape = (EsriShape<FeatureClass>)elementEnd;
                ObjectClass objectClass = shape.Parent;
                rule.ToClassID = objectClass.DSID;
                rule.ToEdgeSubtypeCode = 0;
            }
            else if (elementEnd is EsriShape<Subtype>) {
                EsriShape<Subtype> shape = (EsriShape<Subtype>)elementEnd;
                Subtype subtype = shape.Parent;
                ObjectClass objectClass = subtype.GetParent();
                if (objectClass == null) {
                    rule.ToClassID = -1;
                    rule.ToEdgeSubtypeCode = -1;
                }
                else {
                    rule.ToClassID = objectClass.DSID;
                    rule.ToEdgeSubtypeCode = subtype.SubtypeCode;
                }
            }

            // Resume Rule Events
            rule.Resume();
        }