105040 Add 对接PLM,增加登录功能,记录用户信息

This commit is contained in:
lihanbo 2025-04-07 16:18:05 +08:00
parent c316b6dd32
commit c3a6219321
18 changed files with 1420 additions and 47 deletions

View File

@ -1,4 +1,5 @@
using Sinvo.EplanHpD.Plugin.DynaClient.CADIService;
using Sinvo.EplanHpD.Plugin.DynaClient.Model;
using System;
using System.Collections.Generic;
using System.Linq;
@ -10,25 +11,77 @@ namespace Sinvo.EplanHpD.Plugin.DynaClient
{
public class DynaServerClient
{
private static DynaServerClient _inst;
public static DynaServerClient GetClient()
{
if(_inst == null)
{
_inst = new DynaServerClient();
}
return _inst;
}
private CADIServicePortTypeClient _client;
public DynaServerClient( )
private DynaServerClient( )
{
InitClient();
}
private void InitClient()
public DynaServerClient(string serverUrl)
{
InitClient(serverUrl);
}
private void InitClient(string serverUrl = "http://192.168.1.205:38080/axis2/services/CADIService?wsdl")
{
var binding = new BasicHttpBinding();
var endpoint = new EndpointAddress("http://192.168.1.206:38080/axis2/services/CADIService?wsdl");
var endpoint = new EndpointAddress(serverUrl);
// 启用Cookie管理
binding.AllowCookies = true;
_client = new CADIServicePortTypeClient(binding, endpoint);
//_client = new CADIServicePortTypeClient();
}
public object Login(string userName,string password,string role,string group,string clientType)
public User Login(string userName,string password,string role,string group,string clientType)
{
var hostName = Environment.MachineName;
return _client.login(userName, group, role, password, hostName, clientType);
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;
}
}
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sinvo.EplanHpD.Plugin.DynaClient.Model
{
public class User
{
public string GUID { get; set; }
public string Name { get; set; }
public string ID { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sinvo.EplanHpD.Plugin.DynaClient.Model
{
public class UserGroup
{
//GUID|ID|NAME|LIBRARYGUID
public string GUID { get; set; }
public string Name { get; set; }
public string ID { get; set; }
public string LibraryGUID { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sinvo.EplanHpD.Plugin.DynaClient.Model
{
public class UserRole
{
//string roleFieldName = "ID|NAME";
public string ID { get; set; }
public string Name { get; set; }
}
}

View File

@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sinvo.EplanHpD.Plugin.DynaClient</RootNamespace>
<AssemblyName>Sinvo.EplanHpD.Plugin.DynaClient</AssemblyName>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
@ -50,7 +50,12 @@
<DesignTime>True</DesignTime>
<DependentUpon>Reference.svcmap</DependentUpon>
</Compile>
<Compile Include="Model\User.cs" />
<Compile Include="Model\UserGroup.cs" />
<Compile Include="Model\UserRole.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="XmlFormatStream.cs" />
<Compile Include="XMLMethod.cs" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services\" />

View File

@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace Sinvo.EplanHpD.Plugin.DynaClient
{
public class XMLMethod
{
/// <summary>
/// XML的SelectSingleNode的替代方法
/// </summary>
/// <param name="xmlDoc"></param>
/// <param name="nodeFullName"></param>
/// <returns></returns>
public static XmlNode GetXmlNode(XmlDocument xmlDoc, string nodeFullName)
{
if (xmlDoc.ChildNodes.Count > 0)
{
int index = nodeFullName.IndexOf("/");
string nodeName = null;
if (index > -1)
{
nodeName = nodeFullName.Substring(0, index);
}
else
{
nodeName = nodeFullName;
}
foreach (XmlNode tempNode in xmlDoc.ChildNodes)
{
if (string.Compare(tempNode.Name, nodeName, true) == 0)
{
if (index > -1)
{
int fullNameLength = nodeFullName.Length - index - 1;
if (fullNameLength < 1)
{
return tempNode;
}
else
{
string childNodeFullName = nodeFullName.Substring(index + 1, fullNameLength);
return GetChildNode(tempNode, childNodeFullName);
}
}
else
{
return tempNode;
}
}
}
}
return null;
}
private static XmlNode GetChildNode(XmlNode node, string nodeFullName)
{
int index = nodeFullName.IndexOf("/");
string nodeName = null;
if (index > -1)
{
nodeName = nodeFullName.Substring(0, index);
}
else
{
nodeName = nodeFullName;
}
foreach (XmlNode tempNode in node.ChildNodes)
{
if (string.Compare(tempNode.Name, nodeName, true) == 0)
{
if (index > -1)
{
int fullNameLength = nodeFullName.Length - index - 1;
if (fullNameLength < 1)
{
return tempNode;
}
else
{
string childNodeFullName = nodeFullName.Substring(index + 1, fullNameLength);
return GetChildNode(tempNode, childNodeFullName);
}
}
else
{
return tempNode;
}
}
}
return null;
}
}
}

View File

@ -0,0 +1,500 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace Sinvo.EplanHpD.Plugin.DynaClient
{
class XmlFormatStream
{
private const string XTN_PDMOUT_STATUS = "pdmOut/status";
private const string XTN_PDMOUT_MESSAGE = "pdmOut/message";
private const string XTN_PDMOUT_RESULT = "pdmOut/result";
private const string XTN_PDMOUT_RESULT_FIELDTYPE = "pdmOut/result/fieldtype";
private const string XTN_PDMOUT_RESULT_FIELDNAME = "pdmOut/result/fieldname";
private const string XTN_PDMOUT_RESULT_VALUE_ROW = "pdmOut/result/value/row";
private const string XTN_PDMIN = "pdmIn";
private const string XTN_PDM_IN_SERIAL = "serial";
private const string XTN_PDM_IN_PARAM = "param";
private const string XTN_PDM_IN_FIELD_TYPE = "fieldtype";
private const string XTN_PDM_IN_FIELD_NAME = "fieldname";
private const string XTN_PDM_IN_FIELD_VALUE = "value";
private const string XTN_PDM_IN_FIELD_VALUE_ROW = "row";
private const string XAN_PDM_IN_PARAM_TYPE = "type";
/// <summary>
/// 检查XML流是不是个异常
/// </summary>
/// <param name="xmlStream"></param>
public static void CheckXmlException(string xmlStream)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlStream);
XmlNode statusNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_STATUS);
if (statusNode == null)
{
return;
}
string strStatus = statusNode.InnerText;
if (strStatus.CompareTo("1") == 0)
{
// 失败
XmlNode msgNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_MESSAGE);
if (msgNode == null)
{
throw new Exception();
}
string strFailedMsg = msgNode.InnerText;
throw new Exception(strFailedMsg);
}
else if (strStatus.CompareTo("201") == 0)
{
throw new Exception("登录过期!");
}
}
/// <summary>
/// PDM XML格式返回值转化成String类型
/// </summary>
/// <param name="xmlStream">xml流字符串</param>
/// <returns></returns>
public static string PDMSimpleReturnXmlStreamToString(string xmlStream)
{
//<pdmOut>
// <serial>simple</serial>
// <starttime>2009-07-08 10:40:00</starttime>
// <endtime>2009-07-08 10:40:02</endtime>
// <status>0/1</status>
// <message>login sucessfully!</message>
// <exception />
// <result type="string">5F2BB7B637654441BB3460C3A55386A7</result>
//</pdmOut>
string strResult = "";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlStream);
XmlNode statusNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_STATUS);
if (statusNode == null)
{
throw new Exception();
}
string strStatus = statusNode.InnerText;
if (strStatus.CompareTo("1") == 0)
{
// 失败
XmlNode msgNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_MESSAGE);
if (msgNode == null)
{
throw new Exception();
}
string strFailedMsg = msgNode.InnerText;
throw new Exception(strFailedMsg);
}
else if (strStatus.CompareTo("201") == 0)
{
throw new Exception("登录过期!");
}
else
{
XmlNode resultNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_RESULT);
if (resultNode == null)
{
throw new Exception();
}
strResult = resultNode.InnerText;
return strResult;
}
}
/// <summary>
/// 获取由PDMRecordReturnXMLStreamToString解析后的某个字段的值
/// </summary>
/// <param name="strFieldName">传入要获取的字段名</param>
/// <param name="arrFieldTypeString">所要查找的所有字段类型</param>
/// <param name="arrFieldNameString">所要查找的所有字段名称</param>
/// <param name="arrFieldValueString">所要查找的所有字段值</param>
/// <param name="strFieldType">返回查找字段的类型</param>
/// <param name="strFieldValue">返回查找字段的值</param>
/// <returns></returns>
public static bool GetFieldValueByName(string strFieldName, string[] arrFieldTypeString,
string[] arrFieldNameString, string[] arrFieldValueString,
out string strFieldType, out string strFieldValue)
{
strFieldType = "";
strFieldValue = "";
if (string.IsNullOrEmpty(strFieldName))
{
return false;
}
if ((arrFieldTypeString == null) || (arrFieldNameString == null) || (arrFieldValueString == null))
{
return false;
}
if (arrFieldNameString.Length < 1)
{
return false;
}
if (arrFieldTypeString.Length != arrFieldNameString.Length)
{
return false;
}
if (arrFieldTypeString.Length != arrFieldValueString.Length)
{
return false;
}
for (int i = 0; i < arrFieldNameString.Length; i++)
{
if (string.Compare(arrFieldNameString[i], strFieldName) == 0)
{
strFieldType = arrFieldTypeString[i];
strFieldValue = arrFieldValueString[i];
return true;
}
}
return false;
}
public static List<string> PDMRecordReturnXMLStreamRowToList(string xmlStream)
{
//<pdmOut>
// <serial>record</serial>
// <starttime>2014-11-25 17:19:16</starttime>
// <endtime>2014-11-25 17:19:16</endtime>
// <status>0</status>
// <result type="record">
// <fieldtype>String</fieldtype>
// <fieldname>filename</fieldname> <--字段名为FileName其实传回的是文件的本地完整路径
// <value>
// <row>D:\\ws\\SolidWorks\\测试博众-图档管理性能\\BZPART01.SLDPRT|D:\\ws\\SolidWorks\\测试博众-图档管理性能\\BZPART23.SLDPRT</row>
// </value>
// </result>
//</pdmOut>
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlStream);
XmlNode pdmOut = doc.SelectSingleNode("pdmOut");
if (pdmOut == null)
return null;
XmlNode rt = pdmOut.SelectSingleNode("result");
if (rt == null)
return null;
XmlNode val = rt.SelectSingleNode("value");
if (val == null)
return null;
XmlNode row = val.SelectSingleNode("row");
if (row == null)
return null;
string[] strs = row.InnerText.Trim().Split('|');
if (strs.Length > 0)
{
return new List<string>(strs);
}
return null;
}
public static void PDMRecordReturnXMLStreamToString(string xmlStream,
out string fieldTypeString,
out string fieldNameString,
out List<string> fieldValueStringList)
{
#region WebService XML流格式返回值格式
//<pdmOut>
// <serial>record</serial>
// <starttime>2009-07-08 10:40:00</starttime>
// <endtime>2009-07-08 10:40:02</endtime>
// <status>0/1</status>
// <message>login sucessfully!</message>
// <exception />
// <result type="record">
// <type>string|string|string|boolean|byte|int|float|double|date|datetime</type>
// <field>guid|md$number|md$description|booleanValue|byteValue|intValue|floatValue|doubleValue|dateValue|datetimeValue</field>
// <value>
// <row>doc$vf@8606abcd|doc-001|文档|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:10:00</row>
// <row>doc$vf@8606abce|doc-002|文档|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:20:00</row>
// <row>doc$vf@8606abd0|doc-003|文档|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:30:00</row>
// <row>doc$vf@8606abd1|doc-004|文档|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:40:00</row>
// </value>
// </result>
//</pdmOut>
#endregion
fieldTypeString = "";
fieldNameString = "";
fieldValueStringList = new List<string>();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlStream);
XmlNode statusNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_STATUS);
if (statusNode == null)
{
throw new Exception();
}
string strStatus = statusNode.InnerText;
if (strStatus.CompareTo("1") == 0)
{
// 失败
XmlNode messageNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_MESSAGE);
if (messageNode == null)
{
throw new Exception();
}
string strFailedMsg = messageNode.InnerText;
throw new Exception(strFailedMsg);
}
else if (strStatus.CompareTo("201") == 0)
{
throw new Exception("登录过期!");
}
else
{
XmlNode fieldTypeNode = null;
XmlNode fieldNameNode = null;
fieldTypeNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_RESULT_FIELDTYPE);
fieldNameNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_RESULT_FIELDNAME);
if (fieldTypeNode == null || fieldNameNode == null)
{
throw new Exception();
}
fieldTypeString = fieldTypeNode.InnerText;
fieldNameString = fieldNameNode.InnerText;
XmlNodeList valueNodeList = xmlDoc.SelectNodes(XTN_PDMOUT_RESULT_VALUE_ROW);
if (valueNodeList != null)
{
foreach (XmlNode tmpNode in valueNodeList)
{
fieldValueStringList.Add(tmpNode.InnerText);
}
}
}
}
/// <summary>
/// Record类型字符串转化成PDM XML流类型参数
/// </summary>
/// <param name="typeString">参数的类型组合字符串</param>
/// <param name="fieldString">参数名称组合字符串</param>
/// <param name="valueStringList">参数值组合字符串列表</param>
/// <returns>XML流类型字符串</returns>
public static string RecordParameterToXmlStream(string typeString, string fieldString, List<string> valueStringList)
{
//<!--record 数据类型-->
// <pdmIn>
// <serial>record</serial>
// <param type="record/bom">
// <fieldtype>string|string|string|boolean|byte|int|float|double|date|datetime</fieldtype>
// <fieldname>guid|md$number|md$description|booleanValue|byteValue|intValue|floatValue|doubleValue|dateValue|datetimeValue</fieldname>
// <value>
// <row>doc$vf@8606abcd|doc-001|11|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:10:00</row>
// <row>doc$vf@8606abce|doc-002|22|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:20:00</row>
// <row>doc$vf@8606abd0|doc-003|33|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:30:00</row>
// <row>doc$vf@8606abd1|doc-004|44|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:40:00</row>
// </value>
// </param>
// </pdmIn>
XmlDocument xmlDoc = new XmlDocument();
XmlElement rootElement = xmlDoc.CreateElement(XTN_PDMIN);
xmlDoc.AppendChild(rootElement);
XmlElement serialElement = xmlDoc.CreateElement(XTN_PDM_IN_SERIAL);
serialElement.InnerText = "record";
rootElement.AppendChild(serialElement);
XmlElement paramElement = xmlDoc.CreateElement(XTN_PDM_IN_PARAM);
paramElement.SetAttribute(XAN_PDM_IN_PARAM_TYPE, "record");
rootElement.AppendChild(paramElement);
XmlElement typeElement = xmlDoc.CreateElement(XTN_PDM_IN_FIELD_TYPE);
typeElement.InnerText = typeString;
paramElement.AppendChild(typeElement);
XmlElement fieldElement = xmlDoc.CreateElement(XTN_PDM_IN_FIELD_NAME);
fieldElement.InnerText = fieldString;
paramElement.AppendChild(fieldElement);
XmlElement valueElement = xmlDoc.CreateElement(XTN_PDM_IN_FIELD_VALUE);
paramElement.AppendChild(valueElement);
foreach (string tmpValueString in valueStringList)
{
XmlElement tmpRowElement = xmlDoc.CreateElement(XTN_PDM_IN_FIELD_VALUE_ROW);
tmpRowElement.InnerText = tmpValueString;
valueElement.AppendChild(tmpRowElement);
}
//LogFile.WriteMessageToLog($"RecordParameterToXmlStream->\r\n{xmlDoc.InnerXml}");
return xmlDoc.InnerXml;
}
/// <summary>
/// 从XML流中转换成对象
/// </summary>
/// <typeparam name="T">要转换成的对象类型</typeparam>
/// <param name="xml">XML字符串</param>
/// <param name="clazz">对象类型</param>
/// <returns>转换后的对象</returns>
public static List<T> ConvertXMLToObjectList<T>(string xml)
{
#region WebService XML流格式返回值格式
//<pdmOut>
// <serial>record</serial>
// <starttime>2009-07-08 10:40:00</starttime>
// <endtime>2009-07-08 10:40:02</endtime>
// <status>0/1</status>
// <message>login sucessfully!</message>
// <exception />
// <result type="record">
// <type>string|string|string|boolean|byte|int|float|double|date|datetime</type>
// <field>guid|md$number|md$description|booleanValue|byteValue|intValue|floatValue|doubleValue|dateValue|datetimeValue</field>
// <value>
// <row>doc$vf@8606abcd|doc-001|文档|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:10:00</row>
// <row>doc$vf@8606abce|doc-002|文档|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:20:00</row>
// <row>doc$vf@8606abd0|doc-003|文档|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:30:00</row>
// <row>doc$vf@8606abd1|doc-004|文档|true|1|2|1.0|2.0|2009-07-08|2009-07-08 00:40:00</row>
// </value>
// </result>
//</pdmOut>
#endregion
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);
XmlNode statusNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_STATUS);
if (statusNode == null)
{
throw new Exception("XML流中未找到状态节点");
}
string strStatus = statusNode.InnerText;
if (strStatus.CompareTo("1") == 0)
{
// 失败
XmlNode msgNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_MESSAGE);
if (msgNode == null)
{
throw new Exception("XML流中未找到消息节点");
}
string strFailedMsg = msgNode.InnerText;
throw new Exception(strFailedMsg);
}
else if (strStatus.CompareTo("201") == 0)
{
throw new Exception("登录过期!");
}
else
{
XmlNode resultNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_RESULT);
if (resultNode == null)
{
throw new Exception("XML流中未找到结果节点");
}
XmlNode fieldTypeNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_RESULT_FIELDTYPE);
XmlNode fieldNameNode = XMLMethod.GetXmlNode(xmlDoc, XTN_PDMOUT_RESULT_FIELDNAME);
XmlNodeList valueNodeList = xmlDoc.SelectNodes(XTN_PDMOUT_RESULT_VALUE_ROW);
if (fieldTypeNode == null || fieldNameNode == null || valueNodeList == null)
{
throw new Exception("XML流中数据格式不正确");
}
// 解析字段类型和字段名称
string[] fieldTypes = fieldTypeNode.InnerText.Split('|');
string[] fieldNames = fieldNameNode.InnerText.Split('|');
// 验证字段类型与字段名称数量是否匹配
if (fieldTypes.Length != fieldNames.Length)
{
throw new Exception("字段类型和字段名称数量不匹配");
}
// 创建结果列表
List<T> resultList = new List<T>();
// 处理每一行数据
foreach (XmlNode rowNode in valueNodeList)
{
string[] values = rowNode.InnerText.Split('|');
// 验证值的数量是否匹配字段数量
if (values.Length != fieldNames.Length)
{
throw new Exception($"字段值数量({values.Length})与字段名称数量({fieldNames.Length})不匹配");
}
var clazz = typeof(T);
// 创建对象实例
T obj = (T)Activator.CreateInstance(clazz);
// 设置对象属性
for (int i = 0; i < fieldNames.Length; i++)
{
try
{
// 获取属性信息
var property = clazz.GetProperty(fieldNames[i],
System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.IgnoreCase);
if (property != null && property.CanWrite)
{
// 根据字段类型转换值
object convertedValue = ConvertValueByType(values[i], fieldTypes[i]);
property.SetValue(obj, convertedValue);
}
}
catch (Exception ex)
{
throw new Exception($"设置属性 {fieldNames[i]} 值失败: {ex.Message}");
}
}
resultList.Add(obj);
}
// 如果只有一个结果,直接返回该对象
return resultList;
}
}
/// <summary>
/// 根据字段类型将字符串值转换为对应的类型
/// </summary>
/// <param name="value">字符串值</param>
/// <param name="type">字段类型</param>
/// <returns>转换后的对象</returns>
private static object ConvertValueByType(string value, string type)
{
switch (type.ToLower())
{
case "string":
return value;
case "boolean":
return Convert.ToBoolean(value);
case "byte":
return Convert.ToByte(value);
case "int":
return Convert.ToInt32(value);
case "float":
return Convert.ToSingle(value);
case "double":
return Convert.ToDouble(value);
case "date":
return DateTime.Parse(value).Date;
case "datetime":
return DateTime.Parse(value);
default:
return value;
}
}
}
}

