AccountService.cs 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.ServiceModel;
  6. using System.Xml;
  7. using System.Collections;
  8. using System.Text.RegularExpressions;
  9. using System.Reflection;
  10. using System.IO;
  11. using Aitex.Core.Account;
  12. using Aitex.Core.RT.Event;
  13. using Aitex.Core.RT.Key;
  14. using Aitex.Core.RT.OperationCenter;
  15. using Aitex.Core.RT.Log;
  16. using Aitex.Core.Util;
  17. using Aitex.Common.Util;
  18. namespace Aitex.Core.Account
  19. {
  20. public sealed class AccountService : IAccountService
  21. {
  22. public string Module = "System";
  23. /// <summary>
  24. /// user login verify
  25. /// </summary>
  26. /// <param name="accountId"></param>
  27. /// <param name="password"></param>
  28. /// <returns></returns>
  29. public LoginResult Login(string accountId, string accountPwd)
  30. {
  31. if (KeyManager.Instance.IsExpired)
  32. {
  33. EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not login");
  34. return new LoginResult(){ActSucc = false,Description = "Software is expired. Can not login"};
  35. }
  36. OP.Record(Module, string.Format("用户{0}尝试登入系统。", accountId));
  37. return AccountManager.Login(accountId, accountPwd);
  38. }
  39. /// <summary>
  40. /// user logout system
  41. /// </summary>
  42. /// <param name="accountId"></param>
  43. public void Logout(string accountId)
  44. {
  45. OP.Record(Module, string.Format("用户{0}登出系统。", accountId));
  46. try
  47. {
  48. // Authorization.Exit(accountId);
  49. }
  50. catch { }
  51. AccountManager.Logout(accountId);
  52. }
  53. /// <summary>
  54. /// get user data by accountId
  55. /// </summary>
  56. /// <param name="accountId"></param>
  57. /// <param name="password"></param>
  58. /// <returns></returns>
  59. public GetAccountInfoResult GetAccountInfo(string accountId)
  60. {
  61. return AccountManager.GetAccountInfo(accountId);
  62. }
  63. /// <summary>
  64. /// change account password
  65. /// </summary>
  66. /// <param name="accountId"></param>
  67. /// <param name="newPassword"></param>
  68. public ChangePwdResult ChangePassword(string accountId, string newPassword)
  69. {
  70. if (KeyManager.Instance.IsExpired)
  71. {
  72. EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
  73. return new ChangePwdResult();
  74. }
  75. OP.Record(Module, string.Format("更改用户{0}的密码。", accountId));
  76. LOG.Write(string.Format("账号操作,更改用户{0}的密码", accountId));
  77. return AccountManager.ChangePassword(accountId, newPassword);
  78. }
  79. /// <summary>
  80. /// create account
  81. /// </summary>
  82. /// <param name="newAccount"></param>
  83. /// <returns></returns>
  84. public CreateAccountResult CreateAccount(Account newAccount)
  85. {
  86. if (KeyManager.Instance.IsExpired)
  87. {
  88. EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
  89. return new CreateAccountResult();
  90. }
  91. OP.Record(Module, string.Format("创建账号{0}。", newAccount));
  92. LOG.Write(string.Format("账号操作,创建用户{0}。", newAccount.AccountId));
  93. return AccountManager.CreateAccount(newAccount);
  94. }
  95. /// <summary>
  96. /// Administrator user calls this method to delete an account.
  97. /// </summary>
  98. /// <param name="account"></param>
  99. /// <returns></returns>
  100. public DeleteAccountResult DeleteAccount(string accountId)
  101. {
  102. if (KeyManager.Instance.IsExpired)
  103. {
  104. EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
  105. return new DeleteAccountResult();
  106. }
  107. OP.Record(Module, string.Format("删除账号{0}。", accountId));
  108. return AccountManager.DeleteAccount(accountId);
  109. }
  110. /// <summary>
  111. /// Update account information
  112. /// </summary>
  113. /// <param name="accountList"></param>
  114. /// <returns></returns>
  115. public UpdateAccountResult UpdateAccount(Account account)
  116. {
  117. if (KeyManager.Instance.IsExpired)
  118. {
  119. EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
  120. return new UpdateAccountResult();
  121. }
  122. OP.Record(Module, string.Format("更新{0}的账号信息。", account));
  123. return AccountManager.UpdateAccount(account);
  124. }
  125. /// <summary>
  126. /// get account list
  127. /// </summary>
  128. /// <returns></returns>
  129. public GetAccountListResult GetAccountList()
  130. {
  131. return AccountManager.GetAccountList();
  132. }
  133. /// <summary>
  134. /// 获取当前所有已登录的用户列表
  135. /// </summary>
  136. /// <returns></returns>
  137. public List<Account> GetLoginUsers()
  138. {
  139. return AccountManager.GetLoginUserList();
  140. }
  141. /// <summary>
  142. /// 强制注销用户登录
  143. /// </summary>
  144. /// <param name="accountId"></param>
  145. /// <param name="kickoutReason"></param>
  146. public void KickUserOut(string accountId, string kickoutReason)
  147. {
  148. OP.Record(Module, string.Format("将用户{0}强制退出系统,原因:{1}。", accountId, kickoutReason));
  149. try
  150. {
  151. // Authorization.Exit(accountId);
  152. }
  153. catch { }
  154. AccountManager.Kickout(accountId, kickoutReason);
  155. }
  156. /// <summary>
  157. /// get all roles' perrmission
  158. /// </summary>
  159. /// <returns></returns>
  160. public SerializableDictionary<string, SerializableDictionary<string, ViewPermission>> GetAllRolesPermission()
  161. {
  162. return AccountManager.GetAllRolesPermission();
  163. }
  164. /// <summary>
  165. /// save all roles' permission
  166. /// </summary>
  167. /// <param name="data"></param>
  168. /// <returns></returns>
  169. public bool SaveAllRolesPermission(Dictionary<string, Dictionary<string, ViewPermission>> data)
  170. {
  171. if (KeyManager.Instance.IsExpired)
  172. {
  173. EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
  174. return false;
  175. }
  176. return AccountManager.SaveAllRolesPermission(data);
  177. }
  178. /// <summary>
  179. /// get all view's list
  180. /// </summary>
  181. /// <returns></returns>
  182. public SerializableDictionary<string, string> GetAllViewList()
  183. {
  184. return AccountManager.GetAllViewList();
  185. }
  186. /// <summary>
  187. /// Get all defined roles
  188. /// </summary>
  189. /// <returns></returns>
  190. public IEnumerable<string> GetAllRoles()
  191. {
  192. return AccountManager.GetAllRoles();
  193. }
  194. /// <summary>
  195. /// 检查账号是否仍旧有效
  196. /// </summary>
  197. /// <param name="accountId"></param>
  198. public void CheckAlive(string accountId)
  199. {
  200. AccountManager.CheckAlive(accountId);
  201. }
  202. /*
  203. public void RequestAuthorization(string accountId, string ip)
  204. {
  205. Authorization.Request(accountId, ip);
  206. }
  207. public void AbortAuthorization()
  208. {
  209. Authorization.Abort();
  210. }
  211. public void GrantAuthorization(bool isGranted)
  212. {
  213. Authorization.Grant(isGranted);
  214. }
  215. */
  216. /*
  217. public List<int> LoadInterestedEvents(string accountEmail)
  218. {
  219. return Aitex.Server.Kit.AccountEventsManager.Instance.LoadAccountEvents(accountEmail);
  220. }
  221. public void SaveInterestedEvents(string accountEmail, List<int> events)
  222. {
  223. Aitex.Server.Kit.AccountEventsManager.Instance.SaveAccountEvents(accountEmail, events);
  224. }
  225. public int GetMaxInterestedEvents()
  226. {
  227. return Aitex.Server.Kit.AccountEventsManager.Instance.GetMaxInterestedEvents();
  228. }
  229. public void SaveWarningEvents(List<int> warningEvents)
  230. {
  231. Aitex.Server.Kit.BuzzingWarningEvents.Save(warningEvents);
  232. Aitex.Server.LogicControl.TM.Sequencer.Instance.SendBuzzingWarningEvents(warningEvents);
  233. }
  234. public List<int> LoadWarningEvents()
  235. {
  236. return Aitex.Server.Kit.BuzzingWarningEvents.Load();
  237. }
  238. */
  239. string recipePermissionFile = System.IO.Path.Combine(PathManager.GetCfgDir(), "RolePermission.xml");
  240. public string GetProcessViewPermission()
  241. {
  242. XmlDocument _xmlRecipeFormat = new XmlDocument();
  243. try
  244. {
  245. _xmlRecipeFormat.Load(recipePermissionFile);
  246. return _xmlRecipeFormat.InnerXml;
  247. }
  248. catch (Exception ex)
  249. {
  250. LOG.Write(ex);
  251. return "<Aitex></Aitex>";
  252. }
  253. finally
  254. {
  255. }
  256. }
  257. public bool SaveProcessViewPermission(string viewXML)
  258. {
  259. try
  260. {
  261. XmlDocument _xmlRecipeFormat = new XmlDocument();
  262. _xmlRecipeFormat.LoadXml(viewXML);
  263. XmlTextWriter writer = new XmlTextWriter(recipePermissionFile, null);
  264. writer.Formatting = Formatting.Indented;
  265. _xmlRecipeFormat.Save(writer);
  266. writer.Close();
  267. return true;
  268. }
  269. catch (Exception ex)
  270. {
  271. LOG.Write(ex);
  272. return false;
  273. }
  274. }
  275. }
  276. }