示例#1
0
        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", ".h");

                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($"#ifndef {filename.Replace(".","_").ToUpper()}");
                        _writer.WriteLineEx($"#define {filename.Replace(".", "_").ToUpper()}");
                        _writer.WriteLineEx($"#include <memory>");
                        _writer.WriteLineEx($"#include <string>");
                        _writer.WriteLineEx($"#include <vector>");
                        _writer.WriteLineEx($"#include <map>");

                        string[] sheets = imp.GetSheetList();

                        filename = filename.Replace(".h", string.Empty);

                        max     = sheets.GetLength(0);
                        current = 0;

                        _writer.WriteLineEx($"namespace {ExportToCSMgr.NameSpace}");
                        _writer.WriteLineEx("{");
                        _writer.WriteLineEx($"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.WriteLineEx("};");
                        _writer.WriteLineEx($"#endif //{filename.Replace(".", "_").ToUpper()}");
                        _writer.Flush();
                    }
                    ExportBaseUtil.CheckReplaceFile(stream, $"{outputPath}/{createFileName}");
                }
            }
            catch (System.Exception ex)
            {
                Console.Write(ex.Message);
                return(false);
            }
            return(true);
        }
示例#2
0
        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);
        }
示例#4
0
        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);
        }