コード例 #1
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);
        }
コード例 #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 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);
        }