BitrixAQA.General.SQL.GetDBname C# (CSharp) Method

GetDBname() public static method

Метод возвращает имя базы текущей установки
public static GetDBname ( string edition, string dbType ) : string
edition string Редакция
dbType string Тип базы
return string
        public static string GetDBname(string edition, string dbType)
        {
            string DBName = "";
            string fileName = Options.GetOption("/Options/PathToFolderWhereToInstall/edition[@title='" + edition + "']/" + dbType) + "\\bitrix\\php_interface\\dbconn.php";

            if (File.Exists(fileName) == true)
            {
                StreamReader streamReader = new StreamReader(fileName, Encoding.Default);
                string workText = streamReader.ReadToEnd();
                streamReader.Close();

                //смотрим, если тип базы Оракл
                string toReplaceDBType = @"^.*\$DBType = ""oracle"";.*$";

                if (Regex.IsMatch(workText, toReplaceDBType, RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Multiline))
                {
                    string toReplaceOracle = @"^.*\$DBLogin = ""([^""]*)"";.*$";
                    string replacement = @"${1}";

                    if (Regex.IsMatch(workText, toReplaceOracle, RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Multiline))
                        DBName = Regex.Replace(workText, toReplaceOracle, replacement, RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Multiline);
                    else
                    {
                        System.Windows.Forms.DialogResult result = MessageBox.Show("Невозможно получить имя базы отсюда \r\n" + fileName + "\r\n\r\n Выполнение теста прервано",
                            "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);

                        if (result == System.Windows.Forms.DialogResult.OK)
                        {
                            Log.MesError("Невозможно получить имя базы для устаноки " + edition + "_" + dbType + "\r\nВыполнение теста прервано");
                            return null;
                        }
                    }
                }
                else
                {
                    string toReplace = @"^.*\$DBName = ""(.*)"";.*$";
                    string replacement = @"${1}";

                    if (Regex.IsMatch(workText, toReplace, RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Multiline))
                        DBName = Regex.Replace(workText, toReplace, replacement, RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Multiline);
                    else
                    {
                        System.Windows.Forms.DialogResult result = MessageBox.Show("Невозможно получить имя базы отсюда \r\n" + fileName + "\r\n\r\n Выполнение теста прервано",
                            "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);

                        if (result == System.Windows.Forms.DialogResult.OK)
                        {
                            Log.MesError("Невозможно получить имя базы для устаноки " + edition + "_" + dbType + "\r\nВыполнение теста прервано");
                            return null;
                        }
                    }
                }
            }
            else
            {
                System.Windows.Forms.DialogResult result = MessageBox.Show("Не найден файл \r\n" + fileName + "\r\n\r\n Выполнение теста прервано",
                    "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);

                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    Log.MesError("Не найден файл " + fileName + "\r\nВыполнение теста прервано");
                    return null;
                }
            }

            return DBName;
        }