/// <summary> /// Executes the geoprocessing function using the given array of parameter values. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="trackCancel">The track cancel.</param> /// <param name="environmentManager">Provides access to all the current environments and settings of the current client.</param> /// <param name="messages">The messages that are reported to the user.</param> /// <param name="utilities"> /// The utilities object that provides access to the properties and methods of a geoprocessing /// objects. /// </param> protected override void Execute(Dictionary <string, IGPValue> parameters, ITrackCancel trackCancel, IGPEnvironmentManager environmentManager, IGPMessages messages, IGPUtilities2 utilities) { IGPValue field = parameters["in_field"]; IObjectClass table = utilities.OpenTable(parameters["in_table"]); IGPMultiValue modelNames = (IGPMultiValue)parameters["in_field_model_names"]; if (!field.IsEmpty() && modelNames.Count > 0) { var fieldName = field.GetAsText(); int index = table.FindField(fieldName); foreach (var modelName in modelNames.AsEnumerable().Select(o => o.GetAsText())) { messages.Add(esriGPMessageType.esriGPMessageTypeInformative, "Removing the {0} field model name from the {1} field.", modelName, fieldName); ModelNameManager.Instance.RemoveFieldModelName(table, table.Fields.Field[index], modelName); } // Success. parameters["out_results"].SetAsText("true"); } else { // Failure. parameters["out_results"].SetAsText("false"); } }
/// <summary> /// Gets all of the field ArcFM Auto Updaters that have been configured for the specified /// <paramref name="editEvent" /> on the <paramref name="table" /> object class for specified fields. /// </summary> /// <param name="source">The source.</param> /// <param name="table">The object class.</param> /// <param name="subtypeCode">The subtype code.</param> /// <param name="editEvent">The edit event.</param> /// <param name="fieldNames">The field names.</param> /// <returns> /// Returns a <see cref="Dictionary{Key, Value}" /> representing the automatic values for the subtypes and the /// individual fields. /// </returns> /// <exception cref="System.ArgumentNullException"> /// fieldNames /// or /// table /// </exception> /// <exception cref="ArgumentNullException">fieldNames /// or /// table</exception> public static Dictionary <string, IEnumerable <IMMAutoValue> > GetAutoValues(this IMMConfigTopLevel source, IObjectClass table, int subtypeCode, mmEditEvent editEvent, params string[] fieldNames) { if (source == null) { return(null); } if (fieldNames == null) { throw new ArgumentNullException("fieldNames"); } if (table == null) { throw new ArgumentNullException("table"); } Dictionary <string, IEnumerable <IMMAutoValue> > list = new Dictionary <string, IEnumerable <IMMAutoValue> >(); IMMSubtype subtype = source.GetSubtypeByID(table, subtypeCode, false); if (subtype != null) { foreach (var fieldName in fieldNames) { int index = table.FindField(fieldName); var values = subtype.GetAutoValues(index, editEvent); list.Add(fieldName, values); } } return(list); }
/// <summary> /// Gets a dictionary of the fields that are assigned the <paramref name="modelNames" /> organized by the model name /// followed by the field indexes. /// specified <paramref name="source" />. /// </summary> /// <param name="source">The object class</param> /// <param name="modelNames">The model names.</param> /// <returns> /// Returns the <see cref="Dictionary{Key, Value}" /> representing the field model name for the field indexes. /// </returns> /// <exception cref="ArgumentNullException">modelNames</exception> public static Dictionary <string, List <int> > GetFieldIndexes(this IObjectClass source, params string[] modelNames) { if (source == null) { return(null); } if (modelNames == null) { throw new ArgumentNullException("modelNames"); } Dictionary <string, List <int> > indexes = new Dictionary <string, List <int> >(StringComparer.Create(CultureInfo.CurrentCulture, true)); foreach (var modelName in modelNames) { var list = new List <int>(); if (indexes.ContainsKey(modelName)) { list = indexes[modelName]; } else { indexes.Add(modelName, list); } list.AddRange(source.GetFields(modelName).Select(field => source.FindField(field.Name))); } return(indexes); }
/// <summary> /// Executes the geoprocessing function using the given array of parameter values. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="trackCancel">The track cancel.</param> /// <param name="environmentManager">Provides access to all the current environments and settings of the current client.</param> /// <param name="messages">The messages that are reported to the user.</param> /// <param name="utilities"> /// The utilities object that provides access to the properties and methods of a geoprocessing /// objects. /// </param> protected override void Execute(Dictionary <string, IGPValue> parameters, ITrackCancel trackCancel, IGPEnvironmentManager environmentManager, IGPMessages messages, IGPUtilities2 utilities) { IGPValue value = parameters["in_table"]; IObjectClass table = utilities.OpenTable(value); if (table != null) { IMMConfigTopLevel configTopLevel = ConfigTopLevel.Instance; configTopLevel.Workspace = utilities.GetWorkspace(value); // Load all of the subtypes when the user specified "All" or "-1". int subtype = parameters["in_subtype"].Cast(-1); var subtypeCodes = new List <int>(new[] { subtype }); if (subtype == -1) { ISubtypes subtypes = (ISubtypes)table; subtypeCodes.AddRange(subtypes.Subtypes.AsEnumerable().Select(o => o.Key)); } IGPMultiValue onCreate = (IGPMultiValue)parameters["in_create"]; IGPMultiValue onUpdate = (IGPMultiValue)parameters["in_update"]; IGPMultiValue onDelete = (IGPMultiValue)parameters["in_delete"]; // Load the "Attribute" AUs. var uids = new Dictionary <mmEditEvent, IEnumerable <IUID> >(); uids.Add(mmEditEvent.mmEventFeatureCreate, onCreate.AsEnumerable().Cast <IGPAutoValue>().Select(o => o.UID)); uids.Add(mmEditEvent.mmEventFeatureUpdate, onUpdate.AsEnumerable().Cast <IGPAutoValue>().Select(o => o.UID)); uids.Add(mmEditEvent.mmEventFeatureDelete, onDelete.AsEnumerable().Cast <IGPAutoValue>().Select(o => o.UID)); IGPValue field = parameters["in_field"]; int index = table.FindField(field.GetAsText()); // Enumerate through all of the subtypes making changes. foreach (var subtypeCode in subtypeCodes) { // Load the configurations for the table and subtype. IMMSubtype mmsubtype = configTopLevel.GetSubtypeByID(table, subtypeCode, false); // Load the field configurations. IMMField mmfield = null; mmsubtype.GetField(index, ref mmfield); // Update the list to have these UIDs removed. ID8List list = (ID8List)mmfield; base.Remove(uids, list, messages); } // Commit the changes to the database. configTopLevel.SaveFeatureClassToDB(table); // Success. parameters["out_results"].SetAsText("true"); } else { // Failure. parameters["out_results"].SetAsText("false"); } }
private SortedDictionary <string, object> GetCodeValues( [NotNull] string fieldName, [NotNull] IObjectClass objectClass) { int fieldIndex = objectClass.FindField(fieldName); Assert.True(fieldIndex >= 0, "Unknown field {0}", fieldName); IField field = objectClass.Fields.Field[fieldIndex]; return(GetCodeValuesCore(field, objectClass)); }
public GdbRow(int oid, [NotNull] IObjectClass gdbTable) { OID = oid; _gdbTable = gdbTable; var oidFieldIndex = _gdbTable.FindField(_gdbTable.OIDFieldName); if (oidFieldIndex >= 0) { set_Value(oidFieldIndex, oid); } }
protected virtual SortedDictionary <string, object> GetCodeValuesCore( [NotNull] IField field, [NotNull] IObjectClass table) { _msg.VerboseDebugFormat("Reading values for field {0}", field.Name); SortedDictionary <string, object> codeValues; var codedValueDomain = field.Domain as ICodedValueDomain; if (codedValueDomain == null) { int fieldIndex = table.FindField(field.Name); if (table is ISubtypes subtypesTbl && subtypesTbl.SubtypeFieldIndex == fieldIndex) { IList <Subtype> subtypes = DatasetUtils.GetSubtypes(table); codeValues = new SortedDictionary <string, object>(); foreach (Subtype subtype in subtypes) { codeValues.Add(subtype.Name, subtype.Code); } return(codeValues); } } Assert.True(codedValueDomain != null, "Field '{0}' not a coded value domain", field.Name); SortedDictionary <object, string> valueCodes = DomainUtils.GetCodedValueMap <object>(codedValueDomain); codeValues = new SortedDictionary <string, object>(); foreach (KeyValuePair <object, string> pair in valueCodes) { _msg.VerboseDebugFormat("Adding key / value pair {0} / {1} to result", pair.Value, pair.Key); codeValues.Add(pair.Value, pair.Key); } Assert.True(codeValues.ContainsKey(_nullValue) == false, _nullValue + " exists in domain of field " + field.Name); // add <Null> Value object nullObject = GetNullObject(field, valueCodes); codeValues.Add(_nullValue, nullObject); return(codeValues); }
private string GetDomainName([NotNull] string fieldName) { IObjectClass objectClass = ConfiguratorUtils.OpenFromDefaultDatabase(Dataset); int fieldIndex = objectClass.FindField(fieldName); IField field = objectClass.Fields.Field[fieldIndex]; IDomain domain = field.Domain; return(domain == null ? "No Domain" : domain.Name); }
/// <summary> /// Finds index of the <see cref="IField" /> that has been assigned the <paramref name="modelName" /> that is within /// the /// specified <paramref name="source" />. /// </summary> /// <param name="source">The object class</param> /// <param name="modelName">The field model name.</param> /// <param name="throwException"> /// if set to <c>true</c> if an exception should be thrown when the model name is not /// assigned. /// </param> /// <returns> /// Returns the <see cref="int" /> representing the index of the field assigned the model name. /// </returns> /// <exception cref="MissingFieldModelNameException"></exception> public static int GetFieldIndex(this IObjectClass source, string modelName, bool throwException) { if (source == null) { return(-1); } if (modelName == null) { throw new ArgumentNullException("modelName"); } IField field = source.GetField(modelName, throwException); return((field != null) ? source.FindField(field.Name) : -1); }
/// <summary> /// Pre validates the given set of values. /// </summary> /// <param name="parameters">The parameters.</param> /// <param name="environmentManager">Provides access to all the current environments and settings of the current client.</param> /// <param name="utilities"> /// The utilities object that provides access to the properties and methods of a geoprocessing /// objects. /// </param> protected override void UpdateParameters(Dictionary <string, IGPParameter> parameters, IGPEnvironmentManager environmentManager, IGPUtilities2 utilities) { // Retrieve the input parameter value. IGPValue table = utilities.UnpackGPValue(parameters["in_table"]); if (!table.IsEmpty()) { // Create the domain based on the fields on the table. IObjectClass oclass = utilities.OpenTable(table); if (oclass != null) { IFields fields = oclass.Fields; if (fields != null) { IGPCodedValueDomain codedValueDomain = new GPCodedValueDomainClass(); foreach (var o in fields.AsEnumerable()) { codedValueDomain.AddStringCode(o.Name, o.Name); } IGPParameterEdit3 derivedFields = (IGPParameterEdit3)parameters["in_field"]; derivedFields.Domain = (IGPDomain)codedValueDomain; } IGPValue field = utilities.UnpackGPValue(parameters["in_field"]); if (!field.IsEmpty()) { int index = oclass.FindField(field.GetAsText()); IGPCodedValueDomain codedValueDomain = new GPCodedValueDomainClass(); foreach (var o in oclass.GetFieldModelNames(oclass.Fields.Field[index])) { codedValueDomain.AddStringCode(o, o); } IGPParameterEdit3 derivedParameter = (IGPParameterEdit3)parameters["in_field_model_names"]; derivedParameter.Domain = (IGPDomain)codedValueDomain; } } } }
private static IEnumerable <int> GetCompareFieldIndexes( [NotNull] IObjectClass objectClass, [NotNull] IEnumerable <string> fieldNames) { IFields fields = objectClass.Fields; foreach (string fieldName in fieldNames) { int index = objectClass.FindField(fieldName); Assert.ArgumentCondition(index >= 0, "Field {0} not found in {1}", fieldName, DatasetUtils.GetName(objectClass)); IField field = fields.Field[index]; esriFieldType fieldType = field.Type; Assert.ArgumentCondition(IsSupportedCompareFieldType(fieldType), "Type of field {0} is not supported for comparison: {1}", fieldName, fieldType); yield return(index); } }