View File

@ -1,24 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="CADIServiceSoap11Binding" />
<binding name="CADIServiceSoap11Binding"/>
</basicHttpBinding>
<customBinding>
<binding name="CADIServiceSoap12Binding">
<textMessageEncoding messageVersion="Soap12" />
<httpTransport />
<textMessageEncoding messageVersion="Soap12"/>
<httpTransport/>
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://192.168.1.205:38080/axis2/services/CADIService.CADIServiceHttpSoap11Endpoint/"
binding="basicHttpBinding" bindingConfiguration="CADIServiceSoap11Binding"
contract="CADIService.CADIServicePortType" name="CADIServiceHttpSoap11Endpoint" />
<endpoint address="http://192.168.1.205:38080/axis2/services/CADIService.CADIServiceHttpSoap12Endpoint/"
binding="customBinding" bindingConfiguration="CADIServiceSoap12Binding"
contract="CADIService.CADIServicePortType" name="CADIServiceHttpSoap12Endpoint" />
<endpoint address="http://192.168.1.205:38080/axis2/services/CADIService.CADIServiceHttpSoap11Endpoint/" binding="basicHttpBinding" bindingConfiguration="CADIServiceSoap11Binding" contract="CADIService.CADIServicePortType" name="CADIServiceHttpSoap11Endpoint"/>
<endpoint address="http://192.168.1.205:38080/axis2/services/CADIService.CADIServiceHttpSoap12Endpoint/" binding="customBinding" bindingConfiguration="CADIServiceSoap12Binding" contract="CADIService.CADIServicePortType" name="CADIServiceHttpSoap12Endpoint"/>
</client>
</system.serviceModel>
</configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sinvo.EplanHpD.Plugin.Service.Model
{
public class UserInfo
{
public string GUID { get; set; }
public string Name { get; set; }
public string ID { get; set; }
public string Role { get; set; }
public string Group { get; set; }
public string ServerUrl { get; set; }
}
}

