public bool ReplaceAllFiles(FileConfig oFile, string urlDocker, string onlinePath, string binSoapUiPAth, bool soapFileUserCheck, bool variableFileCheck, bool tnsFileCheck)
        {
            bool checkVariable = false;
            bool checkSoap     = false;
            bool checkTsn      = false;

            try
            {
                Variable   oVariablesLoad = new Variable();
                WebRequest request        = WebRequest.Create(string.Concat(urlDocker, "environment.html"));
                request.Credentials = CredentialCache.DefaultCredentials;
                WebResponse  response    = request.GetResponse();
                Stream       dataStream  = response.GetResponseStream();
                StreamReader reader      = new StreamReader(dataStream);
                string       str         = "";
                string       finalString = "";
                while (str != null)
                {
                    finalString = finalString + str;
                    str         = reader.ReadLine();
                }
                response.Close();
                RegexOptions options = RegexOptions.None;
                Regex        regex   = new Regex("[ ]{2,}", options);


                finalString = finalString.Replace("<pre>Runtime environment details---------------------------", "");
                finalString = finalString.Replace("Additional port:", "");
                finalString = finalString.Replace("Database name, server, port:", "").Replace("Server name:", "").Replace("Web services port:", "").Replace("Web clients port:", "");
                finalString = finalString.Replace("SSH access to CBIO container (password=test): ssh", "").Replace("</pre>", "").Replace("-p", "").Replace(",", "");
                finalString = regex.Replace(finalString, " ");

                string[] infoServerBySpace = finalString.Trim().Split(' ');

                oVariablesLoad.urlDocker       = string.Concat(urlDocker, "environment.html");
                oVariablesLoad.dbName          = infoServerBySpace[0];
                oVariablesLoad.dbHost          = infoServerBySpace[1];
                oVariablesLoad.dbUser          = "******";
                oVariablesLoad.dbPassword      = "******";
                oVariablesLoad.dbPort          = infoServerBySpace[2];
                oVariablesLoad.hostUrl         = infoServerBySpace[3];
                oVariablesLoad.webServicesPort = infoServerBySpace[4];
                oVariablesLoad.webClientsPort  = infoServerBySpace[5];
                oVariablesLoad.unixUser        = infoServerBySpace[6].Split('@')[0];
                oVariablesLoad.sshPort         = infoServerBySpace[7];
                oVariablesLoad.unixPass        = "******";
                oVariablesLoad.onlineWin32Path = onlinePath;
                oVariablesLoad.binSoapUiPath   = binSoapUiPAth;
                oVariablesLoad.variablesPath   = oFile.filePathVariable;
                oVariablesLoad.tnsnamesPath    = oFile.filePathTsn;
                oVariablesLoad.soapPath        = oFile.filePathSoap;

                if (variableFileCheck == false)
                {
                    checkVariable = replaceByFile(oFile.filePathVariable, variableTemplate, oVariablesLoad);
                }

                if (soapFileUserCheck == false)
                {
                    checkSoap = replaceByFile(oFile.filePathSoap, soapui_template, oVariablesLoad);
                }

                if (tnsFileCheck == false)
                {
                    checkTsn = replaceByFile(oFile.filePathTsn, tnsnames_template, oVariablesLoad);
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                MessageBox.Show(message);
            }


            if (checkVariable || checkSoap || checkTsn)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        private void btnReplaceFiles_Click(object sender, EventArgs e)
        {
            string[] nomeFileVariable = textBox1.Text.Split('\\');
            string[] nomeFileTsnName  = txtTnsName.Text.Split('\\');
            string[] nomeFileSoap     = txtSoapUi.Text.Split('\\');


            if (chkNotUsed.Checked == false || chkSoap.Checked == false || chkTns.Checked == false)
            {
                if (!(nomeFileVariable[nomeFileVariable.Length - 1] == "variables.py" && nomeFileTsnName[nomeFileTsnName.Length - 1] == "tnsnames.ora" && nomeFileSoap[nomeFileSoap.Length - 1] == "soapui.properties"))
                {
                    errorProvider1.SetError(textBox1, "Must be variables.py path");
                    errorProvider1.SetError(txtTnsName, "Must be tnsnames.ora path");
                    errorProvider1.SetError(txtSoapUi, "Must be soapui.properties path");

                    MessageBox.Show("File name wrong, please to check file name choosen (variable,tsnames and soapui)  !", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else if (textBox1.Text != string.Empty && txtTnsName.Text != string.Empty && txtSoapUi.Text != string.Empty && textBox4.Text != string.Empty &&
                         txtSoapUiPath.Text != string.Empty && txtOnlinePath.Text != string.Empty)
                {
                    errorProvider1.Clear();
                    FileConfig oFiles = new FileConfig();

                    oFiles.fileNameVariable = variable;
                    oFiles.filePathVariable = textBox1.Text;

                    oFiles.fileNameTsn = tsnName;
                    oFiles.filePathTsn = txtTnsName.Text;

                    oFiles.fileNameSoap = soapUI;
                    oFiles.filePathSoap = txtSoapUi.Text;

                    bool validaReplace = false;



                    validaReplace = oConfiguraFile.ReplaceAllFiles(oFiles, textBox4.Text.Trim(), txtSoapUiPath.Text.Trim(), txtOnlinePath.Text.Trim(), chkSoap.Checked, chkNotUsed.Checked, chkTns.Checked);



                    if (validaReplace)
                    {
                        MessageBox.Show("All file were replaced successuflly!!!", "Completed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        showLinks();
                    }
                }
                else
                {
                    errorProvider1.SetError(textBox1, string.Empty);
                    errorProvider1.SetError(txtTnsName, string.Empty);
                    errorProvider1.SetError(txtSoapUi, string.Empty);
                    if (textBox4.Text == string.Empty)
                    {
                        errorProvider1.SetError(textBox4, "Please fill the required field");
                    }
                    MessageBox.Show("All file path must be filled", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                MessageBox.Show("Please choose at least one file for replace!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }