private void PopulateStatusTypes(IJTXConfiguration2 ipJTXConfig) { IJTXStatusSet ipStatuses = ipJTXConfig.Statuses; for (int i = 0; i < ipStatuses.Count; i++) { cboDependentStatus.Items.Add(ipStatuses.get_Item(i).Name); } cboDependentStatus.SelectedIndex = 0; }
/// <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); }