View File

@ -1,4 +1,6 @@
using System;
using Sinvo.EplanHpD.Plugin.DynaClient;
using Sinvo.EplanHpD.Plugin.Service.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -8,5 +10,8 @@ namespace Sinvo.EplanHpD.Plugin.Service
{
public class PluginServices
{
public static UserInfo user;
public static bool IsLogin => user != null && !string.IsNullOrEmpty(user.GUID) && DynaServerClient.GetClient().IsLoginExpired();
}
}

View File

@ -73,6 +73,7 @@
<Compile Include="Model\LectotypeLine.cs" />
<Compile Include="Model\MotorDataModel.cs" />
<Compile Include="Model\MotorModel.cs" />
<Compile Include="Model\UserInfo.cs" />
<Compile Include="PluginServices.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@ -81,5 +82,11 @@
<Version>5.1.4.170</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Sinvo.EplanHpD.Plugin.DynaClient\Sinvo.EplanHpD.Plugin.DynaClient.csproj">
<Project>{e87593a3-ca93-4563-aff6-b10413c18e64}</Project>
<Name>Sinvo.EplanHpD.Plugin.DynaClient</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sinvo.EplanHpD.Plugin.WPFUI.Models
{
public class UserLoginModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private string _userName;
public string UserName
{
get => _userName;
set
{
_userName = value;
OnPropertyChanged(nameof(UserName));
}
}
private string _userPassword;
public string UserPassword
{
get => _userPassword;
set
{
_userPassword = value;
OnPropertyChanged(nameof(UserPassword));
}
}
private string _userRole;
public string UserRole
{
get => _userRole;
set
{
_userRole = value;
OnPropertyChanged(nameof(UserRole));
}
}
private string _userGroup;
public string UserGroup
{
get => _userGroup;
set
{
_userGroup = value;
OnPropertyChanged(nameof(UserGroup));
}
}
private string _userGUID;
public string UserGUID
{
get => _userGUID;
set
{
_userGUID = value;
OnPropertyChanged(nameof(UserGUID));
}
}
private string _userNickName;
public string UserNickName
{
get => _userNickName;
set
{
_userNickName = value;
OnPropertyChanged(nameof(UserNickName));
}
}
}
}

