using LJLib.LocalLog; using LJLib.Net.SPI.Server; using LJLib.Tools.DEncrypt; using LJLib.Tools.File; using System; using System.Data.SqlClient; using System.Diagnostics; using System.IO; using System.Reflection; using System.Threading; using JLHHJSvr.BLL; using JLHHJSvr.Com; using JLHHJSvr.Com.APP; using JLHHJSvr.DBA; using JLHHJSvr.Excutor; using JLHHJSvr.Excutor.APP; using JLHHJSvr.LJLib.HttpServer; namespace JLHHJSvr { public static class GlobalVar { private static ExcutorManager excutorManager = null; private static Timer _timer = null; private static object _syncRoot = new object(); private static bool _initing = false; public static ILJServer server { get { return excutorManager; } } internal static void Init() { Trace.Listeners.Clear(); Trace.Listeners.Add(new LocalTraceListener(new SyncLogger(new Logger(App_Data)))); try { _timer = new Timer((state) => { lock (_syncRoot) { if (_initing) { return; } _initing = true; } try { if (_timer == null) { return; } // 获取数据库连接 string xmlfile = GlobalVar.XmlFile; XmlConfig xmlconfig = new XmlConfig(); string connectionString = xmlconfig.GetXmlFileValue(xmlfile, string.Empty, "ConnectionString", string.Empty); if (string.IsNullOrEmpty(connectionString)) { Trace.Write("未设置数据库连接"); } else { try { connectionString = DESEncrypt.Decrypt(connectionString, "4A61A8B51C3E42BCAE991F6C913A6A33");//DONE: 解密 GlobalVar.ConnectionString = connectionString; // DONE: 更新数据库 var version = new ParkDbVersion(); version.CreateTables(GlobalVar.ConnectionString); BllHelper.InitUser(GlobalVar.ConnectionString); _timer.Dispose(); _timer = null; } catch (Exception ex) { Trace.Write(ex.ToString()); GlobalVar.ConnectionString = string.Empty; } } } catch (Exception ex) { Trace.Write(ex.ToString()); } finally { _initing = false; } }, null, 0, 10000); // HTTP服务 excutorManager = new ExcutorManager(); // excutorManager.AddMap("HelloWord", typeof(HelloWordRequest), new HelloWordExcutor()); excutorManager.AddMap("Login", typeof(LoginRequest), new LoginExcutor());//登陆 //excutorManager.AddMap("GetUserInfo", typeof(GetUserInfoRequest), new GetUserInfoExcutor()); excutorManager.AddMap("GetSysUserFileString", typeof(GetSysUserFileStringRequest), new GetSysUserFileStringExcutor()); excutorManager.AddMap("SetSysUserFileString", typeof(SetSysUserFileStringRequest), new SetSysUserFileStringExcutor()); excutorManager.AddMap("GetPriceList", typeof(GetPriceListRequest), new GetPriceListExcutor()); excutorManager.AddMap("CommonDynamicSelect", typeof(CommonDynamicSelectRequest), new CommonDynamicSelectExcutor()); excutorManager.AddMap("SavePermitList", typeof(SavePermitListRequest), new SavePermitListExcutor());//保存车位 excutorManager.AddMap("GetPermitList", typeof(GetPermitListRequest), new GetPermitListExcutor());//获取车位列表 excutorManager.AddMap("DelPermitList", typeof(DelPermitListRequest), new DelPermitListExcutor());//删除车位 excutorManager.AddMap("GetRoadList", typeof(GetRoadListRequest), new GetRoadListExcutor());//获取路段列表 excutorManager.AddMap("SaveRoadList", typeof(SaveRoadListRequest), new SaveRoadListExcutor());//保存路段信息 excutorManager.AddMap("DelRoadList", typeof(DelRoadListRequest), new DelRoadListExcutor());//删除路段列表 excutorManager.AddMap("GetOptionList", typeof(GetOptionListRequest), new GetOptionListExcutor());//获得选项列表 excutorManager.AddMap("SetOption", typeof(SetOptionRequest), new SetOptionExcutor());//设置系统选项值 excutorManager.AddMap("GetFileByMd5", typeof(GetFileByMd5Request), new GetFileByMd5Excutor());//根据md5获取文件 excutorManager.AddMap("PostFile", typeof(PostFileRequest), new PostFileExcutor());//上传文件 excutorManager.AddMap("GetCarList", typeof(GetCarListRequest), new GetCarListExcutor());//获取车辆信息汇总 excutorManager.AddMap("DelCarList", typeof(DelCarListRequest), new DelCarListExcutor());//删除车辆信息 excutorManager.AddMap("SaveCarList", typeof(SaveCarListRequest), new SaveCarListExcutor());//保存车辆信息 excutorManager.AddMap("GetBillList", typeof(GetBillListRequest), new GetBillListExcutor());//获取违停列表 excutorManager.AddMap("GetUserList", typeof(GetUserListRequest), new GetUserListExcutor());//获取用户列表 excutorManager.AddMap("SaveUserList", typeof(SaveUserListRequest), new SaveUserListExcutor());//保存用户信息 excutorManager.AddMap("DelUserList", typeof(DelUserListRequest), new DelUserListExcutor());//删除用户列表 excutorManager.AddMap("GetUserPower", typeof(GetUserPowerRequest), new GetUserPowerExcutor());//获取用户的权限信息 excutorManager.AddMap("ModPassword", typeof(ModPasswordRequest), new ModPasswordExcutor());//重置/修改用户密码 excutorManager.AddMap("GetDwLayout", typeof(GetDwLayoutRequest), new GetDwLayoutExcutor()); excutorManager.AddMap("SetDwLayout", typeof(SetDwLayoutRequest), new SetDwLayoutExcutor()); //APP excutorManager.AddMap("GetMainInfo", typeof(GetMainInfoRequest), new GetMainInfoExcutor());//获取主页显示信息的数据 excutorManager.AddMap("GetPermitListQuery", typeof(GetPermitListQueryRequest), new GetPermitListQueryExcutor());//车牌号码查询 excutorManager.AddMap("SaveBill", typeof(SaveBillRequest), new SaveBillExcutor());//新建违停记录 excutorManager.AddMap("EditBill", typeof(EditBillRequest), new EditBillExcutor());//违停单处理/撤销 excutorManager.AddMap("TmpGetRoadList", typeof(TmpGetRoadListRequest), new TmpGetRoadListExcutor());//自主停车备案页面,获取路段列表 excutorManager.AddMap("TmpSavePermit", typeof(TmpSavePermitRequest), new TmpSavePermitExcutor());//自助停车备案保存 } catch (Exception ex) { Trace.Write(ex.ToString()); } } public static string ConnectionString { get; set; } public static string BinPath { get { return Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Replace("file:\\", ""); } } public static bool webapp { get; set; } public static string App_Data { get { string app_data = BinPath; if (webapp) { app_data = Directory.GetParent(app_data).FullName + "\\App_Data"; } if (!Directory.Exists(app_data)) { Directory.CreateDirectory(app_data); } return app_data; } } public static string XmlFile { get { return App_Data + "\\config.xml"; } } public static string App_Files { get { string app_files = App_Data + "\\App_Files"; if (!Directory.Exists(app_files)) { Directory.CreateDirectory(app_files); } return app_files; } } public class ParkFileModel:IFileDBModel { public byte[] GetBytes(string md5) { if (!string.IsNullOrEmpty(md5)) { using (var con = new SqlConnection(ConnectionString)) using (var cmd = con.CreateCommand()) { con.Open(); cmd.CommandText = @"SELECT filedata FROM st_file WHERE filemd5 = @filemd5 "; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@filemd5", md5); using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { return reader["fileData"] == DBNull.Value ? null : (byte[]) reader["fileData"]; } } } } return null; } } } }