/// <summary>
        /// Builds a domain consisting of the Workflow Manager privileges
        /// </summary>
        /// <returns>A coded value domain of strings</returns>
        private IGPDomain BuildPrivilegesDomain()
        {
            IGPCodedValueDomain domain = new GPCodedValueDomainClass();

            // Sort the types first
            SortedList <string, string> sortedValues = new SortedList <string, string>();
            IJTXPrivilegeSet            privileges   = this.WmxDatabase.ConfigurationManager.Privileges;

            for (int i = 0; i < privileges.Count; i++)
            {
                IJTXPrivilege2 priv = privileges.get_Item(i) as IJTXPrivilege2;
                sortedValues.Add(priv.Name, null);
            }

            // Add the "all privileges" option to the list
            sortedValues.Add(C_OPT_ALL_PRIVILEGES, 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);
        }
Example #2
0
        /// <summary>
        /// Builds a domain consisting of the Workflow Manager privileges
        /// </summary>
        /// <param name="wmxDb">A reference to the active Workflow Manager database</param>
        /// <param name="extraValues">An array of string values to be added to the list</param>
        /// <returns>A coded value domain as an IGPDomain</returns>
        public static IGPDomain BuildPrivilegesDomain(IJTXDatabase3 wmxDb, string[] extraValues)
        {
            IGPCodedValueDomain domain = new GPCodedValueDomainClass();

            // Sort the types first
            SortedList <string, string> sortedValues = new SortedList <string, string>();
            IJTXPrivilegeSet            privileges   = wmxDb.ConfigurationManager.Privileges;

            for (int i = 0; i < privileges.Count; i++)
            {
                IJTXPrivilege2 priv = privileges.get_Item(i) as IJTXPrivilege2;
                sortedValues.Add(priv.Name, 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);
        }
        /// <summary>
        /// Required by IGPFunction2 interface; this function is called when the GP tool is ready to be executed.
        /// </summary>
        /// <param name="paramValues"></param>
        /// <param name="trackCancel"></param>
        /// <param name="envMgr"></param>
        /// <param name="msgs"></param>
        public override void Execute(IArray paramValues, ITrackCancel trackCancel, IGPEnvironmentManager envMgr, IGPMessages msgs)
        {
            // Do some common error-checking
            base.Execute(paramValues, trackCancel, envMgr, msgs);

            try
            {
                // Ensure that the current user has admin access to the current Workflow Manager DB
                if (!CurrentUserIsWmxAdministrator())
                {
                    throw new WmauException(WmauErrorCodes.C_USER_NOT_ADMIN_ERROR);
                }

                IJTXConfigurationEdit2 configEdit = this.WmxDatabase.ConfigurationManager as IJTXConfigurationEdit2;

                // Look up the appropriate privilege(s) and group(s)
                IJTXPrivilegeSet privileges = null;
                if (m_privilegeName.Equals(C_OPT_ALL_PRIVILEGES))
                {
                    privileges = configEdit.Privileges;
                }
                else
                {
                    privileges = new JTXPrivilegeSetClass();
                    (privileges as IJTXPrivilegeSetEdit).Add(configEdit.GetPrivilege(m_privilegeName));
                }

                IJTXUserGroupSet groups = null;
                if (m_groupName.Equals(C_OPT_ALL_GROUPS))
                {
                    groups = configEdit.UserGroups;
                }
                else
                {
                    groups = new JTXUserGroupSetClass();
                    (groups as IJTXUserGroupSetEdit).Add(configEdit.GetUserGroup(m_groupName));
                }

                // Add/remove the privilege(s) to the group(s)
                for (int i = 0; i < privileges.Count; i++)
                {
                    IJTXPrivilege2 privilege = privileges.get_Item(i) as IJTXPrivilege2;
                    for (int j = 0; j < groups.Count; j++)
                    {
                        IJTXUserGroupConfig2 targetGroup = groups.get_Item(j) as IJTXUserGroupConfig2;
                        if (m_privilegeAction.Equals(C_OPT_GRANT))
                        {
                            targetGroup.AssignPrivilegeToGroup2(privilege.UID);
                        }
                        else
                        {
                            targetGroup.RemovePrivilegeFromGroup2(privilege.UID);
                        }
                        targetGroup.Store();
                    }
                }

                // Update the output parameter
                WmauParameterMap  paramMap = new WmauParameterMap(paramValues);
                IGPParameterEdit3 outParam = paramMap.GetParamEdit(C_PARAM_OUT_PRIVILEGE_NAME);
                IGPString         strValue = new GPStringClass();
                strValue.Value = m_privilegeName;
                outParam.Value = strValue as IGPValue;

                msgs.AddMessage(Properties.Resources.MSG_DONE);
            }
            catch (WmauException wmEx)
            {
                try
                {
                    msgs.AddError(wmEx.ErrorCodeAsInt, wmEx.Message);
                }
                catch
                {
                    // Catch anything else that possibly happens
                }
            }
            catch (Exception ex)
            {
                try
                {
                    WmauError error = new WmauError(WmauErrorCodes.C_UNSPECIFIED_ERROR);
                    msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message);
                }
                catch
                {
                    // Catch anything else that possibly happens
                }
            }
            finally
            {
                // Release any COM objects here!
            }
        }