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