AccountClient.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics.Eventing.Reader;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Aitex.Core.Account;
  8. using Aitex.Core.Util;
  9. using Aitex.Core.WCF;
  10. using MECF.Framework.Common.Account.Extends;
  11. using LoginResult = Aitex.Core.Account.LoginResult;
  12. namespace MECF.Framework.UI.Core.Accounts
  13. {
  14. public class AccountClient : Singleton<AccountClient>
  15. {
  16. public bool InProcess { get; set; }
  17. public Account CurrentUser { get; set; }
  18. private IAccountService _service;
  19. public IAccountService Service
  20. {
  21. get
  22. {
  23. if (_service == null)
  24. {
  25. if (InProcess)
  26. _service = new AccountService();
  27. else
  28. {
  29. _service = new AccountServiceClient();
  30. }
  31. }
  32. return _service;
  33. }
  34. }
  35. }
  36. public class AccountServiceClient : ServiceClientWrapper<IAccountService>, IAccountService
  37. {
  38. public AccountServiceClient()
  39. : base("Client_IAccountService", "AccountService")
  40. {
  41. }
  42. /// <summary>
  43. /// user login verify
  44. /// </summary>
  45. /// <param name="accountId"></param>
  46. /// <param name="accountPwd"></param>
  47. /// <returns></returns>
  48. public LoginResult Login(string accountId, string accountPwd)
  49. {
  50. LoginResult result = null;
  51. Invoke(svc => { result = svc.Login(accountId, accountPwd); });
  52. return result;
  53. }
  54. LoginResult IAccountService.Login(string accountId, string password)
  55. {
  56. return Login(accountId, password);
  57. }
  58. /// <summary>
  59. /// user logout system
  60. /// </summary>
  61. /// <param name="accountId"></param>
  62. public void Logout(string accountId)
  63. {
  64. Invoke(svc => { svc.Logout(accountId); });
  65. }
  66. /// <summary>
  67. /// get user data by accountId
  68. /// </summary>
  69. /// <param name="accountId"></param>
  70. /// <returns></returns>
  71. public GetAccountInfoResult GetAccountInfo(string accountId)
  72. {
  73. GetAccountInfoResult result = null;
  74. Invoke(svc => { result = svc.GetAccountInfo(accountId); });
  75. return result;
  76. }
  77. public void RegisterViews(List<string> views)
  78. {
  79. Invoke(svc => { svc.RegisterViews(views); });
  80. }
  81. /// <summary>
  82. /// change account password
  83. /// </summary>
  84. /// <param name="accountId"></param>
  85. /// <param name="newPassword"></param>
  86. public ChangePwdResult ChangePassword(string accountId, string newPassword)
  87. {
  88. ChangePwdResult result = null;
  89. Invoke(svc => { result = svc.ChangePassword(accountId, newPassword); });
  90. return result;
  91. }
  92. /// <summary>
  93. /// create account
  94. /// </summary>
  95. /// <param name="newAccount"></param>
  96. /// <returns></returns>
  97. public CreateAccountResult CreateAccount(Account newAccount)
  98. {
  99. CreateAccountResult result = null;
  100. Invoke(svc => { result = svc.CreateAccount(newAccount); });
  101. return result;
  102. }
  103. /// <summary>
  104. /// Administrator user calls this method to delete an account.
  105. /// </summary>
  106. /// <param name="account"></param>
  107. /// <returns></returns>
  108. public DeleteAccountResult DeleteAccount(string accountId)
  109. {
  110. DeleteAccountResult result = null;
  111. Invoke(svc => { result = svc.DeleteAccount(accountId); });
  112. return result;
  113. }
  114. /// <summary>
  115. /// Update account information
  116. /// </summary>
  117. /// <param name="accountList"></param>
  118. /// <returns></returns>
  119. public UpdateAccountResult UpdateAccount(Account account)
  120. {
  121. UpdateAccountResult result = null;
  122. Invoke(svc => { result = svc.UpdateAccount(account); });
  123. return result;
  124. }
  125. /// <summary>
  126. /// get account list
  127. /// </summary>
  128. /// <returns></returns>
  129. public GetAccountListResult GetAccountList()
  130. {
  131. GetAccountListResult result = null;
  132. Invoke(svc => { result = svc.GetAccountList(); });
  133. return result;
  134. }
  135. /// <summary>
  136. /// 获取当前所有已登录的用户列表
  137. /// </summary>
  138. /// <returns></returns>
  139. public List<Account> GetLoginUsers()
  140. {
  141. List<Account> result = null;
  142. Invoke(svc => { result = svc.GetLoginUsers(); });
  143. return result;
  144. }
  145. /// <summary>
  146. /// 强制注销用户登录
  147. /// </summary>
  148. /// <param name="accountId"></param>
  149. /// <param name="kickoutReason"></param>
  150. public void KickUserOut(string accountId, string kickoutReason)
  151. {
  152. Invoke(svc => { svc.KickUserOut(accountId, kickoutReason); });
  153. }
  154. /// <summary>
  155. /// get all roles' perrmission
  156. /// </summary>
  157. /// <returns></returns>
  158. public SerializableDictionary<string, SerializableDictionary<string, ViewPermission>> GetAllRolesPermission()
  159. {
  160. SerializableDictionary<string, SerializableDictionary<string, ViewPermission>> result = null;
  161. Invoke(svc => { result = svc.GetAllRolesPermission(); });
  162. return result;
  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. bool result = false;
  172. Invoke(svc => { result = svc.SaveAllRolesPermission(data); });
  173. return result;
  174. }
  175. /// <summary>
  176. /// get all view's list
  177. /// </summary>
  178. /// <returns></returns>
  179. public SerializableDictionary<string, string> GetAllViewList()
  180. {
  181. SerializableDictionary<string, string> result = null;
  182. Invoke(svc => { result = svc.GetAllViewList(); });
  183. return result;
  184. }
  185. /// <summary>
  186. /// Get all defined roles
  187. /// </summary>
  188. /// <returns></returns>
  189. public IEnumerable<string> GetAllRoles()
  190. {
  191. IEnumerable<string> result = null;
  192. Invoke(svc => { result = svc.GetAllRoles(); });
  193. return result;
  194. }
  195. /// <summary>
  196. /// 检查账号是否仍旧有效
  197. /// </summary>
  198. /// <param name="accountId"></param>
  199. public void CheckAlive(string accountId)
  200. {
  201. Invoke(svc => { svc.CheckAlive(accountId); });
  202. }
  203. /// <summary>
  204. /// 获取流程视图的许可
  205. /// </summary>
  206. /// <returns></returns>
  207. public string GetProcessViewPermission()
  208. {
  209. string result = null;
  210. Invoke(svc => { result = svc.GetProcessViewPermission(); });
  211. return result;
  212. }
  213. /// <summary>
  214. /// 保存流程视图的许可
  215. /// </summary>
  216. /// <param name="viewXML"></param>
  217. /// <returns></returns>
  218. public bool SaveProcessViewPermission(string viewXML)
  219. {
  220. bool result = false;
  221. Invoke(svc => { result = svc.SaveProcessViewPermission(viewXML); });
  222. return result;
  223. }
  224. public List<Role> GetAllRoleList()
  225. {
  226. var result = new List<Role>();
  227. Invoke(svc => { result = svc.GetAllRoleList(); });
  228. return result;
  229. }
  230. public List<AccountEx> GetAllAccountExList()
  231. {
  232. var result = new List<AccountEx>();
  233. Invoke(svc => { result = svc.GetAllAccountExList(); });
  234. return result;
  235. }
  236. public List<Role> GetRoles()
  237. {
  238. var result = new List<Role>();
  239. Invoke(svc => { result = svc.GetRoles(); });
  240. return result;
  241. }
  242. public List<AccountEx> GetAccounts()
  243. {
  244. var result = new List<AccountEx>();
  245. Invoke(svc => { result = svc.GetAccounts(); });
  246. return result;
  247. }
  248. public bool UpdateRole(Role p_newRole)
  249. {
  250. bool result = false;
  251. Invoke(svc => { result = svc.UpdateRole(p_newRole); });
  252. return result;
  253. }
  254. public bool DeleteRole(string p_strRoleID)
  255. {
  256. bool result = false;
  257. Invoke(svc => { result = svc.DeleteRole(p_strRoleID); });
  258. return result;
  259. }
  260. public List<AppMenu> GetMenusByRole(string roleid, List<AppMenu> menulist)
  261. {
  262. var result = new List<AppMenu>();
  263. Invoke(svc => { result = svc.GetMenusByRole(roleid, menulist); });
  264. return result;
  265. }
  266. public int GetMenuPermission(string roleId, string menuName)
  267. {
  268. int result = 0;
  269. Invoke(svc => { result = svc.GetMenuPermission(roleId, menuName); });
  270. return result;
  271. }
  272. public bool UpdateAccountEx(AccountEx account)
  273. {
  274. bool result = false;
  275. Invoke(svc => { result = svc.UpdateAccountEx(account); });
  276. return result;
  277. }
  278. public bool DeleteAccountEx(string accountId)
  279. {
  280. bool result = false;
  281. Invoke(svc => { result = svc.DeleteAccountEx(accountId); });
  282. return result;
  283. }
  284. public LoginResult LoginEx(string accountId, string password, string role)
  285. {
  286. var result = new LoginResult();
  287. Invoke(svc => { result = svc.LoginEx(accountId, password, role); });
  288. return result;
  289. }
  290. public void LogoutEx(string accountId, string loginId)
  291. {
  292. Invoke(svc => { svc.LogoutEx(accountId, loginId); });
  293. }
  294. }
  295. }