示例#1
0
        /// <summary>
        ///     Commits the changes to the database when one or more field values have changed.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="predicate">The predicate that indicates if the field should be checked for changes.</param>
        /// <returns>
        ///     Returns a <see cref="bool" /> representing <c>true</c> when the store was called on the row; otherwise <c>false</c>
        /// </returns>
        /// <exception cref="System.ArgumentNullException">predicate</exception>
        /// <remarks>
        ///     The changes will not be saved, if there was a call to BlockReentrancy of which the IDisposable return value has not
        ///     yet been disposed of.
        /// </remarks>
        public static bool SaveChanges(this IRow source, Predicate <IField> predicate)
        {
            if (source == null)
            {
                return(false);
            }
            if (predicate == null)
            {
                throw new ArgumentNullException("predicate");
            }

            source.CheckReentrancy();

            bool        saveChanges = false;
            IRowChanges rowChanges  = (IRowChanges)source;

            for (int i = 0; i < source.Fields.FieldCount; i++)
            {
                if (predicate(source.Fields.Field[i]) && rowChanges.ValueChanged[i])
                {
                    saveChanges = true;
                    break;
                }
            }

            if (saveChanges)
            {
                source.Store();
            }

            return(saveChanges);
        }
示例#2
0
        /// <summary>
        ///     Updates the column index on the row with the value when the original value and the specified
        ///     <paramref name="value" /> are different.
        /// </summary>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <param name="source">The source.</param>
        /// <param name="index">The index of the field.</param>
        /// <param name="value">The value for the field.</param>
        /// <param name="equalityComparer">
        ///     The equality comparer to use to determine whether or not values are equal.
        ///     If null, the default equality comparer for object is used.
        /// </param>
        /// <returns>
        ///     Returns a <see cref="bool" /> representing <c>true</c> when the row updated; otherwise <c>false</c>
        /// </returns>
        /// <exception cref="IndexOutOfRangeException"></exception>
        private static bool Update <TValue>(this IRowBuffer source, int index, TValue value, IEqualityComparer <TValue> equalityComparer)
        {
            bool pendingChanges = true;

            if (equalityComparer != null)
            {
                IRowChanges rowChanges    = (IRowChanges)source;
                object      originalValue = rowChanges.OriginalValue[index];

                TValue oldValue = TypeCast.Cast(originalValue, default(TValue));
                pendingChanges = !equalityComparer.Equals(oldValue, value);
            }

            if (pendingChanges)
            {
                if (Equals(value, default(TValue)) && source.Fields.Field[index].IsNullable)
                {
                    source.Value[index] = DBNull.Value;
                }
                else
                {
                    source.Value[index] = value;
                }
            }

            return(pendingChanges);
        }
示例#3
0
        /// <summary>
        ///     Gets the field name and original value for those fields that have changed.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="fieldNames">The field names.</param>
        /// <returns>
        ///     Returns a <see cref="Dictionary{String, Object}" /> representing the field name / original values for those fields
        ///     that have changed.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">fieldNames</exception>
        public static Dictionary <string, object> GetChanges(this IRow source, params string[] fieldNames)
        {
            if (source == null)
            {
                return(null);
            }
            if (fieldNames == null)
            {
                throw new ArgumentNullException("fieldNames");
            }

            Dictionary <string, object> list = new Dictionary <string, object>(StringComparer.Create(CultureInfo.CurrentCulture, true));

            IRowChanges rowChanges = (IRowChanges)source;

            for (int i = 0; i < source.Fields.FieldCount; i++)
            {
                foreach (var fieldName in fieldNames)
                {
                    if (source.Fields.Field[i].Name.Equals(fieldName, StringComparison.OrdinalIgnoreCase))
                    {
                        if (rowChanges.ValueChanged[i] && !list.ContainsKey(fieldName))
                        {
                            list.Add(fieldName, rowChanges.OriginalValue[i]);
                        }
                    }
                }
            }

            return(list);
        }
        /// <summary>
        /// Indicate if the given field is changed.
        /// </summary>
        /// <param name="feature"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public static bool FieldChanged(this IFeature feature, string fieldName)
        {
            IRowChanges rowChanges = feature as IRowChanges;
            string      Oldval     = rowChanges.OriginalValue[feature.Fields.FindField(fieldName)].ToString();
            string      newval     = feature.Value[feature.Fields.FindField(fieldName)].ToString();

            if (Oldval.Trim() != newval.Trim())
            {
                return(true);
            }

            return(false);
        }