View File

@ -268,6 +268,7 @@
<Compile Include="Models\ScanCableModel.cs" />
<Compile Include="Models\StuffedDataModel.cs" />
<Compile Include="Models\TerminalModel.cs" />
<Compile Include="Models\UserLoginModel.cs" />
<Compile Include="Selector\LectotypeLengthDataTemplateSelector.cs" />
<Compile Include="Service\MotorLectotypeService.cs" />
<Compile Include="TestWindow.xaml.cs">
@ -383,6 +384,10 @@
<Project>{60d3c75c-e71d-4116-bd7e-cac68c4dd96b}</Project>
<Name>PdfiumViewer</Name>
</ProjectReference>
<ProjectReference Include="..\Sinvo.EplanHpD.Plugin.DynaClient\Sinvo.EplanHpD.Plugin.DynaClient.csproj">
<Project>{e87593a3-ca93-4563-aff6-b10413c18e64}</Project>
<Name>Sinvo.EplanHpD.Plugin.DynaClient</Name>
</ProjectReference>
<ProjectReference Include="..\Sinvo.EplanHpD.Plugin.Service\Sinvo.EplanHpD.Plugin.Service.csproj">
<Project>{AD1AA2BC-9289-46AE-BDC0-30AE13F51B3F}</Project>
<Name>Sinvo.EplanHpD.Plugin.Service</Name>

