/// <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> /// Builds a domain consisting of the IDs of every job in the database that /// has not already been closed. /// </summary> /// <param name="wmxDb">A reference to the active Workflow Manager database</param> /// <returns>A coded value domain as an IGPDomain</returns> public static IGPDomain BuildNonClosedJobIdDomain(IJTXDatabase3 wmxDb) { IGPCodedValueDomain domain = new GPCodedValueDomainClass(); // Set up a query filter to return only those jobs that are not closed IQueryFilter queryFilter = new QueryFilterClass(); queryFilter.WhereClause = ESRI.ArcGIS.JTX.Utilities.Constants.FIELD_STAGE + " <> '" + ((int)jtxJobStage.jtxJobStageClosed).ToString() + "'"; IJTXJobSet nonClosedJobs = wmxDb.JobManager.GetJobsByQuery(queryFilter); // Iterate through this job list, sorting the IDs SortedList <int, string> sortedJobIds = new SortedList <int, string>(); for (int i = 0; i < nonClosedJobs.Count; i++) { IJTXJob3 job = nonClosedJobs.get_Item(i) as IJTXJob3; sortedJobIds[job.ID] = null; } // Build a GP domain from the sorted job IDs. foreach (int id in sortedJobIds.Keys) { IGPValue tempGpVal = new GPLongClass(); tempGpVal.SetAsText(id.ToString()); domain.AddCode(tempGpVal, id.ToString()); } return(domain as IGPDomain); }
/// <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> /// 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> /// Builds a domain consisting of the IDs for every job in the database. /// </summary> /// <param name="wmxDb">A reference to the active Workflow Manager database</param> /// <returns>A coded value domain as an IGPDomain</returns> public static IGPDomain BuildJobIdDomain(IJTXDatabase3 wmxDb) { IGPCodedValueDomain domain = new GPCodedValueDomainClass(); int[] allJobs = wmxDb.JobManager.GetAllJobIDs(); System.Array.Sort(allJobs); foreach (int job in allJobs) { IGPValue tempGpVal = new GPLongClass(); tempGpVal.SetAsText(job.ToString()); domain.AddCode(tempGpVal, job.ToString()); } return(domain as IGPDomain); }
/// <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> /// 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); } // 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; jtxAssignmentType assigneeType; string descriptionStr; string assigneeStr; if (m_assigneeType.Equals(C_OPT_ASSIGN_TO_GROUP)) { assigneeType = jtxAssignmentType.jtxAssignmentTypeGroup; assigneeStr = m_assignee; descriptionStr = "group '" + assigneeStr + "'"; } else if (m_assigneeType.Equals(C_OPT_ASSIGN_TO_USER)) { assigneeType = jtxAssignmentType.jtxAssignmentTypeUser; assigneeStr = m_assignee; descriptionStr = "user '" + assigneeStr + "'"; } else { assigneeType = jtxAssignmentType.jtxAssignmentTypeUnassigned; assigneeStr = string.Empty; descriptionStr = "no one (unassigned)"; } msgs.AddMessage("Assigning job " + m_jobId + " (" + job.Name + ") to " + descriptionStr); job.AssignedType = assigneeType; job.AssignedTo = assigneeStr; 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. job.LogJobAction( configMgr.GetActivityType(ESRI.ArcGIS.JTX.Utilities.Constants.ACTTYPE_ASSIGN_JOB), null, string.Empty); Common.WmauHelperFunctions.SendNotification( ESRI.ArcGIS.JTX.Utilities.Constants.NOTIF_JOB_ASSIGNED, 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); } // Indicate if changes are not actually being made string actionStr = " Deleting"; if (m_previewChanges) { msgs.AddMessage("PREVIEWING CHANGES ONLY; no changes will be made"); actionStr = " Found"; } IJTXConfiguration3 configMgr = WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXConfigurationEdit2 configEdit = WmxDatabase.ConfigurationManager as IJTXConfigurationEdit2; // Find all of the orphans in the database msgs.AddMessage("Searching for orphaned items..."); int orphanCount = UpdateAllOrphans(); msgs.AddMessage("Found " + orphanCount.ToString() + " total orphaned items"); // If requested, delete any workflows first if (m_cleanWorkflows) { List <int> unusedWorkflowIds = m_unusedWorkflows.Keys.ToList(); unusedWorkflowIds.Sort(); foreach (int id in unusedWorkflowIds) { msgs.AddMessage(actionStr + " workflow " + id.ToString() + " (" + m_unusedWorkflows[id] + ")"); if (!this.m_previewChanges) { configMgr.DeleteWorkflow(id); } } } // If requested, delete any step types if (m_cleanStepTypes) { List <int> unusedStepTypeIds = m_unusedStepTypes.Keys.ToList(); unusedStepTypeIds.Sort(); foreach (int stepTypeId in unusedStepTypeIds) { msgs.AddMessage(actionStr + " step type " + stepTypeId.ToString() + " (" + m_unusedStepTypes[stepTypeId] + ")"); if (!this.m_previewChanges) { configEdit.DeleteStepType(stepTypeId); } } } // If requested, delete any status types if (m_cleanStatusTypes) { List <int> unusedStatusTypeIds = m_unusedStatusTypes.Keys.ToList(); unusedStatusTypeIds.Sort(); foreach (int statusTypeId in unusedStatusTypeIds) { msgs.AddMessage(actionStr + " status type " + statusTypeId.ToString() + " (" + m_unusedStatusTypes[statusTypeId] + ")"); if (!this.m_previewChanges) { configEdit.DeleteStatus(statusTypeId); } } } // If requested, delete any priority types if (m_cleanPriorities) { List <int> unusedPriorityTypeIds = m_unusedPriorities.Keys.ToList(); unusedPriorityTypeIds.Sort(); foreach (int priority in unusedPriorityTypeIds) { msgs.AddMessage(actionStr + " priority " + priority.ToString() + " (" + m_unusedPriorities[priority] + ")"); if (!m_previewChanges) { configEdit.DeletePriority(priority); } } } // If requested, delete any unused Task Assistant workbooks if (m_cleanTaWorkbooks) { List <string> unusedTaWorkbookNames = m_unusedTaWorkbooks.Keys.ToList(); unusedTaWorkbookNames.Sort(); foreach (string workbookName in unusedTaWorkbookNames) { msgs.AddMessage(actionStr + " workbook " + workbookName); if (!m_previewChanges) { configMgr.RemoveTaskAssistantWorkflowRecord(workbookName); } } } // If requested, delete any unused users if (m_cleanUsers) { List <string> unusedUserNames = m_unusedUsers.Keys.ToList(); unusedUserNames.Sort(); foreach (string user in unusedUserNames) { msgs.AddMessage(actionStr + " user " + user + " (" + m_unusedUsers[user] + ")"); if (!m_previewChanges) { configEdit.DeleteUser(user); } } } // If requested, delete any unused map documents if (m_cleanMapDocs) { List <string> unusedMapDocs = m_unusedMapDocs.Keys.ToList(); unusedMapDocs.Sort(); foreach (string mapName in unusedMapDocs) { msgs.AddMessage(actionStr + " map document " + mapName + " (" + m_unusedMapDocs[mapName].ToString() + ")"); if (!m_previewChanges) { configMgr.DeleteJTXMap(m_unusedMapDocs[mapName]); } } } // Set the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_NUM_ITEMS_DELETED); IGPLong outValue = new GPLongClass(); outValue.Value = orphanCount; 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_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); ////////////////////////////////////////////////////////////////////// // TODO: Update the job-deletion logic. // // In subsequent builds of Workflow Manager (post-10.0), there may be // a new API that deletes jobs and handles some of the logic included // in this class (ex: checking permissions, deleting versions, etc.). // 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 deleting Workflow Manager jobs, should keep this in mind. ////////////////////////////////////////////////////////////////////// // Delete the requested job try { IJTXJobManager jobManager = this.WmxDatabase.JobManager; IJTXJob3 job = jobManager.GetJob(m_jobToDelete) as IJTXJob3; msgs.AddMessage("Deleting job " + m_jobToDelete + " (" + job.Name + ")"); job.DeleteMXD(); if (job.VersionExists()) { if (CurrentUserHasPrivilege(ESRI.ArcGIS.JTX.Utilities.Constants.PRIV_DELETE_VERSION)) { try { job.DeleteVersion(null); } catch (System.Runtime.InteropServices.COMException comEx) { if (comEx.ErrorCode == (int)fdoError.FDO_E_SE_VERSION_NOEXIST) { // The "VersionExists" method above can apparently be fooled; if it is, an exception with this // error code is thrown. In this case, add a warning and continue on. msgs.AddWarning("Version '" + job.VersionName + "' is assigned to job " + job.ID.ToString() + " but could not be found"); } else { // If there's a different error, then re-throw it for someone else to deal with throw comEx; } } } else { string username = ESRI.ArcGIS.JTXUI.ConfigurationCache.GetCurrentSystemUser(ESRI.ArcGIS.JTXUI.ConfigurationCache.UseUserDomain); msgs.AddWarning("User '" + username + "' does not have permissions to " + "delete job versions; version '" + job.VersionName + "' will not be deleted"); } } jobManager.DeleteJob(m_jobToDelete, true); // Set the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_JOB_DELETED); IGPLong outValue = new GPLongClass(); outValue.Value = m_jobToDelete; outParamEdit.Value = outValue as IGPValue; msgs.AddMessage(Properties.Resources.MSG_DONE); } catch (Exception ex) { WmauError error = new WmauError(WmauErrorCodes.C_DELETE_JOB_VERSION_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); StreamWriter logFileWriter = null; try { int errorCount = 0; if (!string.IsNullOrEmpty(m_logFilePath)) { logFileWriter = new StreamWriter(m_logFilePath); } IJTXConfiguration3 configMgr = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXConfigurationEdit2 configEdit = configMgr as IJTXConfigurationEdit2; IJTXJobManager jobMgr = this.WmxDatabase.JobManager; // Workflow Manager intentionally caches the data workspaces in the system. To ensure // that we have the most current list of data workspaces, invalidate this cache // before attempting to retrieve the list from the system. this.WmxDatabase.InvalidateDataWorkspaceNames(); // Run checks against users ExecuteUserChecks(msgs, ref errorCount, logFileWriter); // Run checks against groups ExecuteGroupChecks(msgs, ref errorCount, logFileWriter); // Run checks against any existing jobs ExecuteJobChecks(msgs, ref errorCount, logFileWriter); // Check for any template job types with an invalid default assignment ExecuteJobTypeChecks(msgs, ref errorCount, logFileWriter); // Check the workflow steps for problems ExecuteWorkflowStepChecks(msgs, ref errorCount, logFileWriter); // Set the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_ISSUES_FOUND); IGPLong outValue = new GPLongClass(); outValue.Value = errorCount; 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_UNSPECIFIED_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } catch { // Catch anything else that possibly happens } } finally { // Release any COM objects here! if (logFileWriter != null) { logFileWriter.Close(); } } }