示例#5
0
        /// <summary>
        ///     Gets the indexes and field names for all of the fields that have changed values.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <returns>
        ///     Returns a <see cref="Dictionary{Int32, String}" /> representing the indexes/names of the fields that have changed.
        /// </returns>
        public static Dictionary <int, string> GetChanges(this IRow source)
        {
            if (source == null)
            {
                return(null);
            }

            Dictionary <int, string> list = new Dictionary <int, string>();
            IRowChanges rowChanges        = (IRowChanges)source;

            for (int i = 0; i < source.Fields.FieldCount; i++)
            {
                if (rowChanges.ValueChanged[i])
                {
                    list.Add(i, source.Fields.Field[i].Name);
                }
            }

            return(list);
        }
        public void SetDynamicValues(IObject inObject, string mode)
        {
            IFeature inFeature = null;
            // IRow inRow = null;

            IMSegmentation mseg = null;
            INetworkFeature netFeat = null;
            IEdgeFeature edgeFeat = null;
            IFeature juncFeat;
            IJunctionFeature iJuncFeat;
            //ProgressBar
            ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = null;
            ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = null;
            ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = null;
            // Create a CancelTracker
            ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass();

            try
            {
                if (AAState._PerformUpdates && AAState._dv == null)
                {

                    AAState.WriteLine("Dynamic Value Table is missing - Name in Config:" + AAState._defaultsTableName);

                    //    MessageBox.Show("The Attribute Assistant is turned on, but the Dynamic Value table is missing, please add the table and toggle the extension on");
                    AAState._PerformUpdates = false;
                    return;
                }
                if (AAState._PerformUpdates && AAState._dv != null)
                {
                    if (inObject == null)
                        return;
                    //Convert row to feature (test for feature is null before using - this could be a table update)
                    inFeature = inObject as IFeature;
                    // inRow = inObject as IRow;
                    string modeVal;

                    if (AAState._dv.Table.Columns[mode].DataType == System.Type.GetType("System.String"))
                    {
                        modeVal = "(" + mode + " = '1' or " + mode + " = 'Yes' or " + mode + " = 'YES' or " + mode + " = 'True' or " + mode + " = 'TRUE')";

                    }
                    else
                    {
                        modeVal = mode + " = 1";
                    }
                    System.Int32 int32_hWnd = ArcMap.Application.hWnd;

                    progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass();
                    stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd);

                    stepProgressor.MinRange = 0;
                    stepProgressor.MaxRange = inObject.Fields.FieldCount;
                    stepProgressor.StepValue = 1;
                    stepProgressor.Message = "Attribute Assistant Progress";
                    // Create the ProgressDialog. This automatically displays the dialog
                    progressDialog = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast

                    // Set the properties of the ProgressDialog
                    progressDialog.CancelEnabled = true;
                    progressDialog.Description = "Checking rules for " + inObject.Class.AliasName;
                    progressDialog.Title = "Attribute Assistant Progress";
                    progressDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressGlobe;
                    progressDialog.ShowDialog();
                    //for each field in this row/feature
                    // Skip orphan junctions (saves time)

                    if (Globals.isOrpanJunction(inFeature))
                        return;
                    //Get table name for this feature
                    _currentDataset = inObject.Class as IDataset;
                    _currentDatasetNameItems = _currentDataset.Name.Split('.');
                    tableName = _currentDatasetNameItems[_currentDatasetNameItems.GetLength(0) - 1];

                    for (int fieldNum = 0; fieldNum <= inObject.Fields.FieldCount; fieldNum++)
                    {

                        stepProgressor.Step();
                        bool editable = true;
                        if (fieldNum == inObject.Fields.FieldCount)
                        {
                            fieldObj = null;

                            fieldName = "";
                            stepProgressor.Message = "Checking rules for field null fields in" + inObject.Class.AliasName;
                            progressDialog.Description = "Checking rules for field null fields in" + inObject.Class.AliasName;
                            AAState.WriteLine("***********************************************************");
                            AAState.WriteLine("");

                            AAState.WriteLine("############ " + DateTime.Now + " ################");
                            editable = true;
                            //  fieldNum++;

                        }
                        else
                        {
                            fieldObj = inObject.Fields.get_Field(fieldNum);

                            fieldName = fieldObj.Name;
                            stepProgressor.Message = "Checking rules for field " + fieldName + " in " + inObject.Class.AliasName;
                            progressDialog.Description = "Checking rules for field " + fieldName + " in " + inObject.Class.AliasName;
                            AAState.WriteLine("***********************************************************");
                            AAState.WriteLine("");
                            AAState.WriteLine("############ " + fieldName + " ################");
                            AAState.WriteLine("############ " + DateTime.Now + " ################");
                            AAState.WriteLine("Is field -  " + fieldName + " Editable = " + fieldObj.Editable);
                            editable = fieldObj.Editable;
                        }
                        bool proc = false;
                        if (editable == true && fieldObj != null)
                        {
                            AAState.WriteLine("Checking rules for field " + fieldName + " in " + inObject.Class.AliasName);

                            AAState._dv.RowFilter = "(TABLENAME = '" + tableName + "' OR TABLENAME like '" + tableName + "|*' OR TABLENAME like '" + tableName + "|%') And FIELDNAME = '" + fieldName + "' and " + modeVal;
                            //AAState._dv.rw
                            AAState.WriteLine("    Row Query: " + "TABLENAME = '" + tableName + "' OR TABLENAME like '" + tableName + "|*' OR TABLENAME like '" + tableName + "|%') And FIELDNAME = '" + fieldName + "' and " + modeVal);
                            if (AAState._dv.Count == 0)
                            {
                                AAState._dv.RowFilter = "TABLENAME = '*' And FIELDNAME = '" + fieldName + "' and " + modeVal;

                                AAState.WriteLine("    Query using " + fieldName + " did not produce any results, trying all fields");
                                AAState.WriteLine("    Row Query: " + "TABLENAME = '*' And FIELDNAME = '" + fieldName + "' and " + modeVal);
                            }
                            if (AAState._dv.Count == 0)
                            {
                                AAState.WriteLine("    No entries found");
                                proc = false;
                            }
                            else
                            {
                                proc = true;
                            }

                        }
                        //   else if (editable == false )
                        //{
                        //    AAState.WriteLine("Checking rules for field " + fieldName + " in " + inObject.Class.AliasName);

                        //    AAState._dv.RowFilter = "(TABLENAME = '" + tableName + "' OR TABLENAME like '" + tableName + "|*' OR TABLENAME like '" + tableName + "|%') And FIELDNAME = '" + fieldName + "' and " + modeVal;
                        //    //AAState._dv.rw
                        //    AAState.WriteLine("    Row Query: " + "TABLENAME = '" + tableName + "' OR TABLENAME like '" + tableName + "|*' OR TABLENAME like '" + tableName + "|%') And FIELDNAME = '" + fieldName + "' and " + modeVal);
                        //    if (AAState._dv.Count == 0)
                        //    {
                        //        AAState._dv.RowFilter = "TABLENAME = '*' And FIELDNAME = '" + fieldName + "' and " + modeVal;

                        //        AAState.WriteLine("    Query using " + fieldName + " did not produce any results, trying all fields");
                        //        AAState.WriteLine("    Row Query: " + "TABLENAME = '*' And FIELDNAME = '" + fieldName + "' and " + modeVal);
                        //    }
                        //    if (AAState._dv.Count == 0)
                        //    {
                        //        AAState.WriteLine("    No entries found");
                        //        proc = false;
                        //    }
                        //    else
                        //    {
                        //        proc = true;
                        //    }

                        //}
                        else if (editable && fieldObj == null)
                        {
                            fieldName = "";
                            AAState._dv.RowFilter = "(TABLENAME = '" + tableName + "' OR TABLENAME like '" + tableName + "|*' OR TABLENAME like '" + tableName + "|%') And (FIELDNAME = '" + fieldName + "' or FIELDNAME IS NULL) and " + modeVal;
                            //AAState._dv.rw
                            AAState.WriteLine("    Row Query: " + "TABLENAME = '" + tableName + "' OR TABLENAME like '" + tableName + "|*' OR TABLENAME like '" + tableName + "|%') And (FIELDNAME = '" + fieldName + "' or FIELDNAME IS NULL) and " + modeVal);
                            if (AAState._dv.Count == 0)
                            {
                                AAState._dv.RowFilter = "TABLENAME = '*' And (FIELDNAME = '" + fieldName + "' or FIELDNAME IS NULL) and " + modeVal;

                                AAState.WriteLine("    Query using " + fieldName + " did not produce any results, trying all fields");
                                AAState.WriteLine("    Row Query: " + "TABLENAME = '*' And And (FIELDNAME = '" + fieldName + "' or FIELDNAME IS NULL) and " + modeVal);
                            }
                            if (AAState._dv.Count == 0)
                            {
                                AAState.WriteLine("    No entries found");
                                proc = false;
                            }
                            else
                            {
                                proc = true;
                            }
                        }
                        if (proc)
                        {

                            AAState.WriteLine("          Value Entry Rows found: " + AAState._dv.Count);
                            AAState.WriteLine("          ----------------------------------------------");
                            // Get requested method and any data parameters
                            AAState.WriteLine("          Looping through Value Methods");
                            AAState.WriteLine("                  ------------------------");
                            foreach (DataRowView drv in AAState._dv)
                            {

                                AAState.WriteLine("                  Checking for Subtype Restriction");
                                valFC = drv["TABLENAME"].ToString().Trim();
                                if (valFC.Contains("|"))
                                {
                                    AAState.WriteLine("                  Subtype restriction Found");
                                    string[] spliVal = valFC.Split('|');

                                    if (Globals.IsInteger(spliVal[1]))
                                    {
                                        int SubVal = Convert.ToInt32(spliVal[1]);
                                        ISubtypes pSub = inObject.Class as ISubtypes;
                                        if (pSub != null)
                                        {
                                            if (pSub.HasSubtype)
                                            {
                                                int obSubVal = (int)inObject.get_Value(pSub.SubtypeFieldIndex);
                                                if (obSubVal == SubVal)
                                                {
                                                    AAState.WriteLine("                  Subtypes match");
                                                }
                                                else
                                                {
                                                    AAState.WriteLine("                  Skipping, not the subtype defined");
                                                    continue;
                                                }
                                            }
                                            else
                                            {
                                                AAState.WriteLine("                  ERROR: Layer does not have subtypes");
                                            }
                                        }
                                        else
                                        {
                                            AAState.WriteLine("                  ERROR: Layer does not have subtypes");
                                        }
                                    }
                                    else
                                    {
                                        AAState.WriteLine("                  ERROR: Subtype not an integar");
                                    }
                                }
                                valMethod = drv["VALUEMETHOD"].ToString().ToUpper().Trim();
                                valData = drv["VALUEINFO"].ToString().Trim();

                                AAState.WriteLine("                  VALUEMETHOD: " + valMethod);
                                AAState.WriteLine("                  VALUEINFO: " + valData);
                                AAState.WriteLine("                  ------------------------");
                                //set field value based on specified method
                                try
                                {
                                    switch (valMethod)
                                    {
                                        case "SPLIT_INTERSECTING_FEATURE":
                                            {
                                                AAState.WriteLine("                  Trying: SPLIT_INTERSECTING_FEATURE");

                                                try
                                                {
                                                    if ((valData != null) && (inFeature != null))
                                                    {
                                                        intersectLayerName = "";
                                                        intersectLayer = null;
                                                        args = valData.Split('|');
                                                        if (args.Length > 0)
                                                        {
                                                            AAState.WriteLine("                  " + args.Length + " Layers listed ");

                                                            for (int i = 0; i < args.Length; i++)
                                                            {

                                                                intersectLayerName = args[i].Trim();
                                                                AAState.WriteLine("                  Searching for " + intersectLayerName);

                                                                intersectLayer = Globals.FindLayer(AAState._editor.Map, intersectLayerName) as IFeatureLayer;

                                                                if (intersectLayer != null)
                                                                {
                                                                    AAState.WriteLine("                  Layer Found " + intersectLayerName);
                                                                    if (intersectLayer.FeatureClass != null)
                                                                    {
                                                                        AAState.WriteLine("                  Datasource is valid for " + intersectLayerName);

                                                                        sFilter = new SpatialFilterClass();
                                                                        AAState.WriteLine("                  Checking source Geometry Type");

                                                                        if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                                        {
                                                                            // esriSpatialRelIntersects does not work properly for point intersecting line.
                                                                            // hence expand point envelope (code cribbed from below)
                                                                            try
                                                                            {
                                                                                ISpatialReferenceResolution pSRResolution;

                                                                                pSRResolution = ((sourceLayer.FeatureClass as IGeoDataset).SpatialReference) as ISpatialReferenceResolution;

                                                                                //  sFilter = new SpatialFilterClass();
                                                                                double intTol = pSRResolution.get_XYResolution(false);
                                                                                bool hasXY = ((sourceLayer.FeatureClass as IGeoDataset).SpatialReference).HasXYPrecision();

                                                                                searchEnvelope = new EnvelopeClass();
                                                                                searchEnvelope.XMin = 0 - intTol;
                                                                                searchEnvelope.YMin = 0 - intTol;
                                                                                searchEnvelope.XMax = 0 + intTol;
                                                                                searchEnvelope.YMax = 0 + intTol;
                                                                                searchEnvelope.CenterAt(inFeature.ShapeCopy as IPoint);

                                                                                //searchEnvelope.SpatialReference = ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference;
                                                                                searchEnvelope.SpatialReference = ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference;
                                                                                searchEnvelope.SnapToSpatialReference();
                                                                                searchEnvelope.Project(AAState._editor.Map.SpatialReference);

                                                                                sFilter.Geometry = Globals.Env2Polygon(searchEnvelope);

                                                                            }
                                                                            catch
                                                                            {
                                                                                sFilter.Geometry = inFeature.ShapeCopy;
                                                                            }

                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  Geoemetry is not a point, using shape envelope");

                                                                            sFilter.Geometry = inFeature.ShapeCopy;
                                                                        }
                                                                        sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                                                        sFilter.GeometryField = intersectLayer.FeatureClass.ShapeFieldName;
                                                                        AAState.WriteLine("                  Searching " + intersectLayerName + "for intersected feature");

                                                                        fCursor = intersectLayer.FeatureClass.Search(sFilter, true);
                                                                        IFeature intsersectFeature;
                                                                        int idx = 1;
                                                                        while ((intsersectFeature = fCursor.NextFeature()) != null)
                                                                        {
                                                                            AAState.WriteLine("                  Splitting Intersected Feature number: " + idx);
                                                                            idx++;

                                                                            IFeatureEdit featureEdit = intsersectFeature as IFeatureEdit;
                                                                            ISet featset = featureEdit.Split(inFeature.Shape);
                                                                            AAState.WriteLine("                  Adding split features to array to call the AA ext");

                                                                            if (featset.Count > 0)
                                                                            {
                                                                                if (newFeatureList == null)
                                                                                {
                                                                                    newFeatureList = new List<IObject>();
                                                                                }
                                                                                object featobj;
                                                                                while ((featobj = featset.Next()) != null)
                                                                                {
                                                                                    IFeature feature = featobj as IFeature;
                                                                                    if (feature != null)
                                                                                    {
                                                                                        newFeatureList.Add(feature as IObject);
                                                                                    }
                                                                                }
                                                                            }
                                                                            AAState.WriteLine("                  Split feature " + intersectLayerName + " into " + featset.Count);
                                                                            if (intsersectFeature != null)
                                                                            {
                                                                                Marshal.ReleaseComObject(intsersectFeature);
                                                                            }

                                                                        }
                                                                    }
                                                                }

                                                                else
                                                                {
                                                                    AAState.WriteLine("                  Warning: Can't find intersecting layer: " + intersectLayerName);
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  ERROR: Unsupported Value Info: " + valData);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: not a feature or no Value Info");
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    AAState.WriteLine("                  ERROR: SPLIT_INTERSECTING_FEATURE" + Environment.NewLine + ex.Message);
                                                }

                                                finally
                                                {
                                                    AAState.WriteLine("                  Finished: SPLIT_INTERSECTING_FEATURE");
                                                }
                                                break;
                                            }

                                        case "NEAREST_FEATURE_ATTRIBUTES":
                                            {
                                                AAState.WriteLine("                  Trying NEAREST_FEATURE_ATTRIBUTES");
                                                try
                                                {
                                                    if ((valData != null) && (inFeature != null))
                                                    {
                                                        sourceLayerName = "";
                                                        string[] sourceFieldNames = null;
                                                        string[] destFieldNames = null;
                                                        searchDistance = 0;

                                                        // Parse arguments
                                                        args = valData.Split('|');
                                                        if (args.Length == 3)
                                                        {
                                                            sourceLayerName = args[0].ToString().Trim();
                                                            sourceFieldNames = args[1].ToString().Split(',');
                                                            destFieldNames = args[2].ToString().Split(',');
                                                            AAState.WriteLine("                  WARNING:  search distance as not specified, defaulting to 0");

                                                        }
                                                        else if (args.Length == 4)
                                                        {
                                                            sourceLayerName = args[0].ToString().Trim();
                                                            sourceFieldNames = args[1].ToString().Split(',');
                                                            destFieldNames = args[2].ToString().Split(',');
                                                            Double.TryParse(args[3], out searchDistance);
                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  ERROR:  the valuemethod is not defined properly for this rule");
                                                            continue;

                                                        }

                                                        if ((sourceFieldNames != null) && (destFieldNames != null) &&
                                                            (sourceFieldNames.Length > 0) && (destFieldNames.Length > 0) &&
                                                            (sourceFieldNames.Length == destFieldNames.Length))
                                                        {
                                                            AAState.WriteLine("                  Looking for layer: " + sourceLayerName);

                                                            sourceLayer = Globals.FindLayer(AAState._editor.Map, sourceLayerName) as IFeatureLayer;
                                                            if (sourceLayer != null)
                                                            {
                                                                if (sourceLayer.FeatureClass != null)
                                                                {
                                                                    AAState.WriteLine("                  layer Found: " + sourceLayerName);

                                                                    string missingFieldMess = null;
                                                                    int[] sourceFieldNums = new int[sourceFieldNames.Length];
                                                                    int[] destFieldNums = new int[destFieldNames.Length];
                                                                    AAState.WriteLine("                  Checking Field Mapping");

                                                                    for (int i = 0; i < sourceFieldNums.Length; i++)
                                                                    {
                                                                        int fnum = sourceLayer.FeatureClass.FindField(sourceFieldNames[i].Trim());
                                                                        if (fnum < 0)
                                                                        {
                                                                            missingFieldMess = sourceFieldNames[i].Trim() + " in table " + sourceLayerName;
                                                                            break;
                                                                        }
                                                                        sourceFieldNums[i] = fnum;
                                                                    }
                                                                    if (missingFieldMess == null)
                                                                    {
                                                                        for (int i = 0; i < destFieldNums.Length; i++)
                                                                        {
                                                                            int fnum = inFeature.Fields.FindField(destFieldNames[i].Trim());
                                                                            if (fnum < 0)
                                                                            {
                                                                                missingFieldMess = destFieldNames[i].Trim() + " in table " + tableName;
                                                                                break;
                                                                            }
                                                                            destFieldNums[i] = fnum;
                                                                        }
                                                                    }
                                                                    if (missingFieldMess == null)
                                                                    {
                                                                        AAState.WriteLine("                  Field Mapping verified");

                                                                        // found source and destination fields.
                                                                        sFilter = new SpatialFilterClass();

                                                                        if (searchDistance > 0)
                                                                        {
                                                                            searchEnvelope = inFeature.ShapeCopy.Envelope;
                                                                            searchEnvelope.Expand(searchDistance, searchDistance, false);
                                                                            sFilter.Geometry = searchEnvelope;
                                                                        }
                                                                        else
                                                                            sFilter.Geometry = inFeature.ShapeCopy;

                                                                        sFilter.GeometryField = sourceLayer.FeatureClass.ShapeFieldName;
                                                                        sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                                                        AAState.WriteLine("                  Searching for Nearest Feature");

                                                                        fCursor = sourceLayer.FeatureClass.Search(sFilter, false);
                                                                        sourceFeature = fCursor.NextFeature();
                                                                        nearestFeature = null;

                                                                        proxOp = (IProximityOperator)inFeature.Shape;
                                                                        lastDistance = searchDistance;
                                                                        if (sourceFeature != null)
                                                                        {
                                                                            AAState.WriteLine("                  Features Found, looping for closest");

                                                                            while (sourceFeature != null)
                                                                            {

                                                                                distance = proxOp.ReturnDistance(sourceFeature.Shape);
                                                                                if (distance <= lastDistance)
                                                                                {
                                                                                    nearestFeature = sourceFeature;
                                                                                    lastDistance = distance;
                                                                                }
                                                                                sourceFeature = fCursor.NextFeature();
                                                                            }
                                                                        }
                                                                        if (nearestFeature != null)
                                                                        {
                                                                            AAState.WriteLine("                  Closest Feature is " + lastDistance + " Away with OID of " + nearestFeature.OID);

                                                                            for (int i = 0; i < sourceFieldNums.Length; i++)
                                                                            {
                                                                                try
                                                                                {
                                                                                    AAState.WriteLine("                  Trying to copy " + sourceFieldNums[i] + " to " + destFieldNums[i]);

                                                                                    inObject.set_Value(destFieldNums[i], nearestFeature.get_Value(sourceFieldNums[i]));
                                                                                }
                                                                                catch
                                                                                {
                                                                                    AAState.WriteLine("                  ERROR: copying " + sourceFieldNums[i] + " to " + destFieldNums[i]);

                                                                                }
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  No Feature was found, default fields");

                                                                            for (int i = 0; i < destFieldNums.Length; i++)
                                                                            {
                                                                                IField field = inObject.Fields.get_Field(destFieldNums[i]);
                                                                                object newval = field.DefaultValue;
                                                                                if (newval == null)
                                                                                {
                                                                                    if (field.IsNullable)
                                                                                    {
                                                                                        inObject.set_Value(destFieldNums[i], null);
                                                                                    }
                                                                                }
                                                                                else
                                                                                {
                                                                                    inObject.set_Value(destFieldNums[i], newval);
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        AAState.WriteLine("                  ERROR: Cant find field " + missingFieldMess);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    AAState.WriteLine("                  ERROR: " + sourceLayerName + " data source is not set");
                                                                }
                                                            }
                                                            else
                                                            {
                                                                AAState.WriteLine("                  ERROR: " + sourceLayerName + " was not found");
                                                            }
                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  ERROR: Invalid Value Info: " + valData);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Not a feature or missing Value Info");
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    AAState.WriteLine("                  ERROR: EUK_NEAREST_FEATURE_ATTRIBUTES" + Environment.NewLine + ex.Message);
                                                }

                                                finally
                                                {
                                                    AAState.WriteLine("                  Finished: EUK_NEAREST_FEATURE_ATTRIBUTES");
                                                }
                                                break;
                                            }
                                        case "MINIMUM_LENGTH":
                                            {
                                                try
                                                {
                                                    AAState.WriteLine("                  Trying MINIMUM_LENGTH");

                                                    double minlength;
                                                    AAState.WriteLine("                  Evaluating Minimum length value");

                                                    if (Double.TryParse(valData, out minlength))
                                                    {
                                                        if (inFeature != null)
                                                        {
                                                            ICurve curve = inFeature.Shape as ICurve;
                                                            if (curve != null)
                                                            {
                                                                if (curve.Length < minlength)
                                                                {
                                                                    String mess = "Line is shorter than " +
                                                                        String.Format("{0:0.00}", minlength) + " " + Globals.GetSpatRefUnitName(inFeature.Shape.SpatialReference, true) +
                                                                        ", aborting edit.";
                                                                    AAState.WriteLine("                  " + mess);

                                                                    MessageBox.Show(mess, "Line too short");
                                                                    AAState._editor.AbortOperation();
                                                                    return;
                                                                }
                                                            }
                                                            else
                                                            {
                                                                AAState.WriteLine("                  ERROR:  Feature is not a Line");

                                                            }
                                                        }
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    AAState.WriteLine("                  Error MINIMUM_LENGTH \n" + ex.Message);
                                                }
                                                finally
                                                {
                                                    AAState.WriteLine("                  Finished MINIMUM_LENGTH");

                                                }

                                                break;
                                            }
                                        case "LINK_TABLE_ASSET":
                                            try
                                            {
                                                intersectLayerName = "";
                                                intersectTable = null;
                                                intersectLayer = null;
                                                intersectLayerFieldName = "";
                                                AAState.WriteLine("                  Trying LINK_TABLE_ASSET");
                                                args = valData.Split('|');
                                                switch (args.GetLength(0))
                                                {
                                                    case 1:  // Feature Layer only
                                                        intersectLayerName = args[0].ToString();
                                                        break;
                                                    case 2:  // Feature Layer| Field to copy
                                                        intersectLayerName = args[0].ToString();
                                                        intersectLayerFieldName = args[1].ToString();

                                                        break;
                                                    case 3:  // Feature Layer| Field to copy | for future
                                                        intersectLayerName = args[0].ToString();
                                                        intersectLayerFieldName = args[1].ToString();
                                                        //sequenceColumnName = args[2].ToString();
                                                        break;
                                                    default:
                                                        AAState.WriteLine("                  ERROR: Unsupported Value Method: " + valData);
                                                        break;
                                                }
                                                intersectLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, intersectLayerName);
                                                intersectTable = Globals.FindStandAloneTable(AAState._editor.Map, intersectLayerName);
                                                ICursor cCurs = null;
                                                if (intersectLayer != null)
                                                {
                                                    //Find Area Field
                                                    intersectFieldPos = intersectLayer.FeatureClass.Fields.FindField(intersectLayerFieldName);
                                                    if (intersectFieldPos < 0)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Asset feature Layer Field(" + intersectLayerFieldName + ") not found");
                                                        break;
                                                    }
                                                    intersectLayerSelection = (IFeatureSelection)intersectLayer;
                                                    if (intersectLayerSelection.SelectionSet.Count == 0)
                                                    {
                                                        AAState.WriteLine("                  ERROR: No assests selected in " + intersectLayerName);

                                                        break;
                                                    }
                                                    if (intersectLayerSelection.SelectionSet.Count > 1)
                                                    {
                                                        AAState.WriteLine("                  ERROR: To many assests are selected in " + intersectLayerName);

                                                        break;
                                                    }

                                                    intersectLayerSelection.SelectionSet.Search(null, true, out cCurs);
                                                }
                                                else if (intersectTable != null)
                                                {
                                                    if (intersectTable.Table == null)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Asset  Layer(" + intersectLayerName + ") not found");
                                                        break;
                                                    }
                                                    //Find Area Field
                                                    intersectFieldPos = intersectTable.Table.Fields.FindField(intersectLayerFieldName);
                                                    if (intersectFieldPos < 0)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Asset Layer Field(" + intersectLayerFieldName + ") not found");
                                                        break;
                                                    }
                                                    intersectTableSelection = (ITableSelection)intersectTable;
                                                    if (intersectTableSelection.SelectionSet.Count == 0)
                                                    {
                                                        AAState.WriteLine("                  ERROR: No assests selected in " + intersectLayerName);

                                                        break;
                                                    }
                                                    if (intersectTableSelection.SelectionSet.Count > 1)
                                                    {
                                                        AAState.WriteLine("                  ERROR: To many assests are selected in " + intersectLayerName);

                                                        break;
                                                    }

                                                    intersectTableSelection.SelectionSet.Search(null, true, out cCurs);
                                                }
                                                else
                                                {
                                                    AAState.WriteLine("                  ERROR: Asset  Layer(" + intersectLayerName + ") not found");
                                                    break;
                                                }

                                                IRow row;

                                                while ((row = cCurs.NextRow()) != null)
                                                {
                                                    string val = row.get_Value(intersectFieldPos).ToString();

                                                    if (inObject.Fields.get_Field(fieldNum).Type == esriFieldType.esriFieldTypeString)
                                                        inObject.set_Value(fieldNum, val);
                                                    else
                                                    {
                                                        if (Globals.IsNumeric(val))
                                                        {

                                                            inObject.set_Value(fieldNum, row.get_Value(intersectFieldPos));
                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  ERROR: Field is a number and ID from Asset is not - ID:" + val);

                                                        }
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: LINK_TABLE_ASSET" + Environment.NewLine + ex.Message);
                                            }

                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: LINK_TABLE_ASSET");
                                            }
                                            break;

                                        case "GET_ADDRESS_USING_GEOCODER":
                                            {
                                                try
                                                {
                                                    AAState.WriteLine("                  Trying GET_ADDRESS_USING_GEOCODER");

                                                    if (!String.IsNullOrEmpty(valData))
                                                    {
                                                        args = valData.Split('|');
                                                        if (args.Length != 2)
                                                        {
                                                            AAState.WriteLine("                  ERROR: Format of valdata incorrect");
                                                            break;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Format of valdata incorrect");
                                                        break;
                                                    }
                                                    AAState.WriteLine("                  Trying to get address locator");
                                                    IReverseGeocoding reverseGeocoding = Globals.OpenLocator(args[0], args[1]);

                                                    if (reverseGeocoding == null)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Reverse Address not locator found");
                                                        break;
                                                    }
                                                    AAState.WriteLine("                  Reverse Address locator found");
                                                    AAState.WriteLine("                  Retrieving Location to reverse geocode");
                                                    IPoint revGCLoc = Globals.GetGeomCenter(inFeature);
                                                    AAState.WriteLine("                  Location retrieved");
                                                    // Create a Point at which to find the address.
                                                    IAddressGeocoding addressGeocoding = (IAddressGeocoding)reverseGeocoding;

                                                    IFields matchFields = addressGeocoding.MatchFields;
                                                    int shpFld = matchFields.FindField("Shape");

                                                    IField shapeField = matchFields.get_Field(shpFld);
                                                    AAState.WriteLine("                  Setting distance");
                                                    // Set the search tolerance for reverse geocoding.
                                                    IReverseGeocodingProperties reverseGeocodingProperties =
                                                        (IReverseGeocodingProperties)reverseGeocoding;
                                                    reverseGeocodingProperties.SearchDistance = 100;
                                                    reverseGeocodingProperties.SearchDistanceUnits = esriUnits.esriFeet;

                                                    // Find the address nearest the Point.
                                                    IPropertySet addressProperties = reverseGeocoding.ReverseGeocode(revGCLoc, false);

                                                    // Print the address properties.
                                                    IAddressInputs addressInputs = (IAddressInputs)reverseGeocoding;
                                                    IFields addressFields = addressInputs.AddressFields;
                                                    object key, value;
                                                    addressProperties.GetAllProperties(out key, out value);

                                                    //object[] keyArray = key as object[];
                                                    //object[] valueArray = value as object[];

                                                    //for (int i = 0; i < keyArray.Length; i++)
                                                    //{
                                                    //    if (keyArray[i].ToString() == "Shape")
                                                    //    {
                                                    //        IPoint addressPoint = valueArray[i] as IPoint;
                                                    //        Console.WriteLine(keyArray[i] + " = " + addressPoint.X + ", " +
                                                    //            addressPoint.Y);
                                                    //    }
                                                    //    else
                                                    //        Console.WriteLine(keyArray[i] + " = " + valueArray[i]);
                                                    //}
                                                    for (int i = 0; i < addressFields.FieldCount; i++)
                                                    {
                                                        IField addressField = addressFields.get_Field(i);
                                                        string tempVal = addressProperties.GetProperty(addressField.Name).ToString();

                                                        inFeature.set_Value(fieldNum, tempVal);

                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    AAState.WriteLine("                  ERROR: GET_ADDRESS_USING_GEOCODER" + Environment.NewLine + ex.Message);
                                                }

                                                finally
                                                {
                                                    AAState.WriteLine("                  Finished: GET_ADDRESS_USING_GEOCODER");
                                                }
                                                break;

                                            }
                                            break;

                                        case "GET_ADDRESS_USING_ARCGIS_SERVICE":  //ARGS: url
                                            try
                                            {
                                                AAState.WriteLine("                  Trying GET_ADDRESS_USING_ARCGIS_SERVICE");
                                                if (fieldObj.Type == esriFieldType.esriFieldTypeString)
                                                {
                                                    if ((inFeature != null) && (inFeature.Shape != null) && !(inFeature.Shape.IsEmpty))
                                                    {

                                                        IPoint revGCLoc = Globals.GetGeomCenter(inFeature);

                                                        if (revGCLoc != null)
                                                        {
                                                            //Test for user specified URL
                                                            if (Globals.IsUrl(valData))
                                                            {
                                                                locatorURL = valData;
                                                                /////locatorURL.TrimEnd(char[] );
                                                                if (!(locatorURL.EndsWith(reverseGeocode)))
                                                                    locatorURL += reverseGeocode;
                                                            }

                                                            //If no valid user speficied URL, test for keywords for North America or European Union locators
                                                            else if (valData == "ESRI_Geocode_NA" || valData == "ESRI_Geocode_EU")
                                                                locatorURL = _agsOnlineLocators + valData + reverseGeocode;
                                                            else if (valData == "TA_Streets_US " || valData == "TA_Address_NA" || valData == "TA_Address_EU")
                                                                locatorURL = _agsOnlineLocators + valData + reverseGeocode;
                                                            //Default to AGS Online USA geocode service

                                                            else if (_agsOnlineLocators.Substring(_agsOnlineLocators.LastIndexOf('/', _agsOnlineLocators.Length - 2)).Contains("Locator"))
                                                                locatorURL = _agsOnlineLocators + "TA_Address_NA" + reverseGeocode;
                                                            else
                                                                locatorURL = _agsOnlineLocators + reverseGeocode;

                                                            //Copy point from this current feature
                                                            _copyPoint = revGCLoc;//inFeature.ShapeCopy as IPoint;

                                                            //Project point to WGS84
                                                            _copyPoint.Project(AAState.srWGS84);

                                                            //Include location parameters in URL
                                                            string results = Globals.FormatLocationRequest(locatorURL, _copyPoint.X, _copyPoint.Y, 100);

                                                            //Send and receieve the request
                                                            WebRequest req = WebRequest.Create(results);
                                                            WebResponse res = req.GetResponse();

                                                            //Convert response from JSON to XML
                                                            XmlDocument doc = new XmlDocument();
                                                            using (Stream s = res.GetResponseStream())
                                                            {
                                                                XmlDictionaryReader xr = JsonReaderWriterFactory.CreateJsonReader(s, XmlDictionaryReaderQuotas.Max);
                                                                doc.Load(xr);
                                                                xr.Close();
                                                                s.Close();

                                                                //Store Address element from Address Results in the specified field
                                                                //if (mode == "ON_CREATE")
                                                                //{
                                                                //    inFeature.set_Value(fieldNum, doc.DocumentElement.FirstChild.FirstChild.InnerText.Replace("    ", " "));
                                                                //}
                                                                //else//on change
                                                                //{
                                                                //    if (inFeature.Fields.get_Field(fieldNum).DefaultValue == inFeature.get_Value(fieldNum))
                                                                //    //if (inFeature.get_Value(fieldNum).ToString() != "")
                                                                //    {
                                                                //        inFeature.set_Value(fieldNum, doc.DocumentElement.FirstChild.FirstChild.InnerText.Replace("    ", " "));
                                                                //    }
                                                                //}
                                                                inFeature.set_Value(fieldNum, doc.DocumentElement.FirstChild.FirstChild.InnerText.Replace("    ", " "));

                                                            }
                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  Could not get location to Reverse Geocode");
                                                        }
                                                    }

                                                }

                                            }
                                            catch
                                            {
                                                AAState.WriteLine("                  ERROR: GET_ADDRESS_USING_ARCGIS_SERVICE");
                                            }

                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: GET_ADDRESS_USING_ARCGIS_SERVICE");
                                            }
                                            break;
                                        case "TIMESTAMP":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: TIMESTAMP");
                                                if (fieldObj.Type == esriFieldType.esriFieldTypeDate)
                                                    inObject.set_Value(fieldNum, DateTime.Now);
                                                else if (fieldObj.Type == esriFieldType.esriFieldTypeString)
                                                    inObject.set_Value(fieldNum, DateTime.Now.ToString());

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: TIMESTAMP " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: TIMESTAMP");
                                            }
                                            break;

                                        case "LAST_VALUE":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: LAST_VALUE");
                                                if (mode == "ON_CREATE")
                                                {

                                                    lastValue = AAState.lastValueProperties.GetProperty(fieldName);
                                                    if (lastValue != null)
                                                    {
                                                        inObject.set_Value(fieldNum, lastValue);
                                                        AAState.WriteLine("                  " + fieldName + ": " + lastValue);
                                                    }
                                                }
                                                else if (mode == "ON_CHANGE" && inObject.get_Value(fieldNum) == null)
                                                {
                                                    lastValue = AAState.lastValueProperties.GetProperty(fieldName);
                                                    if (lastValue != null)
                                                    {
                                                        inObject.set_Value(fieldNum, lastValue);
                                                        AAState.WriteLine("                  " + fieldName + ": " + lastValue);
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: LAST_VALUE " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: LAST_VALUE");
                                            }
                                            break;

                                        case "X_COORDINATE":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: X_COORDINATE");
                                                if ((inFeature != null) && (inFeature.Shape != null) && !(inFeature.Shape.IsEmpty))
                                                {
                                                    if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                    {
                                                        _copyPoint = inFeature.Shape as IPoint;
                                                        inFeature.set_Value(fieldNum, _copyPoint.X);
                                                    }
                                                    else if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                                                    {
                                                        _copyPolyline = inFeature.Shape as IPolyline;
                                                        if (valData == "")
                                                        {
                                                            inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolyline).X);
                                                        }
                                                        else
                                                        {
                                                            args = valData.Split('|');
                                                            if (args[0].ToUpper() == "S")
                                                            {
                                                                inFeature.set_Value(fieldNum, _copyPolyline.FromPoint.X);
                                                            }
                                                            else if (args[0].ToUpper() == "E")
                                                            {
                                                                inFeature.set_Value(fieldNum, _copyPolyline.ToPoint.X);
                                                            }
                                                            else
                                                            {
                                                                inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolyline).X);
                                                            }

                                                        }

                                                    }
                                                    else if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                                                    {
                                                        inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolygon).X);
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Unsupported Geometry");
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: X_COORDINATE: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: X_COORDINATE");
                                            }
                                            break;

                                        case "Y_COORDINATE":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: Y_COORDINATE");
                                                if ((inFeature != null) && (inFeature.Shape != null) && !(inFeature.Shape.IsEmpty))
                                                {
                                                    if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                    {
                                                        _copyPoint = inFeature.Shape as IPoint;
                                                        inFeature.set_Value(fieldNum, _copyPoint.Y);
                                                    }
                                                    else if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                                                    {
                                                        _copyPolyline = inFeature.Shape as IPolyline;
                                                        if (valData == "")
                                                        {
                                                            inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolyline).Y);
                                                        }
                                                        else
                                                        {
                                                            args = valData.Split('|');
                                                            if (args[0].ToUpper() == "S")
                                                            {
                                                                inFeature.set_Value(fieldNum, _copyPolyline.FromPoint.Y);
                                                            }
                                                            else if (args[0].ToUpper() == "E")
                                                            {
                                                                inFeature.set_Value(fieldNum, _copyPolyline.ToPoint.Y);
                                                            }
                                                            else
                                                            {
                                                                inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolyline).Y);
                                                            }

                                                        }

                                                    }
                                                    else if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                                                    {
                                                        _copyPolygon = inFeature.ShapeCopy as IPolygon;

                                                        inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolygon).Y);
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Unsupported Geometry");
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: Y_COORDINATE: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: Y_COORDINATE");
                                            }
                                            break;

                                        case "LATITUDE":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: LATITUDE");
                                                if ((inFeature != null) && (inFeature.Shape != null) && !(inFeature.Shape.IsEmpty))
                                                {

                                                    if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                    {
                                                        _copyPoint = inFeature.ShapeCopy as IPoint;
                                                        _copyPoint.Project(AAState._sr1);

                                                        inFeature.set_Value(fieldNum, _copyPoint.Y);
                                                    }
                                                    else if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                                                    {
                                                        _copyPolyline = inFeature.ShapeCopy as IPolyline;
                                                        _copyPolyline.Project(AAState._sr1);

                                                        if (valData == "")
                                                        {
                                                            inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolyline).X);
                                                        }
                                                        else
                                                        {
                                                            args = valData.Split('|');
                                                            if (args[0].ToUpper() == "S")
                                                            {
                                                                inFeature.set_Value(fieldNum, _copyPolyline.FromPoint.X);
                                                            }
                                                            else if (args[0].ToUpper() == "E")
                                                            {
                                                                inFeature.set_Value(fieldNum, _copyPolyline.ToPoint.X);
                                                            }
                                                            else
                                                            {
                                                                inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolyline).X);
                                                            }

                                                        }

                                                    }
                                                    else if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                                                    {
                                                        _copyPolygon = inFeature.ShapeCopy as IPolygon;
                                                        _copyPolygon.Project(AAState._sr1);

                                                        inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolygon).X);
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Unsupported Geometry");
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  Error: LATITUDE: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: LATITUDE");
                                            }
                                            break;

                                        case "LONGITUDE":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: LONGITUDE");
                                                if ((inFeature != null) && (inFeature.Shape != null) && !(inFeature.Shape.IsEmpty))
                                                {

                                                    if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                    {
                                                        _copyPoint = inFeature.ShapeCopy as IPoint;
                                                        _copyPoint.Project(AAState._sr1);

                                                        inFeature.set_Value(fieldNum, _copyPoint.Y);
                                                    }
                                                    else if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                                                    {
                                                        _copyPolyline = inFeature.Shape as IPolyline;
                                                        _copyPolyline.Project(AAState._sr1);

                                                        if (valData == "")
                                                        {
                                                            inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolyline).Y);
                                                        }
                                                        else
                                                        {
                                                            args = valData.Split('|');
                                                            if (args[0].ToUpper() == "S")
                                                            {
                                                                inFeature.set_Value(fieldNum, _copyPolyline.FromPoint.Y);
                                                            }
                                                            else if (args[0].ToUpper() == "E")
                                                            {
                                                                inFeature.set_Value(fieldNum, _copyPolyline.ToPoint.Y);
                                                            }
                                                            else
                                                            {
                                                                inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolyline).Y);
                                                            }

                                                        }

                                                    }
                                                    else if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                                                    {
                                                        _copyPolygon = inFeature.ShapeCopy as IPolygon;
                                                        _copyPolygon.Project(AAState._sr1);

                                                        inFeature.set_Value(fieldNum, Globals.GetGeomCenter(_copyPolygon).Y);
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Unsupported Geometry");
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: LONGITUDE: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: LONGITUDE");
                                            }
                                            break;

                                        case "FIELD":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: Field");
                                                // verify that field to copy exists
                                                fieldCopy = inObject.Fields.FindField(valData as string);
                                                if (fieldCopy > -1)
                                                {
                                                    if (mode == "ON_CREATE")
                                                    {
                                                        inObject.set_Value(fieldNum, inObject.get_Value(fieldCopy));
                                                    }
                                                    if (mode == "ON_CHANGE")
                                                    {
                                                        //copy value only if current field is empty
                                                        if (inObject.get_Value(fieldNum).ToString() == "")
                                                            inObject.set_Value(fieldNum, inObject.get_Value(fieldCopy));
                                                    }
                                                }
                                                else
                                                {
                                                    AAState.WriteLine("                  " + valData + " is not found");
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: Field: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: Field");
                                            }
                                            break;

                                        //CURRENT_USER
                                        //Value Data options:
                                        //U - windows username only
                                        //W or (blank) - full username including domain i.e. domain\username
                                        //D - database user if available and not dbo
                                        case "CURRENT_USER":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: CURRENT_USER");
                                                lastEditorName = AAState._currentUserInfo.GetCurrentUser(valData, fieldObj.Length);

                                                if (!String.IsNullOrEmpty(lastEditorName))
                                                {
                                                    inObject.set_Value(fieldNum, lastEditorName);
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: CURRENT_USER: "******"                  Finished: CURRENT_USER");
                                            }
                                            break;

                                        case "JUNCTION_ROTATION":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: JUNCTION_ROTATION");
                                                if ((inFeature != null))
                                                {
                                                    AAState.rCalc.RotationType = esriSymbolRotationType.esriRotateSymbolGeographic;
                                                    args = null;

                                                    if (!String.IsNullOrEmpty(valData))
                                                    {
                                                        args = valData.Split('|');
                                                        if (args[0].Length == 0)
                                                        {
                                                            if (args[0].Substring(0, 1).ToLower() == "a")
                                                                AAState.rCalc.RotationType = esriSymbolRotationType.esriRotateSymbolArithmetic;
                                                        }
                                                        if (args[0].Length == 1)
                                                        {
                                                            if (args[0].Substring(0, 1).ToLower() == "a")
                                                                AAState.rCalc.RotationType = esriSymbolRotationType.esriRotateSymbolArithmetic;
                                                            if (Globals.IsNumeric(args[1].ToString()))
                                                                AAState.rCalc.SpinAngle = Convert.ToDouble(args[1]);

                                                        }
                                                    }
                                                    AAState.WriteLine("                  " + AAState.rCalc.RotationType.ToString() + " is being used");
                                                    rotationAngle = AAState.rCalc.GetRotationUsingConnectedEdges(inFeature);
                                                    if (rotationAngle == null)
                                                    {
                                                        AAState.WriteLine("                  Rotation Angle not found or errored out");
                                                        continue;
                                                    }

                                                    //Accept optional second argument to provide extra rotation
                                                    //if ((args != null) && (args.Length > 1) && (Globals.IsInteger(args[1])))
                                                    //    rotationAngle += System.Convert.ToInt32(args[1]);
                                                    if (rotationAngle != -1)
                                                        inObject.set_Value(fieldNum, rotationAngle);
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: JUNCTION_ROTATION \r\n" + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: JUNCTION_ROTATION");
                                            }
                                            break;

                                        //For Release: 1.2
                                        //New Dynamic Value Method: Length - stores calculated length of line feature
                                        case "LENGTH":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: LENGTH");
                                                if (inFeature != null)
                                                {
                                                    curve = (ICurve)inFeature.Shape;
                                                    if (curve != null)
                                                    {
                                                        inObject.set_Value(fieldNum, curve.Length);
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: LENGTH: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: LENGTH");
                                            }
                                            break;

                                        //Release: 1.2
                                        //New Dynamic Value Method: SET_MEASURES - stores calculated M values (from 0 to length of line) for line feature
                                        //Value Data options:
                                        //P = Percent - Ms will be zero to 100
                                        //default - Ms will be zero to length of line
                                        case "SET_MEASURES":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: SET_MEASURES");
                                                if (inFeature != null)
                                                {
                                                    curve = inFeature.Shape as ICurve;
                                                    mseg = inFeature.Shape as IMSegmentation;
                                                    if (curve != null && mseg != null)
                                                        if (valData != null && valData != "" && valData.Substring(0, 1).ToUpper() == "P")
                                                            mseg.SetAndInterpolateMsBetween(0, 100);
                                                        else
                                                            mseg.SetAndInterpolateMsBetween(0, curve.Length);
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: SET_MEASURES: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: SET_MEASURES");
                                            }
                                            break;
                                        //case "EDGE_INTERSECT_SECOND":
                                        //    try
                                        //    {
                                        //        if (inFeature != null)
                                        //        {
                                        //            netFeat = inFeature as INetworkFeature;
                                        //            if (netFeat != null)
                                        //            {
                                        //                if (inFeature.FeatureType == esriFeatureType.esriFTComplexJunction || inFeature.FeatureType == esriFeatureType.esriFTSimpleJunction)
                                        //                {

                                        //                    iJuncFeat = (IJunctionFeature)netFeat;
                                        //                    // IComplexJunctionFeature iCEd = iJuncFeat as IComplexJunctionFeature;
                                        //                    ISimpleJunctionFeature iSJunc = iJuncFeat as ISimpleJunctionFeature;
                                        //                    if (iSJunc == null)
                                        //                        break;
                                        //                    if (iSJunc.EdgeFeatureCount <= 1)
                                        //                        break;
                                        //                    edgeFeat = iSJunc.get_EdgeFeature(1);

                                        //                    // verify that field (in junction) to copy exists

                                        //                    IRow pRow = edgeFeat as IRow;

                                        //                    juncField = pRow.Fields.FindField(valData as string);
                                        //                    if (juncField > -1)
                                        //                    {
                                        //                        inObject.set_Value(fieldNum, pRow.get_Value(juncField));
                                        //                    }
                                        //                }
                                        //            }
                                        //        }
                                        //    }
                                        //    catch
                                        //    {
                                        //    }
                                        //    break;
                                        //case "EDGE_INTERSECT_FIRST":
                                        //    try
                                        //    {
                                        //        if (inFeature != null)
                                        //        {
                                        //            netFeat = inFeature as INetworkFeature;
                                        //            if (netFeat != null)
                                        //            {
                                        //                if (inFeature.FeatureType == esriFeatureType.esriFTComplexJunction || inFeature.FeatureType == esriFeatureType.esriFTSimpleJunction)
                                        //                {

                                        //                    iJuncFeat = (IJunctionFeature)netFeat;
                                        //                    // IComplexJunctionFeature iCEd = iJuncFeat as IComplexJunctionFeature;
                                        //                    ISimpleJunctionFeature iSJunc = iJuncFeat as ISimpleJunctionFeature;
                                        //                    if (iSJunc == null)
                                        //                        break;
                                        //                    if (iSJunc.EdgeFeatureCount <= 0)
                                        //                        break;
                                        //                    edgeFeat = iSJunc.get_EdgeFeature(0);

                                        //                    IRow pRow = edgeFeat as IRow;

                                        //                    juncField = pRow.Fields.FindField(valData as string);
                                        //                    if (juncField > -1)
                                        //                    {
                                        //                        inObject.set_Value(fieldNum, pRow.get_Value(juncField));
                                        //                    }
                                        //                }
                                        //            }
                                        //        }
                                        //    }
                                        //    catch
                                        //    {
                                        //    }
                                        //    break;

                                        //Release: 2.0
                                        //New Dynamic Value Method: TO_EDGE_FIELD transfers a field value from a connected egde feature to a junction feature
                                        //Takes value from the frist edge whose "TO" point connects with this junction
                                        case "TO_EDGE_FIELD":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: TO_EDGE_FIELD");
                                                if (inFeature != null)
                                                {
                                                    netFeat = inFeature as INetworkFeature;
                                                    if (netFeat != null)
                                                    {
                                                        if (inFeature.FeatureType == esriFeatureType.esriFTComplexJunction || inFeature.FeatureType == esriFeatureType.esriFTSimpleJunction)
                                                        {

                                                            iJuncFeat = (IJunctionFeature)netFeat;
                                                            // IComplexJunctionFeature iCEd = iJuncFeat as IComplexJunctionFeature;
                                                            ISimpleJunctionFeature iSJunc = iJuncFeat as ISimpleJunctionFeature;
                                                            if (iSJunc == null)
                                                                break;
                                                            if (iSJunc.EdgeFeatureCount <= 0)
                                                                break;
                                                            if (iSJunc.EdgeFeatureCount > 0)
                                                            {
                                                                for (int i = 0; i < iSJunc.EdgeFeatureCount; i++)
                                                                {
                                                                    edgeFeat = iSJunc.get_EdgeFeature(i);
                                                                    try
                                                                    {
                                                                        juncFeat = (IFeature)edgeFeat.FromJunctionFeature;
                                                                        if (juncFeat.Shape.Equals(inFeature.Shape))
                                                                        {
                                                                            IRow pRow = edgeFeat as IRow;

                                                                            // verify that field (in junction) to copy exists
                                                                            juncField = pRow.Fields.FindField(valData as string);
                                                                            if (juncField > -1)
                                                                            {
                                                                                inObject.set_Value(fieldNum, pRow.get_Value(juncField));
                                                                            }
                                                                            else
                                                                            {
                                                                                AAState.WriteLine("                  " + valData + " field not found in edge");
                                                                            }
                                                                            break;

                                                                        }
                                                                    }
                                                                    catch
                                                                    {
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                AAState.WriteLine("                  No Connected Edges Found");
                                                            }

                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  not an junction feature");
                                                        }

                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  Not a Geometric Network Feature");
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: TO_EDGE_FIELD: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: TO_EDGE_FIELD");
                                            }
                                            break;

                                        //Release: 2.0
                                        //New Dynamic Value Method: FROM_EDGE_FIELD transfers a field value from a connected egde feature to a junction feature
                                        //Takes value from the frist edge whose "FROM" point connects with this junction
                                        case "FROM_EDGE_FIELD":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: FROM_EDGE_FIELD");
                                                if (inFeature != null)
                                                {
                                                    netFeat = inFeature as INetworkFeature;
                                                    if (netFeat != null)
                                                    {
                                                        if (inFeature.FeatureType == esriFeatureType.esriFTComplexJunction || inFeature.FeatureType == esriFeatureType.esriFTSimpleJunction)
                                                        {

                                                            iJuncFeat = (IJunctionFeature)netFeat;
                                                            // IComplexJunctionFeature iCEd = iJuncFeat as IComplexJunctionFeature;
                                                            ISimpleJunctionFeature iSJunc = iJuncFeat as ISimpleJunctionFeature;
                                                            if (iSJunc == null)
                                                                break;
                                                            if (iSJunc.EdgeFeatureCount <= 0)
                                                                break;
                                                            for (int i = 0; i < iSJunc.EdgeFeatureCount; i++)
                                                            {
                                                                edgeFeat = iSJunc.get_EdgeFeature(i);
                                                                try
                                                                {
                                                                    juncFeat = (IFeature)edgeFeat.ToJunctionFeature;
                                                                    if (juncFeat.Shape.Equals(inFeature.Shape))
                                                                    {
                                                                        IRow pRow = edgeFeat as IRow;

                                                                        // verify that field (in junction) to copy exists
                                                                        juncField = pRow.Fields.FindField(valData as string);
                                                                        if (juncField > -1)
                                                                        {
                                                                            inObject.set_Value(fieldNum, pRow.get_Value(juncField));
                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  " + valData + " field not found");
                                                                        }
                                                                        break;

                                                                    }

                                                                }

                                                                catch
                                                                {
                                                                    AAState.WriteLine("                  error ");
                                                                }
                                                            }

                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  not an junction feature");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  Not a Geometric Network Feature");
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: FROM_EDGE_FIELD: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: FROM_EDGE_FIELD");
                                            }
                                            break;

                                        case "FROM_JUNCTION_FIELD":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: FROM_JUNCTION_FIELD");
                                                if (inFeature != null)
                                                {
                                                    netFeat = inFeature as INetworkFeature;
                                                    if (netFeat != null)
                                                    {
                                                        if (inFeature.FeatureType == esriFeatureType.esriFTComplexEdge || inFeature.FeatureType == esriFeatureType.esriFTSimpleEdge)
                                                        {
                                                            edgeFeat = (IEdgeFeature)netFeat;
                                                            juncFeat = (IFeature)edgeFeat.FromJunctionFeature;

                                                            // verify that field (in junction) to copy exists
                                                            juncField = juncFeat.Fields.FindField(valData as string);
                                                            if (juncField > -1)
                                                            {
                                                                inObject.set_Value(fieldNum, juncFeat.get_Value(juncField));
                                                            }
                                                            else
                                                                AAState.WriteLine("                  " + valData + " field not found");
                                                        }
                                                        else
                                                            AAState.WriteLine("                  not an edge feature");
                                                    }
                                                    else
                                                        AAState.WriteLine("                  Not a network feature");
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: FROM_JUNCTION_FIELD: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: FROM_JUNCTION_FIELD");
                                            }
                                            break;

                                        //Release: 1.2
                                        //New Dynamic Value Method: TO_JUNCTION_FIELD transfers a field value from a junction connected at terminal end of a line feature
                                        case "TO_JUNCTION_FIELD":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: TO_JUNCTION_FIELD");
                                                if (inFeature != null)
                                                {

                                                    netFeat = inFeature as INetworkFeature;
                                                    if (netFeat != null)
                                                    {
                                                        if (inFeature.FeatureType == esriFeatureType.esriFTComplexEdge || inFeature.FeatureType == esriFeatureType.esriFTSimpleEdge)
                                                        {
                                                            edgeFeat = (IEdgeFeature)netFeat;
                                                            juncFeat = (IFeature)edgeFeat.ToJunctionFeature;

                                                            // verify that field (in junction) to copy exists
                                                            juncField = juncFeat.Fields.FindField(valData as string);
                                                            if (juncField > -1)
                                                            {
                                                                inObject.set_Value(fieldNum, juncFeat.get_Value(juncField));
                                                            }
                                                            else
                                                            {
                                                                AAState.WriteLine("                  Trying: TO_JUNCTION_FIELD");
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  not an edge feature");
                                                    }
                                                }
                                                else
                                                {
                                                    AAState.WriteLine("                  not an geometric network feature");
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: TO_JUNCTION_FIELD:" + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: TO_JUNCTION_FIELD");
                                            }
                                            break;

                                        //Release: 1.2
                                        //New Dynamic Value Method: GENERATE_ID - uses value in specificed table and increments it as specified
                                        case "GENERATE_ID":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: GENERATE_ID");
                                                if (AAState._gentab != null)
                                                {
                                                    sequenceColumnName = "";
                                                    sequenceColumnNum = -1;
                                                    sequenceValue = -1;
                                                    sequenceFixedWidth = "";
                                                    sequencePadding = 0;
                                                    formatString = "";

                                                    // Parse arguments
                                                    if (valData == null) break;
                                                    args = valData.Split('|');
                                                    switch (args.GetLength(0))
                                                    {
                                                        case 1:  // sequenceColumnName only
                                                            sequenceColumnName = args[0].ToString(); break;
                                                        case 2:  // sequenceColumnName|sequenceFixedWidth
                                                            sequenceColumnName = args[0].ToString();
                                                            sequenceFixedWidth = args[1].ToString();
                                                            break;
                                                        case 3:  // sequenceColumnName|sequenceFixedWidth|formatString
                                                            sequenceColumnName = args[0].ToString();
                                                            sequenceFixedWidth = args[1].ToString();
                                                            formatString = args[2].ToString();
                                                            break;
                                                        default: break;
                                                    }

                                                    //Check for requested zero padding of sequence number
                                                    if (sequenceFixedWidth != "")
                                                        int.TryParse(sequenceFixedWidth.ToString(), out sequencePadding);
                                                    if (sequencePadding > 25)
                                                    {

                                                        AAState.WriteLine("                  WARNING: you are trying to pad your id with a more than 25 - 0's");
                                                        AAState.WriteLine("                  WARNING: " + sequencePadding + " 0's is what you have");

                                                    }
                                                    else if (sequencePadding > 50)
                                                    {
                                                        MessageBox.Show("You are trying to add 50 places to your ID, this is not supported, please fix your dynamic value table");
                                                    }

                                                    //Check for sequence column in generate id table
                                                    sequenceColumnNum = AAState._gentab.FindField(sequenceColumnName);
                                                    if (AAState._gentab.FindField(sequenceColumnName) >= 0)
                                                    {
                                                        //get value of first row, increment it, and return incremented value
                                                        for (int j = 0; j < 51; j++)
                                                        {
                                                            row = AAState._gentab.Update(null, false).NextRow();
                                                            if (row == null)
                                                            {
                                                                break;
                                                            }
                                                            if (row.get_Value(sequenceColumnNum) == null)
                                                            {
                                                                sequenceValue = 0;
                                                            }
                                                            else if (row.get_Value(sequenceColumnNum).ToString() == "")
                                                            {
                                                                sequenceValue = 0;
                                                            }
                                                            else
                                                                sequenceValue = Convert.ToInt32(row.get_Value(sequenceColumnNum));

                                                            sequenceValue += 1;
                                                            // _editEvents.OnChangeFeature -= OnChangeFeature;
                                                            // _editEvents.OnCreateFeature -= OnCreateFeature;

                                                            row.set_Value(sequenceColumnNum, sequenceValue);
                                                            AAState.WriteLine("                  " + row.Fields.get_Field(sequenceColumnNum).AliasName + " changed to " + sequenceValue);

                                                            row.Store();
                                                            //  _editEvents.OnChangeFeature += OnChangeFeature;
                                                            //  _editEvents.OnCreateFeature += OnCreateFeature;
                                                            if (Convert.ToInt32(row.get_Value(sequenceColumnNum)) == sequenceValue)
                                                                break;

                                                        }
                                                        if (sequenceValue == -1)
                                                        {
                                                            AAState.WriteLine("                  ERROR: GENERATE_ID: Sequence Not Found");
                                                        }

                                                        else
                                                        {
                                                            if (inObject.Fields.get_Field(fieldNum).Type == esriFieldType.esriFieldTypeString)
                                                                if (formatString == null || formatString == "" || formatString.ToLower().IndexOf("[seq]") == -1)
                                                                {
                                                                    string setVal = (sequenceValue.ToString("D" + sequencePadding) + sequencePostfix).ToString();

                                                                    if (inObject.Fields.get_Field(fieldNum).Length < setVal.Length && inObject.Fields.get_Field(fieldNum).Length != 0)
                                                                    {
                                                                        AAState.WriteLine("                  ERROR: " + sequenceValue + " is to long for field " + row.Fields.get_Field(sequenceColumnNum).AliasName);
                                                                    }
                                                                    else
                                                                    {
                                                                        inObject.set_Value(fieldNum, sequenceValue.ToString("D" + sequencePadding) + sequencePostfix);
                                                                        AAState.WriteLine("                  " + inObject.Fields.get_Field(fieldNum).AliasName + " set to " + sequenceValue.ToString("D" + sequencePadding) + sequencePostfix);

                                                                    }

                                                                }
                                                                else
                                                                {

                                                                    int locIdx = formatString.ToUpper().IndexOf("[SEQ]");
                                                                    if (locIdx >= 0)
                                                                    {
                                                                        formatString = formatString.Remove(locIdx, 5);
                                                                        formatString = formatString.Insert(locIdx, sequenceValue.ToString("D" + sequencePadding));
                                                                    }
                                                                    //formatString = formatString.Replace("[seq]", sequenceValue.ToString("D" + sequencePadding));

                                                                    if (inObject.Fields.get_Field(fieldNum).Length < formatString.Length && inObject.Fields.get_Field(fieldNum).Length != 0)
                                                                    {
                                                                        AAState.WriteLine("                  ERROR: " + formatString + " is to long for field " + row.Fields.get_Field(sequenceColumnNum).AliasName);
                                                                    }
                                                                    else
                                                                    {
                                                                        inObject.set_Value(fieldNum, formatString);
                                                                        AAState.WriteLine("                  " + inObject.Fields.get_Field(fieldNum).AliasName + " set to " + formatString);
                                                                    }

                                                                }
                                                            else
                                                            {

                                                                inObject.set_Value(fieldNum, sequenceValue);
                                                                AAState.WriteLine("                  " + sequenceColumnNum + " changed to " + sequenceValue);
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  Sequence Field not found");
                                                    }
                                                }
                                                else
                                                {
                                                    AAState.WriteLine("                  ERROR: GENERATE_ID table is not found");

                                                }

                                            }

                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: GENERATE_ID: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: GENERATE_ID");
                                            }
                                            break;

                                        case "GENERATE_ID_BY_INTERSECT":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: GENERATE_ID_BY_INTERSECT");
                                                if (AAState._gentab != null && inFeature != null && !(inFeature.Shape.IsEmpty))
                                                {
                                                    sequenceColumnName = "";
                                                    sequenceColumnNum = -1;
                                                    sequenceValue = -1;
                                                    sequenceFixedWidth = "";
                                                    sequencePadding = 0;
                                                    //genIdAreaFieldName = "";
                                                    intersectLayerName = "";
                                                    intersectLayerFieldName = "";
                                                    formatString = "";
                                                    intersectFieldPos = -1;

                                                    // Parse arguments
                                                    if (valData == null) break;

                                                    args = valData.Split('|');
                                                    if (args.GetLength(0) < 3)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Improper value method");
                                                        break;
                                                    }
                                                    switch (args.GetLength(0))
                                                    {
                                                        case 3:  //columnName
                                                            intersectLayerName = args[0].ToString();
                                                            intersectLayerFieldName = args[1].ToString();
                                                            // genIdAreaFieldName = args[2].ToString();
                                                            sequenceColumnName = args[2].ToString();
                                                            break;
                                                        case 4:  // columnName|sequenceFixedWidth
                                                            //sequenceFixedWidth formats the sequence with leading zeros to create specified width
                                                            intersectLayerName = args[0].ToString();
                                                            intersectLayerFieldName = args[1].ToString();
                                                            //genIdAreaFieldName = args[2].ToString();
                                                            sequenceColumnName = args[2].ToString();
                                                            sequenceFixedWidth = Convert.ToString(0);
                                                            formatString = args[3].ToString();

                                                            break;
                                                        case 5:  // columnName|sequenceFixedWidth|formatString
                                                            //formatString must contain [seq] and [id]  and may contain [area] plus any desired text
                                                            intersectLayerName = args[0].ToString();
                                                            intersectLayerFieldName = args[1].ToString();
                                                            //genIdAreaFieldName = args[2].ToString();
                                                            sequenceColumnName = args[2].ToString();
                                                            sequenceFixedWidth = args[3].ToString();
                                                            formatString = args[4].ToString();
                                                            break;
                                                        default: break;
                                                    }

                                                    //Find Area Layer
                                                    // FindLayerByName(areaLayerName, out areaLayer);
                                                    intersectLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, intersectLayerName);
                                                    if (intersectLayer == null)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Intersecting feature Layer(" + intersectLayerName + ") not found");
                                                        break;
                                                    }
                                                    //Find Area Field
                                                    intersectFieldPos = intersectLayer.FeatureClass.FindField(intersectLayerFieldName);
                                                    if (intersectFieldPos < 0)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Intersecting feature Layer Field(" + intersectLayerFieldName + ") not found");
                                                        break;
                                                    }

                                                    //Find GenID Area Field
                                                    //genIdAreaFieldPos = areaLayer.FeatureClass.FindField(genIdAreaFieldName);
                                                    //if (genIdAreaFieldPos < 0) break;

                                                    //Perform spatial search
                                                    IGeometry pSearchGeo = (IGeometry)inFeature.ShapeCopy;
                                                    pSearchGeo.SpatialReference = (inFeature.Class as IGeoDataset).SpatialReference;
                                                    pSearchGeo.Project((intersectLayer as IGeoDataset).SpatialReference);
                                                    sFilter = new SpatialFilterClass();
                                                    sFilter.Geometry = pSearchGeo;
                                                    sFilter.GeometryField = intersectLayer.FeatureClass.ShapeFieldName;
                                                    sFilter.SubFields = intersectLayerFieldName;
                                                    sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                                    fCursor = intersectLayer.FeatureClass.Search(sFilter, true);
                                                    sourceFeature = fCursor.NextFeature();
                                                    if (sourceFeature != null)
                                                        intersectValue = sourceFeature.get_Value(intersectFieldPos).ToString();
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Intersecting feature not found");
                                                        break;
                                                    }
                                                    //Check for requested zero padding of sequence number
                                                    if (sequenceFixedWidth != "")
                                                        int.TryParse(sequenceFixedWidth.ToString(), out sequencePadding);

                                                    if (sequencePadding > 25)
                                                    {
                                                        AAState.WriteLine("                  WARNING: you are trying to pad your id with a more than 25 - 0's");
                                                        AAState.WriteLine("                  WARNING: " + sequencePadding + " 0's is what you have");

                                                    }

                                                    sequenceColumnName = sequenceColumnName + intersectValue;
                                                    AAState.WriteLine("                  Looking for a field called " + sequenceColumnName + " in the generate ID table");
                                                    sequenceColumnNum = AAState._gentab.FindField(sequenceColumnName);
                                                    if (sequenceColumnNum > -1)
                                                    {
                                                        AAState.WriteLine("                  Field Found");

                                                        //get value of first row, increment it, and return incremented value
                                                        for (int j = 0; j < 51; j++)
                                                        {
                                                            row = AAState._gentab.Update(qFilter, false).NextRow();
                                                            if (row.get_Value(sequenceColumnNum) == null)
                                                            {
                                                                sequenceValue = 0;
                                                            }
                                                            else if (row.get_Value(sequenceColumnNum).ToString() == "")
                                                            {
                                                                sequenceValue = 0;
                                                            }
                                                            else
                                                                sequenceValue = Convert.ToInt32(row.get_Value(sequenceColumnNum));
                                                            sequenceValue += 1;
                                                            row.set_Value(sequenceColumnNum, sequenceValue);
                                                            row.Store();
                                                            if (Convert.ToInt32(row.get_Value(sequenceColumnNum)) == sequenceValue)
                                                                break;

                                                        }
                                                        if (sequenceValue == -1)
                                                        {
                                                            AAState.WriteLine("                  ERROR: Sequence number not found");
                                                        }
                                                        else
                                                        {
                                                            if (inObject.Fields.get_Field(fieldNum).Type == esriFieldType.esriFieldTypeString)
                                                                if (formatString == null || formatString == "" || (formatString.ToUpper().IndexOf("[SEQ]") == -1 && formatString.ToUpper().IndexOf("[ID]") == -1))
                                                                    inObject.set_Value(fieldNum, intersectValue + sequenceValue.ToString("D" + sequencePadding) + sequencePostfix);
                                                                else
                                                                {

                                                                    int locIdx = formatString.ToUpper().IndexOf("[ID]");
                                                                    if (locIdx >= 0)
                                                                    {
                                                                        formatString = formatString.Remove(locIdx, 4);
                                                                        formatString = formatString.Insert(locIdx, intersectValue);
                                                                    }
                                                                    //  formatString = formatString.Replace("[id]", intersectValue);
                                                                    // formatString = formatString.Replace("[seq]", sequenceValue.ToString("D" + sequencePadding));
                                                                    locIdx = formatString.ToUpper().IndexOf("[SEQ]");
                                                                    if (locIdx >= 0)
                                                                    {
                                                                        formatString = formatString.Remove(locIdx, 5);
                                                                        formatString = formatString.Insert(locIdx, sequenceValue.ToString());
                                                                    }
                                                                    //
                                                                    inObject.set_Value(fieldNum, formatString);
                                                                }
                                                            else
                                                                inObject.set_Value(fieldNum, sequenceValue);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Field NOT Found");
                                                    }
                                                }
                                                else
                                                {
                                                    AAState.WriteLine("                  ERROR: GENERATE_ID table is not found");

                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: GENERATE_ID_BY_INTERSECT: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: GENERATE_ID_BY_INTERSECT");
                                            }
                                            break;
                                        //Modified for Release 1.2  (No longer uses ICalculator)
                                        //Requires valid VBScript expression
                                        //Can include string, numeric, and date fields by name in square brackets []
                                        //Example: DateDiff("yyyy",[INSTALLDATE],Now())
                                        case "GENERATE_ID_BY_AREA":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: GENERATE_ID_BY_AREA");
                                                if (AAState._gentab != null && inFeature != null && !(inFeature.Shape.IsEmpty))
                                                {
                                                    sequenceColumnName = "";
                                                    sequenceColumnNum = -1;
                                                    sequenceValue = -1;
                                                    sequenceFixedWidth = "";
                                                    sequencePadding = 0;
                                                    genIdAreaFieldName = "";
                                                    areaLayerName = "";
                                                    areaLayerFieldName = "";
                                                    formatString = "";

                                                    // Parse arguments
                                                    if (valData == null) break;

                                                    args = valData.Split('|');
                                                    if (args.GetLength(0) < 3)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Improper Value Method");
                                                        break;
                                                    }
                                                    switch (args.GetLength(0))
                                                    {
                                                        case 4:  //columnName
                                                            areaLayerName = args[0].ToString();
                                                            areaLayerFieldName = args[1].ToString();
                                                            genIdAreaFieldName = args[2].ToString();
                                                            sequenceColumnName = args[3].ToString();
                                                            break;
                                                        case 5:  // columnName|sequenceFixedWidth
                                                            //sequenceFixedWidth formats the sequence with leading zeros to create specified width
                                                            areaLayerName = args[0].ToString();
                                                            areaLayerFieldName = args[1].ToString();
                                                            genIdAreaFieldName = args[2].ToString();
                                                            sequenceColumnName = args[3].ToString();
                                                            sequenceFixedWidth = args[4].ToString();
                                                            break;
                                                        case 6:  // columnName|sequenceFixedWidth|formatString
                                                            //formatString must contain [seq] and may contain [area] plus any desired text
                                                            areaLayerName = args[0].ToString();
                                                            areaLayerFieldName = args[1].ToString();
                                                            genIdAreaFieldName = args[2].ToString();
                                                            sequenceColumnName = args[3].ToString();
                                                            sequenceFixedWidth = args[4].ToString();
                                                            formatString = args[5].ToString();
                                                            break;
                                                        default: break;
                                                    }

                                                    //Find Area Layer
                                                    // FindLayerByName(areaLayerName, out areaLayer);
                                                    areaLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, areaLayerName);
                                                    if (areaLayer == null)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Area Layer not found: " + areaLayerName);
                                                        break;
                                                    }

                                                    //Find Area Field
                                                    areaFieldPos = areaLayer.FeatureClass.FindField(areaLayerFieldName);
                                                    if (areaFieldPos < 0)
                                                    {
                                                        AAState.WriteLine("                  ERROR: Area Layer field not found: " + areaLayerFieldName);
                                                        break;
                                                    }

                                                    //Find GenID Area Field
                                                    //genIdAreaFieldPos = areaLayer.FeatureClass.FindField(genIdAreaFieldName);
                                                    //if (genIdAreaFieldPos < 0) break;

                                                    //Perform spatial search
                                                    sFilter = new SpatialFilterClass();
                                                    sFilter.Geometry = (IGeometry)inFeature.ShapeCopy;
                                                    sFilter.GeometryField = areaLayer.FeatureClass.ShapeFieldName;
                                                    sFilter.SubFields = areaLayerFieldName;
                                                    sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                                    fCursor = areaLayer.FeatureClass.Search(sFilter, true);
                                                    sourceFeature = fCursor.NextFeature();
                                                    if (sourceFeature != null)
                                                        areaValue = sourceFeature.get_Value(areaFieldPos).ToString();
                                                    else
                                                        break;

                                                    //Check for requested zero padding of sequence number
                                                    if (sequenceFixedWidth != "")
                                                        int.TryParse(sequenceFixedWidth.ToString(), out sequencePadding);

                                                    sequenceColumnNum = AAState._gentab.FindField(sequenceColumnName);
                                                    if (sequenceColumnNum > -1)
                                                    {
                                                        qFilter = new QueryFilterClass();
                                                        qFilter.SubFields = areaLayerFieldName + "," + sequenceColumnName;

                                                        ISQLSyntax sqlSyntax = (ISQLSyntax)AAState._editor.EditWorkspace;
                                                        char[] charBuf = sqlSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix).ToCharArray();
                                                        string strSC = new string(charBuf);
                                                        switch (strSC)
                                                        {
                                                            case "":
                                                                qFilter.WhereClause = genIdAreaFieldName + " = '" + areaValue + "'";
                                                                break;
                                                            case "[":
                                                                qFilter.WhereClause = "[" + genIdAreaFieldName + "]" + " = '" + areaValue + "'";
                                                                break;
                                                            default:
                                                                qFilter.WhereClause = "\"" + genIdAreaFieldName + "\" = '" + areaValue + "'";
                                                                break;
                                                        }

                                                        //get value of first row, increment it, and return incremented value
                                                        for (int j = 0; j < 51; j++)
                                                        {
                                                            row = AAState._gentab.Update(qFilter, false).NextRow();
                                                            if (row.get_Value(sequenceColumnNum) == null)
                                                            {
                                                                sequenceValue = 0;
                                                            }
                                                            else if (row.get_Value(sequenceColumnNum).ToString() == "")
                                                            {
                                                                sequenceValue = 0;
                                                            }
                                                            else
                                                                sequenceValue = Convert.ToInt32(row.get_Value(sequenceColumnNum));
                                                            sequenceValue += 1;
                                                            sequenceValue += 1;
                                                            row.set_Value(sequenceColumnNum, sequenceValue);
                                                            row.Store();
                                                            if (Convert.ToInt32(row.get_Value(sequenceColumnNum)) == sequenceValue)
                                                                break;

                                                        }
                                                        if (sequenceValue == -1)
                                                        {
                                                            //TODO raise error
                                                        }
                                                        else
                                                        {
                                                            if (inObject.Fields.get_Field(fieldNum).Type == esriFieldType.esriFieldTypeString)
                                                                if (formatString == null || formatString == "" || formatString.IndexOf("[seq]") == -1)
                                                                    inObject.set_Value(fieldNum, areaValue + sequenceValue.ToString("D" + sequencePadding) + sequencePostfix);
                                                                else
                                                                {
                                                                    formatString = formatString.Replace("[area]", areaValue);
                                                                    formatString = formatString.Replace("[seq]", sequenceValue.ToString("D" + sequencePadding));
                                                                    inObject.set_Value(fieldNum, formatString);
                                                                }
                                                            else
                                                                inObject.set_Value(fieldNum, sequenceValue);
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    AAState.WriteLine("                  ERROR: GENERATE_ID table is not found");

                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: GENERATE_ID_BY_AREA: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: GENERATE_ID_BY_AREA");
                                            }

                                            break;
                                        //Modified for Release 1.2  (No longer uses ICalculator)
                                        //Requires valid VBScript expression
                                        //Can include string, numeric, and date fields by name in square brackets []
                                        //Example: DateDiff("yyyy",[INSTALLDATE],Now())
                                        case "EXPRESSION":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: EXPRESSION");
                                                if (inObject != null & valData != null)
                                                {
                                                    newValue = valData;
                                                    for (int i = 0; i < inObject.Fields.FieldCount; i++)
                                                    {
                                                        testField = inObject.Fields.get_Field(i);

                                                        int indFld = newValue.ToUpper().IndexOf("[" + testField.Name.ToUpper() + "]");
                                                        while (indFld >= 0)
                                                        {
                                                            AAState.WriteLine("                  replace field: " + testField.Name + " with a value");
                                                            int fldLen = testField.Name.Length;
                                                            string tmpStr1 = newValue.Substring(0, indFld + 1);
                                                            string tmpStr2 = newValue.Substring(indFld + fldLen + 1);
                                                            newValue = tmpStr1 + "_REPLACE_VAL_" + tmpStr2;

                                                            switch (testField.Type)
                                                            {
                                                                case esriFieldType.esriFieldTypeString:

                                                                    if (inObject.get_Value(i) == null || inObject.get_Value(i).ToString() == "")
                                                                    {
                                                                        if (newValue.Contains("IsNull"))
                                                                        {
                                                                            newValue = newValue.Replace("IsNull([" + "_REPLACE_VAL_" + "])", "True");
                                                                        }
                                                                        else if (inObject.get_Value(i) == null)
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", null);
                                                                        }
                                                                        else if (inObject.get_Value(i).ToString() == "")
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", "\"" + inObject.get_Value(i).ToString() + "\"");
                                                                        }
                                                                        else
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", "\"" + inObject.get_Value(i).ToString() + "\"");
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        if (newValue.Contains("IsNull"))
                                                                        {
                                                                            newValue = newValue.Replace("IsNull([" + "_REPLACE_VAL_" + "])", "False");
                                                                        }

                                                                        else
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", "\"" + inObject.get_Value(i).ToString() + "\"");
                                                                        }
                                                                    }

                                                                    // newValue = newValue.Replace("[" + testField.Name + "]", "\"" + inObject.get_Value(i).ToString() + "\"");
                                                                    break;
                                                                case esriFieldType.esriFieldTypeDate:

                                                                    if (inObject.get_Value(i) == null || inObject.get_Value(i).ToString() == "")
                                                                    {
                                                                        if (newValue.Contains("IsNull"))
                                                                        {
                                                                            newValue = newValue.Replace("IsNull([" + "_REPLACE_VAL_" + "])", "True");
                                                                        }
                                                                        else if (inObject.get_Value(i) == null)
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", "CDATE(" + null + ")");
                                                                        }
                                                                        else if (inObject.get_Value(i).ToString() == "")
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", "\"" + inObject.get_Value(i).ToString() + "\"");
                                                                        }
                                                                        else
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", "CDATE(\"" + inObject.get_Value(i).ToString() + "\")");
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        if (newValue.Contains("IsNull"))
                                                                        {
                                                                            newValue = newValue.Replace("IsNull([" + "_REPLACE_VAL_" + "])", "False");
                                                                        }

                                                                        else
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", "CDATE(\"" + inObject.get_Value(i).ToString() + "\")");
                                                                        }
                                                                    }

                                                                    // newValue = newValue.Replace("[" + testField.Name + "]", "CDATE(\"" + inObject.get_Value(i).ToString() + "\")");
                                                                    break;

                                                                default:
                                                                    if (inObject.get_Value(i) == null || inObject.get_Value(i).ToString() == "")
                                                                    {
                                                                        if (newValue.Contains("IsNull"))
                                                                        {
                                                                            newValue = newValue.Replace("IsNull([" + "_REPLACE_VAL_" + "])", "True");
                                                                        }
                                                                        else if (inObject.get_Value(i) == null)
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", null);
                                                                        }
                                                                        else if (inObject.get_Value(i).ToString() == "")
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", null);// "\"" + inObject.get_Value(i).ToString() + "\"");
                                                                        }
                                                                        else
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", "" + inObject.get_Value(i).ToString() + "");
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        if (newValue.Contains("IsNull"))
                                                                        {
                                                                            newValue = newValue.Replace("IsNull([" + "_REPLACE_VAL_" + "])", "False");
                                                                        }

                                                                        else
                                                                        {
                                                                            newValue = newValue.Replace("[" + "_REPLACE_VAL_" + "]", inObject.get_Value(i).ToString());
                                                                        }
                                                                    }
                                                                    //  newValue = newValue.Replace("[" + testField.Name + "]", inObject.get_Value(i).ToString());
                                                                    break;
                                                            }
                                                            indFld = newValue.ToUpper().IndexOf("[" + testField.Name.ToUpper() + "]");
                                                        }
                                                    }
                                                    //MessageBox.Show(newValue);

                                                    try
                                                    {
                                                        newValue = script.Eval(newValue).ToString();
                                                        if (inObject.get_Value(fieldNum).ToString() != newValue)
                                                            inObject.set_Value(fieldNum, newValue);
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        AAState.WriteLine("                  ERROR: evaluating the expression for feature in " + inObject.Class.AliasName + " with OID of " + inObject.OID);
                                                        AAState.WriteLine("                         " + ex.Message);
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: EXPRESSION: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: EXPRESSION");
                                            }
                                            break;

                                        // GUID values are calculated into text fields or into native GUID field types
                                        // When using text field you have an optional argument (valdata) to specify the format
                                        // N-none 32 chars, D-dash 36, B-braces 38, P-Parenthesis 38
                                        case "GUID":
                                            try
                                            {
                                                if (inObject != null)
                                                {
                                                    if (inObject.Fields.get_Field(fieldNum).Type == esriFieldType.esriFieldTypeGUID)
                                                        inObject.set_Value(fieldNum, System.Guid.NewGuid().ToString("B"));
                                                    else if (inObject.Fields.get_Field(fieldNum).Type == esriFieldType.esriFieldTypeString &&
                                                             inObject.Fields.get_Field(fieldNum).Length >= 32)
                                                    {

                                                        valData = valData.Trim();
                                                        if (valData != "N" && valData != "D" && valData != "B" && valData != "P")
                                                            if (inObject.Fields.get_Field(fieldNum).Length >= 38)
                                                                valData = "B";  //Default to braces
                                                            else if (inObject.Fields.get_Field(fieldNum).Length < 36)
                                                                valData = "N";
                                                            else
                                                                valData = "D";
                                                        inObject.set_Value(fieldNum, System.Guid.NewGuid().ToString(valData));
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: EXPRESSION: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: EXPRESSION");
                                            }
                                            break;

                                        case "CREATE_LINKED_RECORD"://Feature Layer|Field To Copy|Field To Populate|Primary Key Field|Foreign Key Field
                                            {
                                                try
                                                {
                                                    AAState.WriteLine("                  Trying: CREATE_LINKED_RECORD");
                                                    if (!String.IsNullOrEmpty(valData))
                                                    {
                                                        args = valData.Split('|');
                                                        if (args.Length != 5)
                                                        {
                                                            AAState.WriteLine("                  ERROR: Format of valdata incorrect");
                                                            break;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Format of valdata incorrect");
                                                        break;
                                                    }
                                                    if (inFeature == null)
                                                    {
                                                        AAState.WriteLine("                  ERROR: The input features is null");
                                                        break;
                                                    }
                                                    sourceLayerName = "";
                                                    sourceFieldName = "";
                                                    sourceField = -1;
                                                    found = false;
                                                    AAState.WriteLine("                  Getting Value Info");
                                                    sourceLayerNames = args[0].ToString().Split(',');
                                                    sourceFieldName = args[1].ToString();
                                                    string targetFieldName = args[2].ToString();
                                                    string sourceIDFieldName = args[3].ToString();
                                                    string targetIDFieldName = args[4].ToString();
                                                    AAState.WriteLine("                  Checking values");
                                                    if (sourceFieldName != null)
                                                    {
                                                        AAState.WriteLine("                  Checking Fields in Source Layer");
                                                        int fldValToCopyIdx = inObject.Fields.FindField(sourceFieldName);
                                                        int fldIDToCopyIdx = inObject.Fields.FindField(sourceIDFieldName);
                                                        if (fldValToCopyIdx > -1 && fldIDToCopyIdx > -1)
                                                        {

                                                            for (int i = 0; i < sourceLayerNames.Length; i++)
                                                            {
                                                                sourceLayerName = sourceLayerNames[i].ToString();

                                                                if (sourceLayerName != "")
                                                                {

                                                                    // Get layer
                                                                    AAState.WriteLine("                  Checking for table to populate");
                                                                    sourceLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, sourceLayerName);

                                                                    if (sourceLayer != null)
                                                                    {

                                                                    }
                                                                    else
                                                                    {
                                                                        ITable pTable = Globals.FindTable(AAState._editor.Map, sourceLayerName);
                                                                        if (pTable != null)
                                                                        {
                                                                            int fldValToPopIdx = pTable.Fields.FindField(targetFieldName);
                                                                            int fldIDToPopIdx = pTable.Fields.FindField(targetIDFieldName);
                                                                            if (fldValToPopIdx > -1 && fldIDToPopIdx > -1)
                                                                            {
                                                                                AAState.WriteLine("                  Trying to create a row in the target table");
                                                                                IRow pNewRow = pTable.CreateRow();
                                                                                AAState.WriteLine("                  Row Created");
                                                                                AAState.WriteLine("                  Trying to Copy ID");
                                                                                try
                                                                                {
                                                                                    pNewRow.set_Value(fldIDToPopIdx, inObject.get_Value(fldIDToCopyIdx));

                                                                                }
                                                                                catch
                                                                                {
                                                                                    AAState.WriteLine("                  ERROR: Could not Copy: " + inObject.get_Value(fldIDToCopyIdx) + " to field: " + targetIDFieldName);
                                                                                }
                                                                                AAState.WriteLine("                  ID successfully copied");
                                                                                AAState.WriteLine("                  Trying to Copy Value");
                                                                                try
                                                                                {
                                                                                    pNewRow.set_Value(fldValToPopIdx, inObject.get_Value(fldValToCopyIdx));

                                                                                }
                                                                                catch
                                                                                {
                                                                                    AAState.WriteLine("                  ERROR: Could not Copy: " + inObject.get_Value(fldValToCopyIdx) + " to field: " + targetFieldName);
                                                                                }
                                                                                AAState.WriteLine("                  Value successfully copied");
                                                                                pNewRow.Store();
                                                                                if (newFeatureList == null)
                                                                                {
                                                                                    newFeatureList = new List<IObject>();
                                                                                }
                                                                                IObject featobj = pNewRow as IObject;

                                                                                if (featobj != null)
                                                                                {
                                                                                    newFeatureList.Add(featobj);
                                                                                }

                                                                                AAState.WriteLine("                  Row successfully stored");
                                                                            }
                                                                            else
                                                                            {
                                                                                AAState.WriteLine("                  ERROR: ID or Field to populate was not found");
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  ERROR: Table to populate not found: " + sourceLayerName);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  ERROR: ID or Field to Copy was not found");
                                                        }

                                                        //if ((!found) && (inObject.Fields.get_Field(fieldNum).IsNullable))
                                                        //{
                                                        //    inObject.set_Value(fieldNum, null);
                                                        //}
                                                    }

                                                }
                                                catch (Exception ex)
                                                {
                                                    AAState.WriteLine("                  ERROR: CREATE_LINKED_RECORD" + Environment.NewLine + ex.Message);
                                                }

                                                finally
                                                {
                                                    AAState.WriteLine("                  Finished: CREATE_LINKED_RECORD");
                                                    // fieldNum = -1;

                                                }
                                                break;

                                            }

                                        case "UPDATE_INTERSECTING_FEATURE"://Intersected Feature|FieldIntersectingFeatureToChange|FromFieldinModifiedFeature
                                            {
                                                try
                                                {
                                                    AAState.WriteLine("                  Trying: UPDATE_INTERSECTING_FEATURE");
                                                    if (!String.IsNullOrEmpty(valData))
                                                    {
                                                        args = valData.Split('|');
                                                        if (args.Length != 3)
                                                        {
                                                            AAState.WriteLine("                  ERROR: Format of valdata incorrect");
                                                            break;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Format of valdata incorrect");
                                                        break;
                                                    }
                                                    if (inFeature == null)
                                                    {
                                                        AAState.WriteLine("                  ERROR: The input features is null");
                                                        break;
                                                    }
                                                    sourceLayerName = "";
                                                    sourceFieldName = "";
                                                    sourceField = -1;
                                                    found = false;
                                                    AAState.WriteLine("                  Getting Value Info");
                                                    sourceLayerNames = args[0].ToString().Split(',');
                                                    sourceFieldName = args[1].ToString();
                                                    string targetFieldName = args[2].ToString();
                                                    AAState.WriteLine("                  Checking values");
                                                    if (sourceFieldName != null)
                                                    {
                                                        for (int i = 0; i < sourceLayerNames.Length; i++)
                                                        {
                                                            sourceLayerName = sourceLayerNames[i].ToString();
                                                            if (sourceLayerName != "")
                                                            {
                                                                // Get layer
                                                                sourceLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, sourceLayerName);

                                                                if (sourceLayer != null)
                                                                {
                                                                    if (inObject.Class != sourceLayer.FeatureClass)
                                                                    {
                                                                        if (Globals.IsEditable(sourceLayer, AAState._editor))
                                                                        {

                                                                            sourceField = sourceLayer.FeatureClass.FindField(sourceFieldName);

                                                                            if (sourceField > -1)
                                                                            {
                                                                                sFilter = new SpatialFilterClass();
                                                                                if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                                                {

                                                                                    try
                                                                                    {
                                                                                        ISpatialReferenceResolution pSRResolution;

                                                                                        pSRResolution = ((sourceLayer.FeatureClass as IGeoDataset).SpatialReference) as ISpatialReferenceResolution;

                                                                                        //  sFilter = new SpatialFilterClass();
                                                                                        double intTol = pSRResolution.get_XYResolution(false);
                                                                                        bool hasXY = ((sourceLayer.FeatureClass as IGeoDataset).SpatialReference).HasXYPrecision();

                                                                                        searchEnvelope = new EnvelopeClass();
                                                                                        searchEnvelope.XMin = 0 - intTol;
                                                                                        searchEnvelope.YMin = 0 - intTol;
                                                                                        searchEnvelope.XMax = 0 + intTol;
                                                                                        searchEnvelope.YMax = 0 + intTol;
                                                                                        searchEnvelope.CenterAt(inFeature.ShapeCopy as IPoint);

                                                                                        //searchEnvelope.SpatialReference = ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference;
                                                                                        searchEnvelope.SpatialReference = ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference;
                                                                                        searchEnvelope.SnapToSpatialReference();
                                                                                        searchEnvelope.Project(AAState._editor.Map.SpatialReference);

                                                                                        sFilter.Geometry = Globals.Env2Polygon(searchEnvelope);

                                                                                    }
                                                                                    catch
                                                                                    {
                                                                                        sFilter.Geometry = inFeature.ShapeCopy;
                                                                                    }

                                                                                }
                                                                                else
                                                                                {
                                                                                    sFilter.Geometry = inFeature.ShapeCopy;
                                                                                }
                                                                                sFilter.GeometryField = sourceLayer.FeatureClass.ShapeFieldName;
                                                                                sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                                                                                fCursor = sourceLayer.FeatureClass.Search(sFilter, false);
                                                                                sourceFeature = fCursor.NextFeature();
                                                                                if (sourceFeature != null)
                                                                                {
                                                                                    int fldIdx = inFeature.Fields.FindField(targetFieldName);
                                                                                    AAState.WriteLine("                  " + targetFieldName + " at index " + fldIdx);
                                                                                    string test = targetFieldName;
                                                                                    if (fldIdx > -1)
                                                                                    {
                                                                                        test = inFeature.get_Value(fldIdx).ToString();
                                                                                        AAState.WriteLine("                  Value Found " + test);
                                                                                    }
                                                                                    AAState.WriteLine("                  Value used " + test);
                                                                                    try
                                                                                    {

                                                                                        if (sourceFeature.Fields.get_Field(sourceField).Type == esriFieldType.esriFieldTypeString)
                                                                                        {
                                                                                            sourceFeature.set_Value(sourceField, test);
                                                                                            sourceFeature.Store();
                                                                                            found = true;
                                                                                            break;
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            if (Globals.IsNumeric(test))
                                                                                            {
                                                                                                if (sourceFeature.Fields.get_Field(sourceField).Type == esriFieldType.esriFieldTypeSmallInteger ||
                                                                                                    sourceFeature.Fields.get_Field(sourceField).Type == esriFieldType.esriFieldTypeInteger)
                                                                                                {

                                                                                                    sourceFeature.set_Value(sourceField, Convert.ToInt32(test));
                                                                                                    sourceFeature.Store();
                                                                                                    found = true;
                                                                                                    break;
                                                                                                }
                                                                                                else if (sourceFeature.Fields.get_Field(sourceField).Type == esriFieldType.esriFieldTypeDouble ||
                                                                                                    sourceFeature.Fields.get_Field(sourceField).Type == esriFieldType.esriFieldTypeSingle)
                                                                                                {
                                                                                                    sourceFeature.set_Value(sourceField, Convert.ToDouble(test));

                                                                                                    sourceFeature.Store(); found = true;
                                                                                                    break;
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                    sourceFeature.set_Value(sourceField, test as object);
                                                                                                    sourceFeature.Store();
                                                                                                    found = true;
                                                                                                    break;
                                                                                                }
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                sourceFeature.set_Value(sourceField, test as object);
                                                                                                sourceFeature.Store();
                                                                                                found = true;
                                                                                                break;
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                    catch
                                                                                    {
                                                                                        AAState.WriteLine("                  ERROR setting value");
                                                                                    }
                                                                                    finally
                                                                                    {
                                                                                        if (found)
                                                                                        {
                                                                                            //   break;
                                                                                        }
                                                                                    }

                                                                                }

                                                                            }
                                                                            else
                                                                            {
                                                                                AAState.WriteLine("                  ERROR: Source field not found: " + sourceFieldName);
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  ERROR/WARNING: Source Layer is not editable: " + sourceLayerName);
                                                                        }
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    AAState.WriteLine("                  ERROR/WARNING: Source Layer not found: " + sourceLayerName);
                                                                }
                                                            }
                                                        }
                                                        //if ((!found) && (inObject.Fields.get_Field(fieldNum).IsNullable))
                                                        //{
                                                        //    inObject.set_Value(fieldNum, null);
                                                        //}
                                                    }

                                                }
                                                catch (Exception ex)
                                                {
                                                    AAState.WriteLine("                  ERROR: UPDATE_INTERSECTING_FEATURE" + Environment.NewLine + ex.Message);
                                                }

                                                finally
                                                {
                                                    AAState.WriteLine("                  Finished: UPDATE_INTERSECTING_FEATURE");
                                                    // fieldNum = -1;

                                                }
                                                break;

                                            }
                                        case "MULTI_FIELD_INTERSECT":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: MULTI_FIELD_INTERSECT");
                                                if (inFeature != null & valData != null)
                                                {
                                                    sourceLayerName = "";
                                                    sourceFieldName = "";
                                                    sourceField = -1;
                                                    found = false;
                                                    //LayerToIntersect|Field To Elevate
                                                    // Parse arguments
                                                    args = valData.Split('|');
                                                    int popFldIdx = 0;
                                                    if (args.GetLength(0) > 2)
                                                    {
                                                        AAState.WriteLine("                  Parsing Valueinfo");

                                                        sourceLayerNames = args[0].ToString().Split(',');
                                                        sourceFieldName = args[1].ToString();
                                                        string[] fieldsToPop = args[2].ToString().Split(',');
                                                        if (args.GetLength(0) == 4)
                                                        {
                                                            AAState.WriteLine("                  Search distance specified");

                                                            if (Globals.IsDouble(args[3]))
                                                            {
                                                                searchDistance = Convert.ToDouble(args[3]);
                                                            }
                                                            else
                                                            {
                                                                searchDistance = 0.0;
                                                            }
                                                        }
                                                        else
                                                        {

                                                            searchDistance = 0.0;
                                                        }

                                                        if (sourceFieldName != null)
                                                        {
                                                            AAState.WriteLine("                  Looping Through Layers");

                                                            for (int i = 0; i < sourceLayerNames.Length; i++)
                                                            {
                                                                if (fieldsToPop.Length == popFldIdx)
                                                                    break;

                                                                sourceLayerName = sourceLayerNames[i].ToString();
                                                                if (sourceLayerName != "")
                                                                {
                                                                    // Get layer
                                                                    sourceLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, sourceLayerName);
                                                                    if (sourceLayer != null)
                                                                    {
                                                                        if (sourceLayer.FeatureClass != null)
                                                                        {
                                                                            sourceField = sourceLayer.FeatureClass.FindField(sourceFieldName);

                                                                            if (sourceField > -1)
                                                                            {
                                                                                sFilter = new SpatialFilterClass();
                                                                                if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                                                {

                                                                                    searchEnvelope = Globals.CalcSearchExtent(sourceLayer, inFeature, searchDistance);

                                                                                    sFilter.Geometry = searchEnvelope;

                                                                                }
                                                                                else
                                                                                {
                                                                                    sFilter.Geometry = inFeature.ShapeCopy;
                                                                                }
                                                                                sFilter.GeometryField = sourceLayer.FeatureClass.ShapeFieldName;
                                                                                sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                                                                                fCursor = sourceLayer.FeatureClass.Search(sFilter, true);
                                                                                sourceFeature = fCursor.NextFeature();
                                                                                while (sourceFeature != null)
                                                                                {
                                                                                    if (fieldsToPop.Length == popFldIdx)
                                                                                        break;

                                                                                    string test = sourceFeature.get_Value(sourceField).ToString();

                                                                                    int tempFieldNum = inObject.Fields.FindField(fieldsToPop[popFldIdx]);
                                                                                    popFldIdx++;
                                                                                    if (tempFieldNum > -1)
                                                                                    {
                                                                                        inObject.set_Value(tempFieldNum, sourceFeature.get_Value(sourceField));
                                                                                    }
                                                                                    sourceFeature = fCursor.NextFeature();

                                                                                }

                                                                            }
                                                                            else
                                                                            {
                                                                                AAState.WriteLine("                  ERROR: Source field not found: " + sourceFieldName);
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  ERROR/WARNING: Datasource is invalid: " + sourceLayerName);
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        AAState.WriteLine("                  ERROR/WARNING: Source Layer not found: " + sourceLayerName);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    AAState.WriteLine("                  ERROR/WARNING: Source Layer string is empty");

                                                                }
                                                            }

                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  ERROR: Field name is invalid");

                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Invalid Value method definition");

                                                    }

                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: MULTI_FIELD_INTERSECT: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: MULTI_FIELD_INTERSECT");
                                            }
                                            break;
                                        case "INTERSECT_STATS":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: INTERSECT_STATS");
                                                if (inFeature != null & valData != null)
                                                {
                                                    sourceLayerName = "";
                                                    sourceFieldName = "";
                                                    sourceField = -1;
                                                    found = false;
                                                    //LayerToIntersect|Field To Elevate
                                                    // Parse arguments
                                                    args = valData.Split('|');
                                                    int AverageCount = 0;
                                                    if (args.GetLength(0) > 2)
                                                    {
                                                        AAState.WriteLine("                  Parsing Valueinfo");

                                                        sourceLayerNames = args[0].ToString().Split(',');
                                                        sourceFieldName = args[1].ToString();
                                                        string statType = args[2].ToString();
                                                        if (args.GetLength(0) == 4)
                                                        {
                                                            AAState.WriteLine("                  Search distance specified");

                                                            if (Globals.IsDouble(args[3]))
                                                                searchDistance = Convert.ToDouble(args[3]);
                                                            else
                                                                searchDistance = 0.0;
                                                        }
                                                        else
                                                        {

                                                            searchDistance = 0.0;
                                                        }
                                                        double result = -999999.1;

                                                        if (sourceFieldName != null)
                                                        {
                                                            AAState.WriteLine("                  Looping Through Layers");

                                                            for (int i = 0; i < sourceLayerNames.Length; i++)
                                                            {

                                                                sourceLayerName = sourceLayerNames[i].ToString();
                                                                if (sourceLayerName != "")
                                                                {
                                                                    // Get layer
                                                                    sourceLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, sourceLayerName);
                                                                    if (sourceLayer != null)
                                                                    {
                                                                        if (sourceLayer.FeatureClass != null)
                                                                        {
                                                                            sourceField = sourceLayer.FeatureClass.FindField(sourceFieldName);

                                                                            if (sourceField > -1)
                                                                            {
                                                                                sFilter = new SpatialFilterClass();
                                                                                if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                                                {

                                                                                    searchEnvelope = Globals.CalcSearchExtent(sourceLayer, inFeature, searchDistance);

                                                                                    sFilter.Geometry = searchEnvelope;

                                                                                }
                                                                                else
                                                                                {
                                                                                    sFilter.Geometry = inFeature.ShapeCopy;
                                                                                }
                                                                                sFilter.GeometryField = sourceLayer.FeatureClass.ShapeFieldName;
                                                                                sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                                                                                fCursor = sourceLayer.FeatureClass.Search(sFilter, true);
                                                                                sourceFeature = fCursor.NextFeature();
                                                                                while (sourceFeature != null)
                                                                                {
                                                                                    string test = sourceFeature.get_Value(sourceField).ToString();
                                                                                    if (Globals.IsNumeric(test))
                                                                                    {
                                                                                        double valToTest = Convert.ToDouble(test);
                                                                                        if (result == -999999.1)
                                                                                        {
                                                                                            result = valToTest;

                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            switch (statType.ToUpper())
                                                                                            {
                                                                                                case "MAX":
                                                                                                    if (result < valToTest)
                                                                                                    {
                                                                                                        result = valToTest;

                                                                                                    }
                                                                                                    break;
                                                                                                case "MIN":
                                                                                                    if (result > valToTest)
                                                                                                    {
                                                                                                        result = valToTest;

                                                                                                    }
                                                                                                    break;
                                                                                                case "SUM":
                                                                                                    result += valToTest;

                                                                                                    break;
                                                                                                case "AVERAGE":
                                                                                                    result += valToTest;
                                                                                                    AverageCount++;
                                                                                                    break;
                                                                                                case "MEAN":
                                                                                                    result += valToTest;
                                                                                                    AverageCount++;

                                                                                                    break;
                                                                                                default:
                                                                                                    AAState.WriteLine("                  ERROR: Unsupported stat type: " + test);
                                                                                                    break;
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        AAState.WriteLine("                  ERROR/WARNING: Non numeric value returned: " + test);
                                                                                    }
                                                                                    sourceFeature = fCursor.NextFeature();

                                                                                }

                                                                            }
                                                                            else
                                                                            {
                                                                                AAState.WriteLine("                  ERROR: Source field not found: " + sourceFieldName);
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  ERROR/WARNING: Datasource is invalid: " + sourceLayerName);
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        AAState.WriteLine("                  ERROR/WARNING: Source Layer not found: " + sourceLayerName);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    AAState.WriteLine("                  ERROR/WARNING: Source Layer string is empty");

                                                                }
                                                            }

                                                            if (result != -999999.1)
                                                            {
                                                                if (AverageCount != 0)
                                                                {
                                                                    result = result / AverageCount;
                                                                }
                                                                inObject.set_Value(fieldNum, result);

                                                            }
                                                            else
                                                            {
                                                                IField field = inObject.Fields.get_Field(fieldNum);
                                                                object newval = field.DefaultValue;
                                                                if (newval == null)
                                                                {
                                                                    if (field.IsNullable)
                                                                    {
                                                                        inObject.set_Value(fieldNum, null);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    inObject.set_Value(fieldNum, newval);
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            AAState.WriteLine("                  ERROR: Field name is invalid");

                                                        }
                                                    }
                                                    else
                                                    {
                                                        AAState.WriteLine("                  ERROR: Invalid Value method definition");

                                                    }

                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: INTERSECT_STATS: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: INTERSECT_STATS");
                                            }
                                            break;
                                        case "INTERSECTING_FEATURE":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: INTERSECTING_FEATURE");
                                                if (inFeature != null & valData != null)
                                                {
                                                    sourceLayerName = "";
                                                    sourceFieldName = "";
                                                    sourceField = -1;
                                                    found = false;

                                                    // Parse arguments
                                                    args = valData.Split('|');
                                                    if (args.GetLength(0) >= 2)
                                                    {
                                                        sourceLayerNames = args[0].ToString().Split(',');
                                                        sourceFieldName = args[1].ToString();

                                                        if (sourceFieldName != null)
                                                        {
                                                            for (int i = 0; i < sourceLayerNames.Length; i++)
                                                            {
                                                                sourceLayerName = sourceLayerNames[i].ToString();
                                                                if (sourceLayerName != "")
                                                                {
                                                                    // Get layer
                                                                    sourceLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, sourceLayerName);
                                                                    if (sourceLayer != null)
                                                                    {
                                                                        sourceField = sourceLayer.FeatureClass.FindField(sourceFieldName);

                                                                        if (sourceField > -1)
                                                                        {
                                                                            sFilter = new SpatialFilterClass();

                                                                            sFilter.GeometryField = sourceLayer.FeatureClass.ShapeFieldName;
                                                                            sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                                                                            sFilter.set_OutputSpatialReference(sourceLayer.FeatureClass.ShapeFieldName, (sourceLayer.FeatureClass as IGeoDataset).SpatialReference);
                                                                            //sFilter.set_OutputSpatialReference(sourceLayer.FeatureClass.ShapeFieldName, AAState._editor.Map.SpatialReference);
                                                                            if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                                                                            {

                                                                                try
                                                                                {
                                                                                    IGeometry pSourceGeo = inFeature.ShapeCopy as IPoint;
                                                                                    pSourceGeo.SpatialReference = ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference;
                                                                                    pSourceGeo.Project((sourceLayer.FeatureClass as IGeoDataset).SpatialReference);
                                                                                    //pSourceGeo.Project(AAState._editor.Map.SpatialReference);

                                                                                    bool hasXY;
                                                                                    hasXY = ((sourceLayer.FeatureClass as IGeoDataset).SpatialReference).HasXYPrecision();
                                                                                    //hasXY = (AAState._editor.Map.SpatialReference).HasXYPrecision();

                                                                                    double intTol = .001;
                                                                                    if (hasXY)
                                                                                    {
                                                                                        ISpatialReferenceResolution pSRResolution;

                                                                                        pSRResolution = ((sourceLayer.FeatureClass as IGeoDataset).SpatialReference) as ISpatialReferenceResolution;
                                                                                        //pSRResolution = (AAState._editor.Map.SpatialReference) as ISpatialReferenceResolution;
                                                                                        intTol = pSRResolution.get_XYResolution(false) * 2;
                                                                                    }

                                                                                    searchEnvelope = new EnvelopeClass();
                                                                                    searchEnvelope.XMin = 0 - intTol;
                                                                                    searchEnvelope.YMin = 0 - intTol;
                                                                                    searchEnvelope.XMax = 0 + intTol;
                                                                                    searchEnvelope.YMax = 0 + intTol;
                                                                                    searchEnvelope.CenterAt(pSourceGeo as IPoint);

                                                                                    searchEnvelope.SpatialReference = ((sourceLayer.FeatureClass as IGeoDataset).SpatialReference);
                                                                                    //searchEnvelope.SpatialReference = (AAState._editor.Map.SpatialReference);

                                                                                    //searchEnvelope.SpatialReference = ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference;
                                                                                    //searchEnvelope.SnapToSpatialReference();
                                                                                    //if (AAState._editor.Map.SpatialReference != ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference)
                                                                                    //{

                                                                                    //  searchEnvelope.Project((sourceLayer.FeatureClass as IGeoDataset).SpatialReference);

                                                                                    //searchEnvelope.Project(AAState._editor.Map.SpatialReference);
                                                                                    //}

                                                                                    sFilter.Geometry = Globals.Env2Polygon(searchEnvelope);

                                                                                    //searchEnvelope.Expand(.1, .1, true);
                                                                                    //searchEnvelope.Expand(searchDistance, searchDistance, false);
                                                                                }
                                                                                catch
                                                                                {
                                                                                    IGeometry pGeo = inFeature.ShapeCopy;
                                                                                    pGeo.SpatialReference = ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference;
                                                                                    pGeo.Project(AAState._editor.Map.SpatialReference);

                                                                                    sFilter.Geometry = pGeo;

                                                                                }
                                                                            }
                                                                            else
                                                                            {
                                                                                IGeometry pGeo = inFeature.ShapeCopy;
                                                                                pGeo.SpatialReference = ((inFeature.Class as IFeatureClass) as IGeoDataset).SpatialReference;
                                                                                pGeo.Project(AAState._editor.Map.SpatialReference);

                                                                                sFilter.Geometry = pGeo;

                                                                            }
                                                                            fCursor = sourceLayer.FeatureClass.Search(sFilter, true);
                                                                            sourceFeature = fCursor.NextFeature();
                                                                            while (sourceFeature != null)
                                                                            {
                                                                                string test = sourceFeature.get_Value(sourceField).ToString();
                                                                                inObject.set_Value(fieldNum, sourceFeature.get_Value(sourceField));
                                                                                found = true;
                                                                                sourceFeature = fCursor.NextFeature();

                                                                            }

                                                                            if (found == false  && AAState._CheckEnvelope)

                                                                            {
                                                                                sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects;
                                                                              //  sFilter.SpatialRelDescription = "T*T***T*T";
                                                                                fCursor = sourceLayer.FeatureClass.Search(sFilter, true);
                                                                                sourceFeature = fCursor.NextFeature();
                                                                                while (sourceFeature != null)
                                                                                {
                                                                                    string test = sourceFeature.get_Value(sourceField).ToString();
                                                                                    inObject.set_Value(fieldNum, sourceFeature.get_Value(sourceField));
                                                                                    found = true;
                                                                                    sourceFeature = fCursor.NextFeature();

                                                                                }

                                                                            }
                                                                            if (found)
                                                                            {
                                                                                break;
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  ERROR: Source field not found: " + sourceFieldName);
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        AAState.WriteLine("                  ERROR/WARNING: Source Layer not found: " + sourceLayerName);
                                                                    }
                                                                }
                                                            }
                                                            if (!found)
                                                            {
                                                                IField field = inObject.Fields.get_Field(fieldNum);
                                                                object newval = field.DefaultValue;
                                                                if (newval == null)
                                                                {
                                                                    if (field.IsNullable)
                                                                    {
                                                                        inObject.set_Value(fieldNum, null);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    inObject.set_Value(fieldNum, newval);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: INTERSECTING_FEATURE: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: INTERSECTING_FEATURE");
                                            }
                                            break;
                                        case "INTERSECTING_RASTER":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: INTERSECTING_RASTER");
                                                if (inFeature != null & valData != null)
                                                {

                                                    sourceLayerName = "";
                                                    formatString = "";
                                                    found = false;

                                                    // Parse arguments
                                                    args = valData.Split('|');
                                                    if (args.Length < 1) break;
                                                    switch (args.Length)
                                                    {
                                                        case 1:
                                                            sourceLayerNames = args[0].ToString().Split(',');
                                                            break;
                                                        case 2:
                                                            sourceLayerNames = args[0].ToString().Split(',');
                                                            formatString = args[1].ToString();
                                                            break;
                                                        default: break;
                                                    }

                                                    // Get layer
                                                    for (int i = 0; i < sourceLayerNames.Length; i++)
                                                    {
                                                        sourceLayerName = sourceLayerNames[i].ToString();
                                                        IPoint pLoc = Globals.GetGeomCenter(inFeature);

                                                        if (pLoc != null)
                                                        {
                                                            string cellVal = GetCellValue(sourceLayerName, pLoc, AAState._editor.Map);// Globals.GetCellValue(sourceLayerName, pLoc, _editor.Map);
                                                            AAState.WriteLine("                  ERROR/WARING: No cell value or raster was found: " + sourceLayerName);
                                                            if (cellVal != null && cellVal != "" && cellVal != "No Raster")
                                                            {

                                                                if (formatString == null || formatString == "" || (inObject.Fields.get_Field(fieldNum).Type != esriFieldType.esriFieldTypeString))
                                                                {
                                                                    inObject.set_Value(fieldNum, cellVal);
                                                                    found = true;
                                                                    break;
                                                                }
                                                                else
                                                                {
                                                                    // formatString = formatString.Replace("[value]",cellVal);
                                                                    formatString = formatString + cellVal;
                                                                    inObject.set_Value(fieldNum, formatString);

                                                                    found = true;
                                                                    break;
                                                                }

                                                            }

                                                        }
                                                    }
                                                    if (!(found) && inObject.Fields.get_Field(fieldNum).IsNullable)
                                                        inObject.set_Value(fieldNum, null);
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: INTERSECTING_RASTER: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: INTERSECTING_RASTER");
                                            }
                                            break;
                                        case "INTERSECTING_LAYER_DETAILS":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: INTERSECTING_LAYER_DETAILS");
                                                if (inFeature != null & valData != null)
                                                {

                                                    sourceLayerName = "";
                                                    formatString = "";
                                                    found = false;

                                                    // Parse arguments
                                                    args = valData.Split('|');
                                                    if (args.Length < 1) break;
                                                    switch (args.Length)
                                                    {
                                                        case 1:
                                                            sourceLayerNames = args[0].ToString().Split(',');
                                                            formatString = "P";
                                                            break;
                                                        case 2:
                                                            sourceLayerNames = args[0].ToString().Split(',');
                                                            formatString = args[1].ToString();
                                                            break;
                                                        default: break;
                                                    }

                                                    // Get layer
                                                    for (int i = 0; i < sourceLayerNames.Length; i++)
                                                    {
                                                        sourceLayerName = sourceLayerNames[i].ToString();
                                                        //AAState.WriteLine("                  Getting Features Centeroid");

                                                        //IPoint pLoc = Globals.GetGeomCenter(inFeature);
                                                        IGeometry pGeo = inFeature.ShapeCopy;

                                                        if (pGeo != null)
                                                        {
                                                            // AAState.WriteLine("                  Centroid Found");
                                                            AAState.WriteLine("                  Getting list of " + sourceLayerName + " Layers");
                                                            IEnumLayer pEnum = Globals.GetLayers(AAState._editor.Map, sourceLayerName);

                                                            if (pEnum != null)
                                                            {
                                                                AAState.WriteLine("                  List retrieved of " + sourceLayerName + " Layers");
                                                                AAState.WriteLine("                  Starting Loop");
                                                                ILayer pLay = pEnum.Next();
                                                                ISpatialFilter pSpatFilt;
                                                                while (pLay != null)
                                                                {

                                                                    if (found)
                                                                    {
                                                                        AAState.WriteLine("                  Exiting Layer Loop");
                                                                        break;
                                                                    }
                                                                    AAState.WriteLine("                  Checking " + pLay.Name);

                                                                    if (pLay is IRasterLayer)
                                                                    {

                                                                        IRasterLayer pRasLay = pLay as IRasterLayer;
                                                                        AAState.WriteLine("                  Trying " + pRasLay.Name);
                                                                        IEnvelope pEnv = pRasLay.AreaOfInterest;
                                                                        // ITopologicalOperator pTopo = pEnv as ITopologicalOperator;
                                                                        IRelationalOperator pRel = pEnv as IRelationalOperator;
                                                                        IRelationalOperator2 pRel2 = pEnv as IRelationalOperator2;

                                                                        if (pRel.Crosses(pGeo) || pRel.Touches(pGeo) || pRel.Overlaps(pGeo) || pRel2.ContainsEx(pGeo, esriSpatialRelationExEnum.esriSpatialRelationExClementini))
                                                                        {
                                                                            AAState.WriteLine("                  Geometry does intersect " + pRasLay.Name);
                                                                            switch (formatString)
                                                                            {
                                                                                case "P":
                                                                                    // IDataset pDS = pFLay.FeatureClass as IDataset;

                                                                                    inObject.set_Value(fieldNum, Globals.GetPathForALayer(pLay));
                                                                                    pRasLay = null;
                                                                                    pEnv = null;

                                                                                    pRel = null;
                                                                                    pRel2 = null;
                                                                                    found = true;
                                                                                    break;
                                                                                case "N":
                                                                                    inObject.set_Value(fieldNum, pLay.Name);
                                                                                    pRasLay = null;
                                                                                    pEnv = null;

                                                                                    pRel = null;
                                                                                    pRel2 = null;
                                                                                    found = true;
                                                                                    break;
                                                                                default:
                                                                                    inObject.set_Value(fieldNum, Globals.GetPathForALayer(pLay));
                                                                                    pRasLay = null;
                                                                                    pEnv = null;

                                                                                    pRel = null;
                                                                                    pRel2 = null;
                                                                                    found = true;
                                                                                    break;
                                                                            }
                                                                        }
                                                                    }
                                                                    else if (pLay is IFeatureLayer)
                                                                    {
                                                                        IFeatureLayer pFLay = pLay as IFeatureLayer;
                                                                        if (pFLay.FeatureClass == inObject.Class)
                                                                        {
                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  Trying " + pFLay.Name);
                                                                            pSpatFilt = new SpatialFilterClass();
                                                                            pSpatFilt.GeometryField = pFLay.FeatureClass.ShapeFieldName;
                                                                            pSpatFilt.Geometry = pGeo as IGeometry;
                                                                            pSpatFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                                                            if (pFLay.FeatureClass.FeatureCount(pSpatFilt) > 0)
                                                                            {
                                                                                AAState.WriteLine("                  Geometry does intersect " + pFLay.Name);
                                                                                switch (formatString)
                                                                                {
                                                                                    case "P":
                                                                                        // IDataset pDS = pFLay.FeatureClass as IDataset;
                                                                                        // AAState.WriteLine("                  Exiting Layer Loop");
                                                                                        inObject.set_Value(fieldNum, Globals.GetPathForALayer(pLay));
                                                                                        pFLay = null;
                                                                                        found = true;
                                                                                        break;
                                                                                    case "N":
                                                                                        inObject.set_Value(fieldNum, pLay.Name);
                                                                                        pFLay = null;
                                                                                        found = true;
                                                                                        break;
                                                                                    default:
                                                                                        inObject.set_Value(fieldNum, Globals.GetPathForALayer(pLay));
                                                                                        pFLay = null;
                                                                                        found = true;
                                                                                        //inObject.set_Value(fieldNum, null);
                                                                                        break;
                                                                                }
                                                                            }
                                                                            else
                                                                            {
                                                                                AAState.WriteLine("                  Does not intersect " + pFLay.Name);
                                                                            }
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        AAState.WriteLine("                  Warning: Unsupported type");
                                                                    }
                                                                    pLay = pEnum.Next();
                                                                }
                                                                pEnum = null;

                                                            }
                                                            else
                                                            {
                                                                AAState.WriteLine("                  ERROR: not matching layer types found");
                                                            }

                                                        }
                                                        else
                                                            AAState.WriteLine("                  ERROR: Geo not Found");
                                                    }
                                                    //if (!(found) && inObject.Fields.get_Field(fieldNum).IsNullable)
                                                    //    inObject.set_Value(fieldNum, null);
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: INTERSECTING_LAYER_DETAILS: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: INTERSECTING_LAYER_DETAILS");
                                            }
                                            break;
                                        case "INTERSECTING_FEATURE_DISTANCE":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: INTERSECTING_FEATURE_DISTANCE");
                                                if (inFeature != null & valData != null)
                                                {
                                                    sourceLayerName = "";
                                                    sourceFieldName = "";
                                                    sourceField = -1;

                                                    // Parse arguments
                                                    args = valData.Split('|');
                                                    if (args.GetLength(0) >= 2)
                                                    {
                                                        //    sourceLayerName = args[0].ToString();
                                                        sourceLayerNames = args[0].ToString().Split(',');
                                                        sourceFieldName = args[1].ToString();
                                                    }
                                                    // Get layer

                                                    if (sourceFieldName != null)
                                                    {
                                                        for (int i = 0; i < sourceLayerNames.Length; i++)
                                                        {
                                                            sourceLayerName = sourceLayerNames[i].ToString();
                                                            if (sourceLayerName != "")

                                                                sourceLayerName = args[i].ToString();
                                                            if (i == 0)
                                                                i++;

                                                            sourceLayer = (IFeatureLayer)Globals.FindLayer(AAState._editor.Map, sourceLayerName);
                                                            if (sourceLayer == null)
                                                            {
                                                                AAState.WriteLine("                  ERROR/WARNING: " + sourceLayer + " was not found");
                                                                continue;
                                                            }

                                                            IFeatureClass iFC = inFeature.Class as IFeatureClass;
                                                            if (sourceLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                                                            {
                                                                AAState.WriteLine("                  ERROR: " + sourceLayer + " is a polygon layer");

                                                                break;
                                                            }
                                                            //if (sourceLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolyline || iFC.ShapeType != esriGeometryType.esriGeometryPoint)
                                                            //    break;
                                                            //FindLayerByName(sourceLayerName, out sourceLayer);
                                                            if (sourceLayer != null)
                                                            {
                                                                sourceField = sourceLayer.FeatureClass.FindField(sourceFieldName);

                                                                if (sourceField > -1)
                                                                {
                                                                    sFilter = new SpatialFilterClass();
                                                                    sFilter.Geometry = inFeature.ShapeCopy;
                                                                    sFilter.GeometryField = sourceLayer.FeatureClass.ShapeFieldName;
                                                                    sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                                                                    fCursor = sourceLayer.FeatureClass.Search(sFilter, true);
                                                                    sourceFeature = fCursor.NextFeature();
                                                                    if (sourceFeature != null)
                                                                    {

                                                                        IPoint pIntPnt;
                                                                        if (inFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                                                                        {
                                                                            pIntPnt = Globals.GetIntersection(inFeature.ShapeCopy, sourceFeature.ShapeCopy as IPolyline) as IPoint;

                                                                        }
                                                                        else
                                                                            pIntPnt = inFeature.ShapeCopy as IPoint;

                                                                        double dAlong = Globals.PointDistanceOnLine(pIntPnt, sourceFeature.Shape as IPolyline, 2);
                                                                        string strUnit = Globals.GetSpatRefUnitName(Globals.GetLayersCoordinateSystem(sourceLayer.FeatureClass), true);
                                                                        if (strUnit == "Foot" && dAlong != 1)
                                                                        {
                                                                            strUnit = "Feet";
                                                                        }
                                                                        else if (strUnit == "Meter" && dAlong != 1)
                                                                        {
                                                                            strUnit = "Meters";
                                                                        }
                                                                        string strDis = dAlong + " " + strUnit + " along " + sourceLayer.Name + " with " + sourceLayer.FeatureClass.Fields.get_Field(sourceField).AliasName + " of " + sourceFeature.get_Value(sourceField);

                                                                        if (inObject.Fields.get_Field(fieldNum).Length < strDis.Length - 1)
                                                                        {

                                                                            strDis = dAlong + " " + strUnit + ": " + sourceFeature.get_Value(sourceField);
                                                                            AAState.WriteLine("                  Text is to long, defaulting to length along: " + strDis);

                                                                            if (inObject.Fields.get_Field(fieldNum).Length < strDis.Length - 1)
                                                                            {

                                                                                if (inObject.Fields.get_Field(fieldNum).Length < strDis.Length - 1)
                                                                                {
                                                                                    strDis = dAlong.ToString();
                                                                                    inObject.set_Value(fieldNum, strDis);
                                                                                    break;
                                                                                }
                                                                                else
                                                                                {
                                                                                    inObject.set_Value(fieldNum, strDis);
                                                                                    break;
                                                                                }
                                                                            }
                                                                            else
                                                                            {
                                                                                strDis = dAlong.ToString();
                                                                                AAState.WriteLine("                  Text is to long, defaulting to length along: " + strDis);
                                                                                if (inObject.Fields.get_Field(fieldNum).Length < strDis.Length - 1)
                                                                                {
                                                                                    strDis = dAlong.ToString();
                                                                                    inObject.set_Value(fieldNum, strDis);
                                                                                    break;
                                                                                }
                                                                                else
                                                                                {
                                                                                    inObject.set_Value(fieldNum, strDis);
                                                                                    break;
                                                                                }
                                                                            }

                                                                        }
                                                                        else
                                                                        {
                                                                            AAState.WriteLine("                  Value set to: " + strDis);
                                                                            inObject.set_Value(fieldNum, strDis);
                                                                            break;
                                                                        }
                                                                    }

                                                                    else if (inObject.Fields.get_Field(fieldNum).IsNullable)
                                                                        inObject.set_Value(fieldNum, null);
                                                                }
                                                                else
                                                                {
                                                                    AAState.WriteLine("                  ERROR: " + sourceLayer + ": field: " + sourceFieldName + " was not found");
                                                                }
                                                            }
                                                            else { }
                                                        }
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: INTERSECTING_FEATURE_DISTANCE: " + ex.Message);
                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: INTERSECTING_FEATURE_DISTANCE");
                                            }
                                            break;

                                        //Release: 1.2
                                        //New Dynamic Value Method: NEARSET_FEATURE - similiar to INTERSECTING_FEATURE but requires a search distance.

                                        case "NEAREST_FEATURE":
                                            try
                                            {
                                                AAState.WriteLine("                  Trying: NEAREST_FEATURE");
                                                if (inFeature != null & valData != null)
                                                {
                                                    sourceLayerName = "";
                                                    sourceFieldName = "";
                                                    searchDistance = 0;
                                                    found = false;

                                                    // Parse arguments
                                                    args = valData.Split('|');
                                                    if (args.GetLength(0) > 1)
                                                    {
                                                        sourceLayerNames = args[0].ToString().Split(',');
                                                        sourceFieldName = args[1].ToString();
                                                    }

                                                    if (args.GetLength(0) > 2)
                                                        Double.TryParse(args[2], out searchDistance);

                                                    if (sourceLayerNames.Length > 0 & sourceFieldName != null)
                                                    {
                                                        for (int i = 0; i < sourceLayerNames.Length; i++)
                                                        {
                                                            sourceLayerName = sourceLayerNames[i].ToString();
                                                            if (sourceLayerName != "")
                                                            {
                                                                sourceLayer = Globals.FindLayer(AAState._editor.Map, sourceLayerName) as IFeatureLayer;
                                                                if (sourceLayer != null)
                                                                {
                                                                    sourceField = sourceLayer.FeatureClass.FindField(sourceFieldName);

                                                                    if (sourceField > -1)
                                                                    {
                                                                        sFilter = new SpatialFilterClass();
                                                                        if (searchDistance > 0)
                                                                        {
                                                                            searchEnvelope = inFeature.ShapeCopy.Envelope;
                                                                            searchEnvelope.Expand(searchDistance, searchDistance, false);
                                                                            sFilter.Geometry = searchEnvelope;
                                                                        }
                                                                        else
                                                                            sFilter.Geometry = inFeature.ShapeCopy;

                                                                        sFilter.GeometryField = sourceLayer.FeatureClass.ShapeFieldName;
                                                                        sFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                                                                        fCursor = sourceLayer.FeatureClass.Search(sFilter, false);
                                                                        sourceFeature = fCursor.NextFeature();
                                                                        nearestFeature = null;

                                                                        proxOp = (IProximityOperator)inFeature.Shape;
                                                                        lastDistance = searchDistance;
                                                                        while (!(sourceFeature == null))
                                                                        {
                                                                            distance = proxOp.ReturnDistance(sourceFeature.Shape);
                                                                            if (distance <= lastDistance)
                                                                            {
                                                                                nearestFeature = sourceFeature;
                                                                                lastDistance = distance;
                                                                            }
                                                                            sourceFeature = fCursor.NextFeature();
                                                                        }

                                                                        if (nearestFeature != null)
                                                                        {
                                                                            inObject.set_Value(fieldNum, nearestFeature.get_Value(sourceField));
                                                                            found = true;
                                                                            break;
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        AAState.WriteLine("                  ERROR: " + sourceLayer + ": field: " + sourceFieldName + " was not found");
                                                                    }

                                                                }
                                                                else
                                                                {
                                                                    AAState.WriteLine("                  ERROR: " + sourceLayer + " was not found");
                                                                }
                                                            }
                                                            else
                                                            {
                                                                AAState.WriteLine("                  ERROR: Empty source layer name");
                                                            }

                                                        }
                                                        if (!found)
                                                        {
                                                            IField field = inObject.Fields.get_Field(fieldNum);
                                                            object newval = field.DefaultValue;
                                                            if (newval == null)
                                                            {
                                                                if (field.IsNullable)
                                                                {
                                                                    inObject.set_Value(fieldNum, null);
                                                                }
                                                            }
                                                            else
                                                            {
                                                                inObject.set_Value(fieldNum, newval);
                                                            }
                                                        }
                                                    }
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                AAState.WriteLine("                  ERROR: NEAREST_FEATURE: " + ex.Message);

                                            }
                                            finally
                                            {
                                                AAState.WriteLine("                  Finished: NEAREST_FEATURE");
                                            }
                                            break;

                                        default:
                                            //    MessageBox.Show(valMethod + " for layer " + tableName + " is not a valid method, check the dynamic value table", "Attribute Assistant");
                                            AAState.WriteLine("ERROR: " + valMethod + " for layer " + tableName + " is not a valid method, check the dynamic value table");

                                            break;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show("TableName:" + tableName + "  FieldName:" + fieldName + System.Environment.NewLine + "ValueMethod:" + valMethod + "  ValueData:" + valData + System.Environment.NewLine + "Message: " + ex.Message, "Attribute Assistant Message");
                                    AAState.WriteLine("ERROR: TableName:" + tableName + "  FieldName:" + fieldName + System.Environment.NewLine + "ValueMethod:" + valMethod + "  ValueData:" + valData + System.Environment.NewLine + "Message: " + ex.Message);
                                }

                            }

                            // if (mode == "ON_CREATE")
                            //{
                            if (inObject != null)
                            {

                                inChanges = inObject as IRowChanges;
                                if (fieldNum < inObject.Fields.FieldCount)
                                {
                                    changed = inChanges.get_ValueChanged(fieldNum);
                                    if (changed)
                                        //  if (fieldName.ToUpper() != "SHAPE")
                                        try
                                        {
                                            // AAState.WriteLine("                      Setting Last Value");
                                            if (AAState.lastValueProperties.GetProperty(fieldName) != null)
                                            {
                                                AAState.WriteLine("                      Setting Last Value");
                                                AAState.WriteLine("                           " + fieldName + ": " + inObject.get_Value(fieldNum).ToString());
                                                AAState.lastValueProperties.SetProperty(fieldName, inObject.get_Value(fieldNum));
                                            }

                                            else
                                            {
                                                AAState.WriteLine("                      Setting Last Value");
                                                AAState.WriteLine("                           " + fieldName + ": " + inObject.get_Value(fieldNum).ToString());

                                                AAState.lastValueProperties.SetProperty(fieldName, inObject.get_Value(fieldNum));
                                            }

                                        }
                                        catch
                                        {
                                            //AAState.WriteLine("        Error Setting Last Value " + inObject.Fields.get_Field(fieldNum).Name);

                                        }
                                    //}
                                }
                            }

                        }

                     }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Problem in setup." + System.Environment.NewLine + "Message:" + ex.Message, "Attribute Assistant Message");
                AAState.WriteLine("Error in setup");
            }
            finally
            {
                if (AAState._tab == inObject.Class)
                {
                    AAState.reInitExt();

                }
                if (progressDialog != null)
                {
                    progressDialog.HideDialog();
                }
                AAState.WriteLine("DONE");
                AAState.WriteLine("---------------------------------------");
                if (fCursor != null)
                {
                    Marshal.ReleaseComObject(fCursor);
                    GC.Collect(300);
                    GC.WaitForFullGCComplete();
                }
            }
        }
示例#7
0
        private void setDynamicDefaults(IObject inObject, string mode)
        {
            try
            {
                //Convert row to feature (test for feature is null before using - this could be a table update)
                IFeature inFeature = inObject as IFeature;

                // Skip Orphan Junctions (saves time)
                if (inFeature != null)
                {
                    INetworkFeature inNetFeat = inObject as INetworkFeature;
                    if ((inNetFeat != null) &&
                        (inFeature.Class.ObjectClassID == inNetFeat.GeometricNetwork.OrphanJunctionFeatureClass.ObjectClassID))
                    {
                        return;
                    }
                }

                //Get cursor to dynamic values table retriving only
                ICursor tabCursor;
                getDefaultRows(inObject, out tabCursor);
                IRow row = null;
                if (tabCursor != null)
                {
                    row = tabCursor.NextRow();
                }

                //for each row in the matching rows (matched by table name or wildcard) returned from the config table
                while (row != null)
                {
                    //get fieldname
                    string fieldName = row.get_Value(dynTargetField).ToString();

                    //if this field is found in the feature/object being added or modified...
                    int fieldNum = inObject.Fields.FindField(fieldName);
                    if (fieldNum > -1)
                    {
                        // get requested method and any data parameters
                        string valMethod = row.get_Value(dynMethodField).ToString();
                        string valData   = row.get_Value(dynDataField).ToString();

                        switch (mode)
                        {
                        case "OnCreate":
                            //Continue to next field in config table if create events were not requested
                            if (row.get_Value(dynCreateField).ToString() == "0")
                            {
                                row = tabCursor.NextRow();
                                continue;
                            }
                            break;

                        case "OnChange":
                            // Collect value for changed feature (stored for LAST VALUE method)
                            IRowChanges inChanges = inObject as IRowChanges;
                            bool        changed   = inChanges.get_ValueChanged(fieldNum);
                            if (changed)
                            {
                                lastValueProperties.SetProperty(fieldName, inObject.get_Value(fieldNum));
                            }
                            //Continue to next field in config table if change events were not requested
                            if (row.get_Value(dynChangeField).ToString() == "0")
                            {
                                row = tabCursor.NextRow();
                                continue;
                            }
                            break;
                        }

                        // set values as specified
                        switch (valMethod)
                        {
                        case "TIMESTAMP":

                            inObject.set_Value(fieldNum, DateTime.Now);
                            break;

                        case "LAST_VALUE":

                            if (mode == "OnCreate")
                            {
                                //if (inObject.get_Value(fieldNum) == null)
                                //{
                                object lastValue = lastValueProperties.GetProperty(fieldName);
                                if (lastValue != null)
                                {
                                    inObject.set_Value(fieldNum, lastValue);
                                }
                                //}
                            }


                            break;

                        case "FIELD":

                            // verify that field to copy exists
                            int fieldCopy = inObject.Fields.FindField(valData as string);
                            if (fieldCopy > -1)
                            {
                                //copy value only if current field is empty
                                string currentValue = inObject.get_Value(fieldNum).ToString();
                                if (currentValue == "")
                                {
                                    inObject.set_Value(fieldNum, inObject.get_Value(fieldCopy));
                                }
                            }
                            break;

                        case "CURRENT_USER":

                            if (lastEditorName == null)
                            {
                                lastEditorName = getCurrentUser();
                            }
                            inObject.set_Value(fieldNum, lastEditorName);
                            break;

                        case "GUID":

                            if (mode == "OnCreate")     // SHould only set this once on create to give the object a unique value
                            {
                                object currentValue = inObject.get_Value(fieldNum);
                                if (DBNull.Value == currentValue)     // Do not overwrite if someone else has already generated
                                {
                                    Guid g = Guid.NewGuid();
                                    inObject.set_Value(fieldNum, g.ToString("B").ToUpper());
                                }
                            }

                            break;

                        case "EXPRESSION":

                            if (mode == "OnCreate")
                            {
                                if (inFeature != null & valData != null)
                                {
                                    try
                                    {
                                        int calcField = inFeature.Fields.FindField(fieldName);
                                        //if (inFeature.get_Value(calcField) == null)
                                        //{
                                        int[] fids = { inFeature.OID };
                                        IGeoDatabaseBridge gdbBridge = new GeoDatabaseHelperClass();
                                        IFeatureCursor     fCursor   = (IFeatureCursor)gdbBridge.GetFeatures((IFeatureClass)inFeature.Class, ref fids, false);

                                        ICalculator calc = new CalculatorClass();
                                        calc.Expression      = valData;
                                        calc.Field           = fieldName;
                                        calc.Cursor          = (ICursor)fCursor;
                                        calc.ShowErrorPrompt = false;

                                        ICalculatorCallback calculatorCallback = new CalculatorCallback();
                                        calc.Callback = calculatorCallback;

                                        calc.Calculate();
                                        calculatorCallback = null;
                                        //}
                                    }
                                    catch { }
                                }
                            }
                            break;

                        default:
                            break;
                        }
                    }
                    row = tabCursor.NextRow();
                }

                if (null != tabCursor)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(tabCursor);
                }
            }
            catch (Exception ex)
            {
                _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Error applying dynamic defaults.", ex.ToString());

                MessageBox.Show("Error: \n" + ex.ToString());
            }
        }