DefaultFunctionsCreator.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using WePlatform.BaseInfo;
  7. using WePlatform.Configuration;
  8. using WePlatform.EF;
  9. namespace WePlatform.SeedData
  10. {
  11. public class DefaultFunctionsCreator
  12. {
  13. private readonly WePlatformDbContext _context;
  14. public DefaultFunctionsCreator(WePlatformDbContext context)
  15. {
  16. _context = context;
  17. LangStr = "\r\n\r\n";
  18. PermissionStr = "";
  19. LangList = new List<string>();
  20. }
  21. public void Create()
  22. {
  23. _context.Database.ExecuteSqlCommand("TRUNCATE TABLE [dbo].[Sys_Functions]");
  24. CreateFunctions("HTSystem", "后台管理系统", "0", FunctionTypeDefinition.Catalog, "Index", "Home", "", "fas fa-home", 0, "", "", false, "Pages", 0);
  25. Resource();
  26. EngineModel();
  27. WePlayer();
  28. OpenPlatform();
  29. System();
  30. Write();
  31. }
  32. #region 应急信息资源库
  33. public void Resource()
  34. {
  35. CreateCatalog("ResourceMg", "HTSystem", "应急信息资源库云服务", 20, "fa fa-cogs");
  36. CreateMenu("SceneMg", "ResourceMg", "情景库管理", 1, "SceneInfo", "ResourceLib", "", "fa fa-cog");
  37. CreateBtn_Curd("SceneMg", "情景", "Scene");
  38. CreateBtn_Other("TemplateMg", "SceneMg", "下载Excel模板", 4, "fa fa-download", "_btnExportTemplate", "Scene/ExportTemplate");
  39. CreateBtn_Other("ExportMg", "SceneMg", "导出情景", 5, "iconfont icon-download", "_btnExport", "Scene/Export");
  40. CreateBtn_Other("ImportMg", "SceneMg", "导入情景", 6, "iconfont icon-upload", "_btnImport", "Scene/Import");
  41. CreateMenu("BehaviorMg", "ResourceMg", "行为规则库管理", 2, "BehaviorInfo", "ResourceLib", "", "fa fa-cog");
  42. CreateBtn_Curd("BehaviorMg", "行为", "Behavior");
  43. //CreateMenu("GuideMg", "应急知识引导库管理", "ResourceMg", 3, "Guide", "ResourceLib", "", "fa fa-cog");
  44. //CreateBtn_Curd("GuideMg", "知识引导", "Guide");
  45. GuideInfo(3);
  46. CreateMenu("EnvironReMg", "ResourceMg", "场景渲染资源库管理", 4, "EnvironResourceInfo", "ResourceLib", "", "fa fa-cog");
  47. CreateBtn_Curd("EnvironReMg", "资源", "EnvironResource");
  48. BasicInfo(5);
  49. }
  50. private void GuideInfo(int sort)
  51. {
  52. CreateCatalog("GuideMg", "ResourceMg", "应急知识信息库", sort, "fa fa-cogs");
  53. CreateMenu("PlanMg", "GuideMg", "应急预案库管理", 1, "Plan", "ResourceLib", "", "fa fa-cog");
  54. CreateBtn_Curd("PlanMg", "预案", "EmergencyPlan");
  55. CreateMenu_NotShow("PlanContentMg", "GuideMg", "应急预案内容维护",2, "fa fa-cog","","");
  56. CreateBtn_Curd("PlanContentMg", "预案", "EmergencyPlan");
  57. CreateBtn_Other("SetUseMg", "PlanContentMg","设为当前",5, "fa fa-cog");
  58. CreateMenu("KnowledgeMg", "GuideMg", "知识库管理", 3, "Knowledge", "ResourceLib", "", "fa fa-cog");
  59. CreateBtn_Curd("KnowledgeMg", "知识", "Knowledge");
  60. CreateMenu("PromptMg", "GuideMg", "引导库管理", 4, "Prompt", "ResourceLib", "", "fa fa-cog");
  61. CreateBtn_Curd("PromptMg", "引导", "Prompt");
  62. CreateMenu("SupplyMg", "GuideMg", "应急物资库管理", 5, "Supply", "ResourceLib", "", "fa fa-cog");
  63. CreateBtn_Curd("SupplyMg", "物资", "Supply");
  64. }
  65. private void BasicInfo(int sort)
  66. {
  67. CreateCatalog("BasicMg", "ResourceMg", "基础信息库", sort, "fa fa-cogs");
  68. CreateMenu("SceneCategoryMg", "BasicMg", "场景类别管理", 1, "SceneCategory", "ResourceLib", "", "fa fa-cog");
  69. CreateBtn_Curd("SceneCategoryMg", "场景类别", "SceneCategory");
  70. CreateMenu("BehaviorRoleMg", "BasicMg", "行为角色管理", 2, "BehaviorRole", "ResourceLib", "", "fa fa-cog");
  71. CreateBtn_Curd("BehaviorRoleMg", "行为角色", "BehaviorRole");
  72. }
  73. #endregion
  74. #region 智能化推演模式支撑
  75. private void EngineModel()
  76. {
  77. CreateCatalog("EngineModelMg", "HTSystem", "智能化推演模型服务", 25, "fa fa-cogs");
  78. CreateMenu("EngineMg", "EngineModelMg", "推演引擎管理", 1, "Engine", "EngineModel", "", "fa fa-cog");
  79. CreateBtn_Curd("EngineMg", "引擎", "Engine");
  80. CreateMenu("ModelMg", "EngineModelMg", "推演模型管理", 2, "Model", "EngineModel", "", "fa fa-cog");
  81. CreateBtn_Curd("ModelMg", "模型", "EngineModel");
  82. CreateMenu("EvalModelMg", "EngineModelMg", "评估模型管理", 3, "EvalModel", "EngineModel", "", "fa fa-cog");
  83. CreateBtn_Curd("EvalModelMg", "模型", "EvalModel");
  84. CreateMenu("EvalTargetMg", "EngineModelMg", "评估指标管理", 4, "EvalTarget", "EngineModel", "", "fa fa-cog");
  85. CreateBtn_Curd("EvalTargetMg", "指标", "EvalTarget");
  86. CreateMenu("EvalReportTemplateMg", "EngineModelMg", "评估报告模板管理", 5, "ReportTemplate", "EngineModel", "", "fa fa-cog");
  87. CreateBtn_Curd("EvalReportTemplateMg", "模板", "EvalReportTemplate");
  88. //CreateMenu("EngineComponentMg", "EngineModelMg", "引擎事务组件管理", 4, "Component", "EngineModel", "", "fa fa-cog");
  89. //CreateBtn_Curd("EngineComponentMg", "组件", "EngineComponent");
  90. }
  91. #endregion
  92. #region 一站式演练策划
  93. private void WePlayer()
  94. {
  95. CreateCatalog("WePlayerMg", "HTSystem", "一站式演练策划服务", 30, "fa fa-cogs");
  96. CreateMenu("FlowMg", "WePlayerMg", "演练情景流策划", 1, "SceneFlow", "WePlayer", "", "fa fa-cog");
  97. CreateBtn_Curd("FlowMg", "情景流", "SceneFlow");
  98. CreateBtn_Other("Copy", "FlowMg", "拷贝情景流", 4,"fa fa-copy","", "SceneFlow/Copy");
  99. //CreateBtn_Other("Solidify", "FlowMg", "固化情景流", 5,"fa fa-copy","", "SceneFlow/Solidify");
  100. CreateMenu("PackageMg", "WePlayerMg", "演练方案包策划", 2, "Package", "WePlayer", "", "fa fa-cog");
  101. CreateBtn_Curd("PackageMg", "方案包", "Package");
  102. CreateBtn_Other("Copy","PackageMg", "拷贝方案包", 4,"fa fa-copy", "", "Package/Copy");
  103. CreateBtn_Other("Solidify", "PackageMg", "固化方案包", 5,"fa fa-copy","", "Package/Solidify");
  104. CreateBtn_NotShow("Detail", "PackageMg", "固化方案包详情", 6,"fa fa-list","None", "Package/Detail");
  105. }
  106. #endregion
  107. #region 开放性平台基础服务
  108. private void OpenPlatform()
  109. {
  110. CreateCatalog("OpenPlatformMg", "HTSystem", "开放性平台基础服务", 35, "fa fa-cogs");
  111. CreateMenu("OpenApiMg", "OpenPlatformMg", "平台开放性接口", 1, "OpenApi", "OpenPlatform", "", "fa fa-cog");
  112. CreateBtn_Query("OpenApiMg",0);
  113. //CreateMenu("SubApiMg", "OpenPlatformMg", "接口注册订阅管理", 2, "SubscriptionApi", "OpenPlatform", "", "fa fa-cog");
  114. //CreateBtn_Query("SubApiMg", 0);
  115. //CreateBtn_Other("Audit","SubApiMg", "审核订阅",1,"fa fa-audit");
  116. }
  117. #endregion
  118. #region SYSTEM
  119. private void System()
  120. {
  121. CreateCatalog("SystemMg", "HTSystem", "系统信息维护", 100, "fa fa-cogs");
  122. CreateMenu("TenantMg", "SystemMg", "租户信息管理", 0, "SysTenants", "BaseSystem", "host");
  123. CreateBtn_Curd("TenantMg", "租户", "Tenants");
  124. CreateMenu("RoleMg", "SystemMg", "角色信息管理", 1, "SysRoles", "BaseSystem", "", "fa fa-users");
  125. CreateBtn_Curd("RoleMg", "角色", "Roles");
  126. CreateBtn_Other("Auth", "RoleMg", "角色授权", 4, "fa fa-cog", null, "Roles/Auth");
  127. CreateMenu("UserMg", "SystemMg", "用户信息管理", 2, "SysUsers", "BaseSystem", "", "fa fa-user");
  128. CreateBtn_Curd("UserMg", "用户", "Users");
  129. CreateBtn_Other("Auth", "UserMg", "用户授权", 4, "fa fa-cog", null, "Users/Auth");
  130. CreateBtn_Other("ResetPassword", "UserMg", "重置密码", 5, "fa fa-lock", "btnResetPwd", "Users/ResetPassword");
  131. CreateBtn_Other("ResetLock", "UserMg", "解除锁定", 5, "fa fa-unlock", "btnResetLock", "Users/ResetLock");
  132. CreateMenu("StateMg", "SystemMg", "系统字典信息管理", 3, "SysStates", "BaseSystem", "", "fa fa-book");
  133. CreateBtn_Curd("StateMg", "字典", "States");
  134. CreateMenu("SettingMg", "SystemMg", "系统配置信息管理", 4, "SysSettings", "BaseSystem", "", "fa fa-cog");
  135. //CreateBtn_Curd("SettingMg", "配置", "Settings");
  136. CreateBtn_Query("SettingMg", 0);
  137. CreateBtn_Update("配置", "SettingMg", 2, "Settings");
  138. CreateMenu("HelpMg", "SystemMg", "系统帮助信息管理", 5, "SysHelps", "BaseSystem", "", "fa fa-question");
  139. CreateBtn_Curd("HelpMg", "帮助", "Helps");
  140. CreateMenu("FunctionMg", "SystemMg", "功能菜单管理", 6, "SysFunctions", "BaseSystem", "", "fa fa-server");
  141. CreateBtn_Curd("FunctionMg", "菜单", "Functions");
  142. CreateBtn_Other("MoveUp", "FunctionMg", "上移菜单", 4, "fa fa-arrow-up", "btnMoveUp", "Functions/MoveUp");
  143. CreateBtn_Other("MoveDown", "FunctionMg", "下移菜单", 5, "fa fa-arrow-down", "btnMoveDown", "Functions/MoveDown");
  144. CreateBtn_Other("Refresh", "FunctionMg", "刷新菜单", 6, "fa fa-retweet", "btnRefresh", "Functions/Refresh");
  145. CreateMenu("LogMg", "SystemMg", "系统日志管理", 7, "SysLogs", "BaseSystem", "", "fa fa-list-alt");
  146. CreateBtn_Query("LogMg", 0);
  147. CreateMenu("UserHelpInfo", "HTSystem", "系统帮助信息", 101, "Index", "Help", "", "fa fa-question");
  148. CreateMenu("UserSysSetting", "HTSystem", "用户配置", 102, "", "", icon: "fa fa-cogs", isShow: false);
  149. CreateBtn_Other("LoginImage", "UserSysSetting", "配置登陆页背景", 1, "fa fa-cog", "_Admin_btnLoginImage", "Settings/LoginImage", false);
  150. CreateBtn_Other("HomeImage", "UserSysSetting", "配置主页背景", 2, "fa fa-cog", "_Admin_btnHomeImage", "Settings/HomeImage", false);
  151. CreateBtn_Other("RefreshCache", "UserSysSetting", "刷新缓存", 3, "fa fa-recycle", "_Admin_btnCache", "Settings/CacheRefresh", false);
  152. CreateBtn_Other("RefreshLang", "UserSysSetting", "刷新语言包", 4, "fa fa-recycle", "_Admin_btnLang", "Settings/LangRefresh", false);
  153. }
  154. #endregion
  155. #region CREATE
  156. /// <summary>
  157. ///创建增删改查按钮
  158. /// </summary>
  159. /// <param name="funName"></param>
  160. /// <param name="parentNo"></param>
  161. /// <param name="url">{WePlatformConsts.ApiAppUrl}{url}/Create 如果url与parentNo不同需指定</param>
  162. private void CreateBtn_Curd(string parentNo, string funName, string url = null)
  163. {
  164. CreateBtn_Query(parentNo, 0);
  165. CreateBtn_Create(funName, parentNo, 1, url);
  166. CreateBtn_Update(funName, parentNo, 2, url);
  167. CreateBtn_Delete(funName, parentNo, 3, url);
  168. }
  169. /// <summary>
  170. ///创建不是增删改查的按钮
  171. /// </summary>
  172. private void CreateBtn_Other(string funNo, string parentNo, string funName, int sort, string icon = "far fa-plus-square", string script = null, string url = null, bool isShow = true, bool isApiUrl = true)
  173. {
  174. script = script ?? $"btn{funNo}";
  175. url = url ?? $"{parentNo}/{funNo}";
  176. url = isApiUrl ? $"{IwbConsts.ApiAppUrl}{url}" : url;
  177. if (isShow)
  178. {
  179. CreateBtn(funNo, parentNo, funName, sort, url, icon, script);
  180. }
  181. else
  182. {
  183. CreateBtn_NotShow(funNo, parentNo, funName, sort, icon, script, url);
  184. }
  185. }
  186. /// <summary>
  187. /// 创建目录
  188. /// </summary>
  189. private void CreateCatalog(string funNo, string parentNo, string funName, int sort,
  190. string icon = "fa fa-indent", string s = "", string c = "", bool auth = true, bool isShow = true)
  191. {
  192. if (isShow)
  193. {
  194. CreateFunctions(funNo, funName, parentNo, FunctionTypeDefinition.Catalog, "", "", "", icon, sort, c, s, auth);
  195. }
  196. else
  197. {
  198. CreateCatalog_NotShow(funNo, parentNo, funName, sort, icon, c, s, auth);
  199. }
  200. }
  201. /// <summary>
  202. /// 创建菜单
  203. /// </summary>
  204. private void CreateMenu(string funNo, string parentNo, string funName, int sort, string action,
  205. string controller, string s = "", string icon = "fa fa-bullseye", string c = "", string url = null,
  206. bool auth = true, bool isShow = true)
  207. {
  208. url = url ?? $"{controller}/{action}";
  209. if (isShow)
  210. {
  211. CreateFunctions(funNo, funName, parentNo, FunctionTypeDefinition.Menu, action, controller, url, icon, sort,
  212. c, s, auth);
  213. }
  214. else
  215. {
  216. CreateMenu_NotShow(funNo, parentNo, funName, sort, icon, action, controller,
  217. url, c, s, auth);
  218. }
  219. }
  220. /// <summary>
  221. /// 创建查询按钮
  222. /// </summary>
  223. private void CreateBtn_Query(string parentNo, int sort)
  224. {
  225. CreateBtn_NotShow("Query", parentNo, "查看页面", sort, "fa fa-eye", "btnQuery", "");
  226. }
  227. /// <summary>
  228. /// 创建添加按钮
  229. /// </summary>
  230. private void CreateBtn_Create(string funName, string parentNo, int sort, string url = null)
  231. {
  232. url = url ?? parentNo;
  233. CreateBtn("Create", parentNo, $"添加{funName}", sort, $"{IwbConsts.ApiAppUrl}{url}/Create", "far fa-plus-square", "_btnCreate");
  234. }
  235. /// <summary>
  236. /// 创建修改按钮
  237. /// </summary>
  238. private void CreateBtn_Update(string funName, string parentNo, int sort, string url = null)
  239. {
  240. url = url ?? parentNo;
  241. CreateBtn("Update", parentNo, $"修改{funName}", sort, $"{IwbConsts.ApiAppUrl}{url}/Update", "far fa-edit", "btnUpdate");
  242. }
  243. /// <summary>
  244. /// 创建删除按钮
  245. /// </summary>
  246. private void CreateBtn_Delete(string funName, string parentNo, int sort, string url = null)
  247. {
  248. url = url ?? parentNo;
  249. CreateBtn("Delete", parentNo, $"删除{funName}", sort, $"{IwbConsts.ApiAppUrl}{url}/Delete", "far fa-minus-square", "btnDelete");
  250. }
  251. /// <summary>
  252. /// 创建按钮
  253. /// </summary>
  254. private void CreateBtn(string funNo, string parentNo, string funName, int sort, string url, string icon,
  255. string s, string c = "btn btn-default", string action = "", string controller = "", bool auth = true)
  256. {
  257. CreateFunctions(funNo, funName, parentNo, FunctionTypeDefinition.Button, action, controller, url, icon, sort, c, s, auth);
  258. }
  259. /// <summary>
  260. /// 创建不显示的目录
  261. /// </summary>
  262. private void CreateCatalog_NotShow(string funNo, string parentNo, string funName, int sort, string icon,
  263. string c = "", string s = "", bool auth = true)
  264. {
  265. CreateFunctions(funNo, funName, parentNo, FunctionTypeDefinition.NotShow, "", "", "", icon, sort, c, s, auth);
  266. }
  267. /// <summary>
  268. /// 创建不显示的菜单
  269. /// </summary>
  270. private void CreateMenu_NotShow(string funNo, string parentNo, string funName, int sort, string icon,
  271. string action, string controller, string url = "", string c = "", string s = "", 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 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)
  279. {
  280. CreateFunctions(funNo, funName, parentNo, FunctionTypeDefinition.NotShow, action, controller, url, icon, sort, c, s, auth);
  281. }
  282. /// <summary>
  283. /// 创建功能菜单
  284. /// </summary>
  285. private void CreateFunctions(string funNo, string funName, string parentNo, int funType,
  286. string action, string controller, string url, string icon, int sort, string @class, string script, bool auth = true, string path = "", int? depth = null)
  287. {
  288. var fun = _context.SysFunctions.FirstOrDefault(e => e.FunctionNo == funNo && e.ParentNo == parentNo);
  289. if (fun == null)
  290. {
  291. string permissionName = path.Replace(",", ".");
  292. if (string.IsNullOrEmpty(path))
  293. {
  294. var parentFun = _context.SysFunctions.FirstOrDefault(f => f.FunctionNo == parentNo);
  295. if (parentFun != null)
  296. {
  297. //path = parentFun.FunctionPath + "," + funNo;
  298. permissionName = parentFun.PermissionName + "." + funNo;
  299. depth = depth ?? parentFun.Depth + 1;
  300. }
  301. else
  302. {
  303. throw new Exception($"未查询到父菜单【{funName}-No:{funNo}-ParentNo:{parentNo}】");
  304. }
  305. }
  306. url = url ?? controller + "/" + action;
  307. fun = new SysFunction
  308. {
  309. FunctionNo = funNo,
  310. ParentNo = parentNo,
  311. FunctionName = funName,
  312. PermissionName = permissionName,
  313. //FunctionPath = path,
  314. FunctionType = funType,
  315. Controller = controller,
  316. Action = action,
  317. Icon = icon,
  318. Sort = sort,
  319. Depth = depth ?? 0,
  320. Class = @class,
  321. Script = script,
  322. Url = url,
  323. NeedAuth = auth
  324. };
  325. _context.SysFunctions.Add(fun);
  326. _context.SaveChanges();
  327. }
  328. var permName = fun.PermissionName.Replace(".", "");
  329. PermissionStr += $" public const string {permName} = \"{fun.PermissionName}\";\r\n";
  330. if (!LangList.Contains(permName))
  331. {
  332. LangList.Add(permName);
  333. LangStr += $" <text name=\"{permName}\" value=\"{fun.FunctionName}\" />\r\n";
  334. }
  335. }
  336. #endregion
  337. #region WRITE
  338. private List<string> LangList { get; set; }
  339. private string LangStr { get; set; }
  340. private string PermissionStr { get; set; }
  341. private void Write()
  342. {
  343. WritePermission();
  344. WriteLang();
  345. }
  346. private void WritePermission()
  347. {
  348. if (string.IsNullOrEmpty(PermissionStr))
  349. {
  350. return;
  351. }
  352. try
  353. {
  354. string content = "namespace WePlatform.Authorization\r\n";
  355. content += "{\r\n";
  356. content += " public static class PermissionNames\r\n";
  357. content += " {\r\n";
  358. content += PermissionStr;
  359. content += " }\r\n";
  360. content += "}\r\n";
  361. var filePath = Path.Combine(GetBasePath(), "WePlatform.Core\\Authorization\\PermissionNames.cs");
  362. var fs = new FileStream(filePath, FileMode.Truncate, FileAccess.ReadWrite);//清空文件内容
  363. fs.Close();
  364. using (FileStream fr = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite))
  365. {
  366. fr.Seek(0, SeekOrigin.Begin);
  367. byte[] bytes = Encoding.UTF8.GetBytes(content);
  368. fr.Write(bytes, 0, bytes.Length);
  369. fr.Flush();
  370. }
  371. }
  372. catch (Exception e)
  373. {
  374. throw (new Exception("Permission:" + e.Message));
  375. }
  376. }
  377. private void WriteLang()
  378. {
  379. if (string.IsNullOrEmpty(LangStr))
  380. {
  381. return;
  382. }
  383. //LangStr = $"<!--FUNCTION NAME START-->\r\n{LangStr}\r\n<!--FUNCTION NAME End-->\r\n";
  384. LangStr += "\r\n";
  385. try
  386. {
  387. var filePath = Path.Combine(GetBasePath(), "WePlatform.Web\\Localization\\SourceFiles\\WePlatform-zh-Hans.xml");
  388. string content;
  389. using (FileStream fr = new FileStream(filePath, FileMode.Open, FileAccess.Read))
  390. {
  391. fr.Seek(0, SeekOrigin.Begin);
  392. byte[] bytes = new byte[fr.Length];
  393. fr.Read(bytes, 0, bytes.Length);
  394. content = Encoding.UTF8.GetString(bytes);
  395. //Regex regex = new Regex("<!--FUNCTION NAME START-->(.*)<!--FUNCTION NAME End-->");
  396. //string content2 = regex.Replace(content, LangStr);
  397. string first = "<!--FUNCTION AND MENU NAME START-->";
  398. string second = "<!--FUNCTION AND MENU NAME END-->";
  399. if (!string.IsNullOrEmpty(content) && content.Contains(first) && content.Contains(second))
  400. {
  401. var start = content.IndexOf(first, 0, StringComparison.Ordinal) + first.Length;
  402. var end = content.IndexOf(second, start, StringComparison.Ordinal);
  403. string temp = content.Substring(start, end - start);
  404. content = content.Replace(temp, LangStr);
  405. }
  406. else
  407. {
  408. throw new Exception("Lang:语言配置信息没有生成!");
  409. }
  410. }
  411. if (!string.IsNullOrEmpty(content))
  412. {
  413. var fs = new FileStream(filePath, FileMode.Truncate, FileAccess.ReadWrite);//清空文件内容
  414. fs.Close();
  415. using (FileStream fr = new FileStream(filePath, FileMode.Append, FileAccess.Write))
  416. {
  417. byte[] newBytes = Encoding.UTF8.GetBytes(content);
  418. fr.Seek(0, SeekOrigin.Begin);
  419. fr.Write(newBytes, 0, newBytes.Length);
  420. fr.Flush();
  421. }
  422. }
  423. }
  424. catch (Exception e)
  425. {
  426. throw (new Exception("Lang:" + e.Message));
  427. }
  428. }
  429. private string GetBasePath()
  430. {
  431. var basePath = AppDomain.CurrentDomain.BaseDirectory;
  432. //string basePath = path.Contains("\\We.Platform")
  433. // ? AppDomain.CurrentDomain.BaseDirectory.Substring(0,
  434. // path.LastIndexOf("\\We.Platform", StringComparison.Ordinal))
  435. // : Path.Combine(AppDomain.CurrentDomain.BaseDirectory.Substring(0,
  436. // path.LastIndexOf("\\WisdomExercisePlatform", StringComparison.Ordinal)), "We.Platform");
  437. string path= Path.Combine(basePath.Substring(0,basePath.LastIndexOf("\\EngineRefactor", StringComparison.Ordinal)), "EngineRefactor\\We.Platform");
  438. return path;
  439. }
  440. #endregion
  441. }
  442. }