AccountService.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Xml;
  4. using Aitex.Core.RT.Event;
  5. using Aitex.Core.RT.Key;
  6. using Aitex.Core.RT.OperationCenter;
  7. using Aitex.Core.RT.Log;
  8. using Aitex.Core.Util;
  9. using Aitex.Common.Util;
  10. using MECF.Framework.Common.Account;
  11. using MECF.Framework.Common.Account.Extends;
  12. namespace Aitex.Core.Account
  13. {
  14. public sealed class AccountService : IAccountService
  15. {
  16. public string Module = "System";
  17. public LoginResult Login(string accountId, string accountPwd)
  18. {
  19. if (KeyManager.Instance.IsExpired)
  20. {
  21. EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not login");
  22. return new LoginResult(){ActSucc = false,Description = "Software is expired"};
  23. }
  24. EV.PostInfoLog(Module, string.Format("User {0} try to login System.", accountId));
  25. return AccountManager.Login(accountId, accountPwd);
  26. }
  27. public void Logout(string accountId)
  28. {
  29. EV.PostInfoLog(Module, string.Format("User {0} logout sytem.", accountId));
  30. try
  31. {
  32. // Authorization.Exit(accountId);
  33. }
  34. catch { }
  35. AccountManager.Logout(accountId);
  36. }
  37. public GetAccountInfoResult GetAccountInfo(string accountId)
  38. {
  39. return AccountManager.GetAccountInfo(accountId);
  40. }
  41. public void RegisterViews(List<string> views)
  42. {
  43. AccountManager.RegisterViews(views);
  44. }
  45. public ChangePwdResult ChangePassword(string accountId, string newPassword)
  46. {
  47. if (KeyManager.Instance.IsExpired)
  48. {
  49. EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
  50. return new ChangePwdResult();
  51. }
  52. EV.PostInfoLog(Module, string.Format("Change user {0} password.", accountId));
  53. //LOG.Write(string.Format("Account operation, change user {0} password.", accountId));
  54. return AccountManager.ChangePassword(accountId, newPassword);
  55. }
  56. public CreateAccountResult CreateAccount(Account newAccount)
  57. {
  58. if (KeyManager.Instance.IsExpired)
  59. {
  60. EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
  61. return new CreateAccountResult();
  62. }
  63. EV.PostInfoLog(Module, string.Format("Create account{0}。", newAccount));
  64. //LOG.Write(string.Format("Account operation, Create user {0}。", newAccount.AccountId));
  65. return AccountManager.CreateAccount(newAccount);
  66. }
  67. public DeleteAccountResult DeleteAccount(string accountId)
  68. {
  69. if (KeyManager.Instance.IsExpired)
  70. {
  71. EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
  72. return new DeleteAccountResult();
  73. }
  74. EV.PostInfoLog(Module, string.Format("Delete account {0}。", accountId));
  75. return AccountManager.DeleteAccount(accountId);
  76. }
  77. public UpdateAccountResult UpdateAccount(Account account)
  78. {
  79. if (KeyManager.Instance.IsExpired)
  80. {
  81. EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
  82. return new UpdateAccountResult();
  83. }
  84. EV.PostInfoLog(Module, string.Format("Update {0} account information。", account));
  85. return AccountManager.UpdateAccount(account);
  86. }
  87. public GetAccountListResult GetAccountList()
  88. {
  89. return AccountManager.GetAccountList();
  90. }
  91. public List<Account> GetLoginUsers()
  92. {
  93. return AccountManager.GetLoginUserList();
  94. }
  95. public void KickUserOut(string accountId, string kickoutReason)
  96. {
  97. //EV.PostInfoLog(Module, string.Format("Force user {0} logout system,reason:{1}。", accountId, kickoutReason));
  98. LOG.Write(eEvent.EV_LOGOFF_INFO, MECF.Framework.Common.Equipment.ModuleName.System, accountId, kickoutReason);
  99. try
  100. {
  101. // Authorization.Exit(accountId);
  102. }
  103. catch { }
  104. AccountManager.Kickout(accountId, kickoutReason);
  105. }
  106. public SerializableDictionary<string, SerializableDictionary<string, ViewPermission>> GetAllRolesPermission()
  107. {
  108. return AccountManager.GetAllRolesPermission();
  109. }
  110. public bool SaveAllRolesPermission(Dictionary<string, Dictionary<string, ViewPermission>> data)
  111. {
  112. if (KeyManager.Instance.IsExpired)
  113. {
  114. EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
  115. return false;
  116. }
  117. return AccountManager.SaveAllRolesPermission(data);
  118. }
  119. public SerializableDictionary<string, string> GetAllViewList()
  120. {
  121. return AccountManager.GetAllViewList();
  122. }
  123. public IEnumerable<string> GetAllRoles()
  124. {
  125. return AccountManager.GetAllRoles();
  126. }
  127. public void CheckAlive(string accountId)
  128. {
  129. AccountManager.CheckAlive(accountId);
  130. }
  131. public string GetProcessViewPermission()
  132. {
  133. string recipePermissionFile = System.IO.Path.Combine(PathManager.GetCfgDir(), "RolePermission.xml");
  134. XmlDocument _xmlRecipeFormat = new XmlDocument();
  135. try
  136. {
  137. _xmlRecipeFormat.Load(recipePermissionFile);
  138. return _xmlRecipeFormat.InnerXml;
  139. }
  140. catch(Exception ex)
  141. {
  142. LOG.WriteExeption(ex);
  143. return "<Aitex></Aitex>";
  144. }
  145. finally
  146. {
  147. }
  148. }
  149. public bool SaveProcessViewPermission(string viewXML)
  150. {
  151. try
  152. {
  153. string recipePermissionFile = System.IO.Path.Combine(PathManager.GetCfgDir(), "RolePermission.xml");
  154. XmlDocument _xmlRecipeFormat = new XmlDocument();
  155. _xmlRecipeFormat.LoadXml(viewXML);
  156. XmlTextWriter writer = new XmlTextWriter(recipePermissionFile, null);
  157. writer.Formatting = Formatting.Indented;
  158. _xmlRecipeFormat.Save(writer);
  159. writer.Close();
  160. return true;
  161. }
  162. catch(Exception ex)
  163. {
  164. LOG.WriteExeption(ex);
  165. return false;
  166. }
  167. }
  168. public List<Role> GetAllRoleList()
  169. {
  170. return AccountExManager.Instance.RoleLoader.RoleList;
  171. }
  172. public List<AccountEx> GetAllAccountExList()
  173. {
  174. return AccountExManager.Instance.RoleLoader.AccountList;
  175. }
  176. public List<Role> GetRoles()
  177. {
  178. return AccountExManager.Instance.RoleLoader.GetRoles();
  179. }
  180. public List<AccountEx> GetAccounts()
  181. {
  182. return AccountExManager.Instance.RoleLoader.GetAccounts();
  183. }
  184. public bool UpdateRole(Role role)
  185. {
  186. return AccountExManager.Instance.RoleLoader.UpdateRole(role);
  187. }
  188. public bool DeleteRole(string roleId)
  189. {
  190. return AccountExManager.Instance.RoleLoader.DeleteRole(roleId);
  191. }
  192. public List<AppMenu> GetMenusByRole(string roleId, List<AppMenu> lstMenu)
  193. {
  194. return AccountExManager.Instance.RoleLoader.GetMenusByRole(roleId, lstMenu) ;
  195. }
  196. public bool UpdateAccountEx(AccountEx account)
  197. {
  198. return AccountExManager.Instance.RoleLoader.UpdateAccount(account);
  199. }
  200. public bool DeleteAccountEx(string accountId)
  201. {
  202. return AccountExManager.Instance.RoleLoader.DeleteAccount(accountId);
  203. }
  204. public LoginResult LoginEx(string accountId, string password, string role)
  205. {
  206. return AccountExManager.Instance.AuthLogin(accountId, password, role);
  207. }
  208. public void LogoutEx(string accountId, string loginId)
  209. {
  210. AccountExManager.Instance.Logout(accountId, loginId );
  211. }
  212. }
  213. }