static string DumpDeclarationsToJson(string inputFile, Declaration declaration) { string schema_errors = null; string output = DeclarationSerializer.Serialize(declaration, ref schema_errors); if (!String.IsNullOrEmpty(schema_errors)) { Logger.Error("Json schema errors:" + schema_errors); } else { Logger.Info("Json schema OK"); } Logger.Info("Output size: " + output.Length); if (ValidateByApi) { string validationResult = ApiClient.ValidateParserOutput(output); if (validationResult != "[]") { string inputFileName = Path.GetFileName(inputFile); string errorsFileName = "validation_errors_" + Path.GetFileNameWithoutExtension(inputFileName) + ".json"; var rep = MiscSerializer.DeserializeValidationReport(validationResult); File.WriteAllText(errorsFileName, validationResult); Logger.Error("Api validation failed. Errors:" + errorsFileName); } } return(output); }
public void XlsxTypeCTest() { string xlsxFile = Path.Combine(TestUtil.GetTestDataPath(), "c_sample.xlsx"); IAdapter adapter = AsposeExcelAdapter.CreateAdapter(xlsxFile); var columnOrdering = ColumnDetector.ExamineTableBeginning(adapter); Smart.Parser.Lib.Parser parser = new Smart.Parser.Lib.Parser(adapter); Declaration declaration = parser.Parse(columnOrdering, false, null); string comments = ""; string output = DeclarationSerializer.Serialize(declaration, ref comments); }
/// <summary> /// Corresponds to CLI "extract" keyword. Converts assembly types to declarations. /// ExtractVerbOptions.ProjectPath has been introduced to add project structure info to declarations. /// </summary> public void Execute() { AssemblyCache assemblies = new AssemblyCache(); // Create list of assemblies (enrolling masks when needed) foreach (string assemblyPath in Assemblies) { string assemblyName = Path.GetFileName(assemblyPath); if (!string.IsNullOrEmpty(assemblyName)) { string assemblyDirectory = string.IsNullOrEmpty(assemblyDirectory = Path.GetDirectoryName(assemblyPath)) ? Environment.CurrentDirectory : Path.GetFullPath(assemblyDirectory); assemblies.AddFiles(Directory.EnumerateFiles(assemblyDirectory, assemblyName)); } } // When no assemblies provided, search inside working directory if (assemblies.IsEmpty) { assemblies.AddFiles(Directory.EnumerateFiles(Environment.CurrentDirectory, "*.dll")); } if (!Directory.Exists(OutputFolder)) { Directory.CreateDirectory(OutputFolder); } foreach (Assembly assembly in assemblies) { Console.Write("A> "); Console.WriteLine(assembly.Location); bool hasDocumentation = CommentNavigator.TryCreate(assembly, out CommentNavigator docNavigator); if (hasDocumentation) { Console.Write("D> "); Console.WriteLine(docNavigator.XmlLocation); } bool isProjectLocated = ProjectNavigator.TryCreate(ProjectPath, assembly, out ProjectNavigator projNavigator); if (isProjectLocated) { Console.Write("P> "); Console.WriteLine(projNavigator.Location); } List <Type> types = TypesExtractor.GetTypes(assembly, Types); foreach (Type type in types) { TypeDecl decl = DeclarationConvertor.TypeToDecl(type, docNavigator, projNavigator); string outputFolder = Path.Combine(OutputFolder, decl.Module.ModuleName.Replace('.', '\\')); Directory.CreateDirectory(outputFolder); string extension = type.IsSubclassOf(typeof(Enum)) ? "clenum" : "cltype"; string outputFile = Path.Combine(outputFolder, $"{decl.Name}.{extension}"); Console.Write(type.FullName); Console.Write(" => "); Console.WriteLine(outputFile); File.WriteAllText(outputFile, DeclarationSerializer.Serialize(decl)); } List <Type> enums = TypesExtractor.GetEnums(assembly, Types); foreach (Type type in enums) { EnumDecl decl = DeclarationConvertor.EnumToDecl(type, docNavigator, projNavigator); string outputFolder = Path.Combine(OutputFolder, decl.Module.ModuleName.Replace('.', '\\')); Directory.CreateDirectory(outputFolder); string extension = type.IsSubclassOf(typeof(Enum)) ? "clenum" : "cltype"; string outputFile = Path.Combine(outputFolder, $"{decl.Name}.{extension}"); Console.Write(type.FullName); Console.Write(" => "); Console.WriteLine(outputFile); File.WriteAllText(outputFile, DeclarationSerializer.Serialize(decl)); } } }