View File

@ -0,0 +1,196 @@
<Window
x:Class="Sinvo.EplanHpD.Plugin.WPFUI.View.LoginWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.View"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewmodel="clr-namespace:Sinvo.EplanHpD.Plugin.WPFUI.ViewModel"
Title="登录"
Width="320"
Height="280"
d:DataContext="{d:DesignInstance Type=viewmodel:LoginViewModel}"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Sinvo.EplanHpD.Plugin.WPFUI;component/Themes/Theme.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<StackPanel
x:Name="mainPanel"
Height="Auto"
VerticalAlignment="Top">
<Image
x:Name="LogoImg"
Height="50"
Source="\\192.168.1.160\plm系统文档\新版本集成插件\Depends\SinvoLogo.png" />
<Grid Margin="20,0">
<Grid.RowDefinitions>
<RowDefinition Height="0.7*" />
<RowDefinition Height="3" />
<RowDefinition Height="*" />
<RowDefinition Height="0.5*" />
<RowDefinition Height="5" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="用户名" />
<TextBox
x:Name="UsernameTxt"
Grid.Row="0"
Grid.Column="1"
Width="190"
LostFocus="UsernameTxt_LostFocus"
Text="{Binding User.UserName}" />
<TextBlock
Grid.Row="2"
Grid.Column="0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="密码" />
<PasswordBox
x:Name="PasswordTxt"
Grid.Row="2"
Grid.Column="1"
Width="190" />
<TextBlock
x:Name="msgTxt"
Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="2"
HorizontalAlignment="Center" />
</Grid>
<Expander
x:Name="optExp"
Margin="20,0"
Padding="0,0"
Background="#eeeeee"
Collapsed="Expander_Collapsed"
Expanded="Expander_Expanded"
Foreground="#1976D2"
Header="更多"
IsExpanded="False">
<StackPanel
Height="80"
Margin="10"
Orientation="Vertical">
<StackPanel Height="40" Orientation="Horizontal">
<TextBlock
Grid.Row="0"
Grid.Column="0"
Width="50"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="部门" />
<ComboBox
x:Name="groupCbx"
Grid.Row="0"
Grid.Column="1"
Width="190"
DisplayMemberPath="Name"
ItemsSource="{Binding Groups}"
SelectedIndex="0"
SelectedValuePath="ID"
SelectionChanged="groupCbx_SelectionChanged" />
</StackPanel>
<StackPanel Height="40" Orientation="Horizontal">
<TextBlock
Grid.Row="1"
Grid.Column="0"
Width="50"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="角色" />
<ComboBox
x:Name="roleCbx"
Grid.Row="1"
Grid.Column="1"
Width="190"
MinWidth="190"
DisplayMemberPath="Name"
ItemsSource="{Binding Roles}"
SelectedIndex="0"
SelectedValuePath="ID" />
</StackPanel>
<!--<StackPanel Height="40" Orientation="Horizontal">
<TextBlock
Grid.Row="2"
Grid.Column="0"
Width="50"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="服务器" />
<ComboBox
x:Name="serverCbx"
Grid.Row="2"
Grid.Column="1"
Width="190"
MaxWidth="190"
DisplayMemberPath="ServerName"
ItemsSource="{Binding Servers}"
SelectedIndex="0"
SelectedValuePath="ServerUrl"
SelectionChanged="serverCbx_SelectionChanged" />
</StackPanel>-->
</StackPanel>
</Expander>
<CheckBox
x:Name="rememberChk"
Margin="20,10"
HorizontalAlignment="Right"
Content="记住登录信息"
IsChecked="{Binding IsRemember}" />
<StackPanel
Height="30"
Margin="20,10"
HorizontalAlignment="Right"
Orientation="Horizontal">
<Button
x:Name="loginBtn"
Width="50"
Margin="5,0"
Click="loginBtn_Click"
DockPanel.Dock="Right"
Style="{StaticResource ButtonPrimary}">
<Button.Content>
<StackPanel
HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Horizontal">
<TextBlock Text="登录" />
</StackPanel>
</Button.Content>
</Button>
<Button
x:Name="cancelBtn"
Width="50"
Margin="5,0"
Click="cancelBtn_Click"
DockPanel.Dock="Right">
<Button.Content>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<TextBlock Text="取消" />
</StackPanel>
</Button.Content>
</Button>
</StackPanel>
</StackPanel>
</Window>

