public int GetFabricVersion(ICadastralFabric2 pFab)
        {
            IDECadastralFabric2 pDECadaFab = null;
            IDEDataset          pDEDS      = null;
            int iVersion = -1;

            try
            {
                IDatasetComponent pDSComponent = (IDatasetComponent)pFab;
                pDEDS      = pDSComponent.DataElement;
                pDECadaFab = (IDECadastralFabric2)pDEDS;
                iVersion   = pDECadaFab.Version;
            }
            catch (COMException ex)
            {
                MessageBox.Show(ex.Message);
            }

            if (pDEDS != null)
            {
                Marshal.ReleaseComObject(pDEDS);
            }

            return(iVersion);
        }
Beispiel #2
0
        private INALayer CreateRouteAnalysisLayer(string sName, INetworkDataset pNetworkDataset)
        {
            INARouteSolver    solver   = new NARouteSolverClass();
            INASolverSettings settings = solver as INASolverSettings;
            INASolver         solver2  = solver as INASolver;

            solver.FindBestSequence  = true;
            solver.PreserveFirstStop = true;
            solver.PreserveLastStop  = false;
            solver.UseTimeWindows    = false;
            solver.OutputLines       = esriNAOutputLineType.esriNAOutputLineTrueShapeWithMeasure;
            IStringArray restrictionAttributeNames = settings.RestrictionAttributeNames;

            restrictionAttributeNames.Add("Oneway");
            settings.RestrictionAttributeNames = restrictionAttributeNames;
            IDatasetComponent component   = pNetworkDataset as IDatasetComponent;
            IDENetworkDataset dataElement = component.DataElement as IDENetworkDataset;
            INAContext        context     = solver2.CreateContext(dataElement, sName);

            (context as INAContextEdit).Bind(pNetworkDataset, new GPMessagesClass());
            INALayer layer = solver2.CreateLayer(context);

            (layer as ILayer).Name = sName;
            return(layer);
        }
Beispiel #3
0
        /*
         * This method returns the current utility network properties
         */
        private IPropertySet GetUNProperties()
        {
            IPropertySet unProps = new PropertySet();

            // Get UN
            IBaseNetwork bn = (IBaseNetwork)unDataset;

            // Get data element
            IDatasetComponent dsComponent = (IDatasetComponent)unDataset;
            IDEDataset        deDS        = dsComponent.DataElement;

            IDEBaseNetwork deBN = (IDEBaseNetwork)deDS;

            unProps.SetProperty("proVersion", deBN.ProVersion);
            unProps.SetProperty("schemaGeneration", deBN.SchemaGeneration);
            unProps.SetProperty("userIdentity", deBN.UserIdentity);
            unProps.SetProperty("creationTime", deBN.CreationTime.ToString());

            // Get topology
            IBaseNetworkTopology bnTopo = (IBaseNetworkTopology)bn;

            unProps.SetProperty("hasValidNetworkTopology", bnTopo.HasValidNetworkTopology());

            return(unProps);
        }
Beispiel #4
0
        double GetMinScaleTolerance(ICadastralFabric pFab)
        {
            IDatasetComponent   pDSComponent = (IDatasetComponent)pFab;
            IDEDataset          pDEDS        = pDSComponent.DataElement;
            IDECadastralFabric3 pDECadaFab   = (IDECadastralFabric3)pDEDS;

            IPropertySet pPropSetTol = null;

            pDECadaFab.GetPropertySet(esriCadastralPropertySetType.esriCadastralPropSetEditSettings, out pPropSetTol);

            object retVal = null;

            try
            {
                retVal = pPropSetTol.GetProperty("esriMinScaleTolerance");
            }
            catch
            {
                Marshal.ReleaseComObject(pDEDS);
                Marshal.ReleaseComObject(pPropSetTol);
                return(1.2); //default value
            }
            double d_retVal = Convert.ToDouble(retVal);

            return(d_retVal);
        }
        /// <summary>
        /// When the solver has been update, the context must be updated as well
        /// </summary>
        private void UpdateContextAfterChangingSettings()
        {
            IDatasetComponent datasetComponent = m_NAContext.NetworkDataset as IDatasetComponent;
            IDENetworkDataset deNetworkDataset = datasetComponent.DataElement as IDENetworkDataset;

            m_NAContext.Solver.UpdateContext(m_NAContext, deNetworkDataset, new GPMessagesClass());
        }
