Exemplo n.º 1
0
        private void btnRunMultiple_Click(object sender, EventArgs e)
        {
            rchOutput.Text = "";

            try
            {
                int TDsuccess = 0, TDfail = 0, SBsuccess = 0, SBfail = 0;
                String[,] success = new String[dgvWorkflows.Rows.Count, 3];
                String[,] fail    = new String[dgvWorkflows.Rows.Count, 3];

                if (txtUserNameMultiple.Text == "" || txtPasswordMultiple.Text == "" || dgvWorkflows.Rows.Count == 0)
                {
                    MessageBox.Show("Not All Information Has Been Entered");
                }
                else
                {
                    Teradata tdmultiple = new Teradata(txtUserNameMultiple.Text, txtPasswordMultiple.Text);
                    this.addMessage("Attempting to Connect to Teradata.....");

                    if (tdmultiple.tryConnect())
                    {
                        this.addMessage("Teradata Connection Successful!");

                        this.addMessage("Checking to see if workflow exists....");

                        for (int i = 0; i < dgvWorkflows.Rows.Count; i++)
                        {
                            if (tdmultiple.doesWorkflowExist(dgvWorkflows.Rows[i].Cells[0].Value.ToString(), dgvWorkflows.Rows[i].Cells[1].Value.ToString()))
                            {
                                this.addMessage(dgvWorkflows.Rows[i].Cells[0].Value.ToString() + " " + dgvWorkflows.Rows[i].Cells[1].Value.ToString() + " Found in DEV");
                                success[TDsuccess, 0] = dgvWorkflows.Rows[i].Cells[0].Value.ToString();
                                success[TDsuccess, 1] = dgvWorkflows.Rows[i].Cells[1].Value.ToString();
                                success[TDsuccess, 2] = dgvWorkflows.Rows[i].Cells[2].Value.ToString();
                                TDsuccess++;
                            }
                            else
                            {
                                fail[TDfail, 0] = dgvWorkflows.Rows[i].Cells[0].Value.ToString();
                                fail[TDfail, 1] = dgvWorkflows.Rows[i].Cells[1].Value.ToString();
                                fail[TDfail, 2] = dgvWorkflows.Rows[i].Cells[2].Value.ToString();
                                TDfail++;
                                this.addMessage(dgvWorkflows.Rows[i].Cells[0].Value.ToString() + " " + dgvWorkflows.Rows[i].Cells[1].Value.ToString() + " NOT Found in DEV");
                            }
                        }

                        this.addMessage("");
                        for (int i = 0; i < TDsuccess; i++)
                        {
                            int milliseconds = 250;
                            Thread.Sleep(milliseconds);//added because it was running too fast, powershell script was still being used by previous process(add multi-threading?)

                            this.addMessage(Environment.NewLine + "Creating SB Task For " + (String)success[i, 0] + "_" + (String)success[i, 1] + ".....");

                            CMD powershell = new CMD(this.buildTaskName((String)success[i, 0], (String)success[i, 1]), this.buildParameter((String)success[i, 0], (String)success[i, 1], (String)success[i, 2]), txtUserNameMultiple.Text, txtPasswordMultiple.Text);

                            if (powershell.getOutput().Contains("Success"))
                            {
                                SBsuccess++;
                            }
                            else
                            {
                                SBfail++;
                            }

                            this.addMessage(powershell.getOutput());

                            powershell.resetOutput();
                        }

                        this.addMessage("");
                        this.addMessage("TD Workflows Found: " + TDsuccess + Environment.NewLine + "TD Workflows Not Found:" + TDfail);
                        this.addMessage("SB Success: " + SBsuccess + Environment.NewLine + "SB Fail: " + SBfail);
                    }
                    else
                    {
                        this.addMessage("Failed Connection: Please See Error Box");
                    }
                }
            }catch (Exception ex)
            {
                this.addMessage(ex.Message);
                MessageBox.Show(ex.Message);
            }
        }