129 lines
4.1 KiB
C#
129 lines
4.1 KiB
C#
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; }
|
|
|
|
public ProductContext _productContext { get; set; }
|
|
|
|
public Connection Connection { get; set; }
|
|
|
|
/// <summary>
|
|
/// 初始化生产制造上下文
|
|
/// </summary>
|
|
/// <param name="paramter">登录参数</param>
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
/// <exception cref="Exception"></exception>
|
|
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}");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_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);
|
|
}
|
|
|
|
public void ShutDown()
|
|
{
|
|
U8LoginInfoPool.Clear();
|
|
|
|
ThreadContext.ServerToken = null;
|
|
|
|
_vbLogin?.ShutDown();
|
|
_productContext=null;
|
|
_netLogin?.ShutDown();
|
|
_netLogin?.Dispose();
|
|
_vbLogin = null;
|
|
_netLogin = null;
|
|
|
|
if (!string.IsNullOrWhiteSpace(Cryptography.m_userToken))
|
|
{
|
|
Cryptography.m_userToken = "";
|
|
}
|
|
}
|
|
|
|
public bool CheckAccId(string cAccId)
|
|
{
|
|
return _vbLogin.get_cAcc_Id() == cAccId;
|
|
}
|
|
}
|
|
}
|