Beispiel #6
0
        /// <summary>
        /// Geodatabase function: get network dataset
        /// </summary>
        /// <param name="networkDataset">Input network dataset</param>
        /// <returns>DE network dataset</returns>
        public IDENetworkDataset GetDENetworkDataset(INetworkDataset networkDataset)
        {
            // Cast from the network dataset to the DatasetComponent
            IDatasetComponent dsComponent = networkDataset as IDatasetComponent;

            // Get the data element
            return(dsComponent.DataElement as IDENetworkDataset);
        }
Beispiel #7
0
        private int GetFabricVersion(ICadastralFabric pFab)
        {
            IDatasetComponent   pDSComponent = (IDatasetComponent)pFab;
            IDEDataset          pDEDS        = pDSComponent.DataElement;
            IDECadastralFabric2 pDECadaFab2  = (IDECadastralFabric2)pDEDS;
            int x = pDECadaFab2.Version;

            return(x);
        }
Beispiel #8
0
        private int CountPropertySetItems(ICadastralFabric pFab, esriCadastralPropertySetType PropertySetType)
        {
            IDatasetComponent   pDSComponent       = (IDatasetComponent)pFab;
            IDEDataset          pDEDS              = pDSComponent.DataElement;
            IDECadastralFabric3 pDECadaFab3        = (IDECadastralFabric3)pDEDS;
            IPropertySet        pPropSetEdSettings = null;

            pDECadaFab3.GetPropertySet(PropertySetType, out pPropSetEdSettings);
            return(pPropSetEdSettings.Count);
        }
Beispiel #9
0
        void SetMinScaleTolerance(ICadastralFabric pFab, double ScaleTolerance)
        {
            IDatasetComponent   pDSComponent       = (IDatasetComponent)pFab;
            IDEDataset          pDEDS              = pDSComponent.DataElement;
            IDECadastralFabric3 pDECadaFab3        = (IDECadastralFabric3)pDEDS;
            IPropertySet        pPropSetEdSettings = null;

            pDECadaFab3.GetPropertySet(esriCadastralPropertySetType.esriCadastralPropSetEditSettings, out pPropSetEdSettings);
            pPropSetEdSettings.SetProperty("esriMinScaleTolerance", ScaleTolerance);
            pDECadaFab3.SetPropertySet(esriCadastralPropertySetType.esriCadastralPropSetEditSettings, pPropSetEdSettings);

            //Update the schema
            ICadastralFabricSchemaEdit pSchemaEd  = (ICadastralFabricSchemaEdit)pFab;
            IDECadastralFabric         pDECadaFab = (IDECadastralFabric)pDECadaFab3;

            pSchemaEd.UpdateSchema(pDECadaFab);
        }
Beispiel #10
0
        private void CreateContextAndSolver(INetworkDataset networkDataset)
        {
            if (networkDataset == null)
            {
                return;
            }

            IDatasetComponent datasetComponent = networkDataset as IDatasetComponent;
            IDENetworkDataset deNetworkDataset = datasetComponent.DataElement as IDENetworkDataset;

            INASolver naSolver = new NAServiceAreaSolverClass();

            m_naContext = naSolver.CreateContext(deNetworkDataset, "ServiceArea");
            INAContextEdit naContextEdit = m_naContext as INAContextEdit;

            naContextEdit.Bind(networkDataset, new GPMessagesClass());
        }
