/// <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> /// 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> /// 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> /// 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> /// 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 } } }