View File

@ -0,0 +1,239 @@
using Sinvo.EplanHpD.Plugin.Service;
using Sinvo.EplanHpD.Plugin.WPFUI.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Sinvo.EplanHpD.Plugin.WPFUI.View
{
/// <summary>
/// LoginWindow.xaml 的交互逻辑
/// </summary>
public partial class LoginWindow : Window
{
/// <summary>
/// 展开更多的时候,窗口的高度增加的固定值
/// </summary>
private double expandFixedHeight = 100;
private LoginViewModel viewModel;
public LoginWindow()
{
InitializeComponent();
this.DataContext = viewModel = new LoginViewModel();
}
/// <summary>
/// 强制显示为模态窗口
/// </summary>
public new void Show()
{
this.ShowDialog();
}
#region
private void Expander_Expanded(object sender, RoutedEventArgs e)
{
if (sender is Expander expander)
{
this.Height += expandFixedHeight;
}
}
private void Expander_Collapsed(object sender, RoutedEventArgs e)
{
if (sender is Expander expander)
{
this.Height -= expandFixedHeight;
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_ = LoadData();
}
private async Task LoadData()
{
//if (viewModel.User != null)
//{
// viewModel.GetGroup();
//}
//if (viewModel.IsRemember)
//{
// var groupIndex = viewModel.Groups.IndexOf(viewModel.Groups.FirstOrDefault(x => x.ID == viewModel.User.UserGroupId));
// this.groupCbx.SelectedIndex = groupIndex;
// var roleIndex = viewModel.Roles.IndexOf(viewModel.Roles.FirstOrDefault(x => x.ID == viewModel.User.UserRoleId));
// this.roleCbx.SelectedIndex = roleIndex;
//}
//if (EplSession.Current.Config != null)
//{
// var serverIndex = viewModel.Servers.IndexOf(viewModel.Servers.FirstOrDefault(x => x.ServerUrl == EplSession.Current.Config.CurrentServer.ServerUrl));
// this.serverCbx.SelectedIndex = serverIndex;
//}
}
private void loginBtn_Click(object sender, RoutedEventArgs e)
{
this.viewModel.User.UserPassword = PasswordTxt.Password;
if (string.IsNullOrWhiteSpace(this.viewModel.User.UserName))
{
this.msgTxt.Text = "请输入用户名!";
this.msgTxt.Foreground = System.Windows.Media.Brushes.Red;
return;
}
if (string.IsNullOrWhiteSpace(this.viewModel.User.UserPassword))
{
this.msgTxt.Text = "请输入密码!";
this.msgTxt.Foreground = System.Windows.Media.Brushes.Red;
return;
}
if (string.IsNullOrWhiteSpace(this.groupCbx.SelectedValue as string))
{
this.msgTxt.Text = "请选择部门!";
this.msgTxt.Foreground = System.Windows.Media.Brushes.Red;
return;
}
if (string.IsNullOrWhiteSpace(this.roleCbx.SelectedValue as string))
{
this.msgTxt.Text = "请选择角色!";
this.msgTxt.Foreground = System.Windows.Media.Brushes.Red;
return;
}
viewModel.User.UserGroup = this.groupCbx.SelectedValue as string;
viewModel.User.UserRole = this.roleCbx.SelectedValue as string;
//try
//{
var result = viewModel.Login();
if(result != null && !string.IsNullOrEmpty(result.GUID))
{
PluginServices.user = new Service.Model.UserInfo
{
Group = viewModel.User.UserGroup,
Role = viewModel.User.UserRole,
//ServerUrl = viewModel.User.ServerUrl,
GUID = result.GUID,
ID = result.ID,
Name = result.Name
};
this.DialogResult = true;
this.Close();
}
else
{
MessageBox.Show("登录失败,请检查用户名和密码是否正确!");
}
// if (result)
// {
// //MessageBox.Show("")
// var serverItem = this.serverCbx.SelectedItem as ServerItemModel;
// //new UserInfo().ShowInfo(viewModel.User.userNickName, serverItem);
// //EplSession.Current.CurServer = serverItem;
// EplSession.Current.SetUser(viewModel.User);
// EplSession.Current.Config.CurrentServer = serverItem;
// EplSession.Current.Config.RememberAccount = this.rememberChk.IsChecked ?? false;
// if (this.rememberChk.IsChecked ?? false)
// {
// viewModel.RememberUser();
// }
// else
// {
// viewModel.ForgetUser();
// }
// // 登录成功,弹出用户信息小窗口
// WindowRouter.ShowWindow("UserInfo", keepAlive: true);
// this.DialogResult = true;
// this.Close();
// }
//}
//catch (System.Exception ex)
//{
// // ERROR 是扩展方法,用于输出错误信息
// ex.ToString().Error();
// //MessageBox.Show(ex.Message);
// msgTxt.Text = ex.Message;
//}
}
private void UsernameTxt_LostFocus(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(UsernameTxt.Text))
{
return;
}
viewModel.User.UserName = UsernameTxt.Text;
LoadGroupAndRole();
}
private void cancelBtn_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private async void groupCbx_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
viewModel.User.UserGroup = this.groupCbx.SelectedValue as string;
await viewModel.GetRolesByCurrentSelect();
if (viewModel.Roles?.Count > 0)
{
await this.Dispatcher.BeginInvoke(() =>
{
this.roleCbx.SelectedIndex = 0;
});
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
#endregion
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
}
private void serverCbx_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//var serverItem = this.serverCbx.SelectedItem as ServerItemModel;
//if (serverItem != null)
//{
// viewModel.ChangeService(serverItem);
// LoadGroupAndRole();
//}
}
private void LoadGroupAndRole()
{
var task = viewModel.GetUserGroup();
task.ContinueWith(x =>
{
this.Dispatcher.InvokeAsync(() =>
{
this.groupCbx.SelectedIndex = 0;
});
});
}
}
}

