EPLAN_PROD_Plugin/Sinvo.EplanHpD.Plugin.DynaC.../DynaServerClient.cs

89 lines
2.6 KiB
C#
Raw Permalink Normal View History

2025-03-28 10:05:48 +08:00
using Sinvo.EplanHpD.Plugin.DynaClient.CADIService;
using Sinvo.EplanHpD.Plugin.DynaClient.Model;
2025-03-28 10:05:48 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
namespace Sinvo.EplanHpD.Plugin.DynaClient
{
public class DynaServerClient
{
private static DynaServerClient _inst;
public static DynaServerClient GetClient()
{
if(_inst == null)
{
_inst = new DynaServerClient();
}
return _inst;
}
2025-03-28 10:05:48 +08:00
private CADIServicePortTypeClient _client;
private DynaServerClient( )
2025-03-28 10:05:48 +08:00
{
InitClient();
}
public DynaServerClient(string serverUrl)
{
InitClient(serverUrl);
}
private void InitClient(string serverUrl = "http://192.168.1.205:38080/axis2/services/CADIService?wsdl")
2025-03-28 10:05:48 +08:00
{
var binding = new BasicHttpBinding();
var endpoint = new EndpointAddress(serverUrl);
// 启用Cookie管理
binding.AllowCookies = true;
2025-03-28 10:05:48 +08:00
_client = new CADIServicePortTypeClient(binding, endpoint);
}
public User Login(string userName,string password,string role,string group,string clientType)
2025-03-28 10:05:48 +08:00
{
var hostName = Environment.MachineName;
var xml = _client.login(userName, group, role, password, hostName, clientType);
return XmlFormatStream.ConvertXMLToObjectList<User>(xml)?.FirstOrDefault();
}
public List<UserGroup> GetUserGroup(string userName)
{
var groupFieldName = "GUID|ID|NAME|LIBRARYGUID";
var xml = _client.listGroupByUser(userName, groupFieldName);
return XmlFormatStream.ConvertXMLToObjectList<UserGroup>(xml);
}
public List<UserRole> GetUserRole(string userName,string groupId)
{
string roleFieldName = "ID|NAME";
var xml = _client.listRoleByUserInGroup(userName, groupId, roleFieldName);
return XmlFormatStream.ConvertXMLToObjectList<UserRole>(xml);
}
public void LoginOut()
{
_client.logout();
}
public bool IsLoginExpired()
{
var xml = _client.isSessionExpired();
try
{
XmlFormatStream.CheckXmlException(xml);
return true;
}
catch (System.Exception)
{
return false;
}
2025-03-28 10:05:48 +08:00
}
}
}