/// <summary> /// 初始化数据 /// </summary> private void Init() { try { // 初始化sql连接 string fileName = Path.Combine(Application.StartupPath, "AutoExport.ini"); string content = FileFolderHelper.FileToString(fileName); IniStructure m_inis = new IniStructure(); m_inis = IniStructure.ReadIniWithContent(content); string connectString = m_inis.GetValue("General", "ConnString"); conn = new SqlConnection(connectString); // 读取根目录路径 rootPath = m_inis.GetValue("General", "RootDir"); // 读取导出表列表 string[] autoTableArray = m_inis.GetKeys("AutoExport"); autoTableList.AddRange(autoTableArray); string[] customTableArray = m_inis.GetKeys("CustomExport"); customTableList.AddRange(customTableArray); // 读取资源文件列表 string[] fileArray = m_inis.GetKeys("Resource"); fileList.AddRange(fileArray); // 读取自动导出表的配置信息 string sqlString = string.Format("SELECT * FROM sys_export_table_cfg"); configTable = GetDataTable(sqlString); // 更新资源文件 DownLoadResource(); // 初始化lua虚拟机 exportLua = new Lua(); exportLua["Conn"] = conn; exportLua["RootDir"] = rootPath; string luaFile = Path.Combine(Application.StartupPath, "export.lua"); exportLua.DoFile(luaFile); postExportLua = new Lua(); postExportLua["Conn"] = conn; postExportLua["RootDir"] = rootPath; postExportLua["___GIsServer"] = true; luaFile = Path.Combine(Application.StartupPath, "post_export.lua"); postExportLua.DoFile(luaFile); } catch (Exception ex) { logText.Append(string.Format("{0} —— 产生异常:{1}\r\n", DateTime.Now, ex.Message)); } }
private static string CreateData(IniStructure IniData, string comment) { //Iterates through all categories and keys and appends all data to Data int CategoryCount = IniData.GetCategories().Length; int[] KeyCountPerCategory = new int[CategoryCount]; string Data = comment; string[] temp = new string[2]; // will contain key-value pair for (int i = 0; i < CategoryCount; i++) // Gets keycount per category { string CategoryName = IniData.GetCategories()[i]; KeyCountPerCategory[i] = IniData.GetKeys(CategoryName).Length; } for (int catcounter = 0; catcounter < CategoryCount; catcounter++) { Data += "\r\n[" + IniData.GetCategoryName(catcounter) + "]\r\n"; // writes [Category] to Data for (int keycounter = 0; keycounter < KeyCountPerCategory[catcounter]; keycounter++) { temp[0] = IniData.GetKeyName(catcounter, keycounter); temp[1] = IniData.GetValue(catcounter, keycounter); Data += temp[0] + "=" + temp[1] + "\r\n"; // writes the key-value pair to Data } } return(Data); }
private static string CreateData(IniStructure IniData, string comment) { //Iterates through all categories and keys and appends all data to Data int CategoryCount = IniData.GetCategories().Length; int[] KeyCountPerCategory = new int[CategoryCount]; string Data = comment; string[] temp = new string[2]; // will contain key-value pair for (int i = 0; i < CategoryCount; i++) // Gets keycount per category { string CategoryName = IniData.GetCategories()[i]; KeyCountPerCategory[i] = IniData.GetKeys(CategoryName).Length; } for (int catcounter = 0; catcounter < CategoryCount; catcounter++) { Data += "\r\n[" + IniData.GetCategoryName(catcounter) + "]\r\n"; // writes [Category] to Data for (int keycounter = 0; keycounter < KeyCountPerCategory[catcounter]; keycounter++) { temp[0] = IniData.GetKeyName(catcounter, keycounter); temp[1] = IniData.GetValue(catcounter, keycounter); Data += temp[0] + "=" + temp[1] + "\r\n"; // writes the key-value pair to Data } } return Data; }
/// <summary> /// 初始化数据 /// </summary> private bool Init() { try { outputDebugString(string.Format("{0} —— 开始Init初始化...", DateTime.Now)); outputDebugString(string.Format("{0} —— 正在初始化sql连接...", DateTime.Now)); // 初始化sql连接 string fileName = Path.Combine(Application.StartupPath, "AutoExport.ini"); string content = FileFolderHelper.FileToString(fileName); IniStructure m_inis = new IniStructure(); m_inis = IniStructure.ReadIniWithContent(content); string connectString = m_inis.GetValue("General", "ConnString"); conn = new SqlConnection(connectString); // 读取根目录路径 outputDebugString(string.Format("{0} —— 正在初始化外部设置...", DateTime.Now)); rootPath = m_inis.GetValue("General", "RootDir"); // 读取导出表列表 string[] autoTableArray = m_inis.GetKeys("AutoExport"); autoTableList.AddRange(autoTableArray); string[] customTableArray = m_inis.GetKeys("CustomExport"); customTableList.AddRange(customTableArray); outputDebugString(string.Format("{0} —— 正在更新资源文件...", DateTime.Now)); // 读取资源文件列表 string[] fileArray = m_inis.GetKeys("Resource"); fileList.AddRange(fileArray); // 读取自动导出表的配置信息 string sqlString = string.Format("SELECT * FROM sys_export_table_cfg"); configTable = GetDataTable(sqlString); // 更新资源文件 if (Program.GSTEP != 2) DownLoadResource(); outputDebugString(string.Format("{0} —— 正在设置path...", DateTime.Now)); // path更新 EV ev = new EV(); ev.evPath(Path.GetDirectoryName(Application.ExecutablePath)); outputDebugString(string.Format("{0} —— 正在初始化lua虚拟机...", DateTime.Now)); // 初始化lua虚拟机 exportLua = new Lua(); exportLua["Conn"] = conn; exportLua["RootDir"] = rootPath; string luaFile = Path.Combine(Application.StartupPath, "export.lua"); exportLua.DoFile(luaFile); postExportLua = new Lua(); postExportLua["___GIsServer"] = true; postExportLua["RootDir"] = rootPath; postExportLua["Conn"] = conn; postExportLua.RegisterFunction("GetDataTableRow", this, typeof(ExportManager).GetMethod("GetDataTableRow")); luaFile = Path.Combine(Application.StartupPath, "post_export.lua"); postExportLua.DoFile(luaFile); outputDebugString(string.Format("{0} —— 完成所有初始化工作!", DateTime.Now)); return true; } catch (Exception ex) { outputDebugStringError(string.Format("{0} —— 初始化init产生异常:{1}", DateTime.Now, ex.Message)); return false; } }
/// <summary> /// 初始化数据 /// </summary> private bool Init() { try { outputDebugString(string.Format("{0} —— 开始Init初始化...", DateTime.Now)); outputDebugString(string.Format("{0} —— 正在初始化sql连接...", DateTime.Now)); // 初始化sql连接 string fileName = Path.Combine(Application.StartupPath, "AutoExport.ini"); string content = FileFolderHelper.FileToString(fileName); IniStructure m_inis = new IniStructure(); m_inis = IniStructure.ReadIniWithContent(content); string connectString = m_inis.GetValue("General", "ConnString"); conn = new SqlConnection(connectString); // 读取根目录路径 outputDebugString(string.Format("{0} —— 正在初始化外部设置...", DateTime.Now)); rootPath = m_inis.GetValue("General", "RootDir"); // 读取导出表列表 string[] autoTableArray = m_inis.GetKeys("AutoExport"); autoTableList.AddRange(autoTableArray); string[] customTableArray = m_inis.GetKeys("CustomExport"); customTableList.AddRange(customTableArray); outputDebugString(string.Format("{0} —— 正在更新资源文件...", DateTime.Now)); // 读取资源文件列表 string[] fileArray = m_inis.GetKeys("Resource"); fileList.AddRange(fileArray); // 读取自动导出表的配置信息 string sqlString = string.Format("SELECT * FROM sys_export_table_cfg"); configTable = GetDataTable(sqlString); // 更新资源文件 if (Program.GSTEP != 2) { DownLoadResource(); } outputDebugString(string.Format("{0} —— 正在设置path...", DateTime.Now)); // path更新 EV ev = new EV(); ev.evPath(Path.GetDirectoryName(Application.ExecutablePath)); outputDebugString(string.Format("{0} —— 正在初始化lua虚拟机...", DateTime.Now)); // 初始化lua虚拟机 exportLua = new Lua(); exportLua["Conn"] = conn; exportLua["RootDir"] = rootPath; string luaFile = Path.Combine(Application.StartupPath, "export.lua"); exportLua.DoFile(luaFile); postExportLua = new Lua(); postExportLua["___GIsServer"] = true; postExportLua["RootDir"] = rootPath; postExportLua["Conn"] = conn; postExportLua.RegisterFunction("GetDataTableRow", this, typeof(ExportManager).GetMethod("GetDataTableRow")); luaFile = Path.Combine(Application.StartupPath, "post_export.lua"); postExportLua.DoFile(luaFile); outputDebugString(string.Format("{0} —— 完成所有初始化工作!", DateTime.Now)); return(true); } catch (Exception ex) { outputDebugStringError(string.Format("{0} —— 初始化init产生异常:{1}", DateTime.Now, ex.Message)); return(false); } }