public void GetTopologyRules()
        {
            using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\TestData\GrandTeton.gdb"))))
                using (Topology topology = geodatabase.OpenDataset <Topology>("Backcountry_Topology"))
                {
                    #region GetTopologyRules

                    using (TopologyDefinition topologyDefinition = topology.GetDefinition())
                    {
                        IReadOnlyList <TopologyRule> rules = topologyDefinition.GetRules();

                        Console.WriteLine($"There are {rules.Count} topology rules defined for the topology:");
                        Console.WriteLine("ID \t Origin Class \t Origin Subtype \t Destination Class \t Destination Subtype \t Rule Type");

                        foreach (TopologyRule rule in rules)
                        {
                            Console.Write($"{rule.ID}");

                            Console.Write(!String.IsNullOrEmpty(rule.OriginClass) ? $"\t{rule.OriginClass}" : "\t\"\"");

                            Console.Write(rule.OriginSubtype != null ? $"\t{rule.OriginSubtype.GetName()}" : "\t\"\"");

                            Console.Write(!String.IsNullOrEmpty(rule.DestinationClass) ? $"\t{rule.DestinationClass}" : "\t\"\"");

                            Console.Write(rule.DestinationSubtype != null ? $"\t{rule.DestinationSubtype.GetName()}" : "\t\"\"");

                            Console.Write($"\t{rule.RuleType}");

                            Console.WriteLine();
                        }
                    }

                    #endregion GetTopologyRules
                }
        }
        private static void ExploreTopologyRules(Topology topology)
        {
            using (TopologyDefinition topologyDefinition = topology.GetDefinition())
            {
                IReadOnlyList <TopologyRule> rules = topologyDefinition.GetRules();

                Console.WriteLine("***************************************************************************");
                Console.WriteLine($"There are {rules.Count} topology rules defined for the topology:");
                Console.WriteLine("ID \t Origin Class \t Origin Subtype \t Destination Class \t Destination Subtype \t Rule Type");

                foreach (TopologyRule rule in rules)
                {
                    Console.Write($"{rule.ID}");

                    Console.Write(!String.IsNullOrEmpty(rule.OriginClass) ? $"\t{rule.OriginClass}" : "\t\"\"");

                    Console.Write(rule.OriginSubtype != null ? $"\t{rule.OriginSubtype.GetName()}" : "\t\"\"");

                    Console.Write(!String.IsNullOrEmpty(rule.DestinationClass) ? $"\t{rule.DestinationClass}" : "\t\"\"");

                    Console.Write(rule.DestinationSubtype != null ? $"\t{rule.DestinationSubtype.GetName()}" : "\t\"\"");

                    Console.Write($"\t{rule.RuleType}");

                    Console.WriteLine();
                }
            }
        }
        private static void ExploreTopologyDefinition(Geodatabase geodatabase, Topology topology)
        {
            // Similar to the rest of the Definition objects in the Core.Data API, there are two ways to open a dataset's
            // definition -- via the Topology dataset itself or via the Geodatabase.

            using (TopologyDefinition definitionViaTopology = topology.GetDefinition())
            {
                OutputDefinition(geodatabase, definitionViaTopology);
            }

            using (TopologyDefinition definitionViaGeodatabase = geodatabase.GetDefinition <TopologyDefinition>(GRAND_TETON_TOPO_NAME))
            {
                //OutputDefinition(geodatabase, definitionViaGeodatabase);
            }
        }
        private void ProcessDefinition(Geodatabase geodatabase, Topology topology)
        {
            // Similar to the rest of the Definition objects in the Core.Data API, there are two ways to open a dataset's
            // definition -- via the Topology dataset itself or via the Geodatabase.

            using (TopologyDefinition definitionViaTopology = topology.GetDefinition())
            {
                OutputDefinition(geodatabase, definitionViaTopology);
            }

            using (TopologyDefinition definitionViaGeodatabase = geodatabase.GetDefinition <TopologyDefinition>("Backcountry_Topology"))
            {
                OutputDefinition(geodatabase, definitionViaGeodatabase);
            }
        }
        public async Task Handle(DeleteTravelBookingTopologyCommand command, IMessageHandlerContext context)
        {
            var nm = new ManagementClient(_serviceBusConfiguration.ConnectionString);

            try
            {
                foreach (var queueDescription in TopologyDefinition.QueueDescriptions().Reverse())
                {
                    await nm.DeleteQueueAsync(queueDescription.Path);
                }
            }
            finally
            {
                await nm.CloseAsync();
            }
        }
        public async Task Handle(CreateTravelBookingTopologyCommand command, IMessageHandlerContext context)
        {
            var nm = new ManagementClient(_serviceBusConfiguration.ConnectionString);

            try
            {
                foreach (var qd in TopologyDefinition.QueueDescriptions())
                {
                    if (await nm.QueueExistsAsync(qd.Path))
                    {
                        await nm.GetQueueAsync(qd.Path);
                    }
                    else
                    {
                        await nm.CreateQueueAsync(qd);
                    }
                }

                foreach (var qd in TopologyDefinition.TopicDescriptions())
                {
                    if (await nm.TopicExistsAsync(qd.Path))
                    {
                        await nm.GetTopicAsync(qd.Path);
                    }
                    else
                    {
                        await nm.CreateTopicAsync(qd);
                    }
                }

                foreach (var qd in TopologyDefinition.TopicSubscriptionDescriptions())
                {
                    if (await nm.SubscriptionExistsAsync(qd.TopicPath, qd.SubscriptionName))
                    {
                        await nm.GetSubscriptionAsync(qd.TopicPath, qd.SubscriptionName);
                    }
                    else
                    {
                        await nm.CreateSubscriptionAsync(qd.TopicPath, qd.SubscriptionName);
                    }
                }
            }
            finally
            {
                await nm.CloseAsync();
            }
        }
        private void OutputDefinition(Geodatabase geodatabase, TopologyDefinition topologyDefinition)
        {
            Console.WriteLine($"Topology cluster tolerance => {topologyDefinition.GetClusterTolerance()}");
            Console.WriteLine($"Topology Z cluster tolerance => {topologyDefinition.GetZClusterTolerance()}");

            IReadOnlyList <string> featureClassNames = topologyDefinition.GetFeatureClassNames();

            Console.WriteLine($"There are {featureClassNames.Count} feature classes that are participating in the topology:");

            foreach (string name in featureClassNames)
            {
                // Open each feature class that participates in the topology.

                using (FeatureClass featureClass = geodatabase.OpenDataset <FeatureClass>(name))
                    using (FeatureClassDefinition featureClassDefinition = featureClass.GetDefinition())
                    {
                        Console.WriteLine($"\t{featureClass.GetName()} ({featureClassDefinition.GetShapeType()})");
                    }
            }
        }
        private static void ExploreTopologyErrors(Topology topology)
        {
            // Get all the errors and exceptions currently associated with the topology.

            Console.WriteLine("***************************************************************************");
            IReadOnlyList <TopologyError> allErrorsAndExceptions = topology.GetErrors(new ErrorDescription(topology.GetExtent()));

            Console.WriteLine($"There are {allErrorsAndExceptions.Count} errors and exceptions associated with the topology.");

            Console.WriteLine("OriginClassName \t OriginObjectID \t DestinationClassName \t DestinationObjectID \t RuleType \t IsException \t Shape type \t Shape width & height \t  Rule ID \t");

            foreach (TopologyError error in allErrorsAndExceptions)
            {
                Console.WriteLine($"'{error.OriginClassName}' \t {error.OriginObjectID} \t '{error.DestinationClassName}' \t " +
                                  $"{error.DestinationObjectID} \t {error.RuleType} \t {error.IsException} \t {error.Shape.GeometryType} \t " +
                                  $"{error.Shape.Extent.Width},{error.Shape.Extent.Height} \t {error.RuleID}");
            }

            // Get all the errors due to features violating the "PointProperlyInsideArea" topology rule.

            TopologyDefinition definition = topology.GetDefinition();
            TopologyRule       pointProperlyInsideAreaRule = definition.GetRules().First(rule => rule.RuleType == TopologyRuleType.PointProperlyInsideArea);

            ErrorDescription errorDescription = new ErrorDescription(topology.GetExtent())
            {
                TopologyRule = pointProperlyInsideAreaRule
            };

            IReadOnlyList <TopologyError> errorsDueToViolatingPointProperlyInsideAreaRule = topology.GetErrors(errorDescription);

            Console.WriteLine($"There are {errorsDueToViolatingPointProperlyInsideAreaRule.Count} feature violating the 'PointProperlyInsideArea' topology rule.");

            // Mark all errors from features violating the 'PointProperlyInsideArea' topology rule as exceptions.

            foreach (TopologyError error in errorsDueToViolatingPointProperlyInsideAreaRule)
            {
                topology.MarkAsException(error);
            }

            // Now verify all the errors from features violating the 'PointProperlyInsideArea' topology rule have indeed been
            // marked as exceptions.
            //
            // By default, ErrorDescription is initialized to ErrorType.ErrorAndException.  Here we want ErrorType.ErrorOnly.

            errorDescription = new ErrorDescription(topology.GetExtent())
            {
                ErrorType    = ErrorType.ErrorOnly,
                TopologyRule = pointProperlyInsideAreaRule
            };

            IReadOnlyList <TopologyError> errorsAfterMarkedAsExceptions = topology.GetErrors(errorDescription);

            Console.WriteLine($"There are {errorsAfterMarkedAsExceptions.Count} feature violating the 'PointProperlyInsideArea' topology rule after all the errors have been marked as exceptions.");

            // Finally, reset all the exceptions as errors by unmarking them as exceptions.

            foreach (TopologyError error in errorsDueToViolatingPointProperlyInsideAreaRule)
            {
                topology.UnmarkAsException(error);
            }

            IReadOnlyList <TopologyError> errorsAfterUnmarkedAsExceptions = topology.GetErrors(errorDescription);

            Console.WriteLine($"There are {errorsAfterUnmarkedAsExceptions.Count} feature violating the 'PointProperlyInsideArea' topology rule after all the exceptions have been reset as errors.");
        }
        public void WorkWithTopologyErrors()
        {
            using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\TestData\GrandTeton.gdb"))))
                using (Topology topology = geodatabase.OpenDataset <Topology>("Backcountry_Topology"))
                {
                    #region GetTopologyErrors

                    // Get all the errors and exceptions currently associated with the topology.

                    IReadOnlyList <TopologyError> allErrorsAndExceptions = topology.GetErrors(new ErrorDescription(topology.GetExtent()));
                    Console.WriteLine($"errors and exceptions count => {allErrorsAndExceptions.Count}");

                    Console.WriteLine("OriginClassName \t OriginObjectID \t DestinationClassName \t DestinationObjectID \t RuleType \t IsException \t Shape type \t Shape width & height \t  Rule ID \t");

                    foreach (TopologyError error in allErrorsAndExceptions)
                    {
                        Console.WriteLine($"'{error.OriginClassName}' \t {error.OriginObjectID} \t '{error.DestinationClassName}' \t " +
                                          $"{error.DestinationObjectID} \t {error.RuleType} \t {error.IsException} \t {error.Shape.GeometryType} \t " +
                                          $"{error.Shape.Extent.Width},{error.Shape.Extent.Height} \t {error.RuleID}");
                    }

                    #endregion GetTopologyErrors

                    #region MarkAndUnmarkAsErrors

                    // Get all the errors due to features violating the "PointProperlyInsideArea" topology rule.

                    using (TopologyDefinition topologyDefinition = topology.GetDefinition())
                    {
                        TopologyRule pointProperlyInsideAreaRule = topologyDefinition.GetRules().First(rule => rule.RuleType == TopologyRuleType.PointProperlyInsideArea);

                        ErrorDescription errorDescription = new ErrorDescription(topology.GetExtent())
                        {
                            TopologyRule = pointProperlyInsideAreaRule
                        };

                        IReadOnlyList <TopologyError> errorsDueToViolatingPointProperlyInsideAreaRule = topology.GetErrors(errorDescription);
                        Console.WriteLine($"There are {errorsDueToViolatingPointProperlyInsideAreaRule.Count} feature violating the 'PointProperlyInsideArea' topology rule.");

                        // Mark all errors from features violating the 'PointProperlyInsideArea' topology rule as exceptions.

                        foreach (TopologyError error in errorsDueToViolatingPointProperlyInsideAreaRule)
                        {
                            topology.MarkAsException(error);
                        }

                        // Now verify all the errors from features violating the 'PointProperlyInsideArea' topology rule have indeed been
                        // marked as exceptions.
                        //
                        // By default, ErrorDescription is initialized to ErrorType.ErrorAndException.  Here we want ErrorType.ErrorOnly.

                        errorDescription = new ErrorDescription(topology.GetExtent())
                        {
                            ErrorType    = ErrorType.ErrorOnly,
                            TopologyRule = pointProperlyInsideAreaRule
                        };

                        IReadOnlyList <TopologyError> errorsAfterMarkedAsExceptions = topology.GetErrors(errorDescription);
                        Console.WriteLine($"There are {errorsAfterMarkedAsExceptions.Count} feature violating the 'PointProperlyInsideArea' topology rule after all the errors have been marked as exceptions.");

                        // Finally, reset all the exceptions as errors by unmarking them as exceptions.

                        foreach (TopologyError error in errorsDueToViolatingPointProperlyInsideAreaRule)
                        {
                            topology.UnmarkAsException(error);
                        }

                        IReadOnlyList <TopologyError> errorsAfterUnmarkedAsExceptions = topology.GetErrors(errorDescription);
                        Console.WriteLine($"There are {errorsAfterUnmarkedAsExceptions.Count} feature violating the 'PointProperlyInsideArea' topology rule after all the exceptions have been reset as errors.");
                    }

                    #endregion MarkAndUnmarkAsErrors
                }
        }