public static bool IsHluLayer(IFeatureLayer layer, IFields origFields, IFieldChecker fieldChecker, object[] validWorkspaces, Dictionary<Type, int> typeMapSystemToSQL, ref HluGISLayer.incid_mm_polygonsDataTable hluLayerStructure, out int[] hluFieldMap, out string[] hluFieldNames) { hluFieldMap = null; hluFieldNames = null; if ((layer == null) || !layer.Valid || (((IFeatureLayerDefinition)layer).DefinitionSelectionSet != null)) return false; bool isHlu = true; try { IFeatureClass testFeatureClass = layer.FeatureClass; if (hluLayerStructure == null) hluLayerStructure = new HluGISLayer.incid_mm_polygonsDataTable(); IFeatureWorkspace testWorkspace = ((IDataset)testFeatureClass).Workspace as IFeatureWorkspace; if (testWorkspace == null) throw (new Exception("Invalid feature workspace.")); if (System.Array.IndexOf(validWorkspaces, ((IWorkspace)testWorkspace).WorkspaceFactory.GetClassID().Value) == -1) throw (new Exception("Invalid workspace type.")); if (testFeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon) throw (new Exception("Invalid geometry type.")); IFieldsEdit fieldsEdit = (IFieldsEdit)origFields; foreach (DataColumn c in hluLayerStructure.Columns) { IField newField = new FieldClass(); IFieldEdit2 newFieldEdit = (IFieldEdit2)newField; newFieldEdit.Name_2 = c.ColumnName; int fieldType; if (!typeMapSystemToSQL.TryGetValue(c.DataType, out fieldType)) throw (new Exception("Invalid field type.")); newFieldEdit.Type_2 = (esriFieldType)fieldType; if ((c.MaxLength != -1) && (newField.Type == esriFieldType.esriFieldTypeString)) newFieldEdit.Length_2 = c.MaxLength; fieldsEdit.AddField(newField); } fieldChecker.ValidateWorkspace = (IWorkspace)testWorkspace; IEnumFieldError error; IFields fixedFields; fieldChecker.Validate(origFields, out error, out fixedFields); hluFieldMap = new int[origFields.FieldCount]; hluFieldNames = new string[hluFieldMap.Length]; for (int i = 0; i < fixedFields.FieldCount; i++) { IField fixedField = fixedFields.get_Field(i); int ordinal = testFeatureClass.Fields.FindField(fixedField.Name); if (ordinal == -1) throw (new Exception("Field name does not match the HLU GIS layer structure.")); IField fcField = testFeatureClass.Fields.get_Field(ordinal); if (fcField.Type != fixedField.Type) throw (new Exception("Field type does not match the HLU GIS layer structure.")); if ((fcField.Type == esriFieldType.esriFieldTypeString) && (fcField.Length > fixedField.Length)) throw (new Exception("Field length does not match the HLU GIS layer structure.")); hluFieldMap[i] = ordinal; //--------------------------------------------------------------------- // FIXED: KI107 (GIS layer column names) // Use the field names from the GIS layer so that they can be found // when performing any SELECT statements. hluFieldNames[i] = fcField.Name; //hluFieldNames[i] = fixedField.Name; //--------------------------------------------------------------------- } } catch { return false; } return isHlu; }
public static bool IsHluLayer(IFeatureLayer layer, IFields origFields, IFieldChecker fieldChecker, object[] validWorkspaces, Dictionary <Type, int> typeMapSystemToSQL, ref HluGISLayer.incid_mm_polygonsDataTable hluLayerStructure, out int[] hluFieldMap, out string[] hluFieldNames) { hluFieldMap = null; hluFieldNames = null; if ((layer == null) || !layer.Valid || (((IFeatureLayerDefinition)layer).DefinitionSelectionSet != null)) { return(false); } bool isHlu = true; try { IFeatureClass testFeatureClass = layer.FeatureClass; if (hluLayerStructure == null) { hluLayerStructure = new HluGISLayer.incid_mm_polygonsDataTable(); } IFeatureWorkspace testWorkspace = ((IDataset)testFeatureClass).Workspace as IFeatureWorkspace; if (testWorkspace == null) { throw (new Exception("Invalid feature workspace.")); } if (System.Array.IndexOf(validWorkspaces, ((IWorkspace)testWorkspace).WorkspaceFactory.GetClassID().Value) == -1) { throw (new Exception("Invalid workspace type.")); } if (testFeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon) { throw (new Exception("Invalid geometry type.")); } IFieldsEdit fieldsEdit = (IFieldsEdit)origFields; foreach (DataColumn c in hluLayerStructure.Columns) { IField newField = new FieldClass(); IFieldEdit2 newFieldEdit = (IFieldEdit2)newField; newFieldEdit.Name_2 = c.ColumnName; int fieldType; if (!typeMapSystemToSQL.TryGetValue(c.DataType, out fieldType)) { throw (new Exception("Invalid field type.")); } newFieldEdit.Type_2 = (esriFieldType)fieldType; if ((c.MaxLength != -1) && (newField.Type == esriFieldType.esriFieldTypeString)) { newFieldEdit.Length_2 = c.MaxLength; } fieldsEdit.AddField(newField); } fieldChecker.ValidateWorkspace = (IWorkspace)testWorkspace; IEnumFieldError error; IFields fixedFields; fieldChecker.Validate(origFields, out error, out fixedFields); hluFieldMap = new int[origFields.FieldCount]; hluFieldNames = new string[hluFieldMap.Length]; for (int i = 0; i < fixedFields.FieldCount; i++) { IField fixedField = fixedFields.get_Field(i); int ordinal = testFeatureClass.Fields.FindField(fixedField.Name); if (ordinal == -1) { throw (new Exception("Field name does not match the HLU GIS layer structure.")); } IField fcField = testFeatureClass.Fields.get_Field(ordinal); if (fcField.Type != fixedField.Type) { throw (new Exception("Field type does not match the HLU GIS layer structure.")); } if ((fcField.Type == esriFieldType.esriFieldTypeString) && (fcField.Length > fixedField.Length)) { throw (new Exception("Field length does not match the HLU GIS layer structure.")); } hluFieldMap[i] = ordinal; hluFieldNames[i] = fixedField.Name; } } catch { return(false); } return(isHlu); }
/// <summary> /// Checks whether or not a given field is valid. /// </summary> /// <param name="field">The field data to validate.</param> /// <param name="type">The field type.</param> /// <returns>returns true if the field is valid; false otherwise.</returns> public bool IsFieldValid(string field, Item.FieldType type) { return(_checkers.ContainsKey(type) ? _checkers[type].Validate(field) : _defaultChecker.Validate(field)); }