Beispiel #11
0
        /// <summary>
        /// Create a new network analysis layer and set some solver settings
        /// </summary>
        private INALayer CreateRouteAnalysisLayer(String layerName, INetworkDataset networkDataset)
        {
            INARouteSolver    naRouteSolver    = new NARouteSolverClass();
            INASolverSettings naSolverSettings = naRouteSolver as INASolverSettings;
            INASolver         naSolver         = naRouteSolver as INASolver;

            //Get the NetworkDataset's Data Element
            IDatasetComponent datasetComponent = networkDataset as IDatasetComponent;
            IDENetworkDataset deNetworkDataset = datasetComponent.DataElement as IDENetworkDataset;

            //Create the NAContext and bind to it
            INAContext naContext;

            naContext = naSolver.CreateContext(deNetworkDataset, layerName);
            INAContextEdit naContextEdit = naContext as INAContextEdit;

            naContextEdit.Bind(networkDataset, new GPMessagesClass());

            //Create the NALayer
            INALayer naLayer;

            naLayer = naSolver.CreateLayer(naContext);
            (naLayer as ILayer).Name = layerName;

            //Set properties on the route solver interface
            naRouteSolver.FindBestSequence  = true;
            naRouteSolver.PreserveFirstStop = true;
            naRouteSolver.PreserveLastStop  = false;
            naRouteSolver.UseTimeWindows    = false;
            naRouteSolver.OutputLines       = esriNAOutputLineType.esriNAOutputLineTrueShapeWithMeasure;

            //Set some properties on the general INASolverSettings interface
            IStringArray restrictions = naSolverSettings.RestrictionAttributeNames;

            restrictions.Add("Oneway");
            naSolverSettings.RestrictionAttributeNames = restrictions;

            // Update the context based on the changes made to the solver settings
            naSolver.UpdateContext(naContext, deNetworkDataset, new GPMessagesClass());

            //Return the layer
            return(naLayer);
        }
Beispiel #12
0
        public static INALayer CreateNetworkAnalysisLayer(string name, INetworkDataset networkDataset,
                                                          INASolver naSolver)
        {
            if (naSolver is INARouteSolver)
            {
                return(CreateRouteAnalysisLayer(name, networkDataset, naSolver as INARouteSolver));
            }
            if (naSolver is INAClosestFacilitySolver)
            {
                return(CreateClosestFacilityLayer(name, networkDataset, naSolver as INAClosestFacilitySolver));
            }
            IDatasetComponent component   = (IDatasetComponent)networkDataset;
            IDENetworkDataset dataElement = (IDENetworkDataset)component.DataElement;
            INAContext        context     = naSolver.CreateContext(dataElement, name);

            ((INAContextEdit)context).Bind(networkDataset, null);
            INALayer layer = naSolver.CreateLayer(context);

            ((ILayer)layer).Name = name;
            return(layer);
        }
Beispiel #13
0
        public static INALayer CreateClosestFacilityLayer(string layerName, INetworkDataset networkDataset,
                                                          INAClosestFacilitySolver naClosesFacilitySolver)
        {
            INASolverSettings settings    = naClosesFacilitySolver as INASolverSettings;
            INASolver         solver      = naClosesFacilitySolver as INASolver;
            IDatasetComponent component   = networkDataset as IDatasetComponent;
            IDENetworkDataset dataElement = component.DataElement as IDENetworkDataset;
            INAContext        context     = solver.CreateContext(dataElement, layerName);

            (context as INAContextEdit).Bind(networkDataset, new GPMessagesClass());
            INALayer layer = solver.CreateLayer(context);

            (layer as ILayer).Name = layerName;
            naClosesFacilitySolver.CreateTraversalResult = true;
            naClosesFacilitySolver.TravelDirection       = esriNATravelDirection.esriNATravelDirectionFromFacility;
            naClosesFacilitySolver.OutputLines           = esriNAOutputLineType.esriNAOutputLineTrueShapeWithMeasure;
            IStringArray restrictionAttributeNames = settings.RestrictionAttributeNames;

            restrictionAttributeNames.Add("Oneway");
            settings.RestrictionAttributeNames = restrictionAttributeNames;
            solver.UpdateContext(context, dataElement, new GPMessagesClass());
            return(layer);
        }
