AccountService.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. try
  99. {
  100. // Authorization.Exit(accountId);
  101. }
  102. catch { }
  103. AccountManager.Kickout(accountId, kickoutReason);
  104. }
  105. public SerializableDictionary<string, SerializableDictionary<string, ViewPermission>> GetAllRolesPermission()
  106. {
  107. return AccountManager.GetAllRolesPermission();
  108. }
  109. public bool SaveAllRolesPermission(Dictionary<string, Dictionary<string, ViewPermission>> data)
  110. {
  111. if (KeyManager.Instance.IsExpired)
  112. {
  113. EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
  114. return false;
  115. }
  116. return AccountManager.SaveAllRolesPermission(data);
  117. }
  118. public SerializableDictionary<string, string> GetAllViewList()
  119. {
  120. return AccountManager.GetAllViewList();
  121. }
  122. public IEnumerable<string> GetAllRoles()
  123. {
  124. return AccountManager.GetAllRoles();
  125. }
  126. public void CheckAlive(string accountId)
  127. {
  128. AccountManager.CheckAlive(accountId);
  129. }
  130. public string GetProcessViewPermission()
  131. {
  132. string recipePermissionFile = System.IO.Path.Combine(PathManager.GetCfgDir(), "RolePermission.xml");
  133. XmlDocument _xmlRecipeFormat = new XmlDocument();
  134. try
  135. {
  136. _xmlRecipeFormat.Load(recipePermissionFile);
  137. return _xmlRecipeFormat.InnerXml;
  138. }
  139. catch (Exception ex)
  140. {
  141. LOG.Write(ex);
  142. return "<Aitex></Aitex>";
  143. }
  144. finally
  145. {
  146. }
  147. }
  148. public bool SaveProcessViewPermission(string viewXML)
  149. {
  150. try
  151. {
  152. string recipePermissionFile = System.IO.Path.Combine(PathManager.GetCfgDir(), "RolePermission.xml");
  153. XmlDocument _xmlRecipeFormat = new XmlDocument();
  154. _xmlRecipeFormat.LoadXml(viewXML);
  155. XmlTextWriter writer = new XmlTextWriter(recipePermissionFile, null);
  156. writer.Formatting = Formatting.Indented;
  157. _xmlRecipeFormat.Save(writer);
  158. writer.Close();
  159. return true;
  160. }
  161. catch (Exception ex)
  162. {
  163. LOG.Write(ex);
  164. return false;
  165. }
  166. }
  167. public List<Role> GetAllRoleList()
  168. {
  169. return AccountExManager.Instance.RoleLoader.RoleList;
  170. }
  171. public List<AccountEx> GetAllAccountExList()
  172. {
  173. return AccountExManager.Instance.RoleLoader.AccountList;
  174. }
  175. public List<Role> GetRoles()
  176. {
  177. return AccountExManager.Instance.RoleLoader.GetRoles();
  178. }
  179. public List<AccountEx> GetAccounts()
  180. {
  181. return AccountExManager.Instance.RoleLoader.GetAccounts();
  182. }
  183. public bool UpdateRole(Role role)
  184. {
  185. return AccountExManager.Instance.RoleLoader.UpdateRole(role);
  186. }
  187. public bool DeleteRole(string roleId)
  188. {
  189. return AccountExManager.Instance.RoleLoader.DeleteRole(roleId);
  190. }
  191. public List<AppMenu> GetMenusByRole(string roleId, List<AppMenu> lstMenu)
  192. {
  193. return AccountExManager.Instance.RoleLoader.GetMenusByRole(roleId, lstMenu) ;
  194. }
  195. public int GetMenuPermission(string roleId, string menuName)
  196. {
  197. return AccountExManager.Instance.RoleLoader.GetMenuPermission(roleId, menuName);
  198. }
  199. public bool UpdateAccountEx(AccountEx account)
  200. {
  201. return AccountExManager.Instance.RoleLoader.UpdateAccount(account);
  202. }
  203. public bool DeleteAccountEx(string accountId)
  204. {
  205. return AccountExManager.Instance.RoleLoader.DeleteAccount(accountId);
  206. }
  207. public LoginResult LoginEx(string accountId, string password, string role)
  208. {
  209. return AccountExManager.Instance.AuthLogin(accountId, password, role);
  210. }
  211. public void LogoutEx(string accountId, string loginId)
  212. {
  213. AccountExManager.Instance.Logout(accountId, loginId );
  214. }
  215. }
  216. }