/// <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) { System.Diagnostics.Debug.Assert(m_ipDatabase != null); IJTXJob pJob = m_ipDatabase.JobManager.GetJob(JobID); //Automatic status assignment IJTXConfiguration pConfig = m_ipDatabase.ConfigurationManager; IJTXConfigurationProperties pConfigProps = (IJTXConfigurationProperties)pConfig; IJTXWorkflowConfiguration pWFConfig = (IJTXWorkflowConfiguration)pJob; IJTXWorkflowExecution pWFExec = (IJTXWorkflowExecution)pJob; int[] iSteps = pWFExec.GetCurrentSteps(); if (iSteps.Length == 1) { if (pWFExec.IsLastStep(iSteps[0])) { pWFExec.MoveNext(iSteps[0], (int)nullReturnType.null_return); } } pJob.Close(); pJob.EndDate = System.DateTime.Now; if (pConfigProps.PropertyExists(Constants.JTX_PROPERTY_AUTO_STATUS_ASSIGN)) { string strAutoAssign = pConfigProps.GetProperty(Constants.JTX_PROPERTY_AUTO_STATUS_ASSIGN); if (strAutoAssign == "TRUE") { pJob.Status = m_ipDatabase.ConfigurationManager.GetStatus("Closed"); } } pJob.Store(); IJTXActivityType pActType = pConfig.GetActivityType("CloseJob"); if (pActType != null) { pJob.LogJobAction(pActType, null, ""); } JTXUtilities.SendNotification(Constants.NOTIF_JOB_CLOSED, m_ipDatabase, pJob, null); return(0); }
public void OnClick() { // Confirm the user wants to do this DialogResult result = MessageBox.Show("Are you sure you want to clear the AOI from the selected jobs?", "Clear AOI", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { // Get the job set from the list of jobs IJTXJobViewPanel pJobViewPanel = ((IJTXJobViewPanel)m_pApplication.CurrentView.ViewPanel); List <IJTXJob> pSelectedJobs = pJobViewPanel.SelectedJobs; foreach (IJTXJob pJob in pSelectedJobs) { pJob.AOIExtent = null; pJob.Store(); // Update the activity log and send notifications IJTXConfiguration pConfig = m_pApplication.CurrentDatabase.ConfigurationManager; IJTXActivityType pActType = pConfig.GetActivityType(Constants.ACTTYPE_UPDATE_AOI); if (pActType != null) { pJob.LogJobAction(pActType, null, ""); } JTXUtilities.SendNotification(Constants.NOTIF_AOI_UPDATED, m_pApplication.CurrentDatabase, pJob, null); } // If only 1 job is selected, refresh the panels if (pSelectedJobs.Count == 1) { foreach (IJTXJobPanel ipJobPanel in pJobViewPanel.JobPanels) { ipJobPanel.RefreshJob(); } } MessageBox.Show("Cleared the AOI from selected jobs"); } }
/// <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) { if (jobID <= 0) { throw (new ArgumentOutOfRangeException("JobID", jobID, "Job ID must be a positive value")); } System.Diagnostics.Debug.Assert(m_ipDatabase != null); IJTXJobManager pJobMan = m_ipDatabase.JobManager; IJTXJob2 pJob = pJobMan.GetJob(jobID) as IJTXJob2; // Make sure all the information exists to create this verion if (pJob.ActiveDatabase == null) { System.Windows.Forms.MessageBox.Show("Job does not have a data workspace"); return(-1); } if (pJob.ParentVersion == "") { System.Windows.Forms.MessageBox.Show("Job does not have a parent version"); return(-1); } string strVersionNameOverride; bool bVNOverride = StepUtilities.GetArgument(ref argv, m_expectedArgs[1], true, out strVersionNameOverride); if (pJob.VersionName == "" & !bVNOverride) { System.Windows.Forms.MessageBox.Show("The job does not have a version name"); return(-1); } IVersion pNewVersion; string strVersionName; if (bVNOverride) { strVersionName = strVersionNameOverride; } else { strVersionName = pJob.VersionName; } int index = strVersionName.IndexOf(".", 0); if (index >= 0) { strVersionName = strVersionName.Substring(index + 1); } esriVersionAccess verAccess = esriVersionAccess.esriVersionAccessPrivate; string strVerScope = ""; if (StepUtilities.GetArgument(ref argv, m_expectedArgs[0], true, out strVerScope)) { strVerScope = strVerScope.ToLower().Trim(); if (strVerScope == "public") { verAccess = esriVersionAccess.esriVersionAccessPublic; } else if (strVerScope == "protected") { verAccess = esriVersionAccess.esriVersionAccessProtected; } } pJob.VersionName = strVersionName; pNewVersion = pJob.CreateVersion(verAccess); if (pNewVersion == null) { throw (new System.SystemException("Unable to create version")); } IPropertySet pOverrides = new PropertySetClass(); pOverrides.SetProperty("[VERSION]", pNewVersion.VersionName); IJTXActivityType pActType = m_ipDatabase.ConfigurationManager.GetActivityType(Constants.ACTTYPE_CREATE_VERSION); if (pActType != null) { pJob.LogJobAction(pActType, pOverrides, ""); } JTXUtilities.SendNotification(Constants.NOTIF_VERSION_CREATED, m_ipDatabase, pJob, pOverrides); System.Runtime.InteropServices.Marshal.ReleaseComObject(pNewVersion); return(0); }
//////////////////////////////////////////////////////////////////////// // METHOD: SetJobProperties private IJTXJob SetJobProperties(IJTXJobManager pJobMan, IJTXJob pJob, IJTXJob2 pParentJob) { m_ipDatabase.LogMessage(5, 2000, "Before LogJobAction (CreateJobs)"); IJTXActivityType pActType = m_ipDatabase.ConfigurationManager.GetActivityType(Constants.ACTTYPE_COMMENT); pParentJob.LogJobAction(pActType, null, String.Format(Properties.Resources.ActTypeMessage, pJob.ID.ToString())); if (!string.IsNullOrEmpty(m_paramExtendedProperties)) { m_ipDatabase.LogMessage(5, 2000, "Before Create Extended Properties"); ExtendedPropertyIdentifier childExProps = new ExtendedPropertyIdentifier(); try { ParseExtendedPropertiesParam(out childExProps); } catch (Exception ex) { string msg = string.Format( "Unable to read parent job's extended property. Job ID: {0} ERROR: {1}", pParentJob.ID, ex.Message); m_ipDatabase.LogMessage(3, 1000, msg); } try { CreateExtendedPropertyRecord(pJob, childExProps); } catch (Exception ex) { string msg = string.Format( "Unable to set child job's extended property. Child Job ID: {0} ERROR: {1}", pJob.ID, ex.Message); m_ipDatabase.LogMessage(3, 1000, msg); } m_ipDatabase.LogMessage(5, 2000, "After Create Extended Properties"); } // Create dependencies on parent job if configured m_ipDatabase.LogMessage(5, 2000, "Before Setting Dependencies"); if (m_paramDependNextStep || m_paramDependThisStep) { IJTXJobDependencies ipDependencyManager = pJobMan as IJTXJobDependencies; CreateDependencyOnParentJob(ipDependencyManager, pParentJob, pJob.ID); } m_ipDatabase.LogMessage(5, 2000, "After Setting Dependencies"); // Create or assign version if configured m_ipDatabase.LogMessage(5, 2000, "Before Versioning"); if (m_paramCreateVersionType != CreateVersionType.None) { if (pParentJob.ActiveDatabase != null && !String.IsNullOrEmpty(pJob.ParentVersion) && (m_paramCreateVersionType != CreateVersionType.UseParentJobsVersion || pParentJob.VersionExists())) { CreateChildVersion(ref pJob); } else { MessageBox.Show("Could not create version. Please ensure parent data workspace and versions are set correctly", Properties.Resources.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else if (m_paramAssignVersionType != AssignVersionType.None) { if (pParentJob.ActiveDatabase != null) { AssignChildVersion(pParentJob, ref pJob); } else { MessageBox.Show("Could not assign version. Please ensure parent data workspace is set correctly", Properties.Resources.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } m_ipDatabase.LogMessage(5, 2000, "After Versioning"); // Store the job and save the changes m_ipDatabase.LogMessage(5, 2000, "Before Storing Job"); pJob.Store(); m_ipDatabase.LogMessage(5, 2000, "After Storing Job"); return(pJob); }
/// <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) { System.Diagnostics.Debug.Assert(m_ipDatabase != null); string strValue = ""; int jobTypeID = 0; if (!StepUtilities.GetArgument(ref argv, m_expectedArgs[0], true, out strValue)) { throw new ArgumentNullException(m_expectedArgs[0], string.Format("\nMissing the {0} parameter!", m_expectedArgs[0])); } if (!Int32.TryParse(strValue, out jobTypeID)) { throw new ArgumentNullException(m_expectedArgs[0], "Argument must be an integrer!"); } IJTXJobType pJobType = m_ipDatabase.ConfigurationManager.GetJobTypeByID(jobTypeID); IJTXJobManager pJobMan = m_ipDatabase.JobManager; IJTXJob pNewJob = pJobMan.CreateJob(pJobType, 0, true); IJTXActivityType pActType = m_ipDatabase.ConfigurationManager.GetActivityType(Constants.ACTTYPE_CREATE_JOB); if (pActType != null) { pNewJob.LogJobAction(pActType, null, ""); } JTXUtilities.SendNotification(Constants.NOTIF_JOB_CREATED, m_ipDatabase, pNewJob, null); // Assign a status to the job if the Auto Assign Job Status setting is enabled IJTXConfigurationProperties pConfigProps = (IJTXConfigurationProperties)m_ipDatabase.ConfigurationManager; if (pConfigProps.PropertyExists(Constants.JTX_PROPERTY_AUTO_STATUS_ASSIGN)) { string strAutoAssign = pConfigProps.GetProperty(Constants.JTX_PROPERTY_AUTO_STATUS_ASSIGN); if (strAutoAssign == "TRUE") { pNewJob.Status = m_ipDatabase.ConfigurationManager.GetStatus("Created"); } } // Associate the current job with the new job with a parent-child relationship pNewJob.ParentJob = JobID; // Assign the job as specified in the arguments string strAssignTo = ""; if (StepUtilities.GetArgument(ref argv, m_expectedArgs[1], true, out strAssignTo)) { pNewJob.AssignedType = jtxAssignmentType.jtxAssignmentTypeGroup; pNewJob.AssignedTo = strAssignTo; } else if (StepUtilities.GetArgument(ref argv, m_expectedArgs[2], true, out strAssignTo)) { pNewJob.AssignedType = jtxAssignmentType.jtxAssignmentTypeUser; pNewJob.AssignedTo = strAssignTo; } pNewJob.Store(); // Copy the workflow to the new job WorkflowUtilities.CopyWorkflowXML(m_ipDatabase, pNewJob); // Create 1-1 extended property entries IJTXAuxProperties pAuxProps = (IJTXAuxProperties)pNewJob; System.Array contNames = pAuxProps.ContainerNames; IEnumerator contNamesEnum = contNames.GetEnumerator(); contNamesEnum.Reset(); while (contNamesEnum.MoveNext()) { string strContainerName = (string)contNamesEnum.Current; IJTXAuxRecordContainer pAuxContainer = pAuxProps.GetRecordContainer(strContainerName); if (pAuxContainer.RelationshipType == esriRelCardinality.esriRelCardinalityOneToOne) { pAuxContainer.CreateRecord(); } } m_ipDatabase.LogMessage(5, 1000, System.Diagnostics.Process.GetCurrentProcess().MainWindowTitle); // Update Application message about the new job if (System.Diagnostics.Process.GetCurrentProcess().MainWindowTitle.Length > 0) //if its not running in server { MessageBox.Show("Created " + pJobType.Name + " Job " + pNewJob.ID, "Job Created", MessageBoxButtons.OK, MessageBoxIcon.Information); } return(0); }