private string ValidateChangedFeatures(Layer layer)
        {
            StringBuilder resultString = new StringBuilder();

            // Get utility network and geodatabase
            using (UtilityNetwork utilityNetwork = UtilityNetworkUtils.GetUtilityNetworkFromLayer(layer))
                using (Geodatabase geodatabase = utilityNetwork.GetDatastore() as Geodatabase)
                {
                    // Determine what to validate
                    //    File geodatabase - validate everything, synchronously
                    //    Default version - validate everything, asynchronously
                    //    Branch version - validate changes only, synchronously

                    bool shouldValidateEverything;
                    bool runAsync;

                    if (!geodatabase.IsVersioningSupported())
                    {
                        shouldValidateEverything = true;
                        runAsync = false;
                    }
                    else
                    {
                        using (VersionManager versionManager = geodatabase.GetVersionManager())
                            using (Version currentVersion = versionManager.GetCurrentVersion())
                            {
                                if (IsDefaultVersion(currentVersion))
                                {
                                    shouldValidateEverything = true;
                                    runAsync = true;
                                }
                                else
                                {
                                    shouldValidateEverything = false;
                                    runAsync = false;
                                }
                            }
                    }

                    // If we validating everything, get an envelope from the dirty areas table
                    EnvelopeBuilderEx envelopeBuilder = new EnvelopeBuilderEx(layer.GetSpatialReference());

                    if (shouldValidateEverything)
                    {
                        using (Table dirtyAreaTable = utilityNetwork.GetSystemTable(SystemTableType.DirtyAreas))
                            using (RowCursor rowCursor = dirtyAreaTable.Search())
                            {
                                envelopeBuilder = GetExtentFromRowCursor(envelopeBuilder, rowCursor);
                            }
                    }

                    // else get an envelope using version differences
                    else
                    {
                        using (VersionManager versionManager = geodatabase.GetVersionManager())
                            using (Version currentVersion = versionManager.GetCurrentVersion())
                                using (Version defaultVersion = currentVersion.GetParent())
                                    using (Geodatabase defaultGeodatabase = defaultVersion.Connect())
                                        using (UtilityNetwork defaultUtilityNetwork = defaultGeodatabase.OpenDataset <UtilityNetwork>(utilityNetwork.GetName()))
                                            using (Table dirtyAreaTable = utilityNetwork.GetSystemTable(SystemTableType.DirtyAreas))
                                                using (Table defaultDirtyAreaTable = defaultUtilityNetwork.GetSystemTable(SystemTableType.DirtyAreas))
                                                    using (DifferenceCursor inserts = dirtyAreaTable.Differences(defaultDirtyAreaTable, DifferenceType.Insert))
                                                    {
                                                        envelopeBuilder = GetExtentFromDifferenceCursor(envelopeBuilder, inserts);
                                                    }
                    }

                    // Run validate topology on our envelope
                    Envelope         extent = envelopeBuilder.ToGeometry();
                    ValidationResult result = utilityNetwork.ValidateNetworkTopologyInEditOperation(extent, runAsync ? ServiceSynchronizationType.Asynchronous : ServiceSynchronizationType.Synchronous);
                    if (result.HasErrors)
                    {
                        resultString.AppendLine("Errors found.");
                    }
                    else
                    {
                        resultString.AppendLine("No errors found.");
                    }
                }

            return(resultString.ToString());
        }