测试线程静态前提交
This commit is contained in:
@@ -1,23 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ADODB;
|
||||
using log4net;
|
||||
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 ThreadContext = UFSoft.U8.Framework.ContextSrv.ThreadContext;
|
||||
using VBLogin = U8Login.clsLogin;
|
||||
// ReSharper disable IdentifierTypo
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace UFIDA.U8.Framework.Api.ControlObject.U8M
|
||||
{
|
||||
public class BaseLogin
|
||||
{
|
||||
protected readonly ILog logInfo = LogManager.GetLogger("logInfo");
|
||||
|
||||
|
||||
private NetLogin _netLogin { get; set; }
|
||||
private VBLogin _vbLogin { get; set; }
|
||||
public VBLogin _vbLogin { get; set; }
|
||||
|
||||
public ProductContext _productContext { get; set; }
|
||||
|
||||
@@ -27,78 +29,221 @@ namespace UFIDA.U8.Framework.Api.ControlObject.U8M
|
||||
/// 初始化生产制造上下文
|
||||
/// </summary>
|
||||
/// <param name="paramter">登录参数</param>
|
||||
/// <param name="bMon"></param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public void Init(LoginParamter paramter)
|
||||
public void Init(LoginParamter paramter,bool bMon=true, int traceTimes=0)
|
||||
{
|
||||
|
||||
//if (!string.IsNullOrWhiteSpace(ThreadContext.ServerToken))
|
||||
//{
|
||||
// ThreadContext.ServerToken = null;
|
||||
//}
|
||||
if (traceTimes > 5)
|
||||
throw new Exception("U8登录异常");
|
||||
|
||||
//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))
|
||||
try
|
||||
{
|
||||
//_vbLogin.ShutDown();
|
||||
throw new Exception(_vbLogin.ShareString);
|
||||
}
|
||||
Trace.WriteLine($"U8版本:{_vbLogin.GetVersionInfo()}");
|
||||
Trace.WriteLine($"1--登录令牌:{_netLogin.userToken}");
|
||||
//if (!string.IsNullOrWhiteSpace(ThreadContext.ServerToken))
|
||||
//{
|
||||
// ThreadContext.ServerToken = null;
|
||||
//}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Cryptography.m_userToken))
|
||||
{
|
||||
Cryptography.m_userToken = "";
|
||||
}
|
||||
//if (!string.IsNullOrWhiteSpace(ThreadContext.U8LoginInfo!=null))
|
||||
//{
|
||||
// ThreadContext.U8LoginInfo = null;
|
||||
//}
|
||||
|
||||
if (_netLogin.login(paramter.pSubId, paramter.pUserId, paramter.pPassword, paramter.cSrv, paramter.pDate, paramter.pAccId, paramter.cSerial))
|
||||
{
|
||||
_productContext = _netLogin.SubLogin("AS");
|
||||
if (paramter == null) throw new ArgumentNullException(nameof(paramter));
|
||||
|
||||
if (_productContext == null)
|
||||
throw new Exception($"1--初始化U8登录上下文失败------{_netLogin.ErrDescript}");
|
||||
if (!string.IsNullOrWhiteSpace(Cryptography.m_userToken))
|
||||
{
|
||||
Cryptography.m_userToken = "";
|
||||
}
|
||||
|
||||
Trace.WriteLine($"2--登录令牌:{_netLogin.userToken}");
|
||||
//Trace.WriteLine($"2--上下文令牌:{_productContext.calledContext.token}");
|
||||
if (bMon)
|
||||
{
|
||||
|
||||
#if DEBUG
|
||||
_vbLogin = new VBLogin();
|
||||
|
||||
_vbLogin.ClearError();
|
||||
|
||||
logInfo.Debug($"VB--开始进行U8登录:{paramter.cSrv}--{paramter.pUserId}--{paramter.pAccId}");
|
||||
|
||||
if (!_vbLogin.Login(paramter.pSubId, paramter.pAccId, paramter.pYearId, paramter.pUserId, paramter.pPassword, paramter.pDate, paramter.cSrv, paramter.cSerial) && string.IsNullOrWhiteSpace(_vbLogin.userToken))
|
||||
{
|
||||
throw new Exception($"VB--U8登录失败---{_vbLogin.ShareString}");
|
||||
}
|
||||
|
||||
_netLogin = new NetLogin();
|
||||
|
||||
_productContext= _netLogin.Login("DP", _vbLogin.userToken);
|
||||
|
||||
if (_productContext == null)
|
||||
{
|
||||
logInfo.Debug($"Net--U8上下文构建失败---{_netLogin.ErrDescript}");
|
||||
|
||||
if (!_netLogin.login(paramter.pSubId, paramter.pUserId, paramter.pPassword, paramter.cSrv, paramter.pDate, paramter.pAccId, paramter.cSerial) && string.IsNullOrWhiteSpace(_netLogin.userToken))
|
||||
{
|
||||
//throw new Exception($"Net--U8登录失败---{_netLogin.ErrDescript}");
|
||||
}
|
||||
|
||||
logInfo.Debug($"Net--开始进行上下文构建:{_netLogin.userToken}");
|
||||
|
||||
_productContext = _netLogin.SubLogin("DP") ?? _netLogin.Login("DP", _vbLogin.userToken);
|
||||
//throw new Exception($"Net--U8上下文构建失败---{_netLogin.ErrDescript}");
|
||||
}
|
||||
|
||||
logInfo.Debug($"Net--开始进行上下文刷新:{_productContext.calledContext.token}");
|
||||
|
||||
ClientUserContext.Instance.RefreshContext();
|
||||
|
||||
logInfo.Debug("Net--完成生产制造登录进程");
|
||||
|
||||
#else
|
||||
_netLogin = new NetLogin();
|
||||
|
||||
logInfo.Debug($"Net--开始进行U8登录:{paramter.cSrv}--{paramter.pUserId}--{paramter.pAccId}");
|
||||
|
||||
if (!_netLogin.login(paramter.pSubId, paramter.pUserId, paramter.pPassword, paramter.cSrv, paramter.pDate, paramter.pAccId, paramter.cSerial) && string.IsNullOrWhiteSpace(_netLogin.userToken))
|
||||
{
|
||||
throw new Exception($"Net--U8登录失败---{_netLogin.ErrDescript}");
|
||||
}
|
||||
|
||||
logInfo.Debug($"Net--开始进行上下文构建:{_netLogin.userToken}");
|
||||
|
||||
_productContext = _netLogin.SubLogin("DP");
|
||||
|
||||
if (_productContext == null)
|
||||
{
|
||||
throw new Exception($"Net--U8上下文构建失败---{_netLogin.ErrDescript}");
|
||||
}
|
||||
|
||||
|
||||
logInfo.Debug($"Net--开始进行上下文刷新:{_productContext.calledContext.token}");
|
||||
|
||||
ClientUserContext.Instance.RefreshContext();
|
||||
|
||||
logInfo.Debug("Net--完成生产制造登录进程");
|
||||
|
||||
return;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
_vbLogin = new VBLogin();
|
||||
|
||||
_vbLogin.ClearError();
|
||||
_vbLogin.ConstructLogin(_netLogin.userToken);
|
||||
var taskId = DateTime.Now.Ticks.ToString();
|
||||
_vbLogin.set_TaskId(taskId);
|
||||
|
||||
logInfo.Debug($"VB--开始进行U8登录:{paramter.cSrv}--{paramter.pUserId}--{paramter.pAccId}");
|
||||
|
||||
Trace.WriteLine($"3--登录令牌:{_vbLogin.userToken}");
|
||||
if (!_vbLogin.Login(paramter.pSubId, paramter.pAccId, paramter.pYearId, paramter.pUserId, paramter.pPassword, paramter.pDate, paramter.cSrv, paramter.cSerial) && string.IsNullOrWhiteSpace(_vbLogin.userToken))
|
||||
{
|
||||
throw new Exception($"VB--U8登录失败---{_vbLogin.ShareString}");
|
||||
}
|
||||
|
||||
Trace.WriteLine($"4--正在创建应用池:{_netLogin.userToken}");
|
||||
logInfo.Debug($"VB--开始创建连接对象:{_vbLogin.userToken}");
|
||||
|
||||
Connection = new Connection();
|
||||
Connection.Open(_vbLogin.UfDbName);
|
||||
|
||||
logInfo.Debug("VB--完成登录进程");
|
||||
|
||||
return;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (!bMon)
|
||||
{
|
||||
logInfo.Debug("非生产制造模块无需下面操作");
|
||||
//Trace.WriteLine("非生产制造模块无需下面操作");
|
||||
return;
|
||||
}
|
||||
|
||||
logInfo.Debug($"U8版本:{_vbLogin.GetVersionInfo()}");
|
||||
|
||||
logInfo.Debug($"1--登录令牌:{_vbLogin.userToken}");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Cryptography.m_userToken))
|
||||
{
|
||||
Cryptography.m_userToken = "";
|
||||
}
|
||||
|
||||
_productContext = _netLogin.Login("DP", _vbLogin.userToken);
|
||||
|
||||
if (_productContext != null)
|
||||
{
|
||||
logInfo.Debug($"222--成功初始化上下文信息:{_vbLogin.userToken}");
|
||||
|
||||
ClientUserContext.Instance.RefreshContext();
|
||||
//ThreadContext.ServerToken = _netLogin.userToken;
|
||||
|
||||
Connection = new Connection();
|
||||
Connection.Open(_vbLogin.UfDbName);
|
||||
|
||||
logInfo.Debug($"333--完成局部构建:{_netLogin.userToken}");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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($"11--初始化U8登录上下文失败------{_netLogin.ErrDescript}");
|
||||
|
||||
logInfo.Debug($"22--登录令牌:{_netLogin.userToken}");
|
||||
//Trace.WriteLine($"2--上下文令牌:{_productContext.calledContext.token}");
|
||||
|
||||
|
||||
//_vbLogin.ClearError();
|
||||
//_vbLogin.ConstructLogin(_netLogin.userToken);
|
||||
//var taskId = DateTime.Now.Ticks.ToString();
|
||||
//_vbLogin.set_TaskId(taskId);
|
||||
|
||||
|
||||
logInfo.Debug($"33--登录令牌:{_vbLogin.userToken}");
|
||||
|
||||
logInfo.Debug($"44--正在创建应用池:{_netLogin.userToken}");
|
||||
|
||||
ClientUserContext.Instance.RefreshContext();
|
||||
//ThreadContext.ServerToken = _netLogin.userToken;
|
||||
|
||||
|
||||
|
||||
logInfo.Debug($"55--完成局部构建:{_netLogin.userToken}");
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
_productContext = _netLogin.Login("AS", _vbLogin.userToken);
|
||||
|
||||
logInfo.Debug($"3--上下文令牌:{_productContext.calledContext.token}");
|
||||
|
||||
if (_productContext == null)
|
||||
throw new Exception($"2--初始化U8登录上下文失败------{_netLogin.ErrDescript}");
|
||||
|
||||
ClientUserContext.Instance.RefreshContext();
|
||||
//ThreadContext.ServerToken = _netLogin.userToken;
|
||||
Connection = new Connection();
|
||||
Connection.Open(_vbLogin.UfDbName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logInfo.Error($"重试次数:{traceTimes},错误信息:{ex.Message}", ex);
|
||||
|
||||
_productContext = _netLogin.Login("AS", _vbLogin.userToken);
|
||||
|
||||
Trace.WriteLine($"3--上下文令牌:{_productContext.calledContext.token}");
|
||||
|
||||
if (_productContext == null)
|
||||
throw new Exception($"2--初始化U8登录上下文失败------{_netLogin.ErrDescript}");
|
||||
|
||||
ClientUserContext.Instance.RefreshContext();
|
||||
Connection = new Connection();
|
||||
Connection.Open(_vbLogin.UfDbName);
|
||||
Init(paramter, bMon, traceTimes + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void ShutDown()
|
||||
@@ -109,15 +254,10 @@ namespace UFIDA.U8.Framework.Api.ControlObject.U8M
|
||||
|
||||
_vbLogin?.ShutDown();
|
||||
_productContext=null;
|
||||
_netLogin?.SubLogout("DP");
|
||||
_netLogin?.ShutDown();
|
||||
_netLogin?.Dispose();
|
||||
_vbLogin = null;
|
||||
_netLogin = null;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Cryptography.m_userToken))
|
||||
{
|
||||
Cryptography.m_userToken = "";
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckAccId(string cAccId)
|
||||
|
||||
Reference in New Issue
Block a user