public static void CheckFP(string folder) { string dbxmlFilesNotExistsMessage = ""; //не найденные файлы, указанные в сценарии string linesNotExistsMessage = ""; //не указанные в сценарии, но существующие в папках патчей string scfilesNotExistsMessage; string fileScText = GetTextsFromPatches(new string[] { folder }, out scfilesNotExistsMessage)[0]; bool quit = false; if (!string.IsNullOrWhiteSpace(scfilesNotExistsMessage)) { quit = MessageBox.Show("Отсутствуют файлы сценария в папках:" + Environment.NewLine + scfilesNotExistsMessage + Environment.NewLine + "Продолжить?", "Предупреждение", MessageBoxButtons.YesNo) == DialogResult.Yes ? false : true; } if (!quit) { string[] lines = fileScText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); //проверка, что все файлы в папках присутствуют в файле сценария foreach (string filename in Directory.EnumerateFiles(folder, "*.*", SearchOption.AllDirectories)) { string filenameUPPER = filename.ToUpper(); string relFileName = new FileInfo(filenameUPPER).Name; //отсечение rn, файлов сценария и файлов vss if (IsValidFileName(relFileName)) { bool found = false; for (int j = 2; j < lines.Length && !found; ++j) { //получаем название файлов из строк int startPath = lines[j].IndexOf("||") + 2; int endPath = lines[j].IndexOf("||", startPath); endPath = endPath == -1 ? lines[j].Length : endPath; string fileFromSc = (folder + "\\" + lines[j].Substring(startPath, endPath - startPath)).ToUpper(); //сверяем с файлом в папке found = filenameUPPER == fileFromSc; } if (!found) //если не нашли нужного, добавляем строку к ошибке { linesNotExistsMessage += filename.Substring(folder.Length + 1) + Environment.NewLine; } } } //проверка, что для всех строк из сценария есть файл for (int j = 2; j < lines.Length; ++j) { //получаем название файлов из строк int startPath = lines[j].IndexOf("||") + 2; int endPath = lines[j].IndexOf("||", startPath); endPath = endPath == -1 ? lines[j].Length : endPath; string fileFromSc = (folder + "\\" + lines[j].Substring(startPath, endPath - startPath)).ToUpper(); if (!File.Exists(fileFromSc)) { dbxmlFilesNotExistsMessage += lines[j] + Environment.NewLine; } } if (dbxmlFilesNotExistsMessage != "" || linesNotExistsMessage != "") { using (ShowWarningsForm swf = new ShowWarningsForm(dbxmlFilesNotExistsMessage, linesNotExistsMessage)) { swf.ShowDialog(); quit = swf.dialogResult != DialogResult.Yes; } } else { MessageBox.Show("Файл сценария и внутренние файлы соответствуют", "Проверка пройдена", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
//сохраняется в texts public static void GetFileScFromScs(string folder, string[] subfolders, string[] texts, out string dbxmlFilesNotExistsMessage, out string linesNotExistsMessage, ref bool quit) { DialogResultExt dialogResult = DialogResultExt.Yes; Forms.AddUsrTsForm addUsrTsForm; dbxmlFilesNotExistsMessage = ""; //не найденные файлы, указанные в сценарии linesNotExistsMessage = ""; //не указанные в сценарии, но существующие в папках патчей for (int i = 0; i < subfolders.Length; ++i) { if (texts[i] != null) { string[] lines = texts[i].Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); List <string> newLines = new List <string>(); string relSubfolderName = new DirectoryInfo(subfolders[i]).Name; //первые 2 строчки не исполняемые for (int j = 2; j < lines.Length; ++j) { int startPath = lines[j].IndexOf("||") + 2; //находим, где кончается первые || lines[j] = lines[j].Insert(startPath, relSubfolderName + "\\"); //вставляем туда название подпапки string prefix = lines[j].Substring(0, startPath - 2); //ORA, IPC или STWF int endPath = lines[j].IndexOf("||", startPath); //находим вторые || endPath = endPath == -1 ? lines[j].Length : endPath; //если их нет, берем до конца string relPath = lines[j].Substring(startPath, endPath - startPath); //получаем путь до файла string fullPath = folder + "\\" + relPath; //получаем полный путь bool isUsrTs = false; if (prefix == "ORA" && dialogResult != DialogResultExt.YesAll) //если решили добавлять все, то добавляем { if (lines[j].ToUpper().IndexOf("\\USER\\") != -1 || lines[j].ToUpper().IndexOf("\\TABLESPACE\\") != -1) //пользователи и табличные пространства обычно добавляются вручную { isUsrTs = true; if (dialogResult != DialogResultExt.NoAll) //если решили не добавлять все, то не спрашиваем снова { addUsrTsForm = new Forms.AddUsrTsForm(fullPath); addUsrTsForm.ShowDialog(); dialogResult = addUsrTsForm.dialogResult; } } else { isUsrTs = false; } } if (!isUsrTs || dialogResult == DialogResultExt.Yes || dialogResult == DialogResultExt.YesAll) //если это не добавление пользователя или тс, или если мы решили все равно добавлять { if (IsValidFileName(new FileInfo(relPath).Name.ToUpper())) //если это накатываемый файл { newLines.Add(lines[j]); } if (!File.Exists(fullPath)) { dbxmlFilesNotExistsMessage += relPath + Environment.NewLine; } } isUsrTs = false; //для следующей строки предполагаем, что все в порядке } texts[i] = String.Join(Environment.NewLine, newLines); //объединяем полученные строчки //проверка, что все файлы в папках присутствуют в файле сценария foreach (string filename in Directory.EnumerateFiles(folder + "\\" + relSubfolderName, "*.*", SearchOption.AllDirectories)) { string filenameUPPER = filename.ToUpper(); string relFileName = new FileInfo(filenameUPPER).Name; //отсечение rn, файлов сценария и файлов vss if (IsValidFileName(relFileName)) { bool found = false; for (int j = 2; j < lines.Length && !found; ++j) { //получаем название файлов из строк int startPath = lines[j].IndexOf("||") + 2; int endPath = lines[j].IndexOf("||", startPath); endPath = endPath == -1 ? lines[j].Length : endPath; string fileFromSc = (folder + "\\" + lines[j].Substring(startPath, endPath - startPath)).ToUpper(); //сверяем с файлом в папке found = filenameUPPER == fileFromSc; } if (!found) //если не нашли нужного, добавляем строку к ошибке { linesNotExistsMessage += filename.Substring(folder.Length + 1) + Environment.NewLine; } } } } } //все dbatools ставим после всех dwh for (int k = 0; k < texts.Length; ++k) { List <string> lines = texts[k].Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList <string>(); List <string> dbatoolsLines = new List <string>(); bool dwhSchemaFound = false; for (int i = 0; i < lines.Count; ++i) { Match matchSchema = Regex.Match(lines[i], @"ORA.*\|\|([^\|]*)$"); if (matchSchema.Success) { string schema1 = matchSchema.Groups[1].Value; //находим строчку DWH if (schema1.Equals("DWH", StringComparison.CurrentCultureIgnoreCase)) { dwhSchemaFound = true; break; } } } if (dwhSchemaFound) { for (int i = lines.Count - 1; i >= 0; --i) { Match matchSchema = Regex.Match(lines[i], @"ORA.*\|\|([^\|]*)$"); if (matchSchema.Success) { string schema1 = matchSchema.Groups[1].Value; //находим строчку DBATOOLS if (schema1.Equals("DBATOOLS", StringComparison.CurrentCultureIgnoreCase)) { //вставляем в начало, тк идем с конца dbatoolsLines.Insert(0, lines[i]); lines.RemoveAt(i); } } } int dwhSchemaIndex = 0; for (int i = lines.Count - 1; i >= 0; --i) { Match matchSchema = Regex.Match(lines[i], @"ORA.*\|\|([^\|]*)$"); if (matchSchema.Success) { string schema1 = matchSchema.Groups[1].Value; //находим строчку DWH if (schema1.Equals("DWH", StringComparison.CurrentCultureIgnoreCase)) { dwhSchemaIndex = i; break; } } } lines.InsertRange(dwhSchemaIndex + 1, dbatoolsLines); } texts[k] = string.Join(Environment.NewLine, lines); } if (dbxmlFilesNotExistsMessage != "" || linesNotExistsMessage != "") { using (ShowWarningsForm swf = new ShowWarningsForm(dbxmlFilesNotExistsMessage, linesNotExistsMessage)) { swf.ShowDialog(); quit = swf.dialogResult != DialogResult.Yes; } } }