/// <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> /// Called when a step of this type is executed in the workflow. /// </summary> /// <param name="JobID">ID of the job being executed</param> /// <param name="StepID">ID of the step being executed</param> /// <param name="argv">Array of arguments passed into the step's execution</param> /// <param name="ipFeedback">Feedback object to return status messages and files</param> /// <returns>Return code of execution for workflow path traversal</returns> public int Execute(int jobID, int stepID, ref object[] argv, ref IJTXCustomStepFeedback ipFeedback) { // Get the arguments string sHoldTypeName = ""; string sHoldRemarks = ""; bool bHoldType = StepUtilities.GetArgument(ref argv, "HoldType", true, out sHoldTypeName); if (!bHoldType) { MessageBox.Show("Invalid arguments entered. No hold type entered."); return(-1); } bool bHoldRemarks = StepUtilities.GetArgument(ref argv, "HoldRemarks", true, out sHoldRemarks); // Get the hold type IJTXConfiguration pJTXConfig = m_ipDatabase.ConfigurationManager; IJTXHoldType pHoldType = pJTXConfig.GetHoldType(sHoldTypeName); if (pHoldType == null) { MessageBox.Show("Invalid hold type name entered: " + sHoldTypeName); return(-1); } // Get the job IJTXJobManager pJobManager = m_ipDatabase.JobManager; IJTXJob pJob = pJobManager.GetJob(jobID); IJTXJobHolds pJobHolds = pJob as IJTXJobHolds; // Add new job hold IJTXJobHold pNewHold = pJobHolds.CreateHold(pHoldType); if (bHoldRemarks) { pNewHold.HoldComments = sHoldRemarks; pNewHold.Store(); } return(0); }
/// <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); } }