namespace NFine.Code { public class OperatorProvider { public static OperatorProvider Provider { get { return new OperatorProvider(); } } private string LoginUserKey = "nfine_loginuserkey_2016WMS"; private string LoginProvider = Configs.GetValue("LoginProvider"); public OperatorModel GetCurrent() { OperatorModel operatorModel = new OperatorModel(); if (LoginProvider == "Cookie") { operatorModel = DESEncrypt.Decrypt(WebHelper.GetCookie(LoginUserKey).ToString()).ToObject(); } else { operatorModel = DESEncrypt.Decrypt(WebHelper.GetSession(LoginUserKey).ToString()).ToObject(); } return operatorModel; } public void AddCurrent(OperatorModel operatorModel) { if (LoginProvider == "Cookie") { WebHelper.WriteCookie(LoginUserKey, DESEncrypt.Encrypt(operatorModel.ToJson()), 525600); } else { WebHelper.WriteSession(LoginUserKey, DESEncrypt.Encrypt(operatorModel.ToJson())); } WebHelper.WriteCookie("nfine_mac", Md5.md5(Net.GetMacByNetworkInterface().ToJson(), 525600)); WebHelper.WriteCookie("nfine_licence", Licence.GetLicence()); } //public OperatorModel GetCurrent() //{ // OperatorModel operatorModel; // if (LoginProvider == "Cookie") // { // operatorModel = DESEncrypt.Decrypt(WebHelper.GetCookie(LoginUserKey).ToString()).ToObject(); // } // else // { // if (WebHelper.GetCookie(LoginUserKey) == null) // { // operatorModel = new OperatorModel(); // } // else // { // operatorModel = DESEncrypt.Decrypt(WebHelper.GetSession(LoginUserKey).ToString()).ToObject(); // } // } // return operatorModel ?? new OperatorModel(); //} //public void AddCurrent(OperatorModel operatorModel) //{ // if (LoginProvider == "Cookie") // { // WebHelper.WriteCookie(LoginUserKey, DESEncrypt.Encrypt(operatorModel.ToJson()), 525600); // } // else // { // WebHelper.WriteSession(LoginUserKey, DESEncrypt.Encrypt(operatorModel.ToJson())); // } // WebHelper.WriteCookie("nfine_mac", Md5.md5(Net.GetMacByNetworkInterface().ToJson(), 32)); // WebHelper.WriteCookie("nfine_licence", Licence.GetLicence()); //} public void RemoveCurrent() { if (LoginProvider == "Cookie") { WebHelper.RemoveCookie(LoginUserKey.Trim()); } else { WebHelper.RemoveSession(LoginUserKey.Trim()); } } } }