123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.ServiceModel;
- using System.Xml;
- using System.Collections;
- using System.Text.RegularExpressions;
- using System.Reflection;
- using System.IO;
- using Aitex.Core.Account;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Key;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.RT.Log;
- using Aitex.Core.Util;
- using Aitex.Common.Util;
- namespace Aitex.Core.Account
- {
- public sealed class AccountService : IAccountService
- {
- public string Module = "System";
- /// <summary>
- /// user login verify
- /// </summary>
- /// <param name="accountId"></param>
- /// <param name="password"></param>
- /// <returns></returns>
- public LoginResult Login(string accountId, string accountPwd)
- {
- if (KeyManager.Instance.IsExpired)
- {
- EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not login");
- return new LoginResult(){ActSucc = false,Description = "Software is expired. Can not login"};
- }
- OP.Record(Module, string.Format("用户{0}尝试登入系统。", accountId));
- return AccountManager.Login(accountId, accountPwd);
- }
- /// <summary>
- /// user logout system
- /// </summary>
- /// <param name="accountId"></param>
- public void Logout(string accountId)
- {
- OP.Record(Module, string.Format("用户{0}登出系统。", accountId));
- try
- {
- // Authorization.Exit(accountId);
- }
- catch { }
- AccountManager.Logout(accountId);
- }
-
- /// <summary>
- /// get user data by accountId
- /// </summary>
- /// <param name="accountId"></param>
- /// <param name="password"></param>
- /// <returns></returns>
- public GetAccountInfoResult GetAccountInfo(string accountId)
- {
- return AccountManager.GetAccountInfo(accountId);
- }
- /// <summary>
- /// change account password
- /// </summary>
- /// <param name="accountId"></param>
- /// <param name="newPassword"></param>
- public ChangePwdResult ChangePassword(string accountId, string newPassword)
- {
- if (KeyManager.Instance.IsExpired)
- {
- EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
- return new ChangePwdResult();
- }
- OP.Record(Module, string.Format("更改用户{0}的密码。", accountId));
- LOG.Write(string.Format("账号操作,更改用户{0}的密码", accountId));
- return AccountManager.ChangePassword(accountId, newPassword);
- }
- /// <summary>
- /// create account
- /// </summary>
- /// <param name="newAccount"></param>
- /// <returns></returns>
- public CreateAccountResult CreateAccount(Account newAccount)
- {
- if (KeyManager.Instance.IsExpired)
- {
- EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
- return new CreateAccountResult();
- }
- OP.Record(Module, string.Format("创建账号{0}。", newAccount));
- LOG.Write(string.Format("账号操作,创建用户{0}。", newAccount.AccountId));
- return AccountManager.CreateAccount(newAccount);
- }
- /// <summary>
- /// Administrator user calls this method to delete an account.
- /// </summary>
- /// <param name="account"></param>
- /// <returns></returns>
- public DeleteAccountResult DeleteAccount(string accountId)
- {
- if (KeyManager.Instance.IsExpired)
- {
- EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
- return new DeleteAccountResult();
- }
- OP.Record(Module, string.Format("删除账号{0}。", accountId));
- return AccountManager.DeleteAccount(accountId);
- }
- /// <summary>
- /// Update account information
- /// </summary>
- /// <param name="accountList"></param>
- /// <returns></returns>
- public UpdateAccountResult UpdateAccount(Account account)
- {
- if (KeyManager.Instance.IsExpired)
- {
- EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
- return new UpdateAccountResult();
- }
- OP.Record(Module, string.Format("更新{0}的账号信息。", account));
- return AccountManager.UpdateAccount(account);
- }
- /// <summary>
- /// get account list
- /// </summary>
- /// <returns></returns>
- public GetAccountListResult GetAccountList()
- {
- return AccountManager.GetAccountList();
- }
- /// <summary>
- /// 获取当前所有已登录的用户列表
- /// </summary>
- /// <returns></returns>
- public List<Account> GetLoginUsers()
- {
- return AccountManager.GetLoginUserList();
- }
- /// <summary>
- /// 强制注销用户登录
- /// </summary>
- /// <param name="accountId"></param>
- /// <param name="kickoutReason"></param>
- public void KickUserOut(string accountId, string kickoutReason)
- {
- OP.Record(Module, string.Format("将用户{0}强制退出系统,原因:{1}。", accountId, kickoutReason));
- try
- {
- // Authorization.Exit(accountId);
- }
- catch { }
- AccountManager.Kickout(accountId, kickoutReason);
- }
- /// <summary>
- /// get all roles' perrmission
- /// </summary>
- /// <returns></returns>
- public SerializableDictionary<string, SerializableDictionary<string, ViewPermission>> GetAllRolesPermission()
- {
- return AccountManager.GetAllRolesPermission();
- }
- /// <summary>
- /// save all roles' permission
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public bool SaveAllRolesPermission(Dictionary<string, Dictionary<string, ViewPermission>> data)
- {
- if (KeyManager.Instance.IsExpired)
- {
- EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
- return false;
- }
- return AccountManager.SaveAllRolesPermission(data);
- }
- /// <summary>
- /// get all view's list
- /// </summary>
- /// <returns></returns>
- public SerializableDictionary<string, string> GetAllViewList()
- {
- return AccountManager.GetAllViewList();
- }
- /// <summary>
- /// Get all defined roles
- /// </summary>
- /// <returns></returns>
- public IEnumerable<string> GetAllRoles()
- {
- return AccountManager.GetAllRoles();
- }
- /// <summary>
- /// 检查账号是否仍旧有效
- /// </summary>
- /// <param name="accountId"></param>
- public void CheckAlive(string accountId)
- {
- AccountManager.CheckAlive(accountId);
- }
- /*
- public void RequestAuthorization(string accountId, string ip)
- {
- Authorization.Request(accountId, ip);
- }
- public void AbortAuthorization()
- {
- Authorization.Abort();
- }
- public void GrantAuthorization(bool isGranted)
- {
- Authorization.Grant(isGranted);
- }
- */
- /*
- public List<int> LoadInterestedEvents(string accountEmail)
- {
- return Aitex.Server.Kit.AccountEventsManager.Instance.LoadAccountEvents(accountEmail);
- }
- public void SaveInterestedEvents(string accountEmail, List<int> events)
- {
- Aitex.Server.Kit.AccountEventsManager.Instance.SaveAccountEvents(accountEmail, events);
- }
- public int GetMaxInterestedEvents()
- {
- return Aitex.Server.Kit.AccountEventsManager.Instance.GetMaxInterestedEvents();
- }
- public void SaveWarningEvents(List<int> warningEvents)
- {
- Aitex.Server.Kit.BuzzingWarningEvents.Save(warningEvents);
- Aitex.Server.LogicControl.TM.Sequencer.Instance.SendBuzzingWarningEvents(warningEvents);
- }
- public List<int> LoadWarningEvents()
- {
- return Aitex.Server.Kit.BuzzingWarningEvents.Load();
- }
- */
- string recipePermissionFile = System.IO.Path.Combine(PathManager.GetCfgDir(), "RolePermission.xml");
-
- public string GetProcessViewPermission()
- {
- XmlDocument _xmlRecipeFormat = new XmlDocument();
- try
- {
- _xmlRecipeFormat.Load(recipePermissionFile);
- return _xmlRecipeFormat.InnerXml;
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- return "<Aitex></Aitex>";
- }
- finally
- {
-
- }
- }
- public bool SaveProcessViewPermission(string viewXML)
- {
- try
- {
- XmlDocument _xmlRecipeFormat = new XmlDocument();
- _xmlRecipeFormat.LoadXml(viewXML);
- XmlTextWriter writer = new XmlTextWriter(recipePermissionFile, null);
- writer.Formatting = Formatting.Indented;
- _xmlRecipeFormat.Save(writer);
- writer.Close();
- return true;
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- return false;
- }
- }
- }
- }
|