//////////////////////////////////////////////////////////////////////// // METHOD: Execute public int Execute(int jobID, int stepID, ref object[] argv, ref IJTXCustomStepFeedback ipFeedback) { // Present form to user for choosing the data workspace // they want to work with for the current job. JTXSamples.DataWorkspaceSelectorDialog frmDataWSSelector = new JTXSamples.DataWorkspaceSelectorDialog(); frmDataWSSelector.StartPosition = FormStartPosition.CenterParent; // Populate the list of data workspaces configured for the JTX system IJTXDatabaseConnectionManager pDBConnManager = new JTXDatabaseConnectionManagerClass(); IJTXDatabaseConnection pDBConnection = pDBConnManager.GetConnection(m_ipDatabase.Alias); for (int a = 0; a < pDBConnection.DataWorkspaceCount; a++) { IJTXWorkspaceConfiguration pDataWorkspace = pDBConnection.get_DataWorkspace(a); frmDataWSSelector.DWName = pDataWorkspace.Name; } // Pass some other information to the form frmDataWSSelector.JTXDB = m_ipDatabase; IJTXJobManager pJobManager = m_ipDatabase.JobManager; IJTXJob2 pJob = pJobManager.GetJob(jobID) as IJTXJob2; frmDataWSSelector.theJob = pJob; if (frmDataWSSelector.ShowDialog() == DialogResult.OK) { return 1; } return 0; }
/// <summary> /// Helper function to set up a GP tool parameter so that the workflow manager /// database can be chosen. /// </summary> /// <returns>A parameter for selecting the target WMX DB</returns> protected IGPParameter3 BuildWmxDbParameter() { IGPParameterEdit paramEdit = null; IGPCodedValueDomain cvDomain = new GPCodedValueDomainClass(); // When we first build out the parameter list, ensure that we indicate // what the current Workflow Manager database is m_wmxDbAlias = string.Empty; IsWorkflowManagerDatabaseSet(); // Parameter allowing specification of the Workflow Manager database IGPString strVal = new GPStringClass(); strVal.Value = m_wmxDbAlias; paramEdit = BuildParameter( esriGPParameterDirection.esriGPParameterDirectionInput, esriGPParameterType.esriGPParameterTypeOptional, Properties.Resources.DESC_COM_WMX_DATABASE, C_PARAM_WMX_DATABASE_ALIAS, (strVal as IGPValue).DataType, strVal as IGPValue); IJTXDatabaseConnectionManager connMgr = new JTXDatabaseConnectionManagerClass(); foreach (string alias in connMgr.DatabaseNames) { cvDomain.AddStringCode(alias, alias); } paramEdit.Domain = cvDomain as IGPDomain; return(paramEdit as IGPParameter3); }
//////////////////////////////////////////////////////////////////////// // METHOD: Execute public int Execute(int jobID, int stepID, ref object[] argv, ref IJTXCustomStepFeedback ipFeedback) { // Present form to user for choosing the data workspace // they want to work with for the current job. JTXSamples.DataWorkspaceSelectorDialog frmDataWSSelector = new JTXSamples.DataWorkspaceSelectorDialog(); frmDataWSSelector.StartPosition = FormStartPosition.CenterParent; // Populate the list of data workspaces configured for the JTX system IJTXDatabaseConnectionManager pDBConnManager = new JTXDatabaseConnectionManagerClass(); IJTXDatabaseConnection pDBConnection = pDBConnManager.GetConnection(m_ipDatabase.Alias); for (int a = 0; a < pDBConnection.DataWorkspaceCount; a++) { IJTXWorkspaceConfiguration pDataWorkspace = pDBConnection.get_DataWorkspace(a); frmDataWSSelector.DWName = pDataWorkspace.Name; } // Pass some other information to the form frmDataWSSelector.JTXDB = m_ipDatabase; IJTXJobManager pJobManager = m_ipDatabase.JobManager; IJTXJob2 pJob = pJobManager.GetJob(jobID) as IJTXJob2; frmDataWSSelector.theJob = pJob; if (frmDataWSSelector.ShowDialog() == DialogResult.OK) { return(1); } return(0); }
private void Form1_Load(object sender, EventArgs e) { // Display the list of WMX connection IJTXDatabaseConnectionManager dbConnMgr = new JTXDatabaseConnectionManagerClass(); cboDBs.Items.AddRange(dbConnMgr.DatabaseNames); cboDBs.SelectedItem = dbConnMgr.ActiveDatabaseName; }
private void btnOK_Click(object sender, EventArgs e) { // Set the active data workspace for the job to the one the user selected. IJTXDatabaseConnectionManager pDBConnManager = new JTXDatabaseConnectionManagerClass(); IJTXDatabaseConnection pDBConnection = pDBConnManager.GetConnection(m_pJTXDatabase.Alias); IJTXWorkspaceConfiguration pSelectedDW = pDBConnection.get_DataWorkspace(cboDWList.SelectedIndex); m_pJob.SetActiveDatabase(pSelectedDW.DatabaseID); m_pJob.Store(); DialogResult = DialogResult.OK; this.Hide(); }
/// <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); } // Create the object needed to get at the data workspaces IJTXDatabaseConnectionManager dbConnectionManager = new JTXDatabaseConnectionManagerClass(); IJTXDatabaseConnection dbConnection = dbConnectionManager.GetConnection(this.WmxDatabase.Alias); // Loop through the data workspaces until we find the one we're looking for, then // delete it bool removedWorkspace = false; for (int i = 0; i < dbConnection.DataWorkspaceCount; i++) { IJTXWorkspaceConfiguration workspaceCfg = dbConnection.get_DataWorkspace(i); if (workspaceCfg.Name.Equals(m_dataWorkspace)) { dbConnection.RemoveDataWorkspace(i); removedWorkspace = true; break; } } // Raise an error if we somehow couldn't find it (should never happen with // the domain on the input param) if (!removedWorkspace) { throw new WmauException(WmauErrorCodes.C_WORKSPACE_NOT_FOUND_ERROR); } // Set the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_DATA_WORKSPACE); IGPString outParamStr = new GPStringClass(); outParamStr.Value = m_dataWorkspace; outParamEdit.Value = outParamStr 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); WorkspaceWorksheetReader reader = null; 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); } reader = new WorkspaceWorksheetReader(this.m_excelFilePath, msgs); // Prepare to set/build the output parameter WmauParameterMap paramMap = new WmauParameterMap(paramValues); IGPParameter3 outParam = paramMap.GetParam(C_PARAM_OUT_WORKSPACES_CREATED); IGPParameterEdit3 outParamEdit = paramMap.GetParamEdit(C_PARAM_OUT_WORKSPACES_CREATED); IGPMultiValue outMultiValue = new GPMultiValueClass(); outMultiValue.MemberDataType = outParam.DataType; // Load the workspace info from the spreadsheet List <Common.WorkspaceInfo> dataWorkspaces = reader.GetWorkspacesFromSpreadsheet(); // Loop through each of the workspaces IJTXDatabaseConnectionManager dbConnectionManager = new JTXDatabaseConnectionManagerClass(); IJTXDatabaseConnection dbConnection = dbConnectionManager.GetConnection(WmxDatabase.Alias); foreach (Common.WorkspaceInfo wmauWorkspaceInfo in dataWorkspaces) { string workspaceName = wmauWorkspaceInfo.Name; if (Common.WmauHelperFunctions.LookupWorkspaceNameObj(this.WmxDatabase, workspaceName) != null) { msgs.AddWarning("Skipping existing workspace '" + workspaceName + "'"); } else { IJTXWorkspaceConfiguration workspaceInfo = dbConnection.AddDataWorkspace(); this.CopyDataWorkspace(wmauWorkspaceInfo, ref workspaceInfo, msgs); workspaceInfo.Store(); msgs.AddMessage("Added new workspace '" + workspaceName + "'"); IGPString outElement = new GPStringClass(); outElement.Value = workspaceName; outMultiValue.AddValue(outElement as IGPValue); } } // Set the value of the output parameter outParamEdit.Value = outMultiValue 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_WORKSPACE_LOAD_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } catch { // Catch anything else that possibly happens } } } finally { if (reader != null) { reader.Close(); } } }
/// <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); WorkspaceWorksheetWriter writer = null; 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); } // Load the workspace information from the database IJTXDatabaseConnectionManager dbConnectionManager = new JTXDatabaseConnectionManagerClass(); IJTXDatabaseConnection dbConnection = dbConnectionManager.GetConnection(WmxDatabase.Alias); int numWorkspaces = dbConnection.DataWorkspaceCount; // Copy the info into an intermediate list List <Common.WorkspaceInfo> workspaceInfo = new List <Common.WorkspaceInfo>(); Dictionary <string, string> namedWorkspaces = new Dictionary <string, string>(); for (int i = 0; i < numWorkspaces; i++) { IJTXWorkspaceConfiguration workspace = dbConnection.get_DataWorkspace(i); Common.WorkspaceInfo tempInfo = new Common.WorkspaceInfo(); tempInfo.Name = workspace.Name; tempInfo.Server = workspace.Server; tempInfo.Instance = workspace.Instance; tempInfo.Database = workspace.Database; tempInfo.Version = workspace.Version; tempInfo.UseOsAuthentication = workspace.OSAuthentication; tempInfo.UseIndividualLogins = workspace.IndividualLogins; int numLogins = workspace.LoginCount; for (int j = 0; j < numLogins; j++) { IJTXWorkspaceLogin tempLogin = workspace.get_Login(j); tempInfo.AddLogin(tempLogin.JTXUserName, tempLogin.UserName, tempLogin.Password, true); } if (namedWorkspaces.Keys.Contains(tempInfo.Name)) { msgs.AddWarning("Multiple workspaces detected with name '" + tempInfo.Name + "'; only the first workspace found will be exported."); } else { workspaceInfo.Add(tempInfo); namedWorkspaces.Add(tempInfo.Name, null); } } // Save the list to an Excel worksheet writer = new WorkspaceWorksheetWriter(this.m_excelFilePath, msgs); writer.SaveWorkspacesToSpreadsheet(workspaceInfo); 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_WORKSPACE_LOAD_ERROR); msgs.AddError(error.ErrorCodeAsInt, error.Message + "; " + ex.Message); } catch { // Catch anything else that possibly happens } } } finally { if (writer != null) { writer.Close(); } } }