/// <summary> /// Pre validates the given set of values. /// This is where you populate derived parameters based on input, among other things. /// </summary> /// <param name="paramValues"></param> /// <param name="pEnvMgr"></param> public override void UpdateParameters(IArray paramValues, IGPEnvironmentManager pEnvMgr) { try { UpdateParametersCommon(paramValues, pEnvMgr); } catch (WmxDefaultDbNotSetException) { // If the default DB wasn't set, stop executing return; } catch (NullReferenceException) { // If one of the parameters was null, stop executing return; } // Build a hash of the parameters for ease of access WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameter3 snName = paramMap.GetParam(C_PARAM_SPATIAL_NOTIFICATION); IGPParameterEdit3 snNameEdit = paramMap.GetParamEdit(C_PARAM_SPATIAL_NOTIFICATION); IGPParameter3 useJobAoi = paramMap.GetParam(C_PARAM_USE_JOB_AOI); IGPParameterEdit3 alternateAoiEdit = paramMap.GetParamEdit(C_PARAM_ALTERNATE_AOI); // Apply a domain to the list of spatial notifications, if possible if (snName.Domain == null || (snName.Domain as IGPCodedValueDomain).CodeCount <= 0) { snNameEdit.Domain = Common.WmauGpDomainBuilder.BuildChangeRulesDomain(this.WmxDatabase); } // Enable/disable the alternate AOI parameter based on the status of the // "use job AOI" parameter alternateAoiEdit.Enabled = !(useJobAoi.Value as IGPBoolean).Value; }
/// <summary> /// Pre validates the given set of values. /// This is where you populate derived parameters based on input, among other things. /// </summary> /// <param name="paramValues"></param> /// <param name="pEnvMgr"></param> public override void UpdateParameters(IArray paramValues, IGPEnvironmentManager pEnvMgr) { try { UpdateParametersCommon(paramValues, pEnvMgr); } catch (WmxDefaultDbNotSetException) { // If the default DB wasn't set, stop executing return; } catch (NullReferenceException) { // If one of the parameters was null, stop executing return; } // Get the parameters as a map for easier access WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameter3 jobId = paramMap.GetParam(C_PARAM_JOB_ID); IGPParameterEdit3 jobIdEdit = paramMap.GetParamEdit(C_PARAM_JOB_ID); // Set the domains for any parameters that need them // Set the job ID domain if it hasn't already been populated if (jobId.Domain == null) { jobIdEdit.Domain = Common.WmauGpDomainBuilder.BuildNonClosedJobIdDomain(this.WmxDatabase); } }
/// <summary> /// Pre validates the given set of values. /// This is where you populate derived parameters based on input, among other things. /// </summary> /// <param name="paramValues"></param> /// <param name="pEnvMgr"></param> public override void UpdateParameters(IArray paramValues, IGPEnvironmentManager pEnvMgr) { try { UpdateParametersCommon(paramValues, pEnvMgr); } catch (WmxDefaultDbNotSetException) { // If the default DB wasn't set, stop executing return; } catch (NullReferenceException) { // If one of the parameters was null, stop executing return; } // Build a hash of which parameter is at which index for ease of access WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameter3 notificationParam = paramMap.GetParam(C_PARAM_EMAIL_NOTIFIER); IGPParameterEdit3 notificationParamEdit = paramMap.GetParamEdit(C_PARAM_EMAIL_NOTIFIER); // Add a domain to the notification parameter if (notificationParam.Domain == null || (notificationParam.Domain as IGPCodedValueDomain).CodeCount <= 0) { notificationParamEdit.Domain = Common.WmauGpDomainBuilder.BuildEmailNotificationDomain(this.WmxDatabase); } }
/// <summary> /// Pre validates the given set of values. /// This is where you populate derived parameters based on input, among other things. /// </summary> /// <param name="paramValues"></param> /// <param name="pEnvMgr"></param> public override void UpdateParameters(IArray paramValues, IGPEnvironmentManager pEnvMgr) { try { UpdateParametersCommon(paramValues, pEnvMgr); } catch (WmxDefaultDbNotSetException) { // If the default DB wasn't set, stop executing return; } catch (NullReferenceException) { // If one of the parameters was null, stop executing return; } WmauParameterMap paramMap = new WmauParameterMap(paramValues); // Retrieve the parameter for source name and add a domain to it IGPParameter3 param = paramMap.GetParam(C_PARAM_MXD_NAME); IGPParameterEdit3 paramEdit = paramMap.GetParamEdit(C_PARAM_MXD_NAME); if (param.Domain == null) { // If there isn't a domain on this parameter yet, that means that it has // not yet had a list of possible MXDs populated. In that case, do // so at this time. paramEdit.Domain = Common.WmauGpDomainBuilder.BuildMapDocumentDomain(this.WmxDatabase); } }
/// <summary> /// Pre validates the given set of values. /// This is where you populate derived parameters based on input, among other things. /// </summary> /// <param name="paramValues"></param> /// <param name="pEnvMgr"></param> public override void UpdateParameters(IArray paramValues, IGPEnvironmentManager pEnvMgr) { try { UpdateParametersCommon(paramValues, pEnvMgr); } catch (WmxDefaultDbNotSetException) { // If the default DB wasn't set, stop executing return; } catch (NullReferenceException) { // If one of the parameters was null, stop executing return; } // Build a hash of the parameters for ease of access WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameter3 dataWorkspace = paramMap.GetParam(C_PARAM_DATA_WORKSPACE); IGPParameterEdit3 dataWorkspaceEdit = paramMap.GetParamEdit(C_PARAM_DATA_WORKSPACE); // Apply a domain to the data workspace list, if necessary if (dataWorkspace.Domain == null || (dataWorkspace.Domain as IGPCodedValueDomain).CodeCount <= 0) { dataWorkspaceEdit.Domain = Common.WmauGpDomainBuilder.BuildWorkspaceDomain(this.WmxDatabase); } }
/// <summary> /// Pre validates the given set of values. /// This is where you populate derived parameters based on input, among other things. /// </summary> /// <param name="paramValues"></param> /// <param name="pEnvMgr"></param> public override void UpdateParameters(IArray paramValues, IGPEnvironmentManager pEnvMgr) { try { UpdateParametersCommon(paramValues, pEnvMgr); } catch (WmxDefaultDbNotSetException) { // If the default DB wasn't set, stop executing return; } catch (NullReferenceException) { // If one of the parameters was null, stop executing return; } // Build a hash of which parameter is at which index for ease of access WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameter3 userParam = paramMap.GetParam(C_PARAM_USER_NAME); IGPParameterEdit3 userParamEdit = paramMap.GetParamEdit(C_PARAM_USER_NAME); // Add a domain to the users parameter if (userParam.Domain == null || (userParam.Domain as IGPCodedValueDomain).CodeCount <= 0) { userParamEdit.Domain = Common.WmauGpDomainBuilder.BuildUsersDomain(this.WmxDatabase, new string[] { C_OPT_ALL_USERS }); } }
/// <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); } // Retrieve the parameter in which the list of MXDs will be stored WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameter3 param = paramMap.GetParam(C_PARAM_MAP_DOCUMENT_LIST); IGPParameterEdit3 paramEdit = paramMap.GetParamEdit(C_PARAM_MAP_DOCUMENT_LIST); // Set up the multi-value objects IGPMultiValue mvValue = new GPMultiValueClass(); mvValue.MemberDataType = param.DataType; // Get the list of MXD names and add them all to the multivalue SortedList <string, string> mapDocuments = this.ListMapDocumentsInDatabase(); foreach (string mapDocName in mapDocuments.Keys) { IGPString strVal = new GPStringClass(); strVal.Value = mapDocName; mvValue.AddValue(strVal as IGPValue); msgs.AddMessage("Map Document: " + mapDocName); } paramEdit.Value = (IGPValue)mvValue; 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 } } }
/// <summary> /// Pre validates the given set of values. /// This is where you populate derived parameters based on input, among other things. /// </summary> /// <param name="paramValues"></param> /// <param name="pEnvMgr"></param> public override void UpdateParameters(IArray paramValues, IGPEnvironmentManager pEnvMgr) { try { UpdateParametersCommon(paramValues, pEnvMgr); } catch (WmxDefaultDbNotSetException) { // If the default DB wasn't set, stop executing return; } catch (NullReferenceException) { // If one of the parameters was null, stop executing return; } // Retrieve the parameter for the jobs to delete and add a domain to it // // NOTE: Add the domain in this function because the Workflow Manager // connection/extension/etc. is not necessarily available when ParameterInfo // is first accessed. WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameter3 param = paramMap.GetParam(C_PARAM_JOB_TO_DELETE); IGPParameterEdit3 paramEdit = paramMap.GetParamEdit(C_PARAM_JOB_TO_DELETE); if (param.Domain == null) { // If there isn't a domain on this parameter yet, that means that it // still needs to be populated. In that case, do so at this time. paramEdit.Domain = Common.WmauGpDomainBuilder.BuildJobIdDomain(this.WmxDatabase); } }
/// <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); // Close the requested job try { IJTXJobManager jobManager = this.WmxDatabase.JobManager; IJTXJob3 job = jobManager.GetJob(m_jobToClose) as IJTXJob3; IJTXConfiguration3 configMgr = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3; if (job.Stage != jtxJobStage.jtxJobStageClosed && !job.CanClose()) { throw new WmauException(WmauErrorCodes.C_CANNOT_CLOSE_JOB_ERROR); } msgs.AddMessage("Closing job " + m_jobToClose + " (" + job.Name + ")"); job.Close(); // Once the job is closed, do the other things that still need to be handled // separately (status updates, notifications, ...) Common.WmauHelperFunctions.UpdateJobStatus(this.WmxDatabase, job); job.Store(); job.LogJobAction( configMgr.GetActivityType(ESRI.ArcGIS.JTX.Utilities.Constants.ACTTYPE_CLOSE_JOB), null, string.Empty); Common.WmauHelperFunctions.SendNotification( ESRI.ArcGIS.JTX.Utilities.Constants.NOTIF_JOB_CLOSED, this.WmxDatabase, job); // Set the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_JOB_CLOSED); IGPLong outValue = new GPLongClass(); outValue.Value = m_jobToClose; outParamEdit.Value = outValue 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) { WmauError error = new WmauError(WmauErrorCodes.C_UNSPECIFIED_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } }
/// <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); } }
/// <summary> /// Post validates the given set of values. /// This is where you flag parameters with warnings and error messages, among other things. /// </summary> /// <param name="paramValues"></param> /// <param name="pEnvMgr"></param> /// <param name="msgs"></param> public override void UpdateMessages(IArray paramValues, IGPEnvironmentManager pEnvMgr, IGPMessages msgs) { // Call the base class function first try { UpdateMessagesCommon(paramValues, pEnvMgr, msgs); } catch (WmxDefaultDbNotSetException) { // If the default DB wasn't set, stop executing return; } // Build a hash of which parameter is at which index, for ease of access WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameter3 snName = paramMap.GetParam(C_PARAM_SPATIAL_NOTIFICATION); IGPParameter3 altAoi = paramMap.GetParam(C_PARAM_ALTERNATE_AOI); IGPParameterEdit3 altAoiEdit = paramMap.GetParamEdit(C_PARAM_ALTERNATE_AOI); // Ensure that there is at least one existing spatial notification in the database if (snName.Domain == null || (snName.Domain as IGPCodedValueDomain).CodeCount <= 0) { WmauError error = new WmauError(WmauErrorCodes.C_NO_SPATIAL_NOTIFICATIONS_FOUND); msgs.ReplaceError(paramMap.GetIndex(C_PARAM_SPATIAL_NOTIFICATION), error.ErrorCodeAsInt, error.Message); } // Check the AOI; ensure that there is exactly one feature selected if (altAoi.Value != null && !altAoi.Value.GetAsText().Equals(string.Empty)) { try { ILayer aoiLayer = m_gpUtilities.DecodeLayer(altAoi.Value); IFeatureLayer featLayer = aoiLayer as IFeatureLayer; IFeatureSelection featSel = aoiLayer as IFeatureSelection; ISelectionSet selSet = featSel.SelectionSet as ISelectionSet; if (featLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon) { WmauError error = new WmauError(WmauErrorCodes.C_AOI_NOT_POLYGON_ERROR); msgs.ReplaceWarning(paramMap.GetIndex(C_PARAM_ALTERNATE_AOI), error.Message); } else if (selSet.Count != 1) { WmauError error = new WmauError(WmauErrorCodes.C_EXPECTED_ONE_SELECTED_FEATURE_ERROR); msgs.ReplaceWarning(paramMap.GetIndex(C_PARAM_ALTERNATE_AOI), error.Message); } } catch (System.Runtime.InteropServices.COMException comEx) { WmauError error = new WmauError(WmauErrorCodes.C_AOI_INPUT_ERROR); msgs.ReplaceError(paramMap.GetIndex(C_PARAM_ALTERNATE_AOI), error.ErrorCodeAsInt, error.Message + "; " + comEx.Message); } } }
/// <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); } // Retrieve the MXD and delete it IJTXConfiguration3 configMgr = WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXMap map = configMgr.GetJTXMap(m_mxdName); configMgr.DeleteJTXMap(map.ID); // Update the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_MXD_NAME); IGPString outValue = new GPStringClass(); outValue.Value = m_mxdName; outParamEdit.Value = outValue 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_DELETE_MXD_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } catch { // Catch anything else that possibly happens } } finally { // Release any COM objects here! } }
/// <summary> /// Pre validates the given set of values. /// This is where you populate derived parameters based on input, among other things. /// </summary> /// <param name="paramValues"></param> /// <param name="pEnvMgr"></param> public override void UpdateParameters(IArray paramValues, IGPEnvironmentManager pEnvMgr) { try { UpdateParametersCommon(paramValues, pEnvMgr); } catch (WmxDefaultDbNotSetException) { // If the default DB wasn't set, stop executing return; } catch (NullReferenceException) { // If one of the parameters was null, stop executing return; } // Build a hash of the parameters for ease of access WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameter3 snName = paramMap.GetParam(C_PARAM_SPATIAL_NOTIFICATION); IGPParameterEdit3 snNameEdit = paramMap.GetParamEdit(C_PARAM_SPATIAL_NOTIFICATION); IGPParameter3 dataWorkspace = paramMap.GetParam(C_PARAM_DATA_WORKSPACE); IGPParameterEdit3 dataWorkspaceEdit = paramMap.GetParamEdit(C_PARAM_DATA_WORKSPACE); IGPParameter3 monitorAllColumns = paramMap.GetParam(C_PARAM_MONITOR_ALL_COLUMNS); IGPParameterEdit3 selectColumns = paramMap.GetParamEdit(C_PARAM_COLUMNS); // Apply a domain to the list of spatial notifications, if possible if (snName.Domain == null || (snName.Domain as IGPCodedValueDomain).CodeCount <= 0) { snNameEdit.Domain = Common.WmauGpDomainBuilder.BuildChangeRulesDomain(this.WmxDatabase); } // Apply a domain to the data workspace list, if possible if (dataWorkspace.Domain == null || (dataWorkspace.Domain as IGPCodedValueDomain).CodeCount <= 0) { dataWorkspaceEdit.Domain = Common.WmauGpDomainBuilder.BuildWorkspaceDomain(this.WmxDatabase); } // Enable/disable the column param based on the "monitor all columns" param selectColumns.Enabled = !(monitorAllColumns.Value as IGPBoolean).Value; }
/// <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 { // Retrieve the parameter in which the list of workbook names will be stored WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameter3 param = paramMap.GetParam(C_PARAM_TAM_WORKBOOK_LIST); IGPParameterEdit3 paramEdit = paramMap.GetParamEdit(C_PARAM_TAM_WORKBOOK_LIST); // Set up the multi-value objects IGPMultiValue mvValue = new GPMultiValueClass(); mvValue.MemberDataType = param.DataType; // Get the list of TA workbook names and add them all to the multivalue SortedList <string, string> tamWorkbooks = this.ListTamWorkbooksInDatabase(); foreach (string workbookAlias in tamWorkbooks.Keys) { IGPString strVal = new GPStringClass(); strVal.Value = workbookAlias; mvValue.AddValue(strVal as IGPValue); msgs.AddMessage("Workbook: " + workbookAlias); } paramEdit.Value = (IGPValue)mvValue; 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 } } }
/// <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); // Retrieve the parameter in which the list of workbook names will be stored IGPParameter3 param = paramMap.GetParam(C_PARAM_JOB_ID_LIST); IGPParameterEdit3 paramEdit = paramMap.GetParamEdit(C_PARAM_JOB_ID_LIST); IGPParameter3 filterParam = paramMap.GetParam(C_PARAM_SQL_QUERY_FILTER); // Get the multivalue object into which the output will be stored IGPMultiValue outputValues = new GPMultiValueClass(); outputValues.MemberDataType = param.DataType; for (int i = 0; i < outputValues.Count; i++) { outputValues.Remove(i); } // Get the list of job IDs and add them all to the multivalue SortedList <int, string> jobs = this.ListJobsInDatabase(filterParam.Value.GetAsText()); msgs.AddMessage("Jobs matching query:"); foreach (KeyValuePair <int, string> item in jobs) { IGPLong value = new GPLongClass(); value.Value = item.Key; outputValues.AddValue(value as IGPValue); msgs.AddMessage(" " + value.Value.ToString() + " (" + item.Value + ")"); } paramEdit.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); } }
/// <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); // Assign the requested job try { IJTXJobManager jobManager = this.WmxDatabase.JobManager; IJTXConfiguration3 configMgr = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXJob3 job = jobManager.GetJob(m_jobId) as IJTXJob3; // As of Jan. 2011, the core Workflow Manager libraries do not // seem to check if the user has the privilege to add a comment // if a job as a hold on it. So run the check here. IJTXJobHolds jobHolds = job as IJTXJobHolds; if (jobHolds.Holds != null && jobHolds.Holds.Count > 0 && !CurrentUserHasPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_CAN_ADD_COMMENTS_FOR_HELD_JOBS)) { throw new WmauException(WmauErrorCodes.C_NO_ADD_COMMENTS_HELD_JOBS_ERROR); } // If we get this far, then add the comment to the job. IJTXActivityType commentType = configMgr.GetActivityType(ESRI.ArcGIS.JTX.Utilities.Constants.ACTTYPE_COMMENT); job.LogJobAction(commentType, null, m_comment); job.Store(); // Set the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_JOB_ID); IGPLong outValue = new GPLongClass(); outValue.Value = m_jobId; outParamEdit.Value = outValue 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) { WmauError error = new WmauError(WmauErrorCodes.C_UNSPECIFIED_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } }
/// <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); // Assign the requested job try { IJTXJobManager jobManager = this.WmxDatabase.JobManager; IJTXWorkflowExecution3 jobExec = jobManager.GetJob(m_jobId) as IJTXWorkflowExecution3; // Don't try to deal with the case of multiple active steps int[] currentStepIds = jobExec.GetCurrentSteps(); if (currentStepIds.Length != 1) { throw new WmauException(WmauErrorCodes.C_NO_OR_MULTIPLE_STEPS_ERROR); } jobExec.RunStepChecks(currentStepIds[0], true); IJTXExecuteInfo execInfo = jobExec.RunStep(currentStepIds[0], false, true, false, this); if (execInfo.ThrewError) { throw new WmauException( WmauErrorCodes.C_JOB_EXECUTION_ERROR, new Exception(execInfo.ErrorCode.ToString() + ": " + execInfo.ErrorDescription)); } // Set the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_JOB_ID); IGPLong outValue = new GPLongClass(); outValue.Value = m_jobId; outParamEdit.Value = outValue 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) { WmauError error = new WmauError(WmauErrorCodes.C_UNSPECIFIED_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } }
/// <summary> /// Helper function to change the active Workflow Manager database to the /// database with the given alias. /// </summary> /// <param name="newDbAlias"></param> private void ChangeWmxDatabase(string newDbAlias, WmauParameterMap paramMap) { m_wmxDbAlias = newDbAlias; if (!IsWorkflowManagerDatabaseSet()) { throw new WmauException(WmauErrorCodes.C_INVALID_WMX_DB_ERROR); } // Once the Workflow Manager database has been changed, foreach (string paramName in m_dependentParamNames) { paramMap.GetParamEdit(paramName).Domain = null; } }
/// <summary> /// Pre validates the given set of values. /// This is where you populate derived parameters based on input, among other things. /// </summary> /// <param name="paramValues"></param> /// <param name="pEnvMgr"></param> public override void UpdateParameters(IArray paramValues, IGPEnvironmentManager pEnvMgr) { try { UpdateParametersCommon(paramValues, pEnvMgr); } catch (WmxDefaultDbNotSetException) { // If the default DB wasn't set, stop executing return; } catch (NullReferenceException) { // If one of the parameters was null, stop executing return; } // Get the parameters as a map for easier access WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameter3 jobId = paramMap.GetParam(C_PARAM_JOB_ID); IGPParameterEdit3 jobIdEdit = paramMap.GetParamEdit(C_PARAM_JOB_ID); IGPParameter3 notifName = paramMap.GetParam(C_PARAM_NOTIFICATION_NAME); IGPParameterEdit3 notifNameEdit = paramMap.GetParamEdit(C_PARAM_NOTIFICATION_NAME); // Set the domains for any parameters that need them // Set the job ID domain if it hasn't already been populated if (jobId.Domain == null) { jobIdEdit.Domain = Common.WmauGpDomainBuilder.BuildJobIdDomain(this.WmxDatabase); } // Add a domain to the notification parameter if (notifName.Domain == null || (notifName.Domain as IGPCodedValueDomain).CodeCount <= 0) { notifNameEdit.Domain = Common.WmauGpDomainBuilder.BuildEmailNotificationDomain(this.WmxDatabase); } }
/// <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 { // Send the notification IJTXJobManager jobManager = this.WmxDatabase.JobManager; Common.WmauHelperFunctions.SendNotification( m_notificationName, this.WmxDatabase, jobManager.GetJob(m_jobId)); // Set the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_JOB_ID); IGPLong outValue = new GPLongClass(); outValue.Value = m_jobId; outParamEdit.Value = outValue 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) { WmauError error = new WmauError(WmauErrorCodes.C_UNSPECIFIED_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } }
/// <summary> /// Post validates the given set of values. /// This is where you flag parameters with warnings and error messages, among other things. /// </summary> /// <param name="paramValues"></param> /// <param name="pEnvMgr"></param> /// <param name="msgs"></param> public override void UpdateMessages(IArray paramValues, IGPEnvironmentManager pEnvMgr, IGPMessages msgs) { // Call the base class function first try { UpdateMessagesCommon(paramValues, pEnvMgr, msgs); } catch (WmxDefaultDbNotSetException) { // If the default DB wasn't set, stop executing return; } // Build a hash of which parameter is at which index for ease of access WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameter3 snNameParam = paramMap.GetParam(C_PARAM_NAME); IGPParameterEdit3 snNameParamEdit = paramMap.GetParamEdit(C_PARAM_NAME); // Ensure that the named spatial notification doesn't already exist if (snNameParam.Value != null && !snNameParam.Value.GetAsText().Equals(string.Empty)) { IJTXDatabase2 db = this.WmxDatabase as IJTXDatabase2; string changeRuleName = snNameParam.Value.GetAsText(); IJTXChangeRuleSet allChangeRules = db.SpatialNotificationManager.ChangeRules; for (int i = 0; i < allChangeRules.Count; i++) { IJTXChangeRule tempRule = allChangeRules.get_Item(i); if (tempRule.Name.Equals(snNameParam.Value.GetAsText())) { WmauError error = new WmauError(WmauErrorCodes.C_SN_EXISTS_ERROR); msgs.ReplaceError(paramMap.GetIndex(C_PARAM_NAME), error.ErrorCodeAsInt, error.Message); break; } } } }
/// <summary> /// Pre validates the given set of values. /// This is where you populate derived parameters based on input, among other things. /// </summary> /// <param name="paramValues"></param> /// <param name="pEnvMgr"></param> public override void UpdateParameters(IArray paramValues, IGPEnvironmentManager pEnvMgr) { try { UpdateParametersCommon(paramValues, pEnvMgr); } catch (WmxDefaultDbNotSetException) { // If the default DB wasn't set, stop executing return; } catch (NullReferenceException) { // If one of the parameters was null, stop executing return; } // Get the parameters as a map for easier access WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameter3 assigneeType = paramMap.GetParam(C_PARAM_ASSIGNEE_TYPE); IGPParameterEdit3 assigneeTypeEdit = paramMap.GetParamEdit(C_PARAM_ASSIGNEE_TYPE); IGPParameter3 assignee = paramMap.GetParam(C_PARAM_ASSIGNEE); IGPParameterEdit assigneeEdit = paramMap.GetParamEdit(C_PARAM_ASSIGNEE); // If the assignee type has changed, update the domain for the assignee // parameter // // NOTE: Updating the assignee value can cause things to get confused, // particularly when background geoprocessing is enabled. So rather than // do this, let the assignee parameter value conflict with the domain // for that parameter, if need be. if (!assigneeType.Value.GetAsText().Equals(m_assigneeType)) { m_assigneeType = assigneeType.Value.GetAsText(); if (m_assigneeType.Equals(C_OPT_ASSIGN_TO_GROUP)) { assigneeEdit.Domain = Common.WmauGpDomainBuilder.BuildAssignableGroupsDomain(this.WmxDatabase); } else if (m_assigneeType.Equals(C_OPT_ASSIGN_TO_USER)) { assigneeEdit.Domain = Common.WmauGpDomainBuilder.BuildAssignableUsersDomain(this.WmxDatabase); } else if (m_assigneeType.Equals(C_OPT_UNASSIGNED) || String.IsNullOrEmpty(m_assigneeType)) { assigneeEdit.Domain = null; } } // Check to see if the data workspace parameter has changed; if so, store the // new workspace value and mark the domain for the workspace version to be reset. IGPParameter3 workspaceParam = paramMap.GetParam(C_PARAM_DATAWORKSPACE); if (this.IsDataWorkspaceParameterChanged(workspaceParam)) { if (workspaceParam.Value == null) { m_dataWorkspaceId = string.Empty; } else { string temp = workspaceParam.Value.GetAsText(); m_dataWorkspaceId = Common.WmauHelperFunctions.LookupWorkspaceId(this.WmxDatabase, temp); } IGPParameterEdit3 versionParam = paramMap.GetParamEdit(C_PARAM_PARENTVERSION); // Keep the version parameter's value unchanged; changing it "smartly" to help // out a user can lead to trouble. Instead, let any problem value be flagged // as something that's not a member of the domain. //versionParam.Value = null; versionParam.Domain = null; m_parentVersion = string.Empty; } // Set the domains for any parameters that need them if (paramMap.GetParam(C_PARAM_JOB_TYPE).Domain == null) { paramMap.GetParamEdit(C_PARAM_JOB_TYPE).Domain = Common.WmauGpDomainBuilder.BuildJobTypeDomain(this.WmxDatabase); } if (paramMap.GetParam(C_PARAM_JOB_OWNER).Domain == null) { paramMap.GetParamEdit(C_PARAM_JOB_OWNER).Domain = Common.WmauGpDomainBuilder.BuildUsersDomain(this.WmxDatabase); } if (paramMap.GetParam(C_PARAM_PRIORITY).Domain == null) { paramMap.GetParamEdit(C_PARAM_PRIORITY).Domain = Common.WmauGpDomainBuilder.BuildPriorityDomain(this.WmxDatabase); } if (paramMap.GetParam(C_PARAM_PARENTJOBID).Domain == null) { paramMap.GetParamEdit(C_PARAM_PARENTJOBID).Domain = Common.WmauGpDomainBuilder.BuildJobIdDomain(this.WmxDatabase); } if (paramMap.GetParam(C_PARAM_DATAWORKSPACE).Domain == null) { if (CurrentUserHasPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_MANAGE_DATA_WORKSPACE)) { paramMap.GetParamEdit(C_PARAM_DATAWORKSPACE).Domain = Common.WmauGpDomainBuilder.BuildWorkspaceDomain(this.WmxDatabase, new string[] { C_OPT_VAL_NOT_SET }); } else { paramMap.GetParamEdit(C_PARAM_DATAWORKSPACE).Domain = new GPCodedValueDomainClass() as IGPDomain; } } if (paramMap.GetParam(C_PARAM_PARENTVERSION).Domain == null) { if (!m_dataWorkspaceId.Equals(string.Empty) && !m_dataWorkspaceId.Equals(C_OPT_VAL_NOT_SET) && CurrentUserHasPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_MANAGE_VERSION)) { try { string dbName = this.WmxDatabase.GetDataWorkspaceName(m_dataWorkspaceId).Name; paramMap.GetParamEdit(C_PARAM_PARENTVERSION).Domain = Common.WmauGpDomainBuilder.BuildVersionsDomain( this.WmxDatabase, dbName, new string[] { C_OPT_VAL_NOT_SET }); } catch (WmauException) { // If we run into an exception, set the domain to be empty so that // we can detect it and flag an error during parameter validation paramMap.GetParamEdit(C_PARAM_PARENTVERSION).Domain = new GPCodedValueDomainClass(); } } } // After the domains have been set, check to see if any parameters should be // enabled/disabled based on the contents of these domains. assigneeEdit.Enabled = !m_assigneeType.Equals(C_OPT_UNASSIGNED); EnableDisableParamBasedOnDomain(paramMap.GetParam(C_PARAM_DATAWORKSPACE)); EnableDisableParamBasedOnDomain(paramMap.GetParam(C_PARAM_PARENTVERSION)); // Also check the AOI; if the user can't manage a job's AOI, then disable the // parameter paramMap.GetParamEdit(C_PARAM_AOI).Enabled = CurrentUserHasPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_MANAGE_AOI); }
/// <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); } IJTXSpatialNotificationManager snManager = this.WmxDatabase.SpatialNotificationManager; IJTXSpatialNotifierNameSet allSnNames = snManager.SpatialNotifiers; IJTXNotificationConfiguration notificationConfig = this.WmxDatabase.ConfigurationManager as IJTXNotificationConfiguration; // Create a new spatial notification IJTXChangeRule2 changeRule = snManager.AddChangeRule() as IJTXChangeRule2; // Set the name changeRule.Name = m_snName; // Set the notifier IJTXNotificationType srcNotifType = notificationConfig.GetNotificationType(m_emailNotifier); // Set the properties of the spatial notification's e-mail notification to match that // of the source e-mail notification (phew!) IJTXEmailSpatialNotifier emailNotifier = this.CreateSpatialNotifierByName(C_TYPE_EMAIL_NOTIFIER) as IJTXEmailSpatialNotifier; emailNotifier.Subject = srcNotifType.SubjectTemplate; emailNotifier.Body = srcNotifType.MessageTemplate; emailNotifier.SenderEmail = srcNotifType.SenderTemplate; emailNotifier.SenderDisplayName = srcNotifType.SenderDisplayNameTemplate; string[] subscribers = srcNotifType.get_Subscribers(); IStringArray subscribersObj = new StrArrayClass(); foreach (string subscriber in subscribers) { subscribersObj.Add(subscriber); } emailNotifier.Subscribers = subscribersObj; changeRule.Notifier = emailNotifier as IJTXSpatialNotifier; // Set the description, if applicable if (!string.IsNullOrEmpty(m_snDescription)) { changeRule.Description = m_snDescription; } // Set the summarization behavior changeRule.SummarizeNotifications = m_summarize; // Store the resulting change rule changeRule.Store(); // Update the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParam = paramMap.GetParamEdit(C_PARAM_OUT_NAME); IGPString strValue = new GPStringClass(); strValue.Value = m_snName; outParam.Value = strValue as IGPValue; msgs.AddWarning("To avoid database corruption, at least one dataset or area evaluator must be added to notification '" + m_snName + "' immediately!"); 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_SN_CREATION_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } catch { // Catch anything else that possibly happens } } finally { // Release any COM objects here! } }
/// <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); } IJTXConfiguration3 configMgr = WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXMapEdit wmxMapDoc = configMgr.GetJTXMap(this.m_targetName) as IJTXMapEdit; // If we're not allowed to overwrite an existing map document, then do some error checking if (!this.m_overwriteExisting && wmxMapDoc != null) { msgs.AddWarning("Did not overwrite Map Document: " + this.m_targetName); return; } else if (wmxMapDoc != null) { msgs.AddMessage("Replacing Map Document '" + this.m_targetName + "' in database..."); } else // wmxMapDoc == null { msgs.AddMessage("Adding Map Document '" + this.m_targetName + "' to database..."); wmxMapDoc = configMgr.CreateJTXMap() as IJTXMapEdit; } IMapDocument mapDoc = new MapDocumentClass() as IMapDocument; mapDoc.Open(this.m_mxdFilePath, string.Empty); wmxMapDoc.Name = this.m_targetName; if (!string.IsNullOrEmpty(this.m_targetCategory)) { wmxMapDoc.Category = this.m_targetCategory; } if (!string.IsNullOrEmpty(this.m_description)) { wmxMapDoc.Description = this.m_description; } wmxMapDoc.Directory = string.Empty; wmxMapDoc.FileName = string.Empty; wmxMapDoc.MapDocument = mapDoc; wmxMapDoc.Store(); mapDoc.Close(); // Update the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_TARGET_NAME); IGPString outValue = new GPStringClass(); outValue.Value = m_targetName; outParamEdit.Value = outValue 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_MXD_UPLOAD_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } catch { // Catch anything else that possibly happens } } }
/// <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); // Set the default properties for the specified job type try { IJTXConfiguration3 configMgr = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXConfigurationEdit2 configEdit = this.WmxDatabase.ConfigurationManager as IJTXConfigurationEdit2; IJTXJobTypeEdit3 jobType = configEdit.GetJobType(m_jobTypeName) as IJTXJobTypeEdit3; // Set the default data workspace for the selected job type if (m_dataWorkspaceName.Equals(C_OPT_NONE)) { jobType.DefaultDataWorkspace = null; msgs.AddMessage("Clearing default data workspace for job type '" + m_jobTypeName + "'"); } else { // Translate the workspace name to a DB name object IJTXDataWorkspaceName dwName = Common.WmauHelperFunctions.LookupWorkspaceNameObj(this.WmxDatabase, m_dataWorkspaceName); msgs.AddMessage("Default data workspace for job type '" + m_jobTypeName + "' is now '" + dwName.Name + "'"); jobType.DefaultDataWorkspace = dwName; } // Set the default parent version for the selected job type if (m_parentVersion.Equals(C_OPT_NONE)) { msgs.AddMessage("Clearing default parent version for job type '" + m_jobTypeName + "'"); jobType.DefaultParentVersionName_2 = string.Empty; } else { msgs.AddMessage("Default parent version for job type '" + m_jobTypeName + "' is now '" + m_parentVersion + "'"); jobType.DefaultParentVersionName_2 = m_parentVersion; } // Save the changes to the job type jobType.Store(); // Set the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_DATA_WORKSPACE); IGPString outValue = new GPStringClass(); outValue.Value = m_jobTypeName; outParamEdit.Value = outValue 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) { WmauError error = new WmauError(WmauErrorCodes.C_UNSPECIFIED_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } }
/// <summary> /// Pre validates the given set of values. /// This is where you populate derived parameters based on input, among other things. /// </summary> /// <param name="paramValues"></param> /// <param name="pEnvMgr"></param> public override void UpdateParameters(IArray paramValues, IGPEnvironmentManager pEnvMgr) { try { UpdateParametersCommon(paramValues, pEnvMgr); } catch (WmxDefaultDbNotSetException) { // If the default DB wasn't set, stop executing return; } catch (NullReferenceException) { // If one of the parameters was null, stop executing return; } // Get the parameters as a map for easier access WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameter3 jobTypeParam = paramMap.GetParam(C_PARAM_JOB_TYPE); IGPParameterEdit3 jobTypeParamEdit = paramMap.GetParamEdit(C_PARAM_JOB_TYPE); IGPParameter3 dataWorkspace = paramMap.GetParam(C_PARAM_DATA_WORKSPACE); IGPParameterEdit3 dataWorkspaceEdit = paramMap.GetParamEdit(C_PARAM_DATA_WORKSPACE); IGPParameter3 parentVersion = paramMap.GetParam(C_PARAM_PARENT_VERSION); IGPParameterEdit3 parentVersionEdit = paramMap.GetParamEdit(C_PARAM_PARENT_VERSION); // Set the domains for any parameters that need them if (jobTypeParam.Domain == null) { jobTypeParamEdit.Domain = Common.WmauGpDomainBuilder.BuildJobTypeDomain(this.WmxDatabase); } if (dataWorkspace.Domain == null) { dataWorkspaceEdit.Domain = Common.WmauGpDomainBuilder.BuildWorkspaceDomain( this.WmxDatabase, new string[] { C_OPT_NONE }); } // Only update the domain for the parent version field if it hasn't yet been // populated, or if the value of the data workspace parameter has changed string newDataWorkspace = dataWorkspace.Value.GetAsText(); if (parentVersion.Domain == null || !m_dataWorkspaceName.Equals(newDataWorkspace)) { IGPDomain versionDomain = null; string newJobType = jobTypeParam.Value.GetAsText(); IJTXJobType3 jobType = this.WmxDatabase.ConfigurationManager.GetJobType(newJobType) as IJTXJobType3; if (newDataWorkspace.Equals(C_OPT_NONE) || newDataWorkspace.Equals(string.Empty)) { // Case 1: the only acceptable option for the parent version is "none". IGPCodedValueDomain cvDomain = new GPCodedValueDomainClass(); cvDomain.AddStringCode(C_OPT_NONE, C_OPT_NONE); versionDomain = cvDomain as IGPDomain; } else { // Case 2: we need to retrieve the version list for an existing // data workspace try { versionDomain = Common.WmauGpDomainBuilder.BuildVersionsDomain( this.WmxDatabase, newDataWorkspace, new string[] { C_OPT_NONE }); } catch (WmauException) { // Use the "null" as an error value; we'll check for this later versionDomain = null; } } parentVersionEdit.Domain = versionDomain; } }
/// <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); } // Stash away the executing user's information, if appropriate string username = ESRI.ArcGIS.JTXUI.ConfigurationCache.GetCurrentSystemUser(ESRI.ArcGIS.JTXUI.ConfigurationCache.UseUserDomain); IJTXConfiguration3 configMgr = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXUser3 executingUser = configMgr.GetUser(username) as IJTXUser3; // Import the AD information string domain = System.Environment.UserDomainName; string domainUsername = string.Empty; string domainPassword = string.Empty; int numUsers = 0; int numGroups = 0; ActiveDirectoryHelper.SyncronizeJTXDatabaseWithActiveDirectory(this.WmxDatabase, domain, domainUsername, domainPassword, m_userGroup, m_groupGroup, out numGroups, out numUsers); // If the tool was set to preserve the current user's account and the user // was removed from the DB, then re-add their account if (configMgr.GetUser(username) == null) { if (m_preserveCurrentUser) { IJTXConfigurationEdit2 configEdit = this.WmxDatabase.ConfigurationManager as IJTXConfigurationEdit2; IJTXUserConfig newUser = configEdit.CreateUser() as IJTXUserConfig; newUser.FirstName_2 = executingUser.FirstName; newUser.FullName_2 = executingUser.FullName; newUser.LastName_2 = executingUser.LastName; newUser.UserName_2 = executingUser.UserName; (newUser as IJTXUser3).IsAdministrator = executingUser.IsAdministrator; newUser.Store(); msgs.AddMessage("User '" + username + "' not found in Active Directory group '" + m_userGroup + "'; re-added placeholder to Workflow Manager database"); } else { msgs.AddWarning("User '" + username + "' removed from Workflow Manager database"); } } // Update the output parameters WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParam = paramMap.GetParamEdit(C_PARAM_OUT_NUM_USERS); IGPLong value = new GPLongClass(); value.Value = numUsers; outParam.Value = value as IGPValue; outParam = paramMap.GetParamEdit(C_PARAM_OUT_NUM_GROUPS); value = new GPLongClass(); value.Value = numGroups; outParam.Value = value 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! } }
/// <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) { IJTXJob4 job = null; // Do some common error-checking base.Execute(paramValues, trackCancel, envMgr, msgs); ////////////////////////////////////////////////////////////////////// // TODO: Update the job-creation logic. // // In subsequent builds of Workflow Manager (post-10.0), there may be // a new API that creates jobs and handles much of the logic included // in this function (and this class at large). If so, this GP tool // should be revised to make use of this simplified interface. // // Anyone using this tool as a reference, particularly with regards // to creating Workflow Manager jobs, should keep this in mind. ////////////////////////////////////////////////////////////////////// // Try to create the job, as requested try { IJTXJobManager2 jobManager = this.WmxDatabase.JobManager as IJTXJobManager2; IJTXConfiguration configMgr = this.WmxDatabase.ConfigurationManager as IJTXConfiguration; IJTXJobType4 jobTypeObj = configMgr.GetJobType(m_jobTypeAsString) as IJTXJobType4; // Set up the description object to be used to create this job IJTXJobDescription jobDescription = new JTXJobDescriptionClass(); jobDescription.JobTypeName = m_jobTypeAsString; jobDescription.AOI = GetPolygonFromSpecifiedLayer(m_aoiLayer); // Set up the ownership & assignment of the job jobDescription.OwnedBy = m_jobOwner; if (m_assigneeType.Equals(C_OPT_ASSIGN_TO_GROUP)) { jobDescription.AssignedType = jtxAssignmentType.jtxAssignmentTypeGroup; jobDescription.AssignedTo = m_assignee; } else if (m_assigneeType.Equals(C_OPT_ASSIGN_TO_USER)) { jobDescription.AssignedType = jtxAssignmentType.jtxAssignmentTypeUser; jobDescription.AssignedTo = m_assignee; } else if (m_assigneeType.Equals(C_OPT_UNASSIGNED)) { jobDescription.AssignedType = jtxAssignmentType.jtxAssignmentTypeUnassigned; jobDescription.AssignedTo = string.Empty; } else { // Do nothing; let the job type defaults take over msgs.AddMessage("Using job type defaults for job assignment"); jobDescription.AssignedType = jobTypeObj.DefaultAssignedType; jobDescription.AssignedTo = jobTypeObj.DefaultAssignedTo; } // Start date if (m_startDate != null && m_startDate.Value != null) { string tempStr = m_startDate.Value.ToString(); // Workflow Manager stores times as UTC times; input times must // therefore be pre-converted DateTime tempDate = DateTime.Parse(tempStr); jobDescription.StartDate = TimeZone.CurrentTimeZone.ToUniversalTime(tempDate); } else { msgs.AddMessage("Using job type defaults for start date"); jobDescription.StartDate = jobTypeObj.DefaultStartDate; } // Due date if (m_dueDate != null && m_dueDate.Value != null) { string tempStr = m_dueDate.Value.ToString(); // Workflow Manager stores times as UTC times; input times must // therefore be pre-converted DateTime tempDate = DateTime.Parse(tempStr); jobDescription.DueDate = TimeZone.CurrentTimeZone.ToUniversalTime(tempDate); } else { msgs.AddMessage("Using job type defaults for due date"); jobDescription.DueDate = jobTypeObj.DefaultDueDate; } // Priority if (!m_priority.Equals(string.Empty)) { IJTXPriority priority = configMgr.GetPriority(m_priority); jobDescription.Priority = priority; } else { msgs.AddMessage("Using job type defaults for priority"); jobDescription.Priority = jobTypeObj.DefaultPriority; } // Parent job if (m_parentJobId > 0) { jobDescription.ParentJobId = m_parentJobId; } // Data workspace if (m_dataWorkspaceId.Equals(C_OPT_VAL_NOT_SET)) { jobDescription.DataWorkspaceID = string.Empty; } else if (!m_dataWorkspaceId.Equals(string.Empty)) { jobDescription.DataWorkspaceID = m_dataWorkspaceId; } else { msgs.AddMessage("Using job type defaults for data workspace"); if (jobTypeObj.DefaultDataWorkspace != null) { jobDescription.DataWorkspaceID = jobTypeObj.DefaultDataWorkspace.DatabaseID; } } // Parent version if (m_parentVersion.Equals(C_OPT_VAL_NOT_SET)) { jobDescription.ParentVersionName = string.Empty; } else if (!m_parentVersion.Equals(string.Empty)) { jobDescription.ParentVersionName = m_parentVersion; } else { msgs.AddMessage("Using job type defaults for parent version"); jobDescription.ParentVersionName = jobTypeObj.DefaultParentVersionName; } // Auto-execution jobDescription.AutoExecuteOnCreate = m_executeNewJob; // Create the new job int expectedNumJobs = 1; bool checkAoi = true; IJTXJobSet jobSet = null; IJTXExecuteInfo execInfo; try { jobSet = jobManager.CreateJobsFromDescription(jobDescription, expectedNumJobs, checkAoi, out execInfo); } catch (System.Runtime.InteropServices.COMException comEx) { throw new WmauException(WmauErrorCodes.C_CREATE_JOB_ERROR, comEx); } if ((execInfo != null && execInfo.ThrewError) || jobSet == null || jobSet.Count != expectedNumJobs) { if (execInfo != null && !string.IsNullOrEmpty(execInfo.ErrorDescription)) { throw new WmauException( WmauErrorCodes.C_CREATE_JOB_ERROR, new Exception(execInfo.ErrorCode.ToString() + ": " + execInfo.ErrorDescription)); } else { throw new WmauException(WmauErrorCodes.C_CREATE_JOB_ERROR); } } // If it gets all the way down here without errors, set the output ID with the // ID of the job that was created. job = jobSet.Next() as IJTXJob4; WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPValue jobIdGpVal = new GPLongClass(); jobIdGpVal.SetAsText(job.ID.ToString()); IGPParameterEdit3 jobIdParam = paramMap.GetParamEdit(C_PARAM_NEWJOBID); jobIdParam.Value = jobIdGpVal; msgs.AddMessage("Created job: " + job.ID.ToString() + " (" + job.Name + ")"); msgs.AddMessage(Properties.Resources.MSG_DONE); } catch (WmauException wmEx) { try { msgs.AddError(wmEx.ErrorCodeAsInt, wmEx.Message); if (job != null) { this.WmxDatabase.JobManager.DeleteJob(job.ID, true); } } catch { // Catch anything else that possibly happens } } catch (Exception ex) { try { WmauError error = new WmauError(WmauErrorCodes.C_CREATE_JOB_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); if (job != null) { this.WmxDatabase.JobManager.DeleteJob(job.ID, true); } } catch { // Catch anything else that possibly happens } } }
/// <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); // Assign the requested job try { IJTXJobManager jobManager = this.WmxDatabase.JobManager; IJTXJob3 job = jobManager.GetJob(m_jobId) as IJTXJob3; IJTXConfiguration3 configMgr = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3; // As of Jan. 2011, the core Workflow Manager libraries do not // seem to check if the user has the privilege to add an attachment // if a job as a hold on it. So run the check here. IJTXJobHolds jobHolds = job as IJTXJobHolds; if (jobHolds.Holds != null && jobHolds.Holds.Count > 0 && !CurrentUserHasPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_CAN_ADD_ATTACHES_FOR_HELD_JOBS)) { throw new WmauException(WmauErrorCodes.C_NO_ADD_ATTACHMENTS_HELD_JOBS_ERROR); } // If we get this far, then figure out how to associate the attachment // with the job, and add the attachment. jtxFileStorageType attachmentType; if (m_attachmentType.Equals(C_OPT_EMBEDDED)) { attachmentType = jtxFileStorageType.jtxStoreInDB; } else { attachmentType = jtxFileStorageType.jtxStoreAsLink; } msgs.AddMessage("Adding attachment '" + m_attachmentPath + "' to job " + m_jobId + " (" + job.Name + ")"); job.AddAttachment(m_attachmentPath, attachmentType, m_attachmentType); job.Store(); // Do the other things that still need to be handled manually, such as logging // the job's reassignment and sending any necessary notifications. IPropertySet propSet = new PropertySetClass(); propSet.SetProperty(C_PROP_VAL_ATTACHMENT, "'" + m_attachmentPath + "'"); job.LogJobAction( configMgr.GetActivityType(ESRI.ArcGIS.JTX.Utilities.Constants.ACTTYPE_ADD_ATTACHMENT), propSet, string.Empty); Common.WmauHelperFunctions.SendNotification( ESRI.ArcGIS.JTX.Utilities.Constants.NOTIF_ATTACHMENT_ADDED, this.WmxDatabase, job); // Set the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_JOB_ID); IGPLong outValue = new GPLongClass(); outValue.Value = m_jobId; outParamEdit.Value = outValue 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) { WmauError error = new WmauError(WmauErrorCodes.C_UNSPECIFIED_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } }
/// <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); } // Retrieve the TA workbook IJTXConfiguration3 defaultDbReadonly = WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXTaskAssistantWorkflowRecord tamRecord = defaultDbReadonly.GetTaskAssistantWorkflowRecord(this.m_targetName); string styleFileName = this.DetermineStyleFileName(this.m_xmlFilePath); // If we're not allowed to overwrite an existing TA record, then do some error checking if (!this.m_overwriteExisting && tamRecord != null) { msgs.AddWarning("Did not overwrite Task Assistant workbook: " + this.m_targetName); return; } else if (tamRecord != null) { msgs.AddMessage("Replacing Task Assistant workbook '" + m_targetName + "' in database..."); defaultDbReadonly.ReplaceTaskAssistantWorkflowRecord(this.m_targetName, this.m_targetName, this.m_xmlFilePath, styleFileName); } else // tamRecord == null { msgs.AddMessage("Adding Task Assistant workbook '" + m_targetName + "' to database..."); defaultDbReadonly.AddTaskAssistantWorkflowRecord(this.m_targetName, this.m_xmlFilePath, styleFileName); } // Update the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_TARGET_NAME); IGPString outValue = new GPStringClass(); outValue.Value = m_targetName; outParamEdit.Value = outValue 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_TAM_UPLOAD_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } catch { // Catch anything else that possibly happens } } }