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