GlobalVar.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. using LJLib.LocalLog;
  2. using LJLib.Net.SPI.Server;
  3. using LJLib.Tools.DEncrypt;
  4. using LJLib.Tools.File;
  5. using System;
  6. using System.Data.SqlClient;
  7. using System.Diagnostics;
  8. using System.IO;
  9. using System.Reflection;
  10. using System.Threading;
  11. using JLHHJSvr.BLL;
  12. using JLHHJSvr.Com;
  13. using JLHHJSvr.Com.APP;
  14. using JLHHJSvr.DBA;
  15. using JLHHJSvr.Excutor;
  16. using JLHHJSvr.Excutor.APP;
  17. using JLHHJSvr.LJLib.HttpServer;
  18. namespace JLHHJSvr
  19. {
  20. public static class GlobalVar
  21. {
  22. private static ExcutorManager excutorManager = null;
  23. private static Timer _timer = null;
  24. private static object _syncRoot = new object();
  25. private static bool _initing = false;
  26. public static ILJServer server
  27. {
  28. get
  29. {
  30. return excutorManager;
  31. }
  32. }
  33. internal static void Init()
  34. {
  35. Trace.Listeners.Clear();
  36. Trace.Listeners.Add(new LocalTraceListener(new SyncLogger(new Logger(App_Data))));
  37. try
  38. {
  39. _timer = new Timer((state) =>
  40. {
  41. lock (_syncRoot)
  42. {
  43. if (_initing)
  44. {
  45. return;
  46. }
  47. _initing = true;
  48. }
  49. try
  50. {
  51. if (_timer == null)
  52. {
  53. return;
  54. }
  55. // 获取数据库连接
  56. string xmlfile = GlobalVar.XmlFile;
  57. XmlConfig xmlconfig = new XmlConfig();
  58. string connectionString = xmlconfig.GetXmlFileValue(xmlfile, string.Empty, "ConnectionString", string.Empty);
  59. if (string.IsNullOrEmpty(connectionString))
  60. {
  61. Trace.Write("未设置数据库连接");
  62. }
  63. else
  64. {
  65. try
  66. {
  67. connectionString = DESEncrypt.Decrypt(connectionString, "4A61A8B51C3E42BCAE991F6C913A6A33");//DONE: 解密
  68. GlobalVar.ConnectionString = connectionString;
  69. // DONE: 更新数据库
  70. var version = new ParkDbVersion();
  71. version.CreateTables(GlobalVar.ConnectionString);
  72. BllHelper.InitUser(GlobalVar.ConnectionString);
  73. _timer.Dispose();
  74. _timer = null;
  75. }
  76. catch (Exception ex)
  77. {
  78. Trace.Write(ex.ToString());
  79. GlobalVar.ConnectionString = string.Empty;
  80. }
  81. }
  82. }
  83. catch (Exception ex)
  84. {
  85. Trace.Write(ex.ToString());
  86. }
  87. finally
  88. {
  89. _initing = false;
  90. }
  91. }, null, 0, 10000);
  92. // HTTP服务
  93. excutorManager = new ExcutorManager();
  94. // excutorManager.AddMap("HelloWord", typeof(HelloWordRequest), new HelloWordExcutor());
  95. excutorManager.AddMap("Login", typeof(LoginRequest), new LoginExcutor());//登陆
  96. //excutorManager.AddMap("GetUserInfo", typeof(GetUserInfoRequest), new GetUserInfoExcutor());
  97. excutorManager.AddMap("GetSysUserFileString", typeof(GetSysUserFileStringRequest), new GetSysUserFileStringExcutor());
  98. excutorManager.AddMap("SetSysUserFileString", typeof(SetSysUserFileStringRequest), new SetSysUserFileStringExcutor());
  99. excutorManager.AddMap("GetPriceList", typeof(GetPriceListRequest), new GetPriceListExcutor());
  100. excutorManager.AddMap("CommonDynamicSelect", typeof(CommonDynamicSelectRequest), new CommonDynamicSelectExcutor());
  101. excutorManager.AddMap("SavePermitList", typeof(SavePermitListRequest), new SavePermitListExcutor());//保存车位
  102. excutorManager.AddMap("GetPermitList", typeof(GetPermitListRequest), new GetPermitListExcutor());//获取车位列表
  103. excutorManager.AddMap("DelPermitList", typeof(DelPermitListRequest), new DelPermitListExcutor());//删除车位
  104. excutorManager.AddMap("GetRoadList", typeof(GetRoadListRequest), new GetRoadListExcutor());//获取路段列表
  105. excutorManager.AddMap("SaveRoadList", typeof(SaveRoadListRequest), new SaveRoadListExcutor());//保存路段信息
  106. excutorManager.AddMap("DelRoadList", typeof(DelRoadListRequest), new DelRoadListExcutor());//删除路段列表
  107. excutorManager.AddMap("GetOptionList", typeof(GetOptionListRequest), new GetOptionListExcutor());//获得选项列表
  108. excutorManager.AddMap("SetOption", typeof(SetOptionRequest), new SetOptionExcutor());//设置系统选项值
  109. excutorManager.AddMap("GetFileByMd5", typeof(GetFileByMd5Request), new GetFileByMd5Excutor());//根据md5获取文件
  110. excutorManager.AddMap("PostFile", typeof(PostFileRequest), new PostFileExcutor());//上传文件
  111. excutorManager.AddMap("GetCarList", typeof(GetCarListRequest), new GetCarListExcutor());//获取车辆信息汇总
  112. excutorManager.AddMap("DelCarList", typeof(DelCarListRequest), new DelCarListExcutor());//删除车辆信息
  113. excutorManager.AddMap("SaveCarList", typeof(SaveCarListRequest), new SaveCarListExcutor());//保存车辆信息
  114. excutorManager.AddMap("GetBillList", typeof(GetBillListRequest), new GetBillListExcutor());//获取违停列表
  115. excutorManager.AddMap("GetUserList", typeof(GetUserListRequest), new GetUserListExcutor());//获取用户列表
  116. excutorManager.AddMap("SaveUserList", typeof(SaveUserListRequest), new SaveUserListExcutor());//保存用户信息
  117. excutorManager.AddMap("DelUserList", typeof(DelUserListRequest), new DelUserListExcutor());//删除用户列表
  118. excutorManager.AddMap("GetUserPower", typeof(GetUserPowerRequest), new GetUserPowerExcutor());//获取用户的权限信息
  119. excutorManager.AddMap("ModPassword", typeof(ModPasswordRequest), new ModPasswordExcutor());//重置/修改用户密码
  120. excutorManager.AddMap("GetDwLayout", typeof(GetDwLayoutRequest), new GetDwLayoutExcutor());
  121. excutorManager.AddMap("SetDwLayout", typeof(SetDwLayoutRequest), new SetDwLayoutExcutor());
  122. //APP
  123. excutorManager.AddMap("GetMainInfo", typeof(GetMainInfoRequest), new GetMainInfoExcutor());//获取主页显示信息的数据
  124. excutorManager.AddMap("GetPermitListQuery", typeof(GetPermitListQueryRequest), new GetPermitListQueryExcutor());//车牌号码查询
  125. excutorManager.AddMap("SaveBill", typeof(SaveBillRequest), new SaveBillExcutor());//新建违停记录
  126. excutorManager.AddMap("EditBill", typeof(EditBillRequest), new EditBillExcutor());//违停单处理/撤销
  127. excutorManager.AddMap("TmpGetRoadList", typeof(TmpGetRoadListRequest), new TmpGetRoadListExcutor());//自主停车备案页面,获取路段列表
  128. excutorManager.AddMap("TmpSavePermit", typeof(TmpSavePermitRequest), new TmpSavePermitExcutor());//自助停车备案保存
  129. }
  130. catch (Exception ex)
  131. {
  132. Trace.Write(ex.ToString());
  133. }
  134. }
  135. public static string ConnectionString { get; set; }
  136. public static string BinPath
  137. {
  138. get
  139. {
  140. return Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Replace("file:\\", "");
  141. }
  142. }
  143. public static bool webapp { get; set; }
  144. public static string App_Data
  145. {
  146. get
  147. {
  148. string app_data = BinPath;
  149. if (webapp)
  150. {
  151. app_data = Directory.GetParent(app_data).FullName + "\\App_Data";
  152. }
  153. if (!Directory.Exists(app_data))
  154. {
  155. Directory.CreateDirectory(app_data);
  156. }
  157. return app_data;
  158. }
  159. }
  160. public static string XmlFile
  161. {
  162. get
  163. {
  164. return App_Data + "\\config.xml";
  165. }
  166. }
  167. public static string App_Files
  168. {
  169. get
  170. {
  171. string app_files = App_Data + "\\App_Files";
  172. if (!Directory.Exists(app_files))
  173. {
  174. Directory.CreateDirectory(app_files);
  175. }
  176. return app_files;
  177. }
  178. }
  179. public class ParkFileModel:IFileDBModel
  180. {
  181. public byte[] GetBytes(string md5)
  182. {
  183. if (!string.IsNullOrEmpty(md5))
  184. {
  185. using (var con = new SqlConnection(ConnectionString))
  186. using (var cmd = con.CreateCommand())
  187. {
  188. con.Open();
  189. cmd.CommandText = @"SELECT filedata
  190. FROM st_file
  191. WHERE filemd5 = @filemd5 ";
  192. cmd.Parameters.Clear();
  193. cmd.Parameters.AddWithValue("@filemd5", md5);
  194. using (var reader = cmd.ExecuteReader())
  195. {
  196. if (reader.Read())
  197. {
  198. return reader["fileData"] == DBNull.Value ? null : (byte[]) reader["fileData"];
  199. }
  200. }
  201. }
  202. }
  203. return null;
  204. }
  205. }
  206. }
  207. }