public override void DoExport(ClassUtil.ExcelImporter imp, string xlsFileName, string language, List <string> except) { try { if (expBase.Generate(base._Assembly, base.mscorlibAssembly, imp, DestDir, xlsFileName, ref current, ref max, language, except) == false) { ProgramCmd.exit_code = 1; } } catch (Exception e) { ProgramCmd.exit_code = 1; System.Console.Write("Export Error: {0}", e.Message); } }
public void DoWork() { for (int x = 0; x < _xlsList.Count; x++) { var xls = _xlsList[x]; ClassUtil.ExcelImporter imp = null; if (imp == null) { imp = new ClassUtil.ExcelImporter(); if (imp.Open(xls.FullPath) == false) { System.Console.WriteLine("[XLS[{0}] open failure...", xls.FullPath); imp.Dispose(); return; } } for (int i = 1; i < _JobList.Count; i++) // index 0은 Import Table 디렉토리 정보이므로... { var job = _JobList[i]; if ((_cmdMask & job.GetJobType()) == 0) { continue; } if (job.GetFileList().Count == 0 || (job.GetFileList().IndexOf(xls.FileName) >= 0)) { System.Console.WriteLine("Generate {0} for {1} in [{2}]", xls.FileName, job.GetItem(), job.GetDestDir()); if (job.GetJobType() == ProgramCmd.EXPORT_TABLE) { job.DoExport(imp, xls.RealPath, _lang, _except); } else { job.DoExport(imp, xls.FileName, _lang, _except); } } } if (imp != null) { imp.Dispose(); } WriteLog(xls.FullPath, xls.LastWriteTime); } }
public override bool Generate(System.Reflection.Assembly refAssembly, System.Reflection.Assembly mscorlibAssembly, ClassUtil.ExcelImporter imp, string outputPath, string sFileName, ref int current, ref int max, string language, List <string> except) { try { string createFileName = System.Text.RegularExpressions.Regex.Replace(sFileName, @"\.[x][l][s]?\w", ".cs"); using (MemoryStream stream = new MemoryStream()) { var _writer = new IndentedTextWriter(new StreamWriter(stream, new System.Text.ASCIIEncoding()), " "); { string filename = System.IO.Path.GetFileName(createFileName); _writer.WriteLineEx($"// generate {filename}"); _writer.WriteLineEx("// DO NOT TOUCH SOURCE...."); _writer.WriteLineEx("#pragma warning disable IDE0007, IDE0011, IDE0025, IDE1006, IDE0018"); string[] sheets = imp.GetSheetList(); filename = filename.Replace(".cs", string.Empty); max = sheets.GetLength(0); current = 0; _writer.WriteLineEx($"namespace {ExportToCSMgr.NameSpace}.{filename}"); _writer.WriteLineEx("{"); foreach (string sheetName in sheets) { current++; string trimSheetName = sheetName.Trim().Replace(" ", "_"); var rows = imp.GetSheetShortCut(sheetName, language); var columns = ExportBaseUtil.GetColumnInfo(refAssembly, mscorlibAssembly, trimSheetName, rows, except); SheetProcess(_writer, filename, trimSheetName, columns); } _writer.WriteLineEx("};"); _writer.Flush(); } ExportBaseUtil.CheckReplaceFile(stream, $"{outputPath}/{createFileName}"); } } catch (System.Exception ex) { Console.Write(ex.Message); return(false); } return(true); }
public override bool Generate(System.Reflection.Assembly refAssem, System.Reflection.Assembly mscorlibAssembly, ClassUtil.ExcelImporter imp, string outputPath, string sFileName, ref int current, ref int max, string language, List <string> except) { System.Text.Encoding enc = new System.Text.ASCIIEncoding(); string viewFilename = System.IO.Path.GetFileName(sFileName); var regex = new System.Text.RegularExpressions.Regex(@"\.[x][l][s]?\w"); string[] enumTypeFileNames = System.IO.Directory.GetFiles(_enumTypeDir, "*.cs"); string csFileName = $"{_csFileDir}{System.IO.Path.DirectorySeparatorChar}{regex.Replace(viewFilename, ".cs")}"; string csMngFileName = $"{_csFileDir}{System.IO.Path.DirectorySeparatorChar}{regex.Replace(viewFilename, "Manager.cs")}"; string shared_directory = System.IO.Path.GetDirectoryName(typeof(object).Assembly.Location); StringBuilder str = new StringBuilder(); string folder = (System.IO.Path.DirectorySeparatorChar == '/' ? "/" : string.Empty) + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(TableGenerate.ExportBase)).Location.Replace("file:///", String.Empty)); //string folder = System.IO.Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName).ToString(); string[] refAssemblies = new string[] { $"{folder}{System.IO.Path.DirectorySeparatorChar}DocumentFormat.OpenXml.dll", $"{folder}{System.IO.Path.DirectorySeparatorChar}ICSharpCode.SharpZipLib.dll", $"{folder}{System.IO.Path.DirectorySeparatorChar}System.dll", $"{folder}{System.IO.Path.DirectorySeparatorChar}System.Collections.Immutable.dll", $"{folder}{System.IO.Path.DirectorySeparatorChar}System.Private.CoreLib.dll", $"{folder}{System.IO.Path.DirectorySeparatorChar}System.Runtime.dll", $"{folder}{System.IO.Path.DirectorySeparatorChar}System.Xml.dll", $"{folder}{System.IO.Path.DirectorySeparatorChar}System.Data.dll", $"{folder}{System.IO.Path.DirectorySeparatorChar}System.Data.Common.dll", $"{folder}{System.IO.Path.DirectorySeparatorChar}System.Threading.Tasks.Parallel.dll", $"{folder}{System.IO.Path.DirectorySeparatorChar}System.Collections.Concurrent.dll", $"{folder}{System.IO.Path.DirectorySeparatorChar}TableGenerateCmd.dll" }; foreach (string enumTypeFileName in enumTypeFileNames) { str.AppendLine(System.IO.File.ReadAllText(enumTypeFileName, enc)); } str.AppendLine(System.IO.File.ReadAllText(csFileName, enc)); str.AppendLine(System.IO.File.ReadAllText(csMngFileName, enc)); string str_class = string.Empty; string str_loader_class = string.Empty; str_class = regex.Replace(viewFilename, string.Empty); if (ExportToCSMgr.NameSpace.Length > 0) { str_loader_class = $"{ExportToCSMgr.NameSpace}.{str_class}.Loader"; } object[] objects = { imp.GetFileName(), outputPath }; str.AppendLine(include_str); str.AppendLine("namespace ScriptLibrary "); str.AppendLine("{"); str.AppendLine("public class Script "); str.AppendLine("{"); str.AppendLine($" public bool IsGenArrayFull={TableGenerateCmd.ProgramCmd.not_array_length_full.ToString().ToLower()};"); str.AppendLine(" public int ExtractFromExcel(string inputPath, string outputPath)"); str.AppendLine(" {"); str.AppendLine(" string excel_name = string.Empty;"); str.AppendLine($" var loader__ = new {str_loader_class}();"); str.AppendLine(" try"); str.AppendLine(" {"); str.AppendLine($" string directory = System.IO.Directory.GetParent(inputPath).FullName+System.IO.Path.DirectorySeparatorChar+loader__.GetFileName()+System.IO.Path.DirectorySeparatorChar;"); str.AppendLine($" string[] files = new string[0];"); str.AppendLine($" if(System.IO.Directory.Exists(directory))"); str.AppendLine($" files = System.IO.Directory.GetFiles(directory,\"*.xlsm\");"); str.AppendLine($" excel_name = System.IO.Path.GetFileName(inputPath);"); str.AppendLine($" loader__.ExcelLoad(inputPath,\"{language}\");"); str.AppendLine($" foreach(var file in files)"); str.AppendLine($" {{"); str.AppendLine($" excel_name = System.IO.Path.GetFileName(file);"); str.AppendLine($" if( excel_name.Contains(\"~$\"))continue;"); str.AppendLine($" loader__.ExcelLoad(file,\"{language}\");"); str.AppendLine($" }}"); str.AppendLine($" loader__.WriteFile(outputPath);"); str.AppendLine(" }"); str.AppendLine(" catch(System.Exception ex)"); str.AppendLine(" {"); str.AppendLine(" System.Console.WriteLine(excel_name + \":\" + ex.Message);"); str.AppendLine(" return 1; "); str.AppendLine(" }"); str.AppendLine(" return 0;"); str.AppendLine(" }"); str.AppendLine(" public System.Data.DataSet ExtractFromBytes(string inputPath)"); str.AppendLine(" {"); str.AppendLine(" System.Data.DataSet dts = null;"); str.AppendLine($" var loader__ = new {str_loader_class}();"); str.AppendLine(" try"); str.AppendLine(" {"); str.AppendLine($" loader__ = new {str_loader_class}();"); str.AppendLine($" using (var stream = new System.IO.FileStream(inputPath, System.IO.FileMode.Open))"); str.AppendLine(" {"); str.AppendLine($" loader__.ReadStream(stream);"); str.AppendLine($" dts = loader__.DataSet;"); str.AppendLine(" }"); str.AppendLine(" }"); str.AppendLine(" catch(System.Exception ex)"); str.AppendLine(" {"); str.AppendLine(" System.Console.WriteLine(ex.Message);"); str.AppendLine(" }"); str.AppendLine(" return dts;"); str.AppendLine(" }"); str.AppendLine(" public int SaveFromDataSet(System.Data.DataSet dts, string outputPath)"); str.AppendLine(" {"); str.AppendLine($" var loader__ = new {str_loader_class}();"); str.AppendLine(" //try"); str.AppendLine(" //{"); str.AppendLine($" loader__ = new {str_loader_class}();"); str.AppendLine($" loader__.DataSet = dts;"); str.AppendLine($" loader__.WriteFile(outputPath);"); str.AppendLine(" //}"); str.AppendLine(" //catch(System.Exception ex)"); str.AppendLine(" //{"); str.AppendLine(" // System.Console.WriteLine(ex.Message);"); str.AppendLine(" //}"); str.AppendLine(" return 0;"); str.AppendLine(" }"); str.AppendLine("}"); str.AppendLine("}"); System.Reflection.Assembly assembly = null; if (System.IO.Directory.Exists(_dllOutputDir) == false) { System.IO.Directory.CreateDirectory(_dllOutputDir); } try { assembly = CompileFiles(str.ToString(), refAssemblies); } catch (Exception) { //System.IO.File.WriteAllText($"{viewFilename}err.cs", str.ToString()); //System.IO.File.WriteAllText($"{viewFilename}ex.cs", ex.ToString()); throw; } //using (var fs = System.IO.File.OpenRead(outputPath + "/" + str_class + ".dll")) //{ // long uncompressedLen = fs.Length; // byte[] uncompressed = new byte[uncompressedLen]; // fs.Read(uncompressed, 0, (int)uncompressedLen); // int compressedLen = (int)(uncompressedLen * 1.01 + 600); // byte[] compressed = null;//new byte[compressedLen]; // // using (System.IO.MemoryStream ms = new System.IO.MemoryStream(uncompressed)) // { // using (System.IO.MemoryStream zip = new System.IO.MemoryStream()) // { // ICSharpCode.SharpZipLib.BZip2.BZip2.Compress(ms, zip, false, 3); // compressed = zip.ToArray(); // compressedLen = (int)zip.Length; // System.IO.File.WriteAllBytes(outputPath + "/" + str_class + ".dll.bzip2", compressed); // } // } //} //using (var helper = new AsmHelper(assembly)) { var type = assembly.GetType("ScriptLibrary.Script"); dynamic script = Activator.CreateInstance(type); int status = script.ExtractFromExcel(imp.GetFileName(), outputPath); if (status == 1) { //System.IO.File.WriteAllText($"{viewFilename}err.cs", str.ToString()); throw new System.Exception(viewFilename.ToString()); } } current++; return(true); }
public override bool Generate(System.Reflection.Assembly refAssemly, System.Reflection.Assembly mscorlibAssembly, ClassUtil.ExcelImporter imp, string outputPath, string sFileName, ref int current, ref int max, string language, List <string> except) { string createFileName = System.Text.RegularExpressions.Regex.Replace(sFileName, @"\.[x][l][s]?\w", ".sql"); using (var _stream = new MemoryStream(32767)) { var _writer = new StreamWriter(_stream, new System.Text.UTF8Encoding()); { string filename = System.IO.Path.GetFileName(createFileName); string[] sheets = imp.GetSheetList(); filename = filename.Replace(".sql", string.Empty); max = sheets.GetLength(0); current = 0; _writer.WriteLine("/** this document for MySQL "); _writer.WriteLine($" * generated by {sFileName}*/"); _writer.WriteLine(string.Empty); _writer.WriteLine(string.Empty); foreach (string sheetName in sheets) { string trimSheetName = sheetName.Trim().Replace(" ", "_"); string trimFileName = filename.Trim().Replace(" ", "_"); var rows = imp.GetSheetShortCut(sheetName, language); var columns = ExportBaseUtil.GetColumnInfo(refAssemly, mscorlibAssembly, trimSheetName, rows, except); CreateTableProcess(filename, trimSheetName, columns, _writer); } foreach (string sheetName in sheets) { current++; string trimSheetName = sheetName.Trim().Replace(" ", "_"); string trimFileName = filename.Trim().Replace(" ", "_"); var rows = imp.GetSheet(sheetName, language); var columns = ExportBaseUtil.GetColumnInfo(refAssemly, mscorlibAssembly, trimSheetName, rows, except); ExportDataProcess(filename, trimSheetName, columns, rows, _writer); } } ExportBaseUtil.CheckReplaceFile(_stream, $"{outputPath}/{createFileName}"); } return(true); }
public override bool Generate(System.Reflection.Assembly refAssemly, System.Reflection.Assembly mscorlibAssembly, ClassUtil.ExcelImporter imp, string outputPath, string sFileName, ref int current, ref int max, string language, List <string> except) { string exec_path = System.IO.Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName).ToString(); string createFileName = System.Text.RegularExpressions.Regex.Replace(sFileName, @"\.[x][l][s]?\w", ".sql"); using (var _stream = new MemoryStream()) { var _writer = new StreamWriter(_stream, new System.Text.UTF8Encoding()); { string filename = System.IO.Path.GetFileName(createFileName); string[] sheets = imp.GetSheetList(); filename = filename.Replace(".sql", string.Empty); max = sheets.GetLength(0); current = 0; //_writer.WriteLine("PRAGMA encoding = \"UTF-8\""); _writer.WriteLine("/** this document for SQLLite "); _writer.WriteLine($" * generated by {sFileName}*/"); //_writer.WriteLine("PRAGMA hexkey=\"0x0102030405060708090a0b0c0d0e0f10\";"); _writer.WriteLine(string.Empty); _writer.WriteLine(string.Empty); foreach (string sheetName in sheets) { string trimSheetName = sheetName.Trim().Replace(" ", "_"); var rows = imp.GetSheetShortCut(sheetName, language); var columns = ExportBaseUtil.GetColumnInfo(refAssemly, mscorlibAssembly, trimSheetName, rows, except); CreateTableProcess(filename, trimSheetName, columns, _writer); } foreach (string sheetName in sheets) { current++; string trimSheetName = sheetName.Trim().Replace(" ", "_"); var rows = imp.GetSheet(sheetName, language); var columns = ExportBaseUtil.GetColumnInfo(refAssemly, mscorlibAssembly, trimSheetName, rows, except); ExportDataProcess(filename, trimSheetName, columns, rows, _writer); } _writer.WriteLine(".quit"); _writer.Flush(); } ExportBaseUtil.CheckReplaceFile(_stream, $"{outputPath}/{createFileName}"); } string batch_file = $"{System.IO.Directory.GetCurrentDirectory()}/compile_{createFileName}.bat"; { string db_file = $"{outputPath}/{createFileName.Replace(".sql", string.Empty)}.db"; if (File.Exists(db_file) == true) { File.Delete(db_file); } } //string batch_content = exec_path + "/" + "C#-SQLite3.exe " + createFileName.Replace(".sql", string.Empty) + ".db .read " + createFileName; string batch_content = $"{exec_path}/sqlite3.exe {createFileName.Replace(".sql", string.Empty)}.db < {createFileName}"; using (var batch_stream = System.IO.File.CreateText(batch_file)) { batch_stream.Write(batch_content); } var process = new System.Diagnostics.Process(); var startInfo = new System.Diagnostics.ProcessStartInfo(batch_file); startInfo.WorkingDirectory = outputPath; startInfo.RedirectStandardError = true; startInfo.RedirectStandardOutput = true; startInfo.UseShellExecute = false; startInfo.CreateNoWindow = true; process.StartInfo = startInfo; process.Start(); StreamReader readerError = process.StandardError; process.WaitForExit(); System.Console.WriteLine(readerError.ReadToEnd()); //File.Delete(batch_file); //File.Delete($"{outputPath}/{createFileName}"); return(true); }
public override void DoExport(ClassUtil.ExcelImporter imp, string xlsFileName, string language, List <string> except) { }
public abstract void DoExport(ClassUtil.ExcelImporter imp, string xlsFileName, string language, List <string> except);
public override bool Generate(System.Reflection.Assembly refAssembly, System.Reflection.Assembly mscorlibAssembly, ClassUtil.ExcelImporter imp, string outputPath, string sFileName, ref int current, ref int max, string language, List <string> except) { string createFileName = System.Text.RegularExpressions.Regex.Replace(sFileName, @"\.[x][l][s]?\w", "TableManager.cpp"); using (MemoryStream _stream = new MemoryStream()) { var _writer = new StreamWriter(_stream, new System.Text.ASCIIEncoding()); { string filename = System.IO.Path.GetFileName(createFileName); string[] sheets = imp.GetSheetList(); filename = filename.Replace(".cpp", string.Empty); // writer.WriteLine("#include <Base/properties.h>"); // writer.WriteLine("#include <Base/service.h>"); _writer.WriteLineEx($"#include \"{filename}.h\""); _writer.WriteLineEx($"namespace {ExportToCSMgr.NameSpace}"); _writer.WriteLineEx($"{{"); _writer.WriteLineEx($"namespace {filename.Replace(" ", "_").Replace("TableManager", string.Empty)}"); _writer.WriteLineEx($"{{"); max = sheets.GetLength(0); current = 0; foreach (string sheetName in sheets) { current++; string trimSheetName = sheetName.Trim().Replace(" ", "_"); var rows = imp.GetSheetShortCut(sheetName, language); var columns = ExportBaseUtil.GetColumnInfo(refAssembly, mscorlibAssembly, trimSheetName, rows, except); SheetProcess(filename, trimSheetName, columns, _writer); //GetItemProcess(filename, trimSheetName, columns); //AddItemMapProcess(filename, trimSheetName, imp.GetSheetShortCut(sheetName)); //AddArrayToMapProcess(filename, trimSheetName, columns); } //ManagerProcess(filename, sheets); _writer.WriteLineEx($"bool TableManager::LoadTable(std::ifstream& stream)"); _writer.WriteLineEx($"{{"); _writer.WriteLineEx($"bool rtn = true;"); _writer.WriteLineEx($"std::vector<char> bytes;"); _writer.WriteLineEx($"if({ExportToCSMgr.NameSpace}::TableManager::Decompress(stream,bytes)==false) return false;"); _writer.WriteLineEx($"vectorwrapbuf<char> databuf(bytes);"); _writer.WriteLineEx($"std::istream is(&databuf);"); foreach (string sheetName in sheets) { string trimSheetName = sheetName.Trim().Replace(" ", "_"); var rows = imp.GetSheetShortCut(sheetName, language); var columns = ExportBaseUtil.GetColumnInfo(refAssembly, mscorlibAssembly, trimSheetName, rows, except); _writer.WriteLineEx($"{trimSheetName}TableManager {trimSheetName}TableManager;"); } _writer.WriteLineEx($""); foreach (string sheetName in sheets) { string trimSheetName = sheetName.Trim().Replace(" ", "_"); var rows = imp.GetSheetShortCut(sheetName, language); var columns = ExportBaseUtil.GetColumnInfo(refAssembly, mscorlibAssembly, trimSheetName, rows, except); _writer.WriteLineEx($"rtn &= {trimSheetName}TableManager.LoadTable(is);"); } _writer.WriteLineEx($"return rtn;"); _writer.WriteLineEx($"}};"); _writer.WriteLineEx($"}};"); _writer.WriteLineEx($"}};"); _writer.Flush(); } ExportBaseUtil.CheckReplaceFile(_stream, $"{outputPath}/{createFileName}"); } return(true); }
public override bool Generate(System.Reflection.Assembly refAssem, System.Reflection.Assembly mscorlibAssembly, ClassUtil.ExcelImporter imp, string outputPath, string sFileName, ref int current, ref int max, string language, List<string> except) { string createFileName = System.Text.RegularExpressions.Regex.Replace(sFileName, @"\.[x][l][s]?\w", "TableManager.h"); using( var _stream = new MemoryStream(32767)) { var _writer = new StreamWriter(_stream, new System.Text.ASCIIEncoding()); { string filename = System.IO.Path.GetFileName(createFileName); string defineName = filename.Replace(".h", "_H"); defineName = defineName.ToUpper(); _writer.WriteLineEx($"// generate {filename}"); _writer.WriteLineEx("// DO NOT TOUCH SOURCE...."); _writer.WriteLineEx($"#ifndef {defineName}"); _writer.WriteLineEx($"#define {defineName}"); _writer.WriteLineEx(string.Empty); string[] sheets = imp.GetSheetList(); filename = filename.Replace("TableManager.h", string.Empty); _writer.WriteLineEx($"#include \"{filename}.h\""); _writer.WriteLineEx($"#include <TableManager.h>"); max = sheets.GetLength(0); current = 0; _writer.WriteLineEx($"namespace {ExportToCSMgr.NameSpace}"); _writer.WriteLineEx($"{{"); _writer.WriteLineEx($"namespace {filename.Replace(" ", "_").Replace("TableManager", string.Empty)}"); _writer.WriteLineEx($"{{"); //foreach (string sheetName in sheets) //{ // current++; // string trimSheetName = sheetName.Trim().Replace(" ", "_"); // var rows = imp.GetSheetShortCut(sheetName, language); // var columns = ExportBaseUtil.GetColumnInfo(trimSheetName, rows, except); // SheetProcess(filename, trimSheetName, columns); //} _writer.WriteLineEx($"class TableManager"); _writer.WriteLineEx($"{{"); _writer.WriteLineEx("public:"); _writer.WriteLineEx($"static bool LoadTable(std::ifstream& stream);"); _writer.WriteLineEx($"}};"); _writer.WriteLineEx($"}};"); _writer.WriteLineEx($"}};"); _writer.WriteLineEx($"#endif //{defineName}"); _writer.Flush(); } ExportBaseUtil.CheckReplaceFile(_stream, $"{outputPath}/{createFileName}"); } return true; }