Beispiel #14
0
        bool GetReducedRegenerateTolerance(ICadastralFabric pFab)
        {
            IDatasetComponent   pDSComponent = (IDatasetComponent)pFab;
            IDEDataset          pDEDS        = pDSComponent.DataElement;
            IDECadastralFabric3 pDECadaFab   = (IDECadastralFabric3)pDEDS;

            IPropertySet pPropSetTol = null;

            pDECadaFab.GetPropertySet(esriCadastralPropertySetType.esriCadastralPropSetEditSettings, out pPropSetTol);

            object retVal = null;

            try
            {
                retVal = pPropSetTol.GetProperty("esriReduceRegenerateTolerance");
            }
            catch
            {
                return(false); //default value
            }
            bool b_retVal = Convert.ToBoolean(retVal);

            return(b_retVal);
        }
Beispiel #15
0
        /*
         * This method executes a utility network trace to find all the low voltage service points
         * serviced by the specified transformer and returns the service points global IDs
         */
        private IStringArray FindLVServicePoints(string xfrGlobalID)
        {
            //Get required Utility Network interfaces
            IBaseNetwork      unBaseNetwork    = (IBaseNetwork)unDataset;
            IDatasetComponent datasetComponent = (IDatasetComponent)unDataset;
            IDEDataset        deDataset        = datasetComponent.DataElement;
            IDEBaseNetwork    deBaseNetwork    = (IDEBaseNetwork)deDataset;
            IDEUtilityNetwork deUtilityNetwork = (IDEUtilityNetwork)deBaseNetwork;
            IDataElement      deElement        = (IDataElement)deDataset;

            //Create and initialize network tracer
            IUtilityNetworkQuery unQry = unBaseNetwork.CreateQuery();
            ITracer unTracer           = unBaseNetwork.CreateTracer();

            unTracer.Initialize(unQry, (IDataElement)deDataset);

            // Add transformer as trace starting point
            IStringArray startGUID = new StrArrayClass();

            startGUID.Add(xfrGlobalID);
            ILongArray startTerm = new LongArrayClass();

            startTerm.Add(MV_XFR_TERMINAL_ID);

            unTracer.AddTraceLocationForJunctionFeatures(esriTraceLocationType.esriTLTStartingPoint, startGUID, startTerm);

            // Configure trace parameters
            UNTraceConfiguration traceConfig = new UNTraceConfiguration();

            traceConfig.IgnoreBarriersAtStartingPoints = true;
            traceConfig.IncludeContainers = false;
            traceConfig.IncludeBarriers   = false;
            traceConfig.IncludeContent    = true;
            traceConfig.IncludeIsolated   = false;
            traceConfig.IncludeStructures = false;
            traceConfig.IncludeUpToFirstSpatialContainer = false;
            traceConfig.DomainNetworkName   = DOMAIN_NETWORK;
            traceConfig.TierName            = MV_TIER_NAME;
            traceConfig.TargetTierName      = MV_TIER_NAME;
            traceConfig.TraversabilityScope = esriTraversabilityScope.esriTSJunctionsAndEdges;
            traceConfig.FilterScope         = esriTraversabilityScope.esriTSJunctionsAndEdges;
            traceConfig.ValidateConsistency = false;

            // Add output filter to only return service points
            IArray outFilters = new ArrayClass();

            for (int i = 0; i < LV_SERVICE_ASSETTYPES.Length; i++)
            {
                UNOutputFilter outFilter = new UNOutputFilter();
                outFilter.NetworkSourceID = DEVICE_SOURCE_ID;
                outFilter.AssetGroupCode  = LV_SERVICE_ASSETGROUP;
                outFilter.AssetTypeCode   = LV_SERVICE_ASSETTYPES[i];
                outFilters.Add(outFilter);
            }
            traceConfig.OutputFilters = outFilters;

            unTracer.TraceConfiguration = (ITraceConfiguration)traceConfig;

            // Execute the trace
            long[] jEid = new long[1];
            long[] eEid = new long[1];

            unTracer.Trace(esriUtilityNetworkTraceType.esriUNTTDownstream, out jEid, out eEid);

            // Get features from returned elements
            IUNTraceResults unTraceResults = (IUNTraceResults)unTracer;

            ILongArray   junctionNetworkSourceIDs = new LongArrayClass();
            IStringArray junctionGlobalIDs        = new StrArrayClass();
            ILongArray   junctionObjectIDs        = new LongArrayClass();
            ILongArray   junctionTerminalIDs      = new LongArrayClass();
            ILongArray   junctionAssetGroupCodes  = new LongArrayClass();
            ILongArray   junctionAssetTypeCodes   = new LongArrayClass();
            ILongArray   edgeNetworkSourceIDs     = new LongArrayClass();
            IStringArray edgeGlobalIDs            = new StrArrayClass();
            ILongArray   edgeObjectIDs            = new LongArrayClass();
            ILongArray   edgeAssetGroupCodes      = new LongArrayClass();
            ILongArray   edgeAssetTypeCodes       = new LongArrayClass();

            unTraceResults.TraceResultFeatures(out junctionNetworkSourceIDs, out junctionGlobalIDs, out junctionObjectIDs, out junctionTerminalIDs, out junctionAssetGroupCodes, out junctionAssetTypeCodes, out edgeNetworkSourceIDs, out edgeGlobalIDs, out edgeObjectIDs, out edgeAssetGroupCodes, out edgeAssetTypeCodes);

            return(junctionGlobalIDs);
        }
