/// <summary> /// Helper function to recursively extract the queries stored in a job query /// container and add them to a list. /// </summary> /// <param name="container">The container in which the queries are stored</param> /// <param name="prefix"> /// A "prefix" string to prepend to the query names before they're inserted into /// the list /// </param> /// <param name="queryList"> /// A sorted list into which the extracted queries will be added. This function /// is intended to be called recursively in the case of job queries contained /// within subcontainers, so the list is *not* cleared by the function. /// </param> private static void AddQueriesFromContainer( IJTXJobQueryContainer container, string prefix, SortedList <string, string> queryList) { // Add the queries from the container at the current level IJTXJobQuerySet querySet = container.Queries; for (int i = 0; i < querySet.Count; i++) { IJTXJobQuery query = querySet.get_Item(i) as IJTXJobQuery; queryList.Add(prefix + query.Name, null); } // Iterate through each of the subcontainers and add them as well IJTXJobQueryContainerSet subcontainers = container.SubContainers; for (int i = 0; i < subcontainers.Count; i++) { IJTXJobQueryContainer tempContainer = subcontainers.get_Item(i); WmauGpDomainBuilder.AddQueriesFromContainer( tempContainer, prefix + tempContainer.Name + Properties.Resources.CONST_JOB_QUERY_SEP, queryList); } }
/// <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 { WmauParameterMap paramMap = new WmauParameterMap(paramValues); IJTXConfiguration3 configMgr = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3; // Determine which query the user has selected SortedList <string, IJTXJobQuery> queryMap = new SortedList <string, IJTXJobQuery>(); AddQueriesFromContainer(configMgr.GetPublicQueryContainer(), string.Empty, queryMap); if (!queryMap.Keys.Contains(m_queryName)) { throw new WmauException(WmauErrorCodes.C_UNKNOWN_QUERY_ERROR); } // Run the selected job query IJTXJobQuery tempQuery = queryMap[m_queryName]; // TODO: Change this to use ".Evaluate()" once it's fixed List <int> jobIds = ParseJobIdsFromXml(tempQuery.EvaluateXML()); jobIds.Sort(); // Store the job IDs from the query into the output GP param IGPMultiValue outputValues = new GPMultiValueClass(); outputValues.MemberDataType = paramMap.GetParam(C_PARAM_OUT_JOB_ID_LIST).DataType; for (int i = 0; i < jobIds.Count; i++) { IGPLong jobIdVal = new GPLongClass(); jobIdVal.Value = jobIds[i]; outputValues.AddValue(jobIdVal as IGPValue); msgs.AddMessage("Found job: " + jobIds[i]); } paramMap.GetParamEdit(C_PARAM_OUT_JOB_ID_LIST).Value = (IGPValue)outputValues; 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) { WmauError error = new WmauError(WmauErrorCodes.C_UNSPECIFIED_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } }