protected override void OnStart(string[] args) { bool isBound = ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop); if (!isBound) { return; } IAoInitialize aoInitialize = new AoInitializeClass(); aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced); aoInitialize.CheckOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCodeWorkflowManager); IJTXDatabaseManager databaseMan = new JTXDatabaseManagerClass(); m_database = (IJTXDatabase2)databaseMan.GetActiveDatabase(false); //m_lastDate = (DateTime.Now; m_dataWorkspaceNames = m_database.GetDataWorkspaceNames(null); IJTXSpatialNotificationManager spatNotifMan = m_database.SpatialNotificationManager; m_regLayers = spatNotifMan.RegisteredLayerInfos; for (int i = 0; i < m_dataWorkspaceNames.Count; i++) { IWorkspace ws = m_database.GetDataWorkspace(m_dataWorkspaceNames.get_Item(i).DatabaseID, ""); DateTime now = (DateTime)((IDatabaseConnectionInfo2)ws).ConnectionCurrentDateTime; m_workspaces.Add(new WorkspaceInfo(m_dataWorkspaceNames.get_Item(i).DatabaseID, ws, now)); } m_timer.Enabled = true; }
/// <summary> /// Builds a domain of the data workspace names in the system /// </summary> /// <param name="wmxDb">A reference to the active Workflow Manager database</param> /// <param name="extraValues">An array of string values to be added to the list</param> /// <returns>A coded value domain as an IGPDomain</returns> public static IGPDomain BuildWorkspaceDomain(IJTXDatabase3 wmxDb, string[] extraValues) { IGPCodedValueDomain domain = new GPCodedValueDomainClass(); SortedList <string, string> sortedValues = new SortedList <string, string>(); // 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. wmxDb.InvalidateDataWorkspaceNames(); // Sort the types first IJTXDataWorkspaceNameSet allValues = wmxDb.GetDataWorkspaceNames(null); for (int i = 0; i < allValues.Count; i++) { IJTXDataWorkspaceName ws = allValues.get_Item(i); sortedValues.Add(ws.Name, null); } // Add the extra values, if any if (extraValues != null) { foreach (string s in extraValues) { sortedValues.Add(s, null); } } // Add the sorted types to the domain foreach (string value in sortedValues.Keys) { IGPValue tempGpVal = new GPStringClass(); tempGpVal.SetAsText(value); domain.AddCode(tempGpVal, value); } return(domain as IGPDomain); }
/// <summary> /// Given the human-readable name of a data workspace, this function returns the /// unique ID string used by Workflow Manager to identify this workspace connection. /// </summary> /// <param name="wmxDb">A reference to the active Workflow Manager database</param> /// <param name="wsName"> /// The name of the data workspace whose ID is to be retrieved /// </param> /// <returns> /// The ID string for the specified data workspace; returns the empty string if /// no matching workspace can be found. /// </returns> public static string LookupWorkspaceId(IJTXDatabase3 wmxDb, string wsName) { string id = string.Empty; // 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. wmxDb.InvalidateDataWorkspaceNames(); // Get the workspace list from the database IJTXDataWorkspaceNameSet allValues = wmxDb.GetDataWorkspaceNames(null); // Search for the workspace ID with the matching name for (int i = 0; i < allValues.Count; i++) { if (allValues.get_Item(i).Name.Equals(wsName)) { id = allValues.get_Item(i).DatabaseID; break; } } return(id); }
protected override void OnStart(string[] args) { bool isBound = ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop); if (!isBound) return; IAoInitialize aoInitialize = new AoInitializeClass(); aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced); aoInitialize.CheckOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCodeWorkflowManager); IJTXDatabaseManager databaseMan = new JTXDatabaseManagerClass(); m_database = (IJTXDatabase2)databaseMan.GetActiveDatabase(false); //m_lastDate = (DateTime.Now; m_dataWorkspaceNames = m_database.GetDataWorkspaceNames(null); IJTXSpatialNotificationManager spatNotifMan = m_database.SpatialNotificationManager; m_regLayers = spatNotifMan.RegisteredLayerInfos; for (int i = 0; i < m_dataWorkspaceNames.Count; i++) { IWorkspace ws = m_database.GetDataWorkspace(m_dataWorkspaceNames.get_Item(i).DatabaseID, ""); DateTime now = (DateTime)((IDatabaseConnectionInfo2)ws).ConnectionCurrentDateTime; m_workspaces.Add(new WorkspaceInfo(m_dataWorkspaceNames.get_Item(i).DatabaseID, ws, now)); } m_timer.Enabled = true; }
/// <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 parameter in which the data workspace names will be stored WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameter3 param = paramMap.GetParam(C_PARAM_WORKSPACE_LIST); IGPParameterEdit3 paramEdit = paramMap.GetParamEdit(C_PARAM_WORKSPACE_LIST); // Set up the multi-value objects IGPMultiValue mvValue = new GPMultiValueClass(); mvValue.MemberDataType = param.DataType; // 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(); // Get the list of names SortedList <string, string> sortedValues = new SortedList <string, string>(); IJTXDataWorkspaceNameSet allValues = this.WmxDatabase.GetDataWorkspaceNames(null); for (int i = 0; i < allValues.Count; i++) { IJTXDataWorkspaceName ws = allValues.get_Item(i); sortedValues.Add(ws.Name, null); } // Add the names to the output parameter foreach (string name in sortedValues.Keys) { IGPString strVal = new GPStringClass(); strVal.Value = name; mvValue.AddValue(strVal as IGPValue); msgs.AddMessage("Workspace: " + name); } paramEdit.Value = (IGPValue)mvValue; 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! } }