private string GetData(string source) { var spans = Scanner.GetSpans(source, true); if (spans.Any(a => a.Errors.Any())) { return(spans.SelectMany(a => a.Errors.Select(b => b.Message)).Aggregate((a, b) => $"{a}\r\n{b}")); } var content = SpansToContent.Convert(spans); return(content.GetSqlCode(@"\Test\Test.dv")); }
private List <DataBlock> GetOutput(string source) { var blocks = new List <DataBlock>(); var spans = Scanner.GetSpans(source, true); Assert.IsFalse(spans.Any(a => a.Errors.Any()), "spans.Any(a=>a.Errors.Any())"); foreach (var block in spans.GetStatementBlocks()) { blocks.Add(SpansToContent.GetBlock(block)); } return(blocks); }
protected override byte[] GenerateCode(string inputFileContent) { var projectItem = GetProjectItem(); var codeProvider = GetCodeProvider(); var spans = Scanner.GetSpans(inputFileContent, true); var originalName = GetLastKnownFileName(projectItem); if (!originalName.Equals(projectItem.Name, StringComparison.InvariantCultureIgnoreCase)) { RemoveOrphanedItem(projectItem, $"{originalName}.{codeProvider.FileExtension}"); } if (spans.Any(a => a.Errors.Any())) { return(Encoding.UTF8.GetBytes("Error Generating Content")); } var content = SpansToContent.Convert(spans); var enumCode = content.GetEnumCode(codeProvider, FileNamespace); if (!string.IsNullOrWhiteSpace(enumCode)) { CreateEnumFile(codeProvider, Encoding.UTF8.GetBytes(enumCode), projectItem); } else { foreach (ProjectItem item in projectItem.ProjectItems) { if (item.Name.EndsWith(".cs")) { item.Delete(); } } } var solution = projectItem.ContainingProject.DTE.Solution; var relativePath = InputFilePath.Remove(0, Path.GetDirectoryName(solution.FullName)?.Length ?? 0); var sqlBytes = Encoding.UTF8.GetBytes(content.GetSqlCode(relativePath)); if (string.IsNullOrWhiteSpace(content.CopySql)) { return(sqlBytes); } var copyLocation = solution.FindProjectItem(content.CopySql); if (copyLocation == null) { GeneratorError(1, $"Could not find {content.CopySql} for copy operation", 0, 0); return(sqlBytes); } var targetPath = copyLocation.Properties.Item("FullPath").Value.ToString(); if (!Directory.Exists(targetPath)) { GeneratorError(1, $"{content.CopySql} is not a folder", 0, 0); return(sqlBytes); } if (!projectItem.Name.Equals(originalName, StringComparison.InvariantCultureIgnoreCase)) { RemoveOrphanedItem(copyLocation, $"{originalName}.sql"); } var copyFile = $"{targetPath}{projectItem.Name}.sql"; if (WriteFile(copyFile, sqlBytes)) { copyLocation.ProjectItems.AddFromFile(copyFile).Properties.Item("BuildAction").Value = "None"; } return(sqlBytes); }