View File

@ -7,6 +7,7 @@ using EPLAN.Harness.ProjectCore.Occurrences;
using EPLAN.Harness.ProjectCore.Occurrences.Designer;
using HandyControl.Controls;
using HandyControl.Tools.Extension;
using Sinvo.EplanHpD.Plugin.DynaClient.Model;
using Sinvo.EplanHpD.Plugin.Service;
using Sinvo.EplanHpD.Plugin.Service.Model;
using Sinvo.EplanHpD.Plugin.WPFUI.Datas;

View File

@ -1,12 +1,116 @@
using System;
using Sinvo.EplanHpD.Plugin.DynaClient;
using Sinvo.EplanHpD.Plugin.DynaClient.Model;
using Sinvo.EplanHpD.Plugin.Service;
using Sinvo.EplanHpD.Plugin.WPFUI.Models;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sinvo.EplanHpD.Plugin.WPFUI.ViewModel
{
internal class LoginViewModel
public class LoginViewModel: INotifyPropertyChanged
{
private readonly DynaServerClient client = DynaServerClient.GetClient();
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public LoginViewModel()
{
User = new UserLoginModel();
}
private UserLoginModel _user;
public UserLoginModel User
{
get { return _user; }
set
{
_user = value;
OnPropertyChanged(nameof(User));
}
}
private List<UserGroup> _groups;
public List<UserGroup> Groups
{
get { return _groups; }
set
{
_groups = value;
OnPropertyChanged(nameof(Groups));
}
}
private List<UserRole> _roles;
public List<UserRole> Roles
{
get { return _roles; }
set
{
_roles = value;
OnPropertyChanged(nameof(Roles));
}
}
private List<string> _servers;
public List<string> Servers
{
get { return _servers; }
set
{
_servers = value;
OnPropertyChanged(nameof(Servers));
}
}
public async Task<List<UserGroup>> GetUserGroup()
{
return await Task.Run(() =>
{
var userGroup = client.GetUserGroup(User.UserName);
Groups = userGroup;
return userGroup;
});
}
internal Task GetRolesByCurrentSelect()
{
//var client = new DynaServerClient();
var userRoles = client.GetUserRole(User.UserName,User.UserGroup);
Roles = userRoles;
return Task.CompletedTask;
}
internal User Login()
{
try
{
//var client = new DynaServerClient();
// PLM 没有EPLAN的许可所以只能使用SOLW的类型登录
var user = client.Login(User.UserName, User.UserPassword, User.UserRole, User.UserGroup, "SOLW");
#if DEBUG
//client.LoginOut();
#endif
return user;
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
return null;
}
}
}
}

