/// <summary> /// Helper function to enable/disable a particular parameter based on the possible values /// in its domain. /// </summary> /// <param name="paramObj"> /// The parameter to enabled/disable. The domain for this parameter must be a /// IGPCodedValueDomain. /// </param> private void EnableDisableParamBasedOnDomain(object paramObj) { IGPParameter3 param = paramObj as IGPParameter3; IGPParameterEdit3 paramEdit = paramObj as IGPParameterEdit3; IGPCodedValueDomain domain = param.Domain as IGPCodedValueDomain; paramEdit.Enabled = (domain != null && domain.CodeCount > 0); }
/// <summary> /// Builds a domain containing the usernames of the users to whom a /// user can assign jobs. /// </summary> /// <param name="wmxDb">A reference to the active Workflow Manager database</param> /// <param name="username">The name of the user to be tested</param> /// <param name="extraValues">An array of string values to be added to the list</param> /// <returns>A coded value domain of strings</returns> public static IGPDomain BuildAssignableUsersDomain(IJTXDatabase3 wmxDb, string username, string[] extraValues) { IGPCodedValueDomain domain = null; // Only proceed if the user exists in the Workflow Manager database IJTXUser3 user = wmxDb.ConfigurationManager.GetUser(username) as IJTXUser3; if (user == null) { return(domain as IGPDomain); } // Case 1: If the user can assign the job to anyone, then // just use the "all users" list if (user.HasNamedPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_ASSIGN_ANY_JOB)) { domain = Common.WmauGpDomainBuilder.BuildUsersDomain(wmxDb, extraValues) as IGPCodedValueDomain; } else { domain = new GPCodedValueDomainClass(); string[] eligibleUsers = null; // Case 2: The user can assign jobs to anyone within any of their groups if (user.HasNamedPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_GROUP_JOB_ASSIGN)) { HashSet <string> usernames = new HashSet <string>(); IJTXUserGroupSet groups = user.Groups; for (int i = 0; i < groups.Count; i++) { IJTXUserGroup group = groups.get_Item(i); for (int j = 0; j < group.Users.Count; j++) { usernames.Add(group.Users.get_Item(j).UserName); } } eligibleUsers = usernames.ToArray(); } // Case 3: The user can assign jobs to themselves else if (user.HasNamedPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_INDIVIDUAL_JOB_ASSIGN)) { eligibleUsers = new string[] { username }; } // Case 4: The user can't assign jobs to anyone else { eligibleUsers = new string[0]; } // Sort the types first SortedList <string, string> sortedValues = new SortedList <string, string>(); for (int i = 0; i < eligibleUsers.Length; i++) { sortedValues.Add(eligibleUsers[i], null); } // Add the extra values, if any if (extraValues != null) { foreach (string s in extraValues) { sortedValues.Add(s, null); } } // Add the sorted types to the domain foreach (string value in sortedValues.Keys) { IGPValue tempGpVal = new GPStringClass(); tempGpVal.SetAsText(value); domain.AddCode(tempGpVal, value); } } return(domain as IGPDomain); }
public void UpdateParameters(ESRI.ArcGIS.esriSystem.IArray paramvalues, ESRI.ArcGIS.Geoprocessing.IGPEnvironmentManager pEnvMgr) { try { IGPUtilities3 gpUtilities3 = new GPUtilitiesClass(); IGPValue inputOSMGPValue = gpUtilities3.UnpackGPValue(paramvalues.get_Element(in_osmFeatureClass)); IFeatureClass osmFeatureClass = null; ITable osmInputTable = null; IQueryFilter osmQueryFilter = null; try { gpUtilities3.DecodeFeatureLayer(inputOSMGPValue, out osmFeatureClass, out osmQueryFilter); osmInputTable = osmFeatureClass as ITable; } catch { } try { if (osmInputTable == null) { gpUtilities3.DecodeTableView(inputOSMGPValue, out osmInputTable, out osmQueryFilter); } } catch { } if (osmInputTable == null) { return; } String illegalCharacters = String.Empty; ISQLSyntax sqlSyntax = ((IDataset)osmInputTable).Workspace as ISQLSyntax; if (sqlSyntax != null) { illegalCharacters = sqlSyntax.GetInvalidCharacters(); } // find the field that holds tag binary/xml field int osmTagCollectionFieldIndex = osmInputTable.FindField("osmTags"); // if the Field doesn't exist - wasn't found (index = -1) get out if (osmTagCollectionFieldIndex == -1) { return; } if (((IGPParameter)paramvalues.get_Element(in_attributeSelector)).Altered) { IGPParameter tagCollectionParameter = paramvalues.get_Element(in_attributeSelector) as IGPParameter; IGPMultiValue tagCollectionGPValue = gpUtilities3.UnpackGPValue(tagCollectionParameter) as IGPMultiValue; IGPCodedValueDomain codedTagDomain = tagCollectionParameter.Domain as IGPCodedValueDomain; for (int attributeValueIndex = 0; attributeValueIndex < tagCollectionGPValue.Count; attributeValueIndex++) { string valueString = tagCollectionGPValue.get_Value(attributeValueIndex).GetAsText(); IGPValue testFieldValue = codedTagDomain.FindValue(valueString); if (testFieldValue == null) { codedTagDomain.AddStringCode(valueString, valueString); } } // Get the derived output feature class schema and empty the additional fields. This ensures // that you don't get dublicate entries. // Derived output is the third parameter, so use index 2 for get_Element. IGPParameter3 derivedFeatures = (IGPParameter3)paramvalues.get_Element(out_osmFeatureClass); IGPFeatureSchema schema = (IGPFeatureSchema)derivedFeatures.Schema; schema.AdditionalFields = null; IFieldsEdit fieldsEdit = new FieldsClass(); for (int valueIndex = 0; valueIndex < tagCollectionGPValue.Count; valueIndex++) { string tagString = tagCollectionGPValue.get_Value(valueIndex).GetAsText(); if (tagString != "ALL") { // Check if the input field already exists. string cleanedTagKey = convert2AttributeFieldName(tagString, illegalCharacters); IField tagField = gpUtilities3.FindField(inputOSMGPValue, cleanedTagKey); if (tagField == null) { IFieldEdit fieldEdit = new FieldClass(); fieldEdit.Name_2 = cleanedTagKey; fieldEdit.AliasName_2 = tagCollectionGPValue.get_Value(valueIndex).GetAsText(); fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldEdit.Length_2 = 100; fieldsEdit.AddField(fieldEdit); } } } // Add the additional field to the derived output. IFields fields = fieldsEdit as IFields; schema.AdditionalFields = fields; } //if (inputOSMGPValue.IsEmpty() == false) //{ // if (((IGPParameter)paramvalues.get_Element(in_osmFeatureClass)).HasBeenValidated == false) // { // IGPParameter tagCollectionGPParameter = paramvalues.get_Element(in_attributeSelector) as IGPParameter; // IGPValue tagCollectionGPValue = gpUtilities3.UnpackGPValue(tagCollectionGPParameter); // IGPCodedValueDomain osmTagKeyCodedValues = new GPCodedValueDomainClass(); // if (((IGPMultiValue)tagCollectionGPValue).Count == 0) // { // if (osmTagKeyCodedValues == null) // extractAllTags(ref osmTagKeyCodedValues, osmInputTable, osmQueryFilter, osmTagCollectionFieldIndex, true); // if (osmTagKeyCodedValues != null) // { // tagsParameter = tagCollectionGPParameter as IGPParameterEdit; // tagsParameter.Domain = (IGPDomain)osmTagKeyCodedValues; // } // } // else // { // // let's take the given values and make then part of the domain -- if they are not already // // if we don't do this step then we won't pass the internal validation // IGPCodedValueDomain gpTagDomain = tagCollectionGPParameter.Domain as IGPCodedValueDomain; // if (gpTagDomain != null) // { // if (gpTagDomain.CodeCount == 0) // { // // let's add the value existing in the mentioned multi value to the domain // for (int i = 0; i < ((IGPMultiValue)tagCollectionGPValue).Count; i++) // { // string tagStringValue = ((IGPMultiValue)tagCollectionGPValue).get_Value(i).GetAsText(); // gpTagDomain.AddStringCode(tagStringValue, tagStringValue); // } // ((IGPParameterEdit)tagCollectionGPParameter).Domain = gpTagDomain as IGPDomain; // } // } // } // // Get the derived output feature class schema and empty the additional fields. This ensures // // that you don't get dublicate entries. // // Derived output is the third parameter, so use index 2 for get_Element. // IGPParameter3 derivedFeatures = (IGPParameter3)paramvalues.get_Element(out_osmFeatureClass); // IGPFeatureSchema schema = (IGPFeatureSchema)derivedFeatures.Schema; // schema.AdditionalFields = null; // // Area field name is the second parameter, so use index 1 for get_Element. // IGPMultiValue tagsGPMultiValue = gpUtilities3.UnpackGPValue(paramvalues.get_Element(in_attributeSelector)) as IGPMultiValue; // IFieldsEdit fieldsEdit = new FieldsClass(); // bool extractALLTags = false; // // check if the list contains the "ALL" keyword // for (int valueIndex = 0; valueIndex < tagsGPMultiValue.Count; valueIndex++) // { // if (tagsGPMultiValue.get_Value(valueIndex).GetAsText().Equals("ALL")) // { // extractALLTags = true; // } // } // if (extractALLTags) // { // if (osmTagKeyCodedValues == null) // { // extractAllTags(ref osmTagKeyCodedValues, osmInputTable, osmQueryFilter, osmTagCollectionFieldIndex, false); // } // if (osmTagKeyCodedValues != null) // { // for (int valueIndex = 0; valueIndex < osmTagKeyCodedValues.CodeCount; valueIndex++) // { // // Check if the input field already exists. // string cleanedTagKey = convert2AttributeFieldName(osmTagKeyCodedValues.get_Value(valueIndex).GetAsText(), illegalCharacters); // IField tagField = gpUtilities3.FindField(inputOSMGPValue, cleanedTagKey); // if (tagField == null) // { // IFieldEdit fieldEdit = new FieldClass(); // fieldEdit.Name_2 = cleanedTagKey; // fieldEdit.AliasName_2 = osmTagKeyCodedValues.get_Value(valueIndex).GetAsText(); // fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; // fieldEdit.Length_2 = 100; // fieldsEdit.AddField(fieldEdit); // } // } // } // } // else // { // for (int valueIndex = 0; valueIndex < tagsGPMultiValue.Count; valueIndex++) // { // // Check if the input field already exists. // string cleanedTagKey = convert2AttributeFieldName(tagsGPMultiValue.get_Value(valueIndex).GetAsText(), illegalCharacters); // IField tagField = gpUtilities3.FindField(inputOSMGPValue, cleanedTagKey); // if (tagField == null) // { // IFieldEdit fieldEdit = new FieldClass(); // fieldEdit.Name_2 = cleanedTagKey; // fieldEdit.AliasName_2 = tagsGPMultiValue.get_Value(valueIndex).GetAsText(); // fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; // fieldEdit.Length_2 = 100; // fieldsEdit.AddField(fieldEdit); // } // } // } // // Add the additional field to the derived output. // IFields fields = fieldsEdit as IFields; // schema.AdditionalFields = fields; // } //} } catch { } }