public void JobWorkflowUpdated(IJTXJob job) { lock (m_queuedMessages) { m_queuedMessages.Add("Workflow updated for job: " + job.ID.ToString()); } }
public void StepExecutionStarting(IJTXJob job, int stepId) { lock (m_queuedMessages) { m_queuedMessages.Add("Started running step '" + stepId.ToString() + "' for job: " + job.ID.ToString()); } }
public void StepExecutionComplete(IJTXJob job, int stepId, IJTXExecuteInfo execInfo) { lock (m_queuedMessages) { m_queuedMessages.Add("Finished running step '" + stepId.ToString() + "' for job: " + job.ID.ToString()); } }
/// <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")); } string strNotifType = ""; string strSubscribers = ""; if (!StepUtilities.GetArgument(ref argv, m_expectedArgs[0], true, out strNotifType)) { throw new ArgumentNullException(m_expectedArgs[0], string.Format("\nMissing the {0} parameter!", m_expectedArgs[0])); } bool bSubscribers = StepUtilities.GetArgument(ref argv, m_expectedArgs[1], true, out strSubscribers); IJTXJob ipJob = m_ipDatabase.JobManager.GetJob(jobID); if (bSubscribers) { UpdateSubscriberList(strNotifType, strSubscribers, "add"); } JTXUtilities.SendNotification(strNotifType, m_ipDatabase, ipJob, null); if (bSubscribers) { UpdateSubscriberList(strNotifType, strSubscribers, "remove"); } return(0); }
private string ReplaceToken(string token, IJTXDatabase pDB, IJTXJob pJob, ESRI.ArcGIS.esriSystem.IPropertySet pOverrides) { string tokenout = token; // Drop the [] and convert to uppercase token = token.Substring(1, token.Length - 2).ToUpper(); // Split the prefix from the actual token string[] parts = token.Split(new char[] { ':' }, 2); // make sure it is a environment token (starts with "ENV:") if (parts.Length == 2) { if (parts[0].Equals("ENV")) { // try to get the env variable string value = Environment.GetEnvironmentVariable(parts[1]); if (value != null) { tokenout = value; } } } return(tokenout); }
public Tuple <bool, bool, string> RecreateWorkflow(IJTXJob _job) { bool recreated = false; try { var job = _job as IJTXJob4; if (job == null) { return(MakeError(recreated, "Could not retrieve job")); } if (job.Stage == jtxJobStage.jtxJobStageClosed || job.Stage == jtxJobStage.jtxJobStageDoneWorking) { return(MakeError(recreated, "Cannot recreate workflow for a closed job")); } var workflowExec = job as IJTXWorkflowExecution3; var workflowConfig = job as IJTXWorkflowConfiguration2; var curStepIDs = workflowExec.GetCurrentSteps(); if (curStepIDs.Length != 1) { return(MakeError(recreated, "Must be one and only one current step")); } var curStep = workflowConfig.GetStep(curStepIDs[0]) as IJTXStep4; if (curStep == null) { return(MakeError(recreated, "Could not find current step {0}", curStepIDs[0])); } var curStepName = curStep.StepName; job.RecreateWorkflow(true); // If you aren't auto commiting in your instance, can set this to false, or could get it from system settings recreated = true; int[] newStepIDs = FindStepByName(workflowConfig, curStepName); if (newStepIDs.Length <= 0) { utils.LogJobAction("Comment", db, job, null, "The workflow was recreated"); return(MakeError(recreated, "Could not find {0} step in re-created workflow", curStepName)); } if (newStepIDs.Length > 1) { utils.LogJobAction("Comment", db, job, null, "The workflow was recreated"); return(MakeError(recreated, "Step {0} is not unique in the re-created workflow", curStepName)); } workflowExec.SetCurrentStep(newStepIDs[0]); utils.LogJobAction("Comment", db, job, null, "The workflow was recreated and current step was reset to " + curStepName); return(Tuple.Create <bool, bool, string>(true, true, null)); } catch (Exception ex) { return(MakeError(recreated, ex.Message)); } }
/// <summary> /// This method is called when the current job is updated /// </summary> /// <param name="pUpdatedJob"></param> public void JobUpdated(IJTXJob pUpdatedJob) { if (pUpdatedJob != null) { // The current job was updated m_pJob = pUpdatedJob; LoadJobInfo(); } }
//////////////////////////////////////////////////////////////////////// // METHOD: AssignChildVersion private bool AssignChildVersion(IJTXJob2 pParentJob, ref IJTXJob pJob) { if (m_paramAssignVersionType == AssignVersionType.UseParentJobsVersion) { ((IJTXJob2)pJob).SetActiveDatabase(pParentJob.ActiveDatabase.DatabaseID); pJob.ParentVersion = pParentJob.ParentVersion; pJob.VersionName = pParentJob.VersionName; } return(true); }
public string Parse(string sourceText, IJTXDatabase pDB, IJTXJob pJob, ESRI.ArcGIS.esriSystem.IPropertySet pOverrides) { // Find the token string strSource = sourceText; string strFinal = sourceText; int curpos = strSource.IndexOf('['); int startmarker; int endmarker = -1; int nestedcount; int curtokenpos; string strToken; string strNewValue; while (curpos >= 0) { nestedcount = 1; curtokenpos = curpos + 1; strToken = ""; //need to find the whole token (including any nested tokens) while (nestedcount > 0) { startmarker = strSource.IndexOf('[', curtokenpos); endmarker = strSource.IndexOf(']', curtokenpos); if (startmarker >= 0 && startmarker < endmarker) { nestedcount++; curtokenpos = startmarker + 1; } else if (endmarker < 0) { break; } else { nestedcount--; curtokenpos = endmarker + 1; } } if (endmarker >= 0) { strToken = strSource.Substring(curpos, endmarker - curpos + 1); strNewValue = ReplaceToken(strToken, pDB, pJob, pOverrides); strFinal = strFinal.Replace(strToken, strNewValue); } curpos = strSource.IndexOf('[', curpos + 1); } return(strFinal); }
/// <summary> /// This method is called when a new job is opened /// </summary> /// <param name="pNewJob"></param> public void JobChanged(IJTXJob pNewJob) { if (pNewJob != null) { // A new job was opened m_pJob = pNewJob; // Enable the controls txtJobName.Enabled = true; cmdSave.Enabled = true; // Load the info LoadJobInfo(); } }
//////////////////////////////////////////////////////////////////////// // METHOD: CreateExtendedPropertyRecord private bool CreateExtendedPropertyRecord(IJTXJob job, ExtendedPropertyIdentifier child) { IJTXAuxProperties pAuxProps = (IJTXAuxProperties)job; IJTXAuxRecordContainer pAuxContainer = pAuxProps.GetRecordContainer(child.LongTableName); if (!string.IsNullOrEmpty(m_paramExtendedProperties) && pAuxContainer == null) { string msg = string.Format( "Unable to set extended property for child job {0}. Unable to find child job's extended property table: {1}", job.ID, child.LongTableName); m_ipDatabase.LogMessage(3, 2000, msg); } System.Array contNames = pAuxProps.ContainerNames; System.Collections.IEnumerator contNamesEnum = contNames.GetEnumerator(); contNamesEnum.Reset(); while (contNamesEnum.MoveNext()) { try { string strContainerName = (string)contNamesEnum.Current; if (!string.IsNullOrEmpty(m_paramExtendedProperties) && (strContainerName.ToUpper()).Equals(child.LongTableName.ToUpper())) { pAuxContainer = pAuxProps.GetRecordContainer(strContainerName); if (pAuxContainer.RelationshipType != esriRelCardinality.esriRelCardinalityOneToOne) { throw new Exception("The table relationship is not one-to-one."); } IJTXAuxRecord childRecord = pAuxContainer.GetRecords().get_Item(0);//pAuxContainer.CreateRecord(); SetExtendedPropertyValues(childRecord, child); JobUtilities.LogJobAction(m_ipDatabase, job, Constants.ACTTYPE_UPDATE_EXT_PROPS, "", null); } } catch (Exception ex) { string msg = string.Format( "Unable to create extended property {0} in record for jobid {1}. ERROR: {2}", child.FieldName, job.ID, ex.Message); m_ipDatabase.LogMessage(3, 2000, msg); } } return(true); }
/// <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 int AskNextSteps(IJTXJob pJob, int currStepID, bool bUseDefaultValuesOnly) { lock (m_queuedMessages) { m_queuedMessages.Add("AskNextSteps: Returning -1 for next step"); } IJTXWorkflowExecution3 jobExec = pJob as IJTXWorkflowExecution3; int[] nextSteps = jobExec.GetCurrentSteps(); if (nextSteps.Length != 1) { return(-1); } else { return(nextSteps[0]); } }
/// <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); IJTXJob pJob = m_ipDatabase.JobManager.GetJob(jobID); string strValue = ""; if (StepUtilities.GetArgument(ref argv, m_expectedArgs[0], true, out strValue) || StepUtilities.GetArgument(ref argv, m_expectedArgs[1], true, out strValue)) { if (pJob.VersionExists()) { pJob.DeleteVersion(null); } } if (StepUtilities.GetArgument(ref argv, m_expectedArgs[2], true, out strValue) || StepUtilities.GetArgument(ref argv, m_expectedArgs[3], true, out strValue)) { if (pJob.MXDExists()) { pJob.DeleteMXD(); } } if (StepUtilities.GetArgument(ref argv, m_expectedArgs[4], true, out strValue) || StepUtilities.GetArgument(ref argv, m_expectedArgs[5], true, out strValue)) { IJTXAttachmentSet attachments = pJob.Attachments; for (int i = attachments.Count - 1; i >= 0; i--) { int id = (attachments.get_Item(i).ID); pJob.DeleteAttachment(id); } } return(0); }
/// <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) { IJTXJobManager ipJobManager = m_ipDatabase.JobManager; IJTXConfiguration ipConfig = m_ipDatabase.ConfigurationManager; IJTXJob ipJob = ipJobManager.GetJob(jobID); string strAssignType = ""; string strAssignTo = ""; if (!StepUtilities.GetArgument(ref argv, m_expectedArgs[0], true, out strAssignType)) { throw new ArgumentNullException(m_expectedArgs[0], string.Format("\nMissing the {0} parameter!", m_expectedArgs[0])); } if (!StepUtilities.GetArgument(ref argv, m_expectedArgs[1], true, out strAssignTo)) { throw new ArgumentNullException(m_expectedArgs[1], string.Format("\nMissing the {0} parameter!", m_expectedArgs[1])); } if (strAssignType == "group") { if (ipConfig.GetUserGroup(strAssignTo) == null) { throw new ArgumentOutOfRangeException(m_expectedArgs[1], string.Format("\nThe group {0} is not a group defined in the JTX database!", strAssignTo)); } ipJob.AssignedType = jtxAssignmentType.jtxAssignmentTypeGroup; } else { if (ipConfig.GetUser(strAssignTo) == null) { throw new ArgumentOutOfRangeException(m_expectedArgs[1], string.Format("\nThe user {0} is not a user defined in the JTX database!", strAssignTo)); } ipJob.AssignedType = jtxAssignmentType.jtxAssignmentTypeUser; } ipJob.AssignedTo = strAssignTo; ipJob.Store(); return(0); }
/// <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); }
//////////////////////////////////////////////////////////////////////// // METHOD: CreateChildVersion private bool CreateChildVersion(ref IJTXJob pJob) { IVersion pNewVersion = null; try { string strVersionName = pJob.VersionName; int index = strVersionName.IndexOf(".", 0); if (index >= 0) { strVersionName = strVersionName.Substring(index + 1); } pJob.VersionName = strVersionName; pNewVersion = pJob.CreateVersion(esriVersionAccess.esriVersionAccessPublic); if (pNewVersion == null) { m_ipDatabase.LogMessage(3, 1000, "Unable to create version for child job ID: " + pJob.ID); } else { IPropertySet pOverrides = new PropertySetClass(); pOverrides.SetProperty("[VERSION]", pNewVersion.VersionName); JobUtilities.LogJobAction(m_ipDatabase, pJob, Constants.ACTTYPE_CREATE_VERSION, "", pOverrides); JTXUtilities.SendNotification(Constants.NOTIF_VERSION_CREATED, m_ipDatabase, pJob, pOverrides); } } catch (Exception ex) { m_ipDatabase.LogMessage(3, 1000, "Unable to create version for child job ID: " + pJob.ID + ". ERROR: " + ex.Message); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(pNewVersion); } return(true); }
public void SetJob(IJTXJob ipJob) { }
/// <summary> /// Helper function to send a notification /// </summary> /// <param name="notificationName">The type (name) of the notification to send</param> /// <param name="wmxDb">A reference to the active Workflow Manager database</param> /// <param name="job">The job for which to send the notification</param> public static void SendNotification(string notificationName, IJTXDatabase3 wmxDb, IJTXJob job) { ESRI.ArcGIS.JTX.Utilities.JTXUtilities.SendNotification(notificationName, wmxDb, job, null); }
/// <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); }
//////////////////////////////////////////////////////////////////////// // METHOD: CreateJobs private int CreateJobs(IJTXJob2 pParentJob) { try { System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; bool bAutoCommit = ConfigurationCache.AutoCommitWorkflow; m_ipDatabase.LogMessage(5, 2000, "CreateJobs"); // Set the job template values IJTXJobManager2 pJobMan = m_ipDatabase.JobManager as IJTXJobManager2; IJTXJobDescription pJobDescription = new JTXJobDescriptionClass(); pJobDescription.Description = pParentJob.Description; pJobDescription.Priority = pParentJob.Priority; pJobDescription.ParentJobId = pParentJob.ID; pJobDescription.StartDate = pParentJob.StartDate; if (m_dueDate != Constants.NullDate) { pJobDescription.DueDate = m_dueDate; } else if (m_duration > 0) { pJobDescription.DueDate = System.DateTime.Now.AddDays(m_duration); } else { pJobDescription.DueDate = pParentJob.DueDate; } if (!String.IsNullOrEmpty(m_paramAssignToGroup)) { pJobDescription.AssignedType = jtxAssignmentType.jtxAssignmentTypeGroup; pJobDescription.AssignedTo = m_paramAssignToGroup; } else if (!String.IsNullOrEmpty(m_paramAssignToUser)) { pJobDescription.AssignedType = jtxAssignmentType.jtxAssignmentTypeUser; pJobDescription.AssignedTo = m_paramAssignToUser; } else { pJobDescription.AssignedType = jtxAssignmentType.jtxAssignmentTypeUnassigned; } pJobDescription.OwnedBy = ConfigurationCache.GetCurrentJTXUser().UserName; if (pParentJob.ActiveDatabase != null) { pJobDescription.DataWorkspaceID = pParentJob.ActiveDatabase.DatabaseID; } // Set the parent version. This only makes sense if the active workspace has been set if (pJobDescription.DataWorkspaceID != null) { if (m_paramCreateVersionType == CreateVersionType.None || m_paramCreateVersionType == CreateVersionType.UseParentJobsVersion) { pJobDescription.ParentVersionName = pParentJob.VersionName; // This has to be set here because setting the job workspace resets the value } else if (m_paramCreateVersionType == CreateVersionType.UseJobTypeDefaultSettings) { IJTXJobType pJobType = m_ipDatabase.ConfigurationManager.GetJobType(m_paramJobTypeName); if (pJobType != null) { pJobDescription.ParentVersionName = pJobType.DefaultParentVersionName; } } else if (m_paramCreateVersionType == CreateVersionType.UseParentJobsDefaultVersion) { pJobDescription.ParentVersionName = pParentJob.JobType.DefaultParentVersionName; } else if (m_paramCreateVersionType == CreateVersionType.UseParentJobsParentVersion) { pJobDescription.ParentVersionName = pParentJob.ParentVersion; } } // Determine the number of jobs to make m_ipDatabase.LogMessage(5, 2000, "Before Determining Number of Jobs"); IArray aoiList = null; int numJobs; if (!GetNumberOfJobs(pParentJob, ref aoiList, out numJobs)) { return(1); } if (numJobs <= 0) { MessageBox.Show(Properties.Resources.ZeroJobCount); return(0); } pJobDescription.AOIList = aoiList; m_ipDatabase.LogMessage(5, 2000, "After Determining Number of Jobs"); // Create the job objects m_ipDatabase.LogMessage(5, 2000, "Before CreateJobs"); pJobDescription.JobTypeName = m_paramJobTypeName; IJTXExecuteInfo pExecInfo; m_ipJobs = pJobMan.CreateJobsFromDescription(pJobDescription, numJobs, true, out pExecInfo); m_ipDatabase.LogMessage(5, 2000, "After CreateJobs"); // Populate the job data for (int i = 0; i < m_ipJobs.Count; ++i) { IJTXJob pJob = m_ipJobs.get_Item(i); SetJobProperties(pJobMan, pJob, pParentJob); } return(1); } catch (COMException ex) { if (ex.ErrorCode == (int)fdoError.FDO_E_SE_INVALID_COLUMN_VALUE) { MessageBox.Show(Properties.Resources.InvalidColumn, Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show(ex.Message); } return(0); } catch (Exception ex2) { MessageBox.Show(ex2.Message, Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } finally { System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default; } }
//////////////////////////////////////////////////////////////////////// // 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); }
public string Parse(string sourceText, IJTXDatabase pDB, IJTXJob pJob, ESRI.ArcGIS.esriSystem.IPropertySet pOverrides) { // Find the token string strSource = sourceText; string strFinal = sourceText; int curpos = strSource.IndexOf('['); int startmarker; int endmarker = -1; int nestedcount; int curtokenpos; string strToken; string strNewValue; while (curpos >= 0) { nestedcount = 1; curtokenpos = curpos + 1; strToken = ""; //need to find the whole token (including any nested tokens) while (nestedcount > 0) { startmarker = strSource.IndexOf('[', curtokenpos); endmarker = strSource.IndexOf(']', curtokenpos); if (startmarker >= 0 && startmarker < endmarker) { nestedcount++; curtokenpos = startmarker + 1; } else if (endmarker < 0) { break; } else { nestedcount--; curtokenpos = endmarker + 1; } } if (endmarker >= 0) { strToken = strSource.Substring(curpos, endmarker - curpos + 1); strNewValue = ReplaceToken(strToken, pDB, pJob, pOverrides); strFinal = strFinal.Replace(strToken, strNewValue); } curpos = strSource.IndexOf('[', curpos + 1); } return strFinal; }
void IDockableWindowDef.OnDestroy() { m_pExt = null; m_pJob = null; }
private string ReplaceToken(string token, IJTXDatabase pDB, IJTXJob pJob, ESRI.ArcGIS.esriSystem.IPropertySet pOverrides) { string tokenout = token; // Drop the [] and convert to uppercase token = token.Substring(1,token.Length - 2).ToUpper(); // Split the prefix from the actual token string[] parts = token.Split(new char[] { ':' }, 2); // make sure it is a environment token (starts with "ENV:") if (parts.Length == 2) { if (parts[0].Equals("ENV")) { // try to get the env variable string value = Environment.GetEnvironmentVariable(parts[1]); if (value != null) { tokenout = value; } } } return tokenout; }
//////////////////////////////////////////////////////////////////////// // 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; }
private void AttachMsg(IJTXJob ipJob, string strTool, string strMessage) { // Attach the messages as a file string strFileName = strTool + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + "_Results.log"; string strPath = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), strFileName); using (TextWriter pTextWriter = new StreamWriter(strPath)) { pTextWriter.Write(strMessage); pTextWriter.Close(); } if (File.Exists(strPath)) { try { Log("JTXTempLog: ExecuteGPTool.AttachMsg adding Job Attachment.."); ipJob.AddAttachment(strPath, jtxFileStorageType.jtxStoreInDB, ""); Log("JTXTempLog: ExecuteGPTool.AttachMsg added Job Attachment.."); } catch (Exception ex) { String strMsg = ex.Message; } File.Delete(strPath); } }
//////////////////////////////////////////////////////////////////////// // METHOD: AssignChildVersion private bool AssignChildVersion(IJTXJob2 pParentJob, ref IJTXJob pJob) { if (m_paramAssignVersionType == AssignVersionType.UseParentJobsVersion) { ((IJTXJob2)pJob).SetActiveDatabase(pParentJob.ActiveDatabase.DatabaseID); pJob.ParentVersion = pParentJob.ParentVersion; pJob.VersionName = pParentJob.VersionName; } return true; }
//////////////////////////////////////////////////////////////////////// // METHOD: CreateExtendedPropertyRecord private bool CreateExtendedPropertyRecord(IJTXJob job, ExtendedPropertyIdentifier child) { IJTXAuxProperties pAuxProps = (IJTXAuxProperties)job; IJTXAuxRecordContainer pAuxContainer = pAuxProps.GetRecordContainer(child.LongTableName); if (!string.IsNullOrEmpty(m_paramExtendedProperties) && pAuxContainer == null) { string msg = string.Format( "Unable to set extended property for child job {0}. Unable to find child job's extended property table: {1}", job.ID, child.LongTableName); m_ipDatabase.LogMessage(3, 2000, msg); } System.Array contNames = pAuxProps.ContainerNames; System.Collections.IEnumerator contNamesEnum = contNames.GetEnumerator(); contNamesEnum.Reset(); while (contNamesEnum.MoveNext()) { try { string strContainerName = (string)contNamesEnum.Current; if (!string.IsNullOrEmpty(m_paramExtendedProperties) && (strContainerName.ToUpper()).Equals(child.LongTableName.ToUpper())) { pAuxContainer = pAuxProps.GetRecordContainer(strContainerName); if (pAuxContainer.RelationshipType != esriRelCardinality.esriRelCardinalityOneToOne) { throw new Exception("The table relationship is not one-to-one."); } IJTXAuxRecord childRecord = pAuxContainer.GetRecords().get_Item(0);//pAuxContainer.CreateRecord(); SetExtendedPropertyValues(childRecord, child); JobUtilities.LogJobAction(m_ipDatabase, job, Constants.ACTTYPE_UPDATE_EXT_PROPS, "", null); } } catch (Exception ex) { string msg = string.Format( "Unable to create extended property {0} in record for jobid {1}. ERROR: {2}", child.FieldName, job.ID, ex.Message); m_ipDatabase.LogMessage(3, 2000, msg); } } return true; }
static void Main(string[] args) { JTXOverdueNotification prog = new JTXOverdueNotification(); if (prog.CheckoutLicense()) { try { // Arguments list // /NotifType:<Notification type to send> // example: JTXOverdueNotification.exe /NotifType:OverdueJob object[] pArgObjects = args as object[]; // Get some variables ready string sNotificationTypeName = ""; StepUtilities.GetArgument(ref pArgObjects, "NotifType", true, out sNotificationTypeName); if (sNotificationTypeName == "") { Console.WriteLine("A notification type must be entered."); return; } IJTXDatabaseManager jtxDBMan = new JTXDatabaseManagerClass(); IJTXDatabase pJTXDB = jtxDBMan.GetActiveDatabase(false); IJTXConfiguration pJTXConfig = pJTXDB.ConfigurationManager; // Create a simple query to find jobs that were due before today IQueryFilter pQF = new QueryFilterClass(); // NOTE #1: Verify the date format matches your selected RDBMS // NOTE #2: Verify the status id for 'Closed' with the JTX Administrator pQF.WhereClause = "DUE_DATE < '" + DateTime.Today.ToString() + "'" + " AND STATUS <> 9"; Console.WriteLine(pQF.WhereClause); // Get the notification type for the notification that will be sent IJTXNotificationConfiguration pNotificationConfig = pJTXConfig as IJTXNotificationConfiguration; IJTXNotificationType pNotificationType = pNotificationConfig.GetNotificationType(sNotificationTypeName); if (pNotificationType == null) { Console.WriteLine("Please enter a valid notification type."); return; } // Get the job manager to execute the query and find the jobs in question IJTXJobManager pJobManager = pJTXDB.JobManager; IJTXJobSet pJobs = pJobManager.GetJobsByQuery(pQF); pJobs.Reset(); for (int a = 0; a < pJobs.Count; a++) { IJTXJob pJob = pJobs.Next(); Console.WriteLine(pJob.Name); // Send it! JTXUtilities.SendNotification(sNotificationTypeName, pJTXDB, pJob, null); } } catch (Exception except) { Console.WriteLine("An error occurred: " + except.Message); } prog.CheckinLicense(); Console.WriteLine("Completed."); } }
//////////////////////////////////////////////////////////////////////// // METHOD: CreateChildVersion private bool CreateChildVersion(ref IJTXJob pJob) { IVersion pNewVersion = null; try { string strVersionName = pJob.VersionName; int index = strVersionName.IndexOf(".", 0); if (index >= 0) { strVersionName = strVersionName.Substring(index + 1); } pJob.VersionName = strVersionName; pNewVersion = pJob.CreateVersion(esriVersionAccess.esriVersionAccessPublic); if (pNewVersion == null) { m_ipDatabase.LogMessage(3, 1000, "Unable to create version for child job ID: " + pJob.ID); } else { IPropertySet pOverrides = new PropertySetClass(); pOverrides.SetProperty("[VERSION]", pNewVersion.VersionName); JobUtilities.LogJobAction(m_ipDatabase, pJob, Constants.ACTTYPE_CREATE_VERSION, "", pOverrides); JTXUtilities.SendNotification(Constants.NOTIF_VERSION_CREATED, m_ipDatabase, pJob, pOverrides); } } catch (Exception ex) { m_ipDatabase.LogMessage(3, 1000, "Unable to create version for child job ID: " + pJob.ID + ". ERROR: " + ex.Message); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(pNewVersion); } return true; }