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";
///
/// user login verify
///
///
///
///
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);
}
///
/// user logout system
///
///
public void Logout(string accountId)
{
OP.Record(Module, string.Format("用户{0}登出系统。", accountId));
try
{
// Authorization.Exit(accountId);
}
catch { }
AccountManager.Logout(accountId);
}
///
/// get user data by accountId
///
///
///
///
public GetAccountInfoResult GetAccountInfo(string accountId)
{
return AccountManager.GetAccountInfo(accountId);
}
///
/// change account password
///
///
///
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);
}
///
/// create account
///
///
///
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);
}
///
/// Administrator user calls this method to delete an account.
///
///
///
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);
}
///
/// Update account information
///
///
///
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);
}
///
/// get account list
///
///
public GetAccountListResult GetAccountList()
{
return AccountManager.GetAccountList();
}
///
/// 获取当前所有已登录的用户列表
///
///
public List GetLoginUsers()
{
return AccountManager.GetLoginUserList();
}
///
/// 强制注销用户登录
///
///
///
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);
}
///
/// get all roles' perrmission
///
///
public SerializableDictionary> GetAllRolesPermission()
{
return AccountManager.GetAllRolesPermission();
}
///
/// save all roles' permission
///
///
///
public bool SaveAllRolesPermission(Dictionary> data)
{
if (KeyManager.Instance.IsExpired)
{
EV.PostMessage("System", EventEnum.DefaultWarning, "Software is expired. Can not do the operation");
return false;
}
return AccountManager.SaveAllRolesPermission(data);
}
///
/// get all view's list
///
///
public SerializableDictionary GetAllViewList()
{
return AccountManager.GetAllViewList();
}
///
/// Get all defined roles
///
///
public IEnumerable GetAllRoles()
{
return AccountManager.GetAllRoles();
}
///
/// 检查账号是否仍旧有效
///
///
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 LoadInterestedEvents(string accountEmail)
{
return Aitex.Server.Kit.AccountEventsManager.Instance.LoadAccountEvents(accountEmail);
}
public void SaveInterestedEvents(string accountEmail, List events)
{
Aitex.Server.Kit.AccountEventsManager.Instance.SaveAccountEvents(accountEmail, events);
}
public int GetMaxInterestedEvents()
{
return Aitex.Server.Kit.AccountEventsManager.Instance.GetMaxInterestedEvents();
}
public void SaveWarningEvents(List warningEvents)
{
Aitex.Server.Kit.BuzzingWarningEvents.Save(warningEvents);
Aitex.Server.LogicControl.TM.Sequencer.Instance.SendBuzzingWarningEvents(warningEvents);
}
public List 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 "";
}
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;
}
}
}
}