using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; using ADODB; using UFIDA.U8.Framework.Api.ControlObject.Models; using UFSoft.U8.Framework.ContextSrv; using UFSoft.U8.Framework.Login.UI; using UFSoft.U8.Framework.LoginContext; using NetLogin = UFSoft.U8.Framework.Login.UI.clsLogin; using VBLogin = U8Login.clsLogin; namespace UFIDA.U8.Framework.Api.ControlObject.U8M { public class BaseLogin { private NetLogin _netLogin { get; set; } private VBLogin _vbLogin { get; set; } private ProductContext _productContext { get; set; } public Connection Connection { get; set; } /// /// 初始化生产制造上下文 /// /// 登录参数 /// /// public void Init(LoginParamter paramter) { //if (!string.IsNullOrWhiteSpace(ThreadContext.ServerToken)) //{ // ThreadContext.ServerToken = null; //} //if (!string.IsNullOrWhiteSpace(ThreadContext.U8LoginInfo!=null)) //{ // ThreadContext.U8LoginInfo = null; //} if (paramter == null) throw new ArgumentNullException(nameof(paramter)); _vbLogin = new VBLogin(); _netLogin = new NetLogin(); _vbLogin.ClearError(); if (!_vbLogin.Login(paramter.pSubId, paramter.pAccId, paramter.pYearId, paramter.pUserId, paramter.pPassword, paramter.pDate, paramter.cSrv, paramter.cSerial) && string.IsNullOrWhiteSpace(_vbLogin.userToken)) { //_vbLogin.ShutDown(); throw new Exception(_vbLogin.ShareString); } Trace.WriteLine($"U8版本:{_vbLogin.GetVersionInfo()}"); Trace.WriteLine($"1--登录令牌:{_netLogin.userToken}"); if (!string.IsNullOrWhiteSpace(Cryptography.m_userToken)) { Cryptography.m_userToken = ""; } if (_netLogin.login(paramter.pSubId, paramter.pUserId, paramter.pPassword, paramter.cSrv, paramter.pDate, paramter.pAccId, paramter.cSerial)) { _productContext = _netLogin.SubLogin("AS"); if (_productContext == null) throw new Exception($"1--初始化U8登录上下文失败------{_netLogin.ErrDescript}"); Trace.WriteLine($"2--登录令牌:{_netLogin.userToken}"); //Trace.WriteLine($"2--上下文令牌:{_productContext.calledContext.token}"); _vbLogin.ClearError(); _vbLogin.ConstructLogin(_netLogin.userToken); var taskId = DateTime.Now.Ticks.ToString(); _vbLogin.set_TaskId(taskId); Trace.WriteLine($"3--登录令牌:{_vbLogin.userToken}"); //Trace.WriteLine($"4--正在创建应用池:{_netLogin.userToken}"); //var info = U8LoginInfo.CreateInstance(_netLogin.userToken); //U8LoginInfoPool.Add(_netLogin.userToken, info); //Trace.WriteLine($"4--创建应用池:{info.U8LoginToken}"); //Trace.WriteLine($"4--正在设置线程登录信息:{_netLogin.userToken}"); //ThreadContext.SetLoginInfo(_netLogin.userToken); //Trace.WriteLine($"4--设置线程登录信息:{_netLogin.userToken}"); return; } //if (_vbLogin ==null) //{ // _vbLogin = new VBLogin(); // _vbLogin.ClearError(); // if (!_vbLogin.Login(paramter.pSubId, paramter.pAccId, paramter.pYearId, paramter.pUserId, paramter.pPassword, paramter.pDate, paramter.cSrv, paramter.cSerial) && string.IsNullOrWhiteSpace(_vbLogin.userToken)) // { // //_vbLogin.ShutDown(); // throw new Exception(_vbLogin.ShareString); // } // Trace.WriteLine($"U8版本:{_vbLogin.GetVersionInfo()}"); // Trace.WriteLine($"1--登录令牌:{_netLogin.userToken}"); // if (!string.IsNullOrWhiteSpace(Cryptography.m_userToken)) // { // Cryptography.m_userToken = ""; // } //} //if (!string.IsNullOrWhiteSpace(Cryptography.m_userToken)) //{ // Cryptography.m_userToken = ""; //} _productContext = _netLogin.Login("AS", _vbLogin.userToken); Trace.WriteLine($"3--上下文令牌:{_productContext.calledContext.token}"); if (_productContext == null) throw new Exception($"2--初始化U8登录上下文失败------{_netLogin.ErrDescript}"); Connection = new Connection(); Connection.Open(_vbLogin.UfDbName); } public void ShutDown() { U8LoginInfoPool.Remove(_netLogin.userToken); _vbLogin.ShutDown(); _netLogin.ShutDown(); _netLogin.Dispose(); _vbLogin = null; if (!string.IsNullOrWhiteSpace(Cryptography.m_userToken)) { Cryptography.m_userToken = ""; } } } }