/// <summary> /// Required by IGPFunction2 interface; this function is called when the GP tool is ready to be executed. /// </summary> /// <param name="paramValues"></param> /// <param name="trackCancel"></param> /// <param name="envMgr"></param> /// <param name="msgs"></param> public override void Execute(IArray paramValues, ITrackCancel trackCancel, IGPEnvironmentManager envMgr, IGPMessages msgs) { // Do some common error-checking base.Execute(paramValues, trackCancel, envMgr, msgs); // Close the requested job try { IJTXJobManager jobManager = this.WmxDatabase.JobManager; IJTXJob3 job = jobManager.GetJob(m_jobToClose) as IJTXJob3; IJTXConfiguration3 configMgr = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3; if (job.Stage != jtxJobStage.jtxJobStageClosed && !job.CanClose()) { throw new WmauException(WmauErrorCodes.C_CANNOT_CLOSE_JOB_ERROR); } msgs.AddMessage("Closing job " + m_jobToClose + " (" + job.Name + ")"); job.Close(); // Once the job is closed, do the other things that still need to be handled // separately (status updates, notifications, ...) Common.WmauHelperFunctions.UpdateJobStatus(this.WmxDatabase, job); job.Store(); job.LogJobAction( configMgr.GetActivityType(ESRI.ArcGIS.JTX.Utilities.Constants.ACTTYPE_CLOSE_JOB), null, string.Empty); Common.WmauHelperFunctions.SendNotification( ESRI.ArcGIS.JTX.Utilities.Constants.NOTIF_JOB_CLOSED, this.WmxDatabase, job); // Set the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_JOB_CLOSED); IGPLong outValue = new GPLongClass(); outValue.Value = m_jobToClose; outParamEdit.Value = outValue as IGPValue; msgs.AddMessage(Properties.Resources.MSG_DONE); } catch (WmauException wmEx) { try { msgs.AddError(wmEx.ErrorCodeAsInt, wmEx.Message); } catch { // Catch anything else that possibly happens } } catch (Exception ex) { WmauError error = new WmauError(WmauErrorCodes.C_UNSPECIFIED_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } }
/// <summary> /// Required by IGPFunction2 interface; this function is called when the GP tool is ready to be executed. /// </summary> /// <param name="paramValues"></param> /// <param name="trackCancel"></param> /// <param name="envMgr"></param> /// <param name="msgs"></param> public override void Execute(IArray paramValues, ITrackCancel trackCancel, IGPEnvironmentManager envMgr, IGPMessages msgs) { // Do some common error-checking base.Execute(paramValues, trackCancel, envMgr, msgs); try { // Update the internal parameters used by this GP tool string styleFileName = this.DetermineStyleFileName(this.m_xmlFilePath); // Retrieve the TA workbook IJTXConfiguration3 defaultDbReadonly = WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXTaskAssistantWorkflowRecord tamRecord = defaultDbReadonly.GetTaskAssistantWorkflowRecord(this.m_sourceName); // Delete any existing workflow or style files that we're going to replace this.DeleteFile(this.m_xmlFilePath); this.DeleteFile(styleFileName); // Save the TAM workbook data out to file this.SaveStringToXmlFile(tamRecord.WorkflowXML, this.m_xmlFilePath); this.SaveStringToXmlFile(tamRecord.StyleXML, styleFileName); msgs.AddMessage(Properties.Resources.MSG_DONE); } catch (System.IO.IOException ioEx) { try { WmauError error = new WmauError(WmauErrorCodes.C_FILE_ACCESS_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ioEx.Message); } catch { // Catch anything else that possibly happens } } catch (WmauException wmEx) { try { msgs.AddError(wmEx.ErrorCodeAsInt, wmEx.Message); } catch { // Catch anything else that possibly happens } } catch (Exception ex) { try { WmauError error = new WmauError(WmauErrorCodes.C_TAM_DOWNLOAD_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } catch { // Catch anything else that possibly happens } } }
/// <summary> /// Required by IGPFunction2 interface; this function is called when the GP tool is ready to be executed. /// </summary> /// <param name="paramValues"></param> /// <param name="trackCancel"></param> /// <param name="envMgr"></param> /// <param name="msgs"></param> public override void Execute(IArray paramValues, ITrackCancel trackCancel, IGPEnvironmentManager envMgr, IGPMessages msgs) { // Do some common error-checking base.Execute(paramValues, trackCancel, envMgr, msgs); try { WmauParameterMap paramMap = new WmauParameterMap(paramValues); 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> /// Helper function that runs all of those checks that operate on each user group; /// intended to make the checks slightly more efficient by running them all at once /// rather than looping through all of the elements multiple times /// </summary> /// <param name="msgs">Add any GP messages to this object</param> /// <param name="errorCount">Counter used to track the number of problems found</param> /// <param name="logFileWriter">Object used to write error descriptions to a text file</param> private void ExecuteGroupChecks(IGPMessages msgs, ref int errorCount, StreamWriter logFileWriter) { // Check for groups w/o privileges if (!m_flagGroupsWithoutPrivileges && !m_flagGroupsWithoutEmails && !m_flagGroupsWithoutUsers) { return; } IJTXConfiguration3 configMgr = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXConfigurationEdit2 configEdit = configMgr as IJTXConfigurationEdit2; // Put the items into a sorted list in order to make the output easier to // read/follow IJTXUserGroupSet allGroups = configMgr.UserGroups; SortedList <string, IJTXUserGroup2> allGroupsSorted = new SortedList <string, IJTXUserGroup2>(); for (int i = 0; i < allGroups.Count; i++) { allGroupsSorted[allGroups.get_Item(i).Name] = allGroups.get_Item(i) as IJTXUserGroup2; } // Iterate over each group, performing the specified checks foreach (IJTXUserGroup2 group in allGroupsSorted.Values) { if (m_flagGroupsWithoutPrivileges) { if (group.Privileges.Count < 1) { string message = "Group '" + group.Name + "' has no associated privileges"; RecordMessage(message, msgs, logFileWriter); errorCount++; } } if (m_flagGroupsWithoutEmails) { if (group.Email == null || group.Email.Equals(string.Empty)) { string message = "Group '" + group.Name + "' has no associated e-mail address"; RecordMessage(message, msgs, logFileWriter); errorCount++; } } if (m_flagGroupsWithoutUsers) { if (group.Users.Count <= 0) { string message = "Group '" + group.Name + "' has no users assigned to it"; RecordMessage(message, msgs, logFileWriter); errorCount++; } } } }
/// <summary> /// Required by IGPFunction2 interface; this function is called when the GP tool is ready to be executed. /// </summary> /// <param name="paramValues"></param> /// <param name="trackCancel"></param> /// <param name="envMgr"></param> /// <param name="msgs"></param> public override void Execute(IArray paramValues, ITrackCancel trackCancel, IGPEnvironmentManager envMgr, IGPMessages msgs) { // Do some common error-checking base.Execute(paramValues, trackCancel, envMgr, msgs); try { // Ensure that the current user has admin access to the current Workflow Manager DB if (!CurrentUserIsWmxAdministrator()) { throw new WmauException(WmauErrorCodes.C_USER_NOT_ADMIN_ERROR); } // Retrieve the MXD and delete it IJTXConfiguration3 configMgr = WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXMap map = configMgr.GetJTXMap(m_mxdName); configMgr.DeleteJTXMap(map.ID); // Update the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_MXD_NAME); IGPString outValue = new GPStringClass(); outValue.Value = m_mxdName; outParamEdit.Value = outValue as IGPValue; msgs.AddMessage(Properties.Resources.MSG_DONE); } catch (WmauException wmEx) { try { msgs.AddError(wmEx.ErrorCodeAsInt, wmEx.Message); } catch { // Catch anything else that possibly happens } } catch (Exception ex) { try { WmauError error = new WmauError(WmauErrorCodes.C_DELETE_MXD_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } catch { // Catch anything else that possibly happens } } finally { // Release any COM objects here! } }
/// <summary> /// 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> /// Find those Task Assistant workbooks in the database that are not being used by /// any step that launches ArcMap /// </summary> /// <returns>The total number of orphaned items found</returns> private int UpdateOrphanedTaWorkbooks() { SortedList <string, string> unusedItems = new SortedList <string, string>(); IJTXDatabase3 wmxDb = this.WmxDatabase; IJTXConfiguration3 configMgr = wmxDb.ConfigurationManager as IJTXConfiguration3; IJTXTaskAssistantWorkflowRecordSet allItems = configMgr.TaskAssistantWorkflowRecords; // First check to see if there are even any TA workbooks in the database if (allItems.Count > 0) { Dictionary <string, string> usedTypes = new Dictionary <string, string>(); // Search all the step types for Task Assistant workbooks currently in use IJTXStepTypeSet allStepTypes = wmxDb.ConfigurationManager.StepTypes; for (int i = 0; i < allStepTypes.Count; i++) { IJTXStepType2 stepType = allStepTypes.get_Item(i) as IJTXStepType2; // Skip over unused step types if (m_unusedStepTypes.Keys.Contains(stepType.ID)) { continue; } // Examine the remaining step types for (int j = 0; j < stepType.Arguments.Length; j++) { string stepArg = stepType.Arguments[j].ToString(); if (stepArg.StartsWith(C_WORKBOOK_FLAG)) { string suffix = stepArg.Substring(C_WORKBOOK_FLAG.Length); suffix = suffix.Trim(new char[] { '"' }); usedTypes[suffix] = null; } } } // Loop over all the Task Assistant workbooks, looking for anything // that we didn't identify as "in use" for (int i = 0; i < allItems.Count; i++) { IJTXTaskAssistantWorkflowRecord item = allItems.get_Item(i); if (!usedTypes.ContainsKey(item.Alias)) { m_unusedTaWorkbooks[item.Alias] = null; } } } return(m_unusedTaWorkbooks.Count); }
/// <summary> /// Find those step types in the database that are not being used by any workflow. /// </summary> /// <returns>The total number of orphaned items found</returns> private int UpdateOrphanedStepTypes() { Dictionary <int, int> usedStepTypes = new Dictionary <int, int>(); IJTXDatabase3 wmxDb = this.WmxDatabase; IJTXConfiguration3 configMgr = wmxDb.ConfigurationManager as IJTXConfiguration3; IJTXWorkflowSet workflows = configMgr.Workflows; // Iterate through each workflow, building up the list of used steps for (int i = 0; i < workflows.Count; i++) { // Skip over those workflows that aren't in use IJTXWorkflow workflow = workflows.get_Item(i); if (m_unusedWorkflows.Keys.Contains(workflow.ID)) { continue; } // Examine the remaining workflows IJTXWorkflowConfiguration workflowCfg = workflows.get_Item(i) as IJTXWorkflowConfiguration; int[] stepIds = workflowCfg.GetAllSteps(); foreach (int stepId in stepIds) { int stepTypeId = workflowCfg.GetStep(stepId).StepTypeID; usedStepTypes[stepTypeId] = stepTypeId; } } // Get the complete list of step types in the database IJTXStepTypeSet allStepTypeObjs = configMgr.StepTypes; // Loop over all of the step types. For anything whose step type ID is not // contained in the "used" list, add it to the "unused" list. // If all of the items are used, don't bother trying to add to the // unused list. if (usedStepTypes.Count != allStepTypeObjs.Count) { for (int i = 0; i < allStepTypeObjs.Count; i++) { IJTXStepType2 stepType = allStepTypeObjs.get_Item(i) as IJTXStepType2; int stepTypeId = stepType.ID; if (!usedStepTypes.ContainsKey(stepTypeId)) { m_unusedStepTypes[stepTypeId] = stepType.Name; } } } return(m_unusedStepTypes.Count); }
/// <summary> /// Gets a list of all the TAM workbooks that are stored in the current WMX database /// </summary> /// <returns>A sorted list of the TAM workbooks</returns> private SortedList <string, string> ListTamWorkbooksInDatabase() { SortedList <string, string> tamWorkbookNames = new SortedList <string, string>(); IJTXConfiguration3 configMgr = WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXTaskAssistantWorkflowRecordSet tamWorkbooks = configMgr.TaskAssistantWorkflowRecords; for (int i = 0; i < tamWorkbooks.Count; i++) { IJTXTaskAssistantWorkflowRecord tamWorkbook = tamWorkbooks.get_Item(i); tamWorkbookNames.Add(tamWorkbook.Alias, null); } return(tamWorkbookNames); }
/// <summary> /// Gets a list of all the map documents stored in the current WMX database /// </summary> /// <returns>A sorted list of the MXDs</returns> private SortedList <string, string> ListMapDocumentsInDatabase() { SortedList <string, string> mapDocumentNames = new SortedList <string, string>(); IJTXConfiguration3 configMgr = WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXMapSet mapDocuments = configMgr.JTXMaps; for (int i = 0; i < mapDocuments.Count; i++) { IJTXMap map = mapDocuments.get_Item(i); mapDocumentNames.Add(map.Name, null); } return(mapDocumentNames); }
/// <summary> /// Helper function that runs all of those checks that operate on each user in /// the database; intended to make the checks slightly more efficient by running /// through them all at once rather than looping through all of the elements /// multiple times /// </summary> /// <param name="msgs">Add any GP messages to this object</param> /// <param name="errorCount">Counter used to track the number of problems found</param> /// <param name="logFileWriter">Object used to write error descriptions to a text file</param> private void ExecuteUserChecks(IGPMessages msgs, ref int errorCount, StreamWriter logFileWriter) { // Only continue executing this function if needed if (!m_flagUsersWithoutEmails && !m_flagUsersWithoutGroups) { return; } IJTXConfiguration3 configMgr = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXConfigurationEdit2 configEdit = configMgr as IJTXConfigurationEdit2; // Put the items into a sorted list in order to make the output easier to // read/follow IJTXUserSet allUsers = configMgr.Users; SortedList <string, IJTXUser3> allUsersSorted = new SortedList <string, IJTXUser3>(); for (int i = 0; i < allUsers.Count; i++) { allUsersSorted[allUsers.get_Item(i).UserName] = allUsers.get_Item(i) as IJTXUser3; } // Iterate through each item foreach (IJTXUser3 user in allUsersSorted.Values) { if (m_flagUsersWithoutEmails) { if (user.Email == null || user.Email.Equals(string.Empty)) { string message = "User '" + user.UserName + "' (" + user.FullName + ") does not have an e-mail address configured"; RecordMessage(message, msgs, logFileWriter); errorCount++; } } if (m_flagUsersWithoutGroups) { if (user.Groups.Count < 1) { string message = "User '" + user.UserName + "' (" + user.FullName + ") does not belong to any groups"; RecordMessage(message, msgs, logFileWriter); errorCount++; } } } }
/// <summary> /// Builds a domain consisting of the available job queries in the system. /// </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 BuildJobQueryDomain(IJTXDatabase3 wmxDb) { IGPCodedValueDomain domain = new GPCodedValueDomainClass(); IJTXConfiguration3 configMgr = wmxDb.ConfigurationManager as IJTXConfiguration3; IJTXJobQueryContainer publicQueriesContainer = configMgr.GetPublicQueryContainer(); // Sort the queries first SortedList <string, string> sortedValues = new SortedList <string, string>(); WmauGpDomainBuilder.AddQueriesFromContainer(publicQueriesContainer, string.Empty, sortedValues); // Add the sorted types to the domain foreach (string value in sortedValues.Keys) { domain.AddStringCode(value, value); } return(domain as IGPDomain); }
/// <summary> /// Find those workflows in the database that are not being used by any job type. /// </summary> /// <returns>The total number of orphaned items found</returns> private int UpdateOrphanedWorkflows() { Dictionary <int, int> usedWorkflows = new Dictionary <int, int>(); IJTXDatabase3 wmxDb = this.WmxDatabase; IJTXConfiguration3 configMgr = wmxDb.ConfigurationManager as IJTXConfiguration3; IJTXJobTypeSet jobTypes = configMgr.JobTypes; // Iterate through each item in the set, building up the list of used types for (int i = 0; i < jobTypes.Count; i++) { // TODO: Do not consider items that we know are not in use IJTXJobType3 type = jobTypes.get_Item(i) as IJTXJobType3; // job type don't always need to have a workflow if (type.Workflow != null) { usedWorkflows[type.Workflow.ID] = type.Workflow.ID; } } // Get the complete list of this type of object in the database IJTXWorkflowSet workflows = configMgr.Workflows; // Loop through the complete list of this object type. If any of the IDs // are not in the "used" list, add that object to the "unused" list. // If all of the items are used, don't bother trying to add to the // unused list. if (usedWorkflows.Count != workflows.Count) { for (int i = 0; i < workflows.Count; i++) { IJTXWorkflow workflow = workflows.get_Item(i) as IJTXWorkflow; if (!usedWorkflows.ContainsKey(workflow.ID)) { m_unusedWorkflows[workflow.ID] = workflow.Name; } } } return(m_unusedWorkflows.Count); }
/// <summary> /// Builds a domain containing the names of all the map documents embedded /// 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 BuildMapDocumentDomain(IJTXDatabase3 wmxDb) { IGPCodedValueDomain mxdNames = new GPCodedValueDomainClass(); SortedList <string, string> mapDocumentNames = new SortedList <string, string>(); IJTXConfiguration3 configMgr = wmxDb.ConfigurationManager as IJTXConfiguration3; IJTXMapSet maps = configMgr.JTXMaps; for (int i = 0; i < maps.Count; i++) { IJTXMap map = maps.get_Item(i); mapDocumentNames.Add(map.Name, null); } foreach (string mapDocName in mapDocumentNames.Keys) { mxdNames.AddStringCode(mapDocName, mapDocName); } return(mxdNames as IGPDomain); }
/// <summary> /// Builds a domain containing the names of all the task assistant /// workbooks embedded 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 BuildTamWorkbookDomain(IJTXDatabase3 wmxDb) { IGPCodedValueDomain tamNames = new GPCodedValueDomainClass(); SortedList <string, string> sortedTamNames = new SortedList <string, string>(); IJTXConfiguration3 configMgr = wmxDb.ConfigurationManager as IJTXConfiguration3; IJTXTaskAssistantWorkflowRecordSet tamWorkbooks = configMgr.TaskAssistantWorkflowRecords; for (int i = 0; i < tamWorkbooks.Count; i++) { IJTXTaskAssistantWorkflowRecord tamWorkbook = tamWorkbooks.get_Item(i); sortedTamNames.Add(tamWorkbook.Alias, null); } foreach (string tamName in sortedTamNames.Keys) { tamNames.AddStringCode(tamName, tamName); } return(tamNames as IGPDomain); }
/// <summary> /// Find those users in the database who are not being referenced in any way /// </summary> /// <returns>The total number of orphaned items found</returns> private int UpdateOrphanedUsers() { SortedList <string, string> unusedItems = new SortedList <string, string>(); IJTXDatabase3 wmxDb = this.WmxDatabase; IJTXConfiguration3 configMgr = wmxDb.ConfigurationManager as IJTXConfiguration3; IJTXJobManager jobMgr = wmxDb.JobManager; IJTXUserSet allUsers = configMgr.Users; Dictionary <string, string> usedItems = new Dictionary <string, string>(); // Get all of the users who are members of a group IJTXUserGroupSet allGroups = configMgr.UserGroups; for (int i = 0; i < allGroups.Count; i++) { IJTXUserGroup2 group = allGroups.get_Item(i) as IJTXUserGroup2; for (int j = 0; j < group.Users.Count; j++) { IJTXUser3 user = group.Users.get_Item(j) as IJTXUser3; usedItems[user.UserName] = user.FullName; } } // If necessary, add in the users who have jobs assigned to them if (usedItems.Count < allUsers.Count) { IJTXJobSet allJobs = jobMgr.GetAllJobs(); for (int i = 0; i < allJobs.Count; i++) { IJTXJob3 job = allJobs.get_Item(i) as IJTXJob3; if (job.AssignedType == jtxAssignmentType.jtxAssignmentTypeUser) { IJTXUser3 user = configMgr.GetUser(job.AssignedTo) as IJTXUser3; // It's possible for a user to have a job assigned, but have // already been removed from the DB. Throw an exception in // this case, as the DB needs to be cleaned up. if (user == null) { throw new WmauException(WmauErrorCodes.C_USER_NOT_FOUND_ERROR); } usedItems[user.UserName] = user.FullName; } } } // If necessary, add in the users who have a job type's default assignment // set to them if (usedItems.Count < allUsers.Count) { IJTXJobTypeSet allJobTypes = configMgr.JobTypes; for (int i = 0; i < allJobTypes.Count; i++) { // TODO: Exclude orphaned job types IJTXJobType3 jobType = allJobTypes.get_Item(i) as IJTXJobType3; if (jobType.DefaultAssignedType == jtxAssignmentType.jtxAssignmentTypeUser) { IJTXUser3 user = configMgr.GetUser(jobType.DefaultAssignedTo) as IJTXUser3; // It's possible for a user to have a job assigned, but have // already been removed from the DB. Throw an exception in // this case, as the DB needs to be cleaned up. if (user == null) { throw new WmauException(WmauErrorCodes.C_USER_NOT_FOUND_ERROR); } usedItems[user.UserName] = user.FullName; } } } // If necessary, add in the users who have steps assigned to them // by default if (usedItems.Count < allUsers.Count) { IJTXWorkflowSet allWorkflows = configMgr.Workflows; for (int i = 0; i < allWorkflows.Count; i++) { // Skip over unused workflows IJTXWorkflow workflow = allWorkflows.get_Item(i); if (m_unusedWorkflows.Keys.Contains(workflow.ID)) { continue; } // Examine the other items IJTXWorkflowConfiguration workflowCfg = allWorkflows.get_Item(i) as IJTXWorkflowConfiguration; int[] workflowStepIds = workflowCfg.GetAllSteps(); foreach (int j in workflowStepIds) { IJTXStep3 step = workflowCfg.GetStep(j) as IJTXStep3; if (step.AssignedType == jtxAssignmentType.jtxAssignmentTypeUser) { IJTXUser3 user = configMgr.GetUser(step.AssignedTo) as IJTXUser3; // It's possible for a user to have a job assigned, but have // already been removed from the DB. Throw an exception in // this case, as the DB needs to be cleaned up. if (user == null) { throw new WmauException(WmauErrorCodes.C_USER_NOT_FOUND_ERROR); } usedItems[user.UserName] = user.FullName; } } } } // Loop over all the users in the DB, looking for anything // that we didn't identify as "in use" for (int i = 0; i < allUsers.Count; i++) { IJTXUser3 item = allUsers.get_Item(i) as IJTXUser3; if (!usedItems.ContainsKey(item.UserName)) { m_unusedUsers[item.UserName] = item.FullName; } } return(m_unusedUsers.Count); }
/// <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(); } } }
/// <summary> /// Helper function that runs all of those checks that operate on each job type; /// intended to make the checks slightly more efficient by running through them all /// at once rather than looping through all of the elements multiple times /// </summary> /// <param name="msgs">Add any GP messages to this object</param> /// <param name="errorCount">Counter used to track the number of problems found</param> /// <param name="logFileWriter">Object used to write error descriptions to a text file</param> private void ExecuteJobTypeChecks(IGPMessages msgs, ref int errorCount, StreamWriter logFileWriter) { if (!m_flagInvalidJobTypeAssign && !m_flagJobTypesWithoutWorkflows && !m_flagMissingAoiMxds && !m_flagMissingBaseMxds && !m_flagNonActiveJobTypes) { return; } IJTXConfiguration3 configMgr = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXConfigurationEdit2 configEdit = configMgr as IJTXConfigurationEdit2; // Put the items into a sorted list in order to make the output easier to // read/follow IJTXJobTypeSet allJobTypes = configMgr.JobTypes; SortedList <string, IJTXJobType3> allJobTypesSorted = new SortedList <string, IJTXJobType3>(); for (int i = 0; i < allJobTypes.Count; i++) { allJobTypesSorted[allJobTypes.get_Item(i).Name] = allJobTypes.get_Item(i) as IJTXJobType3; } // Iterate through each item foreach (IJTXJobType3 jobType in allJobTypesSorted.Values) { if (m_flagInvalidJobTypeAssign) { string assignedTo = jobType.DefaultAssignedTo; if (jobType.DefaultAssignedType == jtxAssignmentType.jtxAssignmentTypeUser && configMgr.GetUser(assignedTo) == null) { string message = "Job Type '" + jobType.Name + "' assigned to unknown user '" + assignedTo + "'"; RecordMessage(message, msgs, logFileWriter); errorCount++; } else if (jobType.DefaultAssignedType == jtxAssignmentType.jtxAssignmentTypeGroup && configMgr.GetUserGroup(assignedTo) == null) { string message = "Job Type '" + jobType.Name + "' assigned to unknown group '" + assignedTo + "'"; RecordMessage(message, msgs, logFileWriter); errorCount++; } } if (m_flagJobTypesWithoutWorkflows) { if (jobType.Workflow == null) { string message = "Job Type '" + jobType.Name + "' has no workflow defined"; RecordMessage(message, msgs, logFileWriter); errorCount++; } } if (m_flagMissingAoiMxds) { if (jobType.AOIMap == null) { string message = "Job Type '" + jobType.Name + "' has no AOI map defined"; RecordMessage(message, msgs, logFileWriter); errorCount++; } } if (m_flagMissingBaseMxds) { if (jobType.JobMap == null) { string message = "Job Type '" + jobType.Name + "' has no job map (a.k.a. basemap) defined"; RecordMessage(message, msgs, logFileWriter); errorCount++; } } if (m_flagNonActiveJobTypes) { if (jobType.State != jtxJobTypeState.jtxJobTypeStateActive) { string message = "Job Type '" + jobType.Name + "' is not active"; RecordMessage(message, msgs, logFileWriter); errorCount++; } } } }
/// <summary> /// Required by IGPFunction2 interface; this function is called when the GP tool is ready to be executed. /// </summary> /// <param name="paramValues"></param> /// <param name="trackCancel"></param> /// <param name="envMgr"></param> /// <param name="msgs"></param> public override void Execute(IArray paramValues, ITrackCancel trackCancel, IGPEnvironmentManager envMgr, IGPMessages msgs) { // Do some common error-checking base.Execute(paramValues, trackCancel, envMgr, msgs); // Set the default properties for the specified job type try { IJTXConfiguration3 configMgr = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXConfigurationEdit2 configEdit = this.WmxDatabase.ConfigurationManager as IJTXConfigurationEdit2; IJTXJobTypeEdit3 jobType = configEdit.GetJobType(m_jobTypeName) as IJTXJobTypeEdit3; // Set the default data workspace for the selected job type if (m_dataWorkspaceName.Equals(C_OPT_NONE)) { jobType.DefaultDataWorkspace = null; msgs.AddMessage("Clearing default data workspace for job type '" + m_jobTypeName + "'"); } else { // Translate the workspace name to a DB name object IJTXDataWorkspaceName dwName = Common.WmauHelperFunctions.LookupWorkspaceNameObj(this.WmxDatabase, m_dataWorkspaceName); msgs.AddMessage("Default data workspace for job type '" + m_jobTypeName + "' is now '" + dwName.Name + "'"); jobType.DefaultDataWorkspace = dwName; } // Set the default parent version for the selected job type if (m_parentVersion.Equals(C_OPT_NONE)) { msgs.AddMessage("Clearing default parent version for job type '" + m_jobTypeName + "'"); jobType.DefaultParentVersionName_2 = string.Empty; } else { msgs.AddMessage("Default parent version for job type '" + m_jobTypeName + "' is now '" + m_parentVersion + "'"); jobType.DefaultParentVersionName_2 = m_parentVersion; } // Save the changes to the job type jobType.Store(); // Set the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_DATA_WORKSPACE); IGPString outValue = new GPStringClass(); outValue.Value = m_jobTypeName; outParamEdit.Value = outValue as IGPValue; msgs.AddMessage(Properties.Resources.MSG_DONE); } catch (WmauException wmEx) { try { msgs.AddError(wmEx.ErrorCodeAsInt, wmEx.Message); } catch { // Catch anything else that possibly happens } } catch (Exception ex) { WmauError error = new WmauError(WmauErrorCodes.C_UNSPECIFIED_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } }
/// <summary> /// Required by IGPFunction2 interface; this function is called when the GP tool is ready to be executed. /// </summary> /// <param name="paramValues"></param> /// <param name="trackCancel"></param> /// <param name="envMgr"></param> /// <param name="msgs"></param> public override void Execute(IArray paramValues, ITrackCancel trackCancel, IGPEnvironmentManager envMgr, IGPMessages msgs) { // Do some common error-checking base.Execute(paramValues, trackCancel, envMgr, msgs); try { // Ensure that the current user has admin access to the current Workflow Manager DB if (!CurrentUserIsWmxAdministrator()) { throw new WmauException(WmauErrorCodes.C_USER_NOT_ADMIN_ERROR); } // Retrieve the TA workbook IJTXConfiguration3 defaultDbReadonly = WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXTaskAssistantWorkflowRecord tamRecord = defaultDbReadonly.GetTaskAssistantWorkflowRecord(this.m_targetName); string styleFileName = this.DetermineStyleFileName(this.m_xmlFilePath); // If we're not allowed to overwrite an existing TA record, then do some error checking if (!this.m_overwriteExisting && tamRecord != null) { msgs.AddWarning("Did not overwrite Task Assistant workbook: " + this.m_targetName); return; } else if (tamRecord != null) { msgs.AddMessage("Replacing Task Assistant workbook '" + m_targetName + "' in database..."); defaultDbReadonly.ReplaceTaskAssistantWorkflowRecord(this.m_targetName, this.m_targetName, this.m_xmlFilePath, styleFileName); } else // tamRecord == null { msgs.AddMessage("Adding Task Assistant workbook '" + m_targetName + "' to database..."); defaultDbReadonly.AddTaskAssistantWorkflowRecord(this.m_targetName, this.m_xmlFilePath, styleFileName); } // Update the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_TARGET_NAME); IGPString outValue = new GPStringClass(); outValue.Value = m_targetName; outParamEdit.Value = outValue as IGPValue; msgs.AddMessage(Properties.Resources.MSG_DONE); } catch (WmauException wmEx) { try { msgs.AddError(wmEx.ErrorCodeAsInt, wmEx.Message); } catch { // Catch anything else that possibly happens } } catch (Exception ex) { try { WmauError error = new WmauError(WmauErrorCodes.C_TAM_UPLOAD_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } catch { // Catch anything else that possibly happens } } }
/// <summary> /// Helper function that runs all of those checks that operate on each job; intended /// to make the checks slightly more efficient by running through them all at once /// rather than looping through all of the elements multiple times /// </summary> /// <param name="msgs">Add any GP messages to this object</param> /// <param name="errorCount">Counter used to track the number of problems found</param> /// <param name="logFileWriter">Object used to write error descriptions to a text file</param> private void ExecuteJobChecks(IGPMessages msgs, ref int errorCount, StreamWriter logFileWriter) { // Only continue executing this function if needed if (!m_flagInvalidJobAssign && !m_flagIsSelfParent && !m_flagJobsWithoutTypes) { return; } IJTXConfiguration3 configMgr = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXConfigurationEdit2 configEdit = configMgr as IJTXConfigurationEdit2; IJTXJobManager jobMgr = this.WmxDatabase.JobManager; // Use a database query as an alternate way of finding certain specific // problems with jobs. Declare some of these ComReleaser objects to help // ensure that cursors, etc., are immediately released after they go out // of scope. // Check for jobs without any job types set (should be a DB error) if (m_flagJobsWithoutTypes) { using (ComReleaser cr1 = new ComReleaser(), cr2 = new ComReleaser()) { IFeatureWorkspace featureWorkspace = this.WmxDatabase.JTXWorkspace as IFeatureWorkspace; // Get the name of the correct table from the jobs workspace, so // that the table doesn't have to be owned by the connecting user. string tableName = Common.WmauHelperFunctions.GetQualifiedTableName(Constants.JTX_TABLE_JTX_JOBS_TABLE, this.WmxDatabase.JTXWorkspace); ITable jobsTable = featureWorkspace.OpenTable(tableName); cr1.ManageLifetime(jobsTable); IQueryFilter query = new QueryFilterClass(); query.WhereClause = Constants.FIELD_JOBTYPEID + " IS NULL"; ICursor searchCursor = jobsTable.Search(query, true); cr2.ManageLifetime(searchCursor); // Store the ID and name of each job matching this query int idIndex = jobsTable.FindField(Constants.FIELD_JOBID); int nameIndex = jobsTable.FindField(Constants.FIELD_JOBNAME); IRow row = null; while ((row = searchCursor.NextRow()) != null) { string idStr = row.get_Value(idIndex).ToString(); string nameStr = row.get_Value(nameIndex).ToString(); string msg = "Job " + idStr + " (" + nameStr + ") has no associated job type"; RecordMessage(msg, msgs, logFileWriter); errorCount++; } } } // Check for jobs that are their own parent job if (m_flagIsSelfParent) { using (ComReleaser cr1 = new ComReleaser(), cr2 = new ComReleaser()) { IFeatureWorkspace featureWorkspace = this.WmxDatabase.JTXWorkspace as IFeatureWorkspace; // Get the name of the correct table from the jobs workspace, so // that the table doesn't have to be owned by the connecting user. string tableName = Common.WmauHelperFunctions.GetQualifiedTableName(Constants.JTX_TABLE_JTX_JOBS_TABLE, this.WmxDatabase.JTXWorkspace); ITable jobsTable = featureWorkspace.OpenTable(tableName); cr1.ManageLifetime(jobsTable); const string C_FIELD_PARENT_JOB = "PARENT_JOB"; IQueryFilter query = new QueryFilterClass(); query.WhereClause = Constants.FIELD_JOBID + " = " + C_FIELD_PARENT_JOB; ICursor searchCursor = jobsTable.Search(query, true); cr2.ManageLifetime(searchCursor); // Store the ID and name of each job matching this query int idIndex = jobsTable.FindField(Constants.FIELD_JOBID); int nameIndex = jobsTable.FindField(Constants.FIELD_JOBNAME); IRow row = null; while ((row = searchCursor.NextRow()) != null) { string idStr = row.get_Value(idIndex).ToString(); string nameStr = row.get_Value(nameIndex).ToString(); string msg = "Job " + idStr + " (" + nameStr + ") is its own parent"; RecordMessage(msg, msgs, logFileWriter); errorCount++; } } } // See if there are any checks selected for which we should iterate through // all of the jobs using the WMX interfaces if (m_flagInvalidJobAssign) { // Put the items into a sorted list in order to make the output easier to // read/follow IJTXJobSet allJobs = jobMgr.GetAllJobs(); SortedList <int, IJTXJob3> allJobsSorted = new SortedList <int, IJTXJob3>(); for (int i = 0; i < allJobs.Count; i++) { allJobsSorted[allJobs.get_Item(i).ID] = allJobs.get_Item(i) as IJTXJob3; } // Iterate over all of the jobs foreach (IJTXJob3 job in allJobsSorted.Values) { string assignedTo = job.AssignedTo; // Check for any existing jobs with an invalid job assignment. NOTE: only // want to flag jobs that are not closed if (m_flagInvalidJobAssign && job.Stage != jtxJobStage.jtxJobStageClosed) { if (job.AssignedType == jtxAssignmentType.jtxAssignmentTypeUser && configMgr.GetUser(assignedTo) == null) { string message = "Job '" + job.ID.ToString() + "' assigned to unknown user '" + assignedTo + "'"; RecordMessage(message, msgs, logFileWriter); errorCount++; } else if (job.AssignedType == jtxAssignmentType.jtxAssignmentTypeGroup && configMgr.GetUserGroup(assignedTo) == null) { string message = "Job '" + job.ID.ToString() + "' assigned to unknown group '" + assignedTo + "'"; RecordMessage(message, msgs, logFileWriter); errorCount++; } } } } }
/// <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> /// Helper function that runs all of those checks that operate on each step in /// every workflow; intended to make the checks slightly more efficient by running /// through them all at once rather than looping through all of the elements /// multiple times /// </summary> /// <param name="msgs">Add any GP messages to this object</param> /// <param name="errorCount">Counter used to track the number of problems found</param> /// <param name="logFileWriter">Object used to write error descriptions to a text file</param> private void ExecuteWorkflowStepChecks(IGPMessages msgs, ref int errorCount, StreamWriter logFileWriter) { // Only continue executing this function if needed if (!m_flagInvalidStepAssign && !m_flagUnassignedSteps && !m_flagZeroPctSteps && !m_flagDifferingStepNames) { return; } IJTXConfiguration3 configMgr = this.WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXConfigurationEdit2 configEdit = configMgr as IJTXConfigurationEdit2; // Put the items into a sorted list in order to make the output easier to // read/follow IJTXWorkflowSet allWorkflows = configMgr.Workflows; SortedList <string, IJTXWorkflow> allWorkflowsSorted = new SortedList <string, IJTXWorkflow>(); for (int i = 0; i < allWorkflows.Count; i++) { allWorkflowsSorted[allWorkflows.get_Item(i).Name] = allWorkflows.get_Item(i); } // Iterate through each item foreach (IJTXWorkflow workflow in allWorkflowsSorted.Values) { IJTXWorkflowConfiguration workflowCfg = workflow as IJTXWorkflowConfiguration; int[] allStepIds = workflowCfg.GetAllSteps(); foreach (int j in allStepIds) { IJTXStep3 step = workflowCfg.GetStep(j) as IJTXStep3; string assignedTo = step.AssignedTo; // Check for any default step types with an invalid step assignment if (m_flagInvalidStepAssign) { if (step.AssignedType == jtxAssignmentType.jtxAssignmentTypeUser && configMgr.GetUser(assignedTo) == null) { string message = "Workflow '" + workflow.Name + "', step '" + step.StepName + "' assigned to unknown user '" + assignedTo + "'"; RecordMessage(message, msgs, logFileWriter); errorCount++; } else if (step.AssignedType == jtxAssignmentType.jtxAssignmentTypeGroup && configMgr.GetUserGroup(assignedTo) == null) { string message = "Workflow '" + workflow.Name + "', step '" + step.StepName + "' assigned to unknown group '" + assignedTo + "'"; RecordMessage(message, msgs, logFileWriter); errorCount++; } } // Check for any steps that have not been assigned to a group or user if (m_flagUnassignedSteps) { if (step.AssignedType == jtxAssignmentType.jtxAssignmentTypeUnassigned) { string message = "Workflow '" + workflow.Name + "', step '" + step.StepName + "' is unassigned"; RecordMessage(message, msgs, logFileWriter); errorCount++; } } // Check for any steps whose "post-complete" percentage is 0 if (m_flagZeroPctSteps) { if (step.DefaultPercComplete < double.Epsilon) { string message = "Workflow '" + workflow.Name + "', step '" + step.StepName + "' sets percent complete to 0"; RecordMessage(message, msgs, logFileWriter); errorCount++; } } // Check for any steps whose descriptions in a workflow does not match // the underlying step type name if (m_flagDifferingStepNames) { IJTXStepType2 stepType = configMgr.GetStepTypeByID(step.StepTypeID) as IJTXStepType2; if (!step.StepName.Equals(stepType.Name)) { string message = "Workflow '" + workflow.Name + "', step name '" + step.StepName + "' does not match step type name '" + stepType.Name + "'"; RecordMessage(message, msgs, logFileWriter); errorCount++; } } } // end for each step } // end for each workflow }
/// <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) { // Do some common error-checking base.Execute(paramValues, trackCancel, envMgr, msgs); try { // Ensure that the current user has admin access to the current Workflow Manager DB if (!CurrentUserIsWmxAdministrator()) { throw new WmauException(WmauErrorCodes.C_USER_NOT_ADMIN_ERROR); } // Retrieve the MXD IJTXConfiguration3 defaultDbReadonly = WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXMap map = defaultDbReadonly.GetJTXMap(this.m_sourceName); // Delete any existing file that we're going to replace this.DeleteFile(this.m_mxdFilePath); // Save the map to disk map.CopyToLocation(this.m_mxdFilePath); msgs.AddMessage(Properties.Resources.MSG_DONE); } catch (System.IO.IOException ioEx) { try { WmauError error = new WmauError(WmauErrorCodes.C_FILE_ACCESS_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ioEx.Message); } catch { // Catch anything else that possibly happens } } catch (WmauException wmEx) { try { msgs.AddError(wmEx.ErrorCodeAsInt, wmEx.Message); } catch { // Catch anything else that possibly happens } } catch (Exception ex) { try { WmauError error = new WmauError(WmauErrorCodes.C_MXD_DOWNLOAD_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } catch { // Catch anything else that possibly happens } } }
/// <summary> /// Find those status types in the database that are not being used by any step. /// </summary> /// <returns>The total number of orphaned items found</returns> private int UpdateOrphanedStatusTypes() { Dictionary <int, int> usedStatusTypes = new Dictionary <int, int>(); IJTXDatabase3 wmxDb = this.WmxDatabase; string[] coreStatusNames = { C_STATUS_CLOSED, C_STATUS_CREATED, C_STATUS_DONE_WORKING, C_STATUS_READY_TO_WORK, C_STATUS_WORKING }; IJTXConfiguration3 configMgr = wmxDb.ConfigurationManager as IJTXConfiguration3; // Iterate through each job currently in the system, adding the status types used // by these jobs IJTXJobSet jobs = wmxDb.JobManager.GetAllJobs(); for (int i = 0; i < jobs.Count; i++) { IJTXJob3 job = jobs.get_Item(i) as IJTXJob3; if (job.Status != null) { usedStatusTypes[job.Status.ID] = job.Status.ID; } } // Iterate through each workflow, building up the list of used status types // based on the statuses that are assigned by each step IJTXWorkflowSet workflows = configMgr.Workflows; for (int i = 0; i < workflows.Count; i++) { // Skip over those workflows that aren't in use IJTXWorkflow workflow = workflows.get_Item(i); if (m_unusedWorkflows.Keys.Contains(workflow.ID)) { continue; } // Examine the remaining workflows IJTXWorkflowConfiguration workflowCfg = workflows.get_Item(i) as IJTXWorkflowConfiguration; int[] stepIds = workflowCfg.GetAllSteps(); foreach (int stepId in stepIds) { IJTXStep3 step = workflowCfg.GetStep(stepId) as IJTXStep3; usedStatusTypes[step.StatusID] = step.StatusID; } } // Add the status types used by Workflow Manager itself foreach (string s in coreStatusNames) { IJTXStatus2 status = configMgr.GetStatus(s) as IJTXStatus2; // Avoid problems if someone deleted one of these mandatory types from the database if (status != null) { int id = status.ID; usedStatusTypes[id] = id; } } // Get the complete list of status types in the database IJTXStatusSet allStatusTypes = configMgr.Statuses; // Loop over all of the status types. For anything whose ID is not contained // in the "used" list, add it to the "unused" list. If all of the items are // used, don't bother trying to add to the unused list. if (usedStatusTypes.Count != allStatusTypes.Count) { for (int i = 0; i < allStatusTypes.Count; i++) { IJTXStatus2 statusType = allStatusTypes.get_Item(i) as IJTXStatus2; if (!usedStatusTypes.ContainsKey(statusType.ID)) { m_unusedStatusTypes[statusType.ID] = statusType.Name; } } } return(m_unusedStatusTypes.Count); }
/// <summary> /// Required by IGPFunction2 interface; this function is called when the GP tool is ready to be executed. /// </summary> /// <param name="paramValues"></param> /// <param name="trackCancel"></param> /// <param name="envMgr"></param> /// <param name="msgs"></param> public override void Execute(IArray paramValues, ITrackCancel trackCancel, IGPEnvironmentManager envMgr, IGPMessages msgs) { // Do some common error-checking base.Execute(paramValues, trackCancel, envMgr, msgs); try { // Ensure that the current user has admin access to the current Workflow Manager DB if (!CurrentUserIsWmxAdministrator()) { throw new WmauException(WmauErrorCodes.C_USER_NOT_ADMIN_ERROR); } IJTXConfiguration3 configMgr = WmxDatabase.ConfigurationManager as IJTXConfiguration3; IJTXMapEdit wmxMapDoc = configMgr.GetJTXMap(this.m_targetName) as IJTXMapEdit; // If we're not allowed to overwrite an existing map document, then do some error checking if (!this.m_overwriteExisting && wmxMapDoc != null) { msgs.AddWarning("Did not overwrite Map Document: " + this.m_targetName); return; } else if (wmxMapDoc != null) { msgs.AddMessage("Replacing Map Document '" + this.m_targetName + "' in database..."); } else // wmxMapDoc == null { msgs.AddMessage("Adding Map Document '" + this.m_targetName + "' to database..."); wmxMapDoc = configMgr.CreateJTXMap() as IJTXMapEdit; } IMapDocument mapDoc = new MapDocumentClass() as IMapDocument; mapDoc.Open(this.m_mxdFilePath, string.Empty); wmxMapDoc.Name = this.m_targetName; if (!string.IsNullOrEmpty(this.m_targetCategory)) { wmxMapDoc.Category = this.m_targetCategory; } if (!string.IsNullOrEmpty(this.m_description)) { wmxMapDoc.Description = this.m_description; } wmxMapDoc.Directory = string.Empty; wmxMapDoc.FileName = string.Empty; wmxMapDoc.MapDocument = mapDoc; wmxMapDoc.Store(); mapDoc.Close(); // Update the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_TARGET_NAME); IGPString outValue = new GPStringClass(); outValue.Value = m_targetName; outParamEdit.Value = outValue as IGPValue; msgs.AddMessage(Properties.Resources.MSG_DONE); } catch (WmauException wmEx) { try { msgs.AddError(wmEx.ErrorCodeAsInt, wmEx.Message); } catch { // Catch anything else that possibly happens } } catch (Exception ex) { try { WmauError error = new WmauError(WmauErrorCodes.C_MXD_UPLOAD_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } catch { // Catch anything else that possibly happens } } }
/// <summary> /// Find those map documents embedded in the database that are not being /// referenced in any way /// </summary> /// <returns>The total number of orphaned items found</returns> private int UpdateOrphanedMapDocuments() { SortedList <string, int> unusedItems = new SortedList <string, int>(); IJTXDatabase3 wmxDb = this.WmxDatabase; IJTXConfiguration3 configMgr = wmxDb.ConfigurationManager as IJTXConfiguration3; IJTXConfigurationEdit2 configEdit = wmxDb.ConfigurationManager as IJTXConfigurationEdit2; IJTXMapSet allMaps = configMgr.JTXMaps; Dictionary <string, int> allMapNames = new Dictionary <string, int>(); for (int i = 0; i < allMaps.Count; i++) { IJTXMap map = allMaps.get_Item(i); allMapNames[map.Name] = map.ID; } Dictionary <string, int> usedItems = new Dictionary <string, int>(); // Find the map types that are associated with job types IJTXJobTypeSet allJobTypes = configMgr.JobTypes; for (int i = 0; i < allJobTypes.Count; i++) { // TODO: Skip orphaned job types IJTXJobType3 jobType = allJobTypes.get_Item(i) as IJTXJobType3; if (jobType.AOIMap != null) { usedItems[jobType.AOIMap.Name] = jobType.AOIMap.ID; } if (jobType.JobMap != null) { usedItems[jobType.JobMap.Name] = jobType.JobMap.ID; } } // If necessary, find the map types launched by custom steps. Look for // the "/mxd:" argument as an identifier. IJTXStepTypeSet allStepTypes = wmxDb.ConfigurationManager.StepTypes; for (int i = 0; i < allStepTypes.Count; i++) { IJTXStepType2 stepType = allStepTypes.get_Item(i) as IJTXStepType2; // Skip orphaned step types if (m_unusedStepTypes.Keys.Contains(stepType.ID)) { continue; } for (int j = 0; j < stepType.Arguments.Length; j++) { string stepArg = stepType.Arguments[j].ToString(); if (stepArg.StartsWith(C_MAP_DOC_FLAG)) { string suffix = stepArg.Substring(C_MAP_DOC_FLAG.Length); suffix = suffix.Trim(new char[] { '"' }); if (allMapNames.Keys.Contains(suffix)) { usedItems[suffix] = allMapNames[suffix]; } } } } // Add in the map document that's used as the template map document // (if one exists) IJTXConfigurationProperties configProps = this.WmxDatabase.ConfigurationManager as IJTXConfigurationProperties; string mapIdStr = configProps.GetProperty(Constants.JTX_PROPERTY_MAPVIEW_MAP_GUID); if (mapIdStr != null && !mapIdStr.Equals(string.Empty)) { for (int i = 0; i < allMaps.Count; i++) { IJTXMap tempMap = allMaps.get_Item(i); IJTXIdentifier tempMapId = tempMap as IJTXIdentifier; if (tempMapId.GUID.Equals(mapIdStr)) { usedItems[tempMap.Name] = tempMap.ID; break; } } } // Loop over all the map documents in the DB, looking for anything // that we didn't identify as "in use" foreach (string name in allMapNames.Keys) { if (!usedItems.ContainsKey(name)) { m_unusedMapDocs[name] = allMapNames[name]; } } return(m_unusedMapDocs.Count); }
/// <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); } // 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 } } }