Beispiel #16
0
        public IDENetworkDataset GetDENetworkDataset(INetworkDataset pNetDataset)
        {
            IDatasetComponent component = pNetDataset as IDatasetComponent;

            return(component.DataElement as IDENetworkDataset);
        }
        public static void UpdateEIDArrayParameterValuesFromEIDLists(INetworkAnalystExtension nax, Dictionary <string, List <int> > eidsBySourceName, string baseName)
        {
            if (nax == null)
            {
                return;
            }

            bool             naxEnabled = false;
            IExtensionConfig naxConfig  = nax as IExtensionConfig;

            naxEnabled = naxConfig.State == esriExtensionState.esriESEnabled;

            if (!naxEnabled)
            {
                return;
            }

            INAWindow       naWindow  = nax.NAWindow;
            INALayer        naLayer   = null;
            INAContext      naContext = null;
            INetworkDataset nds       = null;

            naLayer = naWindow.ActiveAnalysis;
            if (naLayer != null)
            {
                naContext = naLayer.Context;
            }

            if (naContext != null)
            {
                nds = naContext.NetworkDataset;
            }

            if (nds == null)
            {
                return;
            }

            IDatasetComponent dsComponent = nds as IDatasetComponent;
            IDENetworkDataset deNet       = dsComponent.DataElement as IDENetworkDataset;

            INASolver          naSolver          = naContext.Solver;
            INASolverSettings2 naSolverSettings2 = naSolver as INASolverSettings2;

            if (naSolverSettings2 == null)
            {
                return;
            }

            string  prefix = GetEIDArrayPrefixFromBaseName(baseName);
            VarType vt     = GetEIDArrayParameterType();

            int cAttributes = nds.AttributeCount;

            for (int a = 0; a < cAttributes; ++a)
            {
                INetworkAttribute2 netAttribute = nds.get_Attribute(a) as INetworkAttribute2;
                IArray             netParams    = netAttribute.Parameters;
                int    cParams = netParams.Count;
                object paramValue;
                for (int p = 0; p < cParams; ++p)
                {
                    INetworkAttributeParameter param = netParams.get_Element(p) as INetworkAttributeParameter;
                    if (param.VarType != (int)vt)
                    {
                        continue;
                    }

                    string paramName  = param.Name;
                    string sourceName = GetSourceNameFromParameterName(prefix, paramName);
                    if (sourceName.Length == 0)
                    {
                        continue;
                    }

                    List <int> eids = null;
                    if (eidsBySourceName.TryGetValue(sourceName, out eids))
                    {
                        if (eids != null)
                        {
                            if (eids.Count == 0)
                            {
                                eids = null;
                            }
                        }
                    }

                    paramValue = (eids != null) ? eids.ToArray() : null;
                    naSolverSettings2.set_AttributeParameterValue(netAttribute.Name, param.Name, paramValue);
                }
            }
        }
        public static void PushParameterValuesToNetwork(INetworkAnalystExtension nax)
        {
            try
            {
                if (nax == null)
                {
                    return;
                }

                bool             naxEnabled = false;
                IExtensionConfig naxConfig  = nax as IExtensionConfig;
                naxEnabled = naxConfig.State == esriExtensionState.esriESEnabled;

                if (!naxEnabled)
                {
                    return;
                }

                INAWindow       naWindow  = nax.NAWindow;
                INALayer        naLayer   = null;
                INAContext      naContext = null;
                INetworkDataset nds       = null;

                naLayer = naWindow.ActiveAnalysis;
                if (naLayer != null)
                {
                    naContext = naLayer.Context;
                }

                if (naContext != null)
                {
                    nds = naContext.NetworkDataset;
                }

                if (nds == null)
                {
                    return;
                }

                IDatasetComponent dsComponent = nds as IDatasetComponent;
                IDENetworkDataset deNet       = dsComponent.DataElement as IDENetworkDataset;

                INASolver          naSolver          = naContext.Solver;
                INASolverSettings2 naSolverSettings2 = naSolver as INASolverSettings2;

                if (naSolverSettings2 == null)
                {
                    return;
                }

                INetworkAttribute2 netAttribute;
                string             attributeName;

                IArray netParameters;
                INetworkAttributeParameter netParameter;
                string paramName;
                int    cParameters;

                object paramValue;

                int cAttributes = nds.AttributeCount;
                for (int a = 0; a < cAttributes; ++a)
                {
                    netAttribute  = nds.get_Attribute(a) as INetworkAttribute2;
                    attributeName = netAttribute.Name;
                    netParameters = netAttribute.Parameters;

                    cParameters = netParameters.Count;
                    for (int p = 0; p < cParameters; ++p)
                    {
                        netParameter = netParameters.get_Element(p) as INetworkAttributeParameter;
                        paramName    = netParameter.Name;

                        paramValue         = naSolverSettings2.get_AttributeParameterValue(attributeName, paramName);
                        netParameter.Value = paramValue;
                    }

                    netAttribute.Refresh();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Push Parameter Values To Network");
            }
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            IGxApplication  gxApp     = m_application as IGxApplication;
            IGxDataset      gxDataset = null;
            esriDatasetType dsType    = esriDatasetType.esriDTAny;

            if (gxApp != null)
            {
                gxDataset = gxApp.SelectedObject as IGxDataset;
                dsType    = gxDataset.Type;
            }

            if (dsType != esriDatasetType.esriDTNetworkDataset)
            {
                return;
            }

            IDataset ds = gxDataset.Dataset;

            if (ds == null)
            {
                return;
            }

            INetworkDataset nds = ds as INetworkDataset;

            if (nds == null)
            {
                return;
            }

            if (!nds.Buildable)
            {
                return;
            }

            INetworkBuild netBuild = nds as INetworkBuild;

            if (netBuild == null)
            {
                return;
            }

            IDatasetComponent dsComponent = nds as IDatasetComponent;
            IDENetworkDataset deNet       = null;

            if (dsComponent != null)
            {
                deNet = dsComponent.DataElement as IDENetworkDataset;
            }

            if (deNet == null)
            {
                return;
            }

            FilterSubsetEvaluator.RemoveFilterSubsetAttribute(deNet);
            ScaleSubsetEvaluator.RemoveScaleSubsetAttributes(deNet);

            FilterSubsetEvaluator.AddFilterSubsetAttribute(deNet);
            ScaleSubsetEvaluator.AddScaleSubsetAttributes(deNet);

            netBuild.UpdateSchema(deNet);
        }
Beispiel #20
0
        private IDENetworkDataset GetDENetworkDataset(INetworkDataset networkDataset)
        {
            IDatasetComponent datasetComponent = networkDataset as IDatasetComponent;

            return(datasetComponent.DataElement as IDENetworkDataset);
        }
        public bool CadastralTableAddFieldV1(ICadastralFabric pCadaFab, esriCadastralFabricTable eTable, esriFieldType FieldType,
                                             string FieldName, string FieldAlias, int FieldLength)
        {
            ITable pTable = pCadaFab.get_CadastralTable(eTable);

            // First check to see if a field with this name already exists
            if (pTable.FindField(FieldName) > -1)
            {
                if (pTable != null)
                {
                    Marshal.ReleaseComObject(pTable);
                }
                return(false);
            }

            IDatasetComponent  pDSComponent = (IDatasetComponent)pCadaFab;
            IDEDataset         pDEDS        = pDSComponent.DataElement;
            IDECadastralFabric pDECadaFab   = (IDECadastralFabric)pDEDS;

            IField2 pField = null;

            try
            {
                //Create a new Field
                pField = new FieldClass();
                //QI for IFieldEdit
                IFieldEdit2 pFieldEdit = (IFieldEdit2)pField;
                pFieldEdit.Type_2       = FieldType;
                pFieldEdit.Editable_2   = true;
                pFieldEdit.IsNullable_2 = true;
                pFieldEdit.Name_2       = FieldName;
                pFieldEdit.AliasName_2  = FieldAlias;
                pFieldEdit.Length_2     = FieldLength;
                //'.RasterDef_2 = pRasterDef
            }
            catch (COMException ex)
            {
                if (pField != null)
                {
                    Marshal.ReleaseComObject(pField);
                }
                MessageBox.Show(ex.Message);
                return(false);
            }

            IArray pArr = pDECadaFab.CadastralTableFieldEdits;

            bool found = false;
            int  cnt   = pArr.Count;
            ICadastralTableFieldEdits pCadaTableFldEdits = null;
            IFields pFields = null;

            for (int i = 0; i <= (cnt - 1); i++)
            {
                pCadaTableFldEdits = (ICadastralTableFieldEdits)pArr.get_Element(i);
                IFieldsEdit pNewFields = new FieldsClass();
                int         fldCnt     = 0;
                if (pCadaTableFldEdits.CadastralTable == eTable)
                {
                    pFields = pCadaTableFldEdits.ExtendedAttributeFields;
                    //Copy existing fields
                    if (pFields != null)
                    {
                        fldCnt = pFields.FieldCount;
                        pNewFields.FieldCount_2 = fldCnt + 1;
                        for (int j = 0; j <= (fldCnt - 1); j++)
                        {
                            pNewFields.Field_2[j] = pFields.get_Field(j);
                        }
                    }
                    else
                    {
                        pNewFields.FieldCount_2 = 1;
                    }

                    //Add the new field
                    pNewFields.Field_2[fldCnt] = pField;
                    //reset extended attribute fields
                    pCadaTableFldEdits.ExtendedAttributeFields = pNewFields;
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                pCadaTableFldEdits = new CadastralTableFieldEditsClass();
                pCadaTableFldEdits.CadastralTable = eTable; //add the field to the table
                pFields = new FieldsClass();
                int         fldCnt      = pFields.FieldCount;
                IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;
                pFieldsEdit.FieldCount_2    = fldCnt + 1;
                pFieldsEdit.Field_2[fldCnt] = pField;
                pCadaTableFldEdits.ExtendedAttributeFields = pFields;
                pArr.Add(pCadaTableFldEdits);
                Marshal.ReleaseComObject(pFields);
            }

            //Set the CadastralTableFieldEdits property on the DE to the array
            pDECadaFab.CadastralTableFieldEdits = pArr;

            // Update the schema
            ICadastralFabricSchemaEdit pSchemaEd = (ICadastralFabricSchemaEdit)pCadaFab;

            pSchemaEd.UpdateSchema(pDECadaFab);

            Marshal.ReleaseComObject(pField);
            return(true);
        }
        private byte[] ProcessEditAreas(IServerObject serverObject, string versionName)
        {
            try
            {
                // Open utility network
                IDataset   unDataset = _soiUtil.GetUNDataset(serverObject, versionName);
                IWorkspace workspace = (IWorkspace)unDataset.Workspace;

                // Get all the dirty areas in the given validation area
                IBaseNetwork baseNetwork    = (IBaseNetwork)unDataset;
                ITable       dirtyAreaTable = baseNetwork.DirtyAreaTable;

                string shapeFieldName    = ((IFeatureClass)dirtyAreaTable).ShapeFieldName;
                int    areaFieldIndex    = dirtyAreaTable.FindField(shapeFieldName);
                int    creatorFieldIndex = dirtyAreaTable.FindField("CREATOR");

                // Get UN schema version
                IDatasetComponent dsComponent   = (IDatasetComponent)unDataset;
                IDEBaseNetwork    deBaseNetwork = (IDEBaseNetwork)dsComponent.DataElement;
                int unVersion = deBaseNetwork.SchemaGeneration;

                // Get inserts made to dirty areas table in the current version
                // For UN > V4, Errors are discarded (ERROCODE>0) to only retain true dirty areas
                // Note that changes made in the last edit session must be saved for this to work
                // as it is not possible to get the modifications until they have been saved.

                IVersionedTable versionedTable = (IVersionedTable)dirtyAreaTable;
                QueryFilter     qryFilter      = null;
                if (unVersion >= 4)
                {
                    qryFilter             = new QueryFilter();
                    qryFilter.WhereClause = _errorCodeFName + "=0";
                }

                IDifferenceCursor diffCursor = versionedTable.Differences(dirtyAreaTable, esriDifferenceType.esriDifferenceTypeInsert, qryFilter);

                // Loop through added rows to construct the modified zone extent
                int       editCount = 0;
                int       OID;
                IRow      diffRow;
                IEnvelope editZone = null;
                string    creator  = "";

                diffCursor.Next(out OID, out diffRow);

                // Return an error if no dirty areas found as it may be because the last edits were not saved
                if (diffRow == null)
                {
                    JSONObject responseJSON = new JSONObject();
                    responseJSON.AddBoolean("success", false);
                    JSONObject errorJSON = new JSONObject();
                    errorJSON.AddLong("extendedCode", (int)fdoError.FDO_E_DIRTY_AREA_BUILD_EXTENT_DO_NOT_INTERSECT);
                    errorJSON.AddString("message", "A dirty area is not present within the validate network topology input extent. A validate network topology process did not occur.");
                    JSONArray detailsJSON = new JSONArray();
                    detailsJSON.AddString("Make sure to save edits before validating.");
                    errorJSON.AddJSONArray("details", detailsJSON);
                    responseJSON.AddJSONObject("error", errorJSON);

                    return(Encoding.UTF8.GetBytes(responseJSON.ToJSONString(null)));
                }

                while (diffRow != null)
                {
                    editCount += 1;
                    creator    = diffRow.Value[creatorFieldIndex].ToString();
                    IGeometry rowShape = (IGeometry)diffRow.Value[areaFieldIndex];
                    IEnvelope rowArea  = rowShape.Envelope;
                    if (editZone != null)
                    {
                        editZone.Union(rowArea);
                    }
                    else
                    {
                        editZone = rowArea.Envelope;
                    }

                    diffCursor.Next(out OID, out diffRow);
                }
                diffCursor     = null;
                versionedTable = null;
                workspace      = null;

                // Add new or modify existing edit zone
                if (editZone != null)
                {
                    AddEditArea(serverObject, creator, versionName, editCount, editZone);
                }
            }
            catch (Exception e)
            {
                _serverLog.LogMessage(ServerLogger.msgType.infoStandard, _soiName + ".AddEditArea()",
                                      200, "Error while adding edit are: " + e.ToString());
            }

            return(null);
        }