View File

@ -6,6 +6,7 @@ using Sinvo.EplanHpD.Plugin.Service;
using Sinvo.EplanHpD.Plugin.WPFUI;
using Sinvo.EplanHpD.Plugin.WPFUI.Extension;
using Sinvo.EplanHpD.Plugin.WPFUI.Utils;
using Sinvo.EplanHpD.Plugin.WPFUI.View;
using System;
using System.Drawing;
using System.IO;
@ -58,10 +59,23 @@ namespace Sinvo.EplanHpD.Plugin
public void Execute(HpdApi api)
{
bool isLogin = false;
if (!PluginServices.IsLogin)
{
var LoginWindow = new LoginWindow();
if(LoginWindow.ShowDialog() == true)
{
isLogin = PluginServices.IsLogin;
}
}
new DBHelper().CodeFirst();
if (isLogin)
{
var doc = api.CurrentProject.GetActiveDocument();
if(window == null)
if (window == null)
{
window = new LectotypeWindow(doc.ID);
// 获取版本号并显示到窗口标题
@ -81,6 +95,7 @@ namespace Sinvo.EplanHpD.Plugin
window.WindowState = System.Windows.WindowState.Normal;
window.Activate();
}
}
}
@ -91,11 +106,7 @@ namespace Sinvo.EplanHpD.Plugin
AppDomainDllLoader.SetLaoder();
ApplicationExt.InitApplication();
Consts.InitConfigs();
#if DEBUG
var client = new DynaServerClient();
// PLM 没有EPLAN的许可所以只能使用SOLW的类型登录
client.Login("105040", "blank", "ADMINISTRATOR", "ADMINISTRATOR", "SOLW");
#endif
}
}