DefaultFunctionsCreator.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using ContractService.BaseInfo;
  8. using ContractService.Configuration;
  9. using ContractService.EF;
  10. namespace ContractService.SeedData
  11. {
  12. public class DefaultFunctionsCreator
  13. {
  14. private readonly ContractServiceDbContext _context;
  15. private string TopFunNo { get; }
  16. public DefaultFunctionsCreator(ContractServiceDbContext context)
  17. {
  18. TopFunNo = ConfigurationManager.AppSettings["SystemFunction.Top.FunctionNo"] ?? "HTSystem";
  19. _context = context;
  20. LangStr = "\r\n\r\n";
  21. PermissionStr = "";
  22. LangList = new List<string>();
  23. }
  24. public void Create()
  25. {
  26. _context.Database.ExecuteSqlCommand("TRUNCATE TABLE [dbo].[Sys_Functions]");
  27. CreateFunctions(TopFunNo, "后台管理系统", "0", FunctionTypeDefinition.Catalog, "Index", "Home", "", "fa fa-home", 0, "", "", false, "Pages", 0);
  28. /* ------------------------------------------------------------------------- */
  29. Legal();
  30. LawFirm();
  31. Client();
  32. Basic();
  33. System();
  34. Write();
  35. }
  36. /* ------------------------------------------------------------------------- */
  37. private void Legal()
  38. {
  39. CreateCatalog("CaseContractMg", TopFunNo, "企业分项合同履行维护", 20, "fa fa-cogs");
  40. CreateMenu("CaseMg", "CaseContractMg", "企业合同履行管理", 0, "Case", "LegalCase", "");
  41. CreateBtn_Curd("CaseMg", "项目", "LegalCase");
  42. //CreateBtn_Other("SetMasterLawyer","CaseMg", "项目负责人", 4,"fa fa-cog", "", "LegalService/SetMasterLawyer");
  43. //CreateBtn_Other("SetLawyer","CaseMg", "分配律师", 5,"fa fa-cog", "", "LegalCase/SetLawyer");
  44. CreateBtn_Other("SetStaff","CaseMg", "关联职员", 4, "fa fa-exchange", "", "LegalCase/SetStaff");
  45. CreateBtn_NotShow("ChangeState", "CaseMg", "变更状态",10, "fa fa-edit", "","");
  46. CreateBtn_NotShow("Note", "CaseMg", "项目备注",11, "fa fa-file-text", "","");
  47. CreateBtn_NotShow("Restart", "CaseMg", "重启项目", 12, "", "fa fa-mail-reply-all", "");
  48. CreateMenu("ContractMg", "CaseContractMg", "企业合同总览", 1, "Contract", "LegalCase", "");
  49. CreateBtn_Curd("ContractMg", "合同", "LegalContract");
  50. CreateBtn_Other("SetStaff", "ContractMg", "关联职员", 4, "fa fa-exchange", "", "LegalContract/SetStaff");
  51. //CreateBtn_Other("SetMasterLawyer", "ContractMg", "合同负责人", 4,"fa fa-cog", "", "LegalContract/SetMasterLawyer");
  52. CreateBtn_NotShow("SetLawyer", "ContractMg", "分配律师", 5, "fa fa-exchange", "SetLawyer", "LegalContract/SetLawyer");
  53. CreateBtn_NotShow("SetLawFirm", "ContractMg", "分配律所", 5, "fa fa-exchange", "SysSetLawFirm", "LegalContract/SetLawFirm");
  54. CreateBtn_NotShow("ChangeState", "ContractMg", "变更状态", 10, "fa fa-edit", "", "");
  55. CreateBtn_NotShow("Note", "ContractMg", "合同备注", 11, "fa fa-file-text", "", "");
  56. CreateBtn_NotShow("LawNote", "ContractMg", "律师提示", 12, "fa fa-file-text", "", "");
  57. CreateBtn_NotShow("Supplement", "ContractMg", "补充合同", 13, "fa fa-plus-square-o", "", "");
  58. CreateBtn_NotShow("Restart", "ContractMg", "重启合同", 14, "", "fa fa-mail-reply-all", "");
  59. CreateMenu_NotShow("KeyPointMg", "ContractMg","关键点信息管理",0, "fa fa-cogs", "","");
  60. //CreateBtn_Curd("KeyPointMg", "关键点", "LegalContractKeyPoint");
  61. CreateBtn_Query("KeyPointMg", 0);
  62. CreateBtn_Create("关键点", "KeyPointMg", 1);
  63. CreateBtn_Other("Update", "KeyPointMg", "关键点", 2,"fa fa-edit","btnUpdate", "LegalContractKeyPoint/Update");
  64. CreateBtn_Delete("关键点", "KeyPointMg", 3);
  65. CreateBtn_NotShow("ChangeState", "KeyPointMg", "变更状态",10, "fa fa-edit", "","");
  66. CreateBtn_NotShow("ChangeEvidence", "KeyPointMg", "变更材料(证据)",11, "fa fa-edit", "","");
  67. CreateBtn_NotShow("Restart", "KeyPointMg", "重启关键点",12, "fa fa-mail-reply-all", "","");
  68. CreateBtn_NotShow("Note", "KeyPointMg", "关键点备注", 13, "fa fa-file-text", "", "");
  69. CreateBtn_NotShow("LawNote", "KeyPointMg", "关键点律师提示", 14, "fa fa-file-text", "", "");
  70. CreateBtn_NotShow("SetOrg", "KeyPointMg", "关键点分配", 15, "fa fa-file-text", "", "");
  71. }
  72. private void LawFirm()
  73. {
  74. CreateCatalog("LegalLawFirmMg", TopFunNo, "律所信息维护", 97, "fa fa-cogs");
  75. CreateMenu("LawFirmMg", "LegalLawFirmMg", "律所信息管理", 0, "Index", "LawFirm", "Sys");
  76. CreateBtn_Curd("LawFirmMg", "律所", "LawFirm");
  77. CreateBtn_Other("MasterLawyer", "LawFirmMg", "律所负责人", 4, "fa fa-user", "", "LawFirm/MasterLawyer");
  78. CreateMenu("LawyerMg", "LegalLawFirmMg", "律师信息管理", 0, "Lawyer", "LawFirm", "");
  79. CreateBtn_Curd("LawyerMg", "律师", "Lawyer");
  80. CreateBtn_Other("Bind", "LawyerMg", "绑定账号", 4, "fa fa-user-plus", "", "Lawyer/Bind");
  81. CreateBtn_Other("UnBind", "LawyerMg", "解绑账号", 5, "fa fa-user-times", "", "Lawyer/UnBind");
  82. //CreateBtn_Other("SetLawFirm", "LawyerMg", "配置律所", 10,"fa fa-cog","", "Lawyer/SetLawFirm");
  83. CreateMenu("LawOrgMg", "LegalLawFirmMg", "律所部门管理", 0, "Organization", "LawFirm", "");
  84. CreateBtn_Curd("LawOrgMg", "部门", "Organization");
  85. CreateBtn_Other("OrgAuth","LawOrgMg", "部门授权", 4,"fa fa-cog","", "Organization/Auth");
  86. }
  87. private void Client()
  88. {
  89. CreateCatalog("ClientMg", TopFunNo, "企业信息维护", 98, "fa fa-cogs");
  90. CreateMenu("CompanyMg", "ClientMg", "企业信息管理", 0, "Company", "Client", "Sys");
  91. CreateBtn_Curd("CompanyMg", "企业", "ClientCompany");
  92. CreateBtn_Other("MasterStaff", "CompanyMg", "企业负责人", 4, "fa fa-user", "", "ClientCompany/MasterStaff");
  93. CreateMenu("StaffMg", "ClientMg", "企业员工信息管理", 0, "Staff", "Client", "");
  94. CreateBtn_Curd("StaffMg", "员工", "ClientStaff");
  95. CreateBtn_Other("Bind", "StaffMg", "绑定账号", 4, "fa fa-user-plus", "", "ClientStaff/Bind");
  96. CreateBtn_Other("UnBind", "StaffMg", "解绑账号", 5, "fa fa-user-times", "", "ClientStaff/UnBind");
  97. CreateMenu("OrgMg", "ClientMg", "企业部门管理", 0, "Organization", "Client", "");
  98. CreateBtn_Curd("OrgMg", "部门", "Organization");
  99. CreateBtn_Other("OrgAuth", "OrgMg", "部门授权", 4,"fa fa-cog","", "Organization/Auth");
  100. }
  101. private void Basic()
  102. {
  103. CreateCatalog("BasicMg", TopFunNo, "基础信息维护", 99, "fa fa-cogs");
  104. CreateMenu("ServiceTypeMg", "BasicMg", "项目类型管理", 0, "ServiceType", "Basic", "");
  105. CreateBtn_Curd("ServiceTypeMg", "项目类型", "ServiceType");
  106. }
  107. #region SYSTEM
  108. private void System()
  109. {
  110. CreateCatalog("SystemMg", TopFunNo, "系统信息维护", 100, "fa fa-cogs");
  111. CreateMenu("TenantMg", "SystemMg", "租户信息管理", 0, "SysTenants", "BaseSystem", "host");
  112. CreateBtn_Curd("TenantMg", "租户", "Tenants");
  113. CreateMenu("RoleMg", "SystemMg", "角色信息管理", 1, "SysRoles", "BaseSystem", "", "fa fa-users");
  114. CreateBtn_Curd("RoleMg", "角色", "Roles");
  115. CreateBtn_Other("Auth", "RoleMg", "角色授权", 4, "fa fa-cog", null, "Roles/Auth");
  116. CreateMenu("UserMg", "SystemMg", "用户信息管理", 2, "SysUsers", "BaseSystem", "", "fa fa-user");
  117. CreateBtn_Curd("UserMg", "用户", "Users");
  118. CreateBtn_Other("Auth", "UserMg", "用户授权", 4, "fa fa-cog", null, "Users/Auth");
  119. CreateBtn_Other("ResetPassword", "UserMg", "重置密码", 5, "fa fa-lock", "btnResetPwd", "Users/ResetPassword");
  120. CreateBtn_Other("ResetLock", "UserMg", "解除登陆锁定", 5, "fa fa-unlock", "btnResetLock", "Users/ResetLock");
  121. CreateMenu("StateMg", "SystemMg", "系统字典信息管理", 3, "SysStates", "BaseSystem", "", "fa fa-book");
  122. //CreateBtn_Curd("StateMg", "字典", "States");
  123. CreateBtn_Query("StateMg", 0);
  124. CreateBtn_Update("字典", "StateMg", 2, "States");
  125. CreateMenu("SettingMg", "SystemMg", "系统配置信息管理", 4, "SysSettings", "BaseSystem", "", "fa fa-cog");
  126. //CreateBtn_Curd("SettingMg", "配置", "Settings");
  127. CreateBtn_Query("SettingMg", 0);
  128. CreateBtn_Update("配置", "SettingMg", 2, "Settings");
  129. CreateMenu("HelpMg", "SystemMg", "系统帮助信息管理", 5, "SysHelps", "BaseSystem", "", "fa fa-question");
  130. CreateBtn_Curd("HelpMg", "帮助", "Helps");
  131. CreateMenu("FunctionMg", "SystemMg", "功能菜单管理", 6, "SysFunctions", "BaseSystem", "", "fa fa-server");
  132. //CreateBtn_Curd("FunctionMg", "菜单", "Functions");
  133. CreateBtn_Query("FunctionMg", 0);
  134. CreateBtn_Update("菜单", "FunctionMg", 2, "Functions");
  135. CreateBtn_Other("MoveUp", "FunctionMg", "上移菜单", 4, "fa fa-arrow-up", "btnMoveUp", "Functions/MoveUp");
  136. CreateBtn_Other("MoveDown", "FunctionMg", "下移菜单", 5, "fa fa-arrow-down", "btnMoveDown", "Functions/MoveDown");
  137. CreateBtn_Other("Refresh", "FunctionMg", "刷新菜单", 6, "fa fa-retweet", "_btnRefresh", "Functions/Refresh");
  138. CreateMenu("LogMg", "SystemMg", "系统日志管理", 7, "SysLogs", "BaseSystem", "", "fa fa-list-alt");
  139. CreateBtn_Query("LogMg", 0);
  140. CreateMenu("UserHelpInfo", "HTSystem", "系统帮助信息", 101, "Index", "Help", "", "fa fa-question");
  141. CreateMenu("UserSysSetting", "HTSystem", "用户配置", 102, "", "", icon: "fa fa-cogs", isShow: false);
  142. CreateBtn_Other("LoginImage", "UserSysSetting", "配置登陆页背景", 1, "fa fa-cog", "_Admin_btnLoginImage", "Settings/LoginImage", false);
  143. CreateBtn_Other("HomeImage", "UserSysSetting", "配置主页背景", 2, "fa fa-cog", "_Admin_btnHomeImage", "Settings/HomeImage", false);
  144. CreateBtn_Other("RefreshCache", "UserSysSetting", "刷新缓存", 3, "fa fa-recycle", "_Admin_btnCache", "Settings/CacheRefresh", false);
  145. CreateBtn_Other("RefreshLang", "UserSysSetting", "刷新语言包", 4, "fa fa-recycle", "_Admin_btnLang", "Settings/LangRefresh", false);
  146. }
  147. #endregion
  148. #region CREATE
  149. /// <summary>
  150. ///创建增删改查按钮
  151. /// </summary>
  152. /// <param name="funName"></param>
  153. /// <param name="parentNo"></param>
  154. /// <param name="url">{IwbConsts.ApiAppUrl}{url}/Create 如果url与parentNo不同需指定</param>
  155. private void CreateBtn_Curd(string parentNo, string funName, string url = null)
  156. {
  157. CreateBtn_Query(parentNo, 0);
  158. CreateBtn_Create(funName, parentNo, 1, url);
  159. CreateBtn_Update(funName, parentNo, 2, url);
  160. CreateBtn_Delete(funName, parentNo, 3, url);
  161. }
  162. /// <summary>
  163. ///创建不是增删改查的按钮
  164. /// </summary>
  165. private void CreateBtn_Other(string funNo, string parentNo, string funName, int sort, string icon = "fa fa-plus-square", string script = null, string url = null, bool isShow = true, bool isApiUrl = true)
  166. {
  167. script = script ?? $"btn{funNo}";
  168. url = url ?? $"{parentNo}/{funNo}";
  169. url = isApiUrl ? $"{IwbConsts.ApiAppUrl}{url}" : url;
  170. if (isShow)
  171. {
  172. CreateBtn(funNo, parentNo, funName, sort, url, icon, script);
  173. }
  174. else
  175. {
  176. CreateBtn_NotShow(funNo, parentNo, funName, sort, icon, script, url);
  177. }
  178. }
  179. /// <summary>
  180. /// 创建目录
  181. /// </summary>
  182. private void CreateCatalog(string funNo, string parentNo, string funName, int sort,
  183. string icon = "fa fa-indent", string s = "", string c = "", bool auth = true, bool isShow = true)
  184. {
  185. if (isShow)
  186. {
  187. CreateFunctions(funNo, funName, parentNo, FunctionTypeDefinition.Catalog, "", "", "", icon, sort, c, s, auth);
  188. }
  189. else
  190. {
  191. CreateCatalog_NotShow(funNo, parentNo, funName, sort, icon, c, s, auth);
  192. }
  193. }
  194. /// <summary>
  195. /// 创建菜单
  196. /// </summary>
  197. private void CreateMenu(string funNo, string parentNo, string funName, int sort, string action,
  198. string controller, string s = "", string icon = "fa fa-dot-circle-o", string c = "", string url = null,
  199. bool auth = true, bool isShow = true)
  200. {
  201. url = url ?? $"{controller}/{action}";
  202. if (isShow)
  203. {
  204. CreateFunctions(funNo, funName, parentNo, FunctionTypeDefinition.Menu, action, controller, url, icon, sort,
  205. c, s, auth);
  206. }
  207. else
  208. {
  209. CreateMenu_NotShow(funNo, parentNo, funName, sort, icon, action, controller,
  210. url, c, s, auth);
  211. }
  212. }
  213. /// <summary>
  214. /// 创建查询按钮
  215. /// </summary>
  216. private void CreateBtn_Query(string parentNo, int sort)
  217. {
  218. CreateBtn_NotShow("Query", parentNo, "查看页面", sort, "fa fa-eye", "btnQuery", "");
  219. }
  220. /// <summary>
  221. /// 创建添加按钮
  222. /// </summary>
  223. private void CreateBtn_Create(string funName, string parentNo, int sort, string url = null)
  224. {
  225. url = url ?? parentNo;
  226. CreateBtn("Create", parentNo, $"添加{funName}", sort, $"{IwbConsts.ApiAppUrl}{url}/Create", "fa fa-plus-square-o", "_btnCreate");
  227. }
  228. /// <summary>
  229. /// 创建修改按钮
  230. /// </summary>
  231. private void CreateBtn_Update(string funName, string parentNo, int sort, string url = null)
  232. {
  233. url = url ?? parentNo;
  234. CreateBtn("Update", parentNo, $"修改{funName}", sort, $"{IwbConsts.ApiAppUrl}{url}/Update", "fa fa-edit", "btnUpdate");
  235. }
  236. /// <summary>
  237. /// 创建删除按钮
  238. /// </summary>
  239. private void CreateBtn_Delete(string funName, string parentNo, int sort, string url = null)
  240. {
  241. url = url ?? parentNo;
  242. CreateBtn("Delete", parentNo, $"删除{funName}", sort, $"{IwbConsts.ApiAppUrl}{url}/Delete", "fa fa-minus-square-o", "btnDelete");
  243. }
  244. /// <summary>
  245. /// 创建按钮
  246. /// </summary>
  247. private void CreateBtn(string funNo, string parentNo, string funName, int sort, string url, string icon,
  248. string s, string c = "btn btn-default", string action = "", string controller = "", bool auth = true)
  249. {
  250. CreateFunctions(funNo, funName, parentNo, FunctionTypeDefinition.Button, action, controller, url, icon, sort, c, s, auth);
  251. }
  252. /// <summary>
  253. /// 创建不显示的目录
  254. /// </summary>
  255. private void CreateCatalog_NotShow(string funNo, string parentNo, string funName, int sort, string icon,
  256. string c = "", string s = "", bool auth = true)
  257. {
  258. CreateFunctions(funNo, funName, parentNo, FunctionTypeDefinition.NotShow, "", "", "", icon, sort, c, s, auth);
  259. }
  260. /// <summary>
  261. /// 创建不显示的菜单
  262. /// </summary>
  263. private void CreateMenu_NotShow(string funNo, string parentNo, string funName, int sort, string icon,
  264. string action, string controller, string url = "", string c = "", string s = "", bool auth = true)
  265. {
  266. CreateFunctions(funNo, funName, parentNo, FunctionTypeDefinition.NotShow, action, controller, url, icon, sort, c, s, auth);
  267. }
  268. /// <summary>
  269. /// 创建不显示的按钮
  270. /// </summary>
  271. private void CreateBtn_NotShow(string funNo, string parentNo, string funName, int sort, string icon, string s, string url, string c = "btn btn-default", string action = "", string controller = "", bool auth = true)
  272. {
  273. CreateFunctions(funNo, funName, parentNo, FunctionTypeDefinition.NotShow, action, controller, url, icon, sort, c, s, auth);
  274. }
  275. /// <summary>
  276. /// 创建功能菜单
  277. /// </summary>
  278. private void CreateFunctions(string funNo, string funName, string parentNo, int funType,
  279. string action, string controller, string url, string icon, int sort, string @class, string script, bool auth = true, string path = "", int? depth = null)
  280. {
  281. var fun = _context.SysFunctions.FirstOrDefault(e => e.FunctionNo == funNo && e.ParentNo == parentNo);
  282. if (fun == null)
  283. {
  284. string permissionName = path.Replace(",", ".");
  285. if (string.IsNullOrEmpty(path))
  286. {
  287. var parentFun = _context.SysFunctions.FirstOrDefault(f => f.FunctionNo == parentNo);
  288. if (parentFun != null)
  289. {
  290. //path = parentFun.FunctionPath + "," + funNo;
  291. permissionName = parentFun.PermissionName + "." + funNo;
  292. depth = depth ?? parentFun.Depth + 1;
  293. }
  294. else
  295. {
  296. throw new Exception($"未查询到父菜单【{funName}-No:{funNo}-ParentNo:{parentNo}】");
  297. }
  298. }
  299. url = url ?? controller + "/" + action;
  300. fun = new SysFunction
  301. {
  302. FunctionNo = funNo,
  303. ParentNo = parentNo,
  304. FunctionName = funName,
  305. PermissionName = permissionName,
  306. //FunctionPath = path,
  307. FunctionType = funType,
  308. Controller = controller,
  309. Action = action,
  310. Icon = icon,
  311. Sort = sort,
  312. Depth = depth ?? 0,
  313. Class = @class,
  314. Script = script,
  315. Url = url,
  316. NeedAuth = auth
  317. };
  318. _context.SysFunctions.Add(fun);
  319. _context.SaveChanges();
  320. }
  321. var permName = fun.PermissionName.Replace(".", "");
  322. PermissionStr += $" public const string {permName} = \"{fun.PermissionName}\";\r\n";
  323. if (!LangList.Contains(permName))
  324. {
  325. LangList.Add(permName);
  326. LangStr += $" <text name=\"{permName}\" value=\"{fun.FunctionName}\" />\r\n";
  327. }
  328. }
  329. #endregion
  330. #region WRITE
  331. private List<string> LangList { get; set; }
  332. private string LangStr { get; set; }
  333. private string PermissionStr { get; set; }
  334. private void Write()
  335. {
  336. WritePermission();
  337. WriteLang();
  338. }
  339. private void WritePermission()
  340. {
  341. if (string.IsNullOrEmpty(PermissionStr))
  342. {
  343. return;
  344. }
  345. try
  346. {
  347. string content = "namespace ContractService.Authorization\r\n";
  348. content += "{\r\n";
  349. content += " public static class PermissionNames\r\n";
  350. content += " {\r\n";
  351. content += PermissionStr;
  352. content += " }\r\n";
  353. content += "}\r\n";
  354. var filePath = Path.Combine(GetBasePath(), "ContractService.Core\\Authorization\\PermissionNames.cs");
  355. var fs = new FileStream(filePath, FileMode.Truncate, FileAccess.ReadWrite);//清空文件内容
  356. fs.Close();
  357. using (FileStream fr = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite))
  358. {
  359. fr.Seek(0, SeekOrigin.Begin);
  360. byte[] bytes = Encoding.UTF8.GetBytes(content);
  361. fr.Write(bytes, 0, bytes.Length);
  362. fr.Flush();
  363. }
  364. }
  365. catch (Exception e)
  366. {
  367. throw (new Exception("Permission:" + e.Message));
  368. }
  369. }
  370. private void WriteLang()
  371. {
  372. if (string.IsNullOrEmpty(LangStr))
  373. {
  374. return;
  375. }
  376. //LangStr = $"<!--FUNCTION NAME START-->\r\n{LangStr}\r\n<!--FUNCTION NAME End-->\r\n";
  377. LangStr += "\r\n";
  378. try
  379. {
  380. var filePath = Path.Combine(GetBasePath(), "ContractService.Web\\Localization\\SourceFiles\\Iwb-zh-Hans.xml");
  381. string content;
  382. using (FileStream fr = new FileStream(filePath, FileMode.Open, FileAccess.Read))
  383. {
  384. fr.Seek(0, SeekOrigin.Begin);
  385. byte[] bytes = new byte[fr.Length];
  386. fr.Read(bytes, 0, bytes.Length);
  387. content = Encoding.UTF8.GetString(bytes);
  388. //Regex regex = new Regex("<!--FUNCTION NAME START-->(.*)<!--FUNCTION NAME End-->");
  389. //string content2 = regex.Replace(content, LangStr);
  390. string first = "<!--FUNCTION AND MENU NAME START-->";
  391. string second = "<!--FUNCTION AND MENU NAME END-->";
  392. if (!string.IsNullOrEmpty(content) && content.Contains(first) && content.Contains(second))
  393. {
  394. var start = content.IndexOf(first, 0, StringComparison.Ordinal) + first.Length;
  395. var end = content.IndexOf(second, start, StringComparison.Ordinal);
  396. string temp = content.Substring(start, end - start);
  397. content = content.Replace(temp, LangStr);
  398. }
  399. else
  400. {
  401. throw new Exception("Lang:语言配置信息没有生成!");
  402. }
  403. }
  404. if (!string.IsNullOrEmpty(content))
  405. {
  406. var fs = new FileStream(filePath, FileMode.Truncate, FileAccess.ReadWrite);//清空文件内容
  407. fs.Close();
  408. using (FileStream fr = new FileStream(filePath, FileMode.Append, FileAccess.Write))
  409. {
  410. byte[] newBytes = Encoding.UTF8.GetBytes(content);
  411. fr.Seek(0, SeekOrigin.Begin);
  412. fr.Write(newBytes, 0, newBytes.Length);
  413. fr.Flush();
  414. }
  415. }
  416. }
  417. catch (Exception e)
  418. {
  419. throw (new Exception("Lang:" + e.Message));
  420. }
  421. }
  422. private string GetBasePath()
  423. {
  424. var basePath = AppDomain.CurrentDomain.BaseDirectory;
  425. //string basePath = path.Contains("\\We.Platform")
  426. // ? AppDomain.CurrentDomain.BaseDirectory.Substring(0,
  427. // path.LastIndexOf("\\We.Platform", StringComparison.Ordinal))
  428. // : Path.Combine(AppDomain.CurrentDomain.BaseDirectory.Substring(0,
  429. // path.LastIndexOf("\\WisdomExercisePlatform", StringComparison.Ordinal)), "We.Platform");
  430. string path = Path.Combine(basePath.Substring(0, basePath.LastIndexOf("\\ContractService", StringComparison.Ordinal)), "");
  431. return path;
  432. }
  433. #endregion
  434. }
  435. }