private bool ChangeFiles(Settings.ChangeConstant changeConstants) { var projects = Workspace.Projects.ToDictionary(p => p.Name, p => p.FullName); return(new ChangeFiles(settings, projects, AppOutput.ConsoleWriteLine, AppOutput.ConsoleWriteException).Execute(changeConstants)); }
public bool Execute(Settings.ChangeConstant changeConstants) { try { ConsoleWriteLine($"Changeing {changeConstants.Name}"); foreach (var fileDiconary in changeConstants.Files) { ConsoleWriteLine($"value: {fileDiconary.Value}"); string filepath = fileDiconary.File; if (!File.Exists(filepath)) { if (string.IsNullOrEmpty(fileDiconary.ProjectName)) { continue; } string projectDirectory = projects.ContainsKey(fileDiconary.ProjectName) ? Path.GetDirectoryName(projects[fileDiconary.ProjectName]) : null; if (string.IsNullOrEmpty(projectDirectory)) { ConsoleWriteLine($"no project by name {fileDiconary.ProjectName} on open solution"); continue; } filepath = Path.Combine(projectDirectory, fileDiconary.File); if (!File.Exists(filepath)) { ConsoleWriteLine($"no File {fileDiconary.File} in project {fileDiconary.ProjectName}"); continue; } } var fileText = File.ReadAllText(filepath); if (!Regex.IsMatch(fileText, fileDiconary.Pattern)) { ConsoleWriteLine($"no match for file {fileDiconary.Pattern} in project {fileDiconary.ProjectName}"); continue; } fileText = Regex.Replace(fileText, fileDiconary.Pattern, fileDiconary.Value); WriteAllText(filepath, fileText); ConsoleWriteLine($"File {fileDiconary.File} in project {fileDiconary.ProjectName} rewrited"); } if (!string.IsNullOrEmpty(changeConstants.Sql?.Script) && changeConstants.Sql?.Databases?.Any() == true) { var sqlScript = File.Exists(changeConstants.Sql?.Script) ? File.ReadAllText(changeConstants.Sql.Script) : changeConstants.Sql.Script; var sqlRunner = new SqlRuner(); var databases = settings.Databases.ConnectionStrings.Where(d => changeConstants.Sql.Databases.Contains(d.Name)); sqlRunner.ExecuteString(changeConstants.Sql.Script, databases); } return(true); } catch (System.Exception e) { ConsoleWriteException(e, new string[] { }); return(false); } }