Commit d4b589f3 authored by 潘栩锋's avatar 潘栩锋 🚴

把绝大部分,都改为使用 unity

parent 4c66ef23
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FObjBase
{
/// <summary>
/// FObj 客户端
/// </summary>
public class FObjServiceClient : FObj,INotifyPropertyChanged
{
/// <summary>
/// 服务Id
/// </summary>
protected UInt32 mServerID;
/// <summary>
/// 连接器
/// </summary>
protected IFConn mConn;
/// <summary>
/// 连接成功
/// </summary>
public bool IsConnected { get; set; }
/// <summary>
/// 使用 服务Id初始化, 还需要 Connect_to_Another_OBJSys
/// </summary>
/// <param name="id"></param>
public FObjServiceClient(UInt32 id)
{
mServerID = id;
}
/// <summary>
/// 使用全局地址字典初始化, 不需要再 手动 Connect_to_Another_OBJSys
/// </summary>
/// <param name="serviceId"></param>
/// <param name="connName"></param>
public FObjServiceClient(UInt32 serviceId, string connName) : this(serviceId)
{
FObjServiceClientManager.Instance.Connect_to_Another_OBJSys(connName, this);
}
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
/// <summary>
/// 连接通知
/// </summary>
/// <param name="from"></param>
public override void ConnectNotify(IFConn from)
{
mConn = from;
IsConnected = from.IsConnected;
}
/// <summary>
/// 注销
/// </summary>
public override void Dispose()
{
CurrObjSys.ObjRemove(
this, mConn);
}
public virtual UInt32[] GetIDs()
{
return new UInt32[] { ID };
}
}
}
using FObjBase;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace FObjBase
{
/// <summary>
/// 管理全部 XxxxServiceClient 的连接关系
/// </summary>
[JsonObject(MemberSerialization.OptIn)]
public class FObjServiceClientManager
{
NLog.ILogger logger = NLog.LogManager.GetCurrentClassLogger();
private static FObjServiceClientManager instance = null;
/// <summary>
/// 全局管理器
/// </summary>
public static FObjServiceClientManager Instance
{
get {
if (instance == null)
{
instance = new FObjServiceClientManager();
instance.Load();
}
return instance;
}
}
/// <summary>
/// 连接地址
/// </summary>
[JsonProperty]
public List<ConnAddr> ConnAddrs = new List<ConnAddr>();
/// <summary>
/// 连接到 另一个Obj系统
/// </summary>
/// <param name="connName"></param>
/// <param name="fObjClient"></param>
/// <returns></returns>
public void Connect_to_Another_OBJSys(string connName, FObjServiceClient fObjClient)
{
//找到地址
var connaddr = ConnAddrs.Find(c => c.ConnName == connName);
if (connaddr == null)
{
//没有,那就创建一个
connaddr = new ConnAddr() { ConnName = connName, Addr = "127.0.0.1:20006" };
}
foreach (var id in fObjClient.GetIDs())
{
if (!connaddr.ClientIds.Contains(id))
{
connaddr.ClientIds.Add(id);
connaddr.Conn = FObjSys.Current.Connect_to_Another_OBJSys(connaddr.ep, id);
}
}
}
/// <summary>
/// 重连
/// </summary>
/// <param name="connName"></param>
/// <param name="addr"></param>
public void ReConnect(string connName, string addr)
{
//找到地址
var connaddr = ConnAddrs.Find(c => c.ConnName == connName);
if (connaddr == null)
{
//没有!!!!,失败!!!
logger.Error($"ReConnect({connaddr},{addr}), 不能找到 ConnAddr");
return;
}
if (connaddr.Conn != null)
{
var conn = connaddr.Conn;
if (!conn.RemoteEP.Equals(Misc.StringConverter.ToIPEndPoint(addr)))
{
//断开之前的连接
FObjSys.Current.Disconnect_to_Another_OBJSys(conn.RemoteEP, connaddr.ClientIds.ToArray());
}
}
connaddr.Conn = FObjSys.Current.Connect_to_Another_OBJSys(connaddr.ep, connaddr.ClientIds.ToArray());
}
string filename = "serviceManager.json";
/// <summary>
/// 加载配置
/// </summary>
public void Load()
{
if (File.Exists(filename))
{
try
{
string json = File.ReadAllText(filename);
JsonConvert.PopulateObject(json, this);
if (this.ConnAddrs == null)
this.ConnAddrs = new List<ConnAddr>();
}
catch
{
}
}
}
/// <summary>
/// 保存配置
/// </summary>
public void Save()
{
try
{
string json = JsonConvert.SerializeObject(this, Formatting.Indented);
File.WriteAllText(filename, json);
}
catch
{
}
}
}
/// <summary>
/// 连接地址
/// </summary>
[JsonObject(MemberSerialization.OptIn)]
public class ConnAddr
{
/// <summary>
/// 连接器名称
/// </summary>
[JsonProperty]
public string ConnName;
/// <summary>
/// 设备地址
/// </summary>
[JsonProperty]
public string Addr;
/// <summary>
/// EndPoint
/// </summary>
public IPEndPoint ep
{
get {
return Misc.StringConverter.ToIPEndPoint(Addr);
}
}
/// <summary>
/// 连接
/// </summary>
public TCPCConn Conn;
/// <summary>
/// 客户端 服务代理Id
/// </summary>
public List<UInt32> ClientIds = new List<UInt32>();
}
}
<?xml version="1.0" encoding="utf-8"?>
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<PropertyChanged />
</Weavers>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="PropertyChanged" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="InjectOnPropertyNameChanged" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if the On_PropertyName_Changed feature is enabled.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="EventInvokerNames" type="xs:string">
<xs:annotation>
<xs:documentation>Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEquality" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="CheckForEqualityUsingBaseEquals" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="UseStaticEqualsFromBase" type="xs:boolean">
<xs:annotation>
<xs:documentation>Used to control if equality checks should use the static Equals method resolved from the base class.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
\ No newline at end of file
using FObjBase;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace FLY.OBJComponents.Client
{
/// <summary>
/// 管理全部 XxxxServiceClient 的连接关系
/// </summary>
[JsonObject(MemberSerialization.OptIn)]
public class ObjServiceClientManager
{
NLog.ILogger logger = NLog.LogManager.GetCurrentClassLogger();
private static ObjServiceClientManager instance = null;
public static ObjServiceClientManager Instance
{
get {
if (instance == null)
{
instance = new ObjServiceClientManager();
instance.Load();
}
return instance;
}
}
[JsonProperty]
public List<ConnAddr> ConnAddrs = new List<ConnAddr>();
[JsonProperty]
public List<ObjServiceClientInfo> ClientInfos = new List<ObjServiceClientInfo>();
public UInt32 Connect_to_Another_OBJSys(string connName, string serviceName, FObj fObj)
{
//找到地址
var connaddr = ConnAddrs.Find(c => c.ConnName == connName);
if (connaddr == null)
{
//没有!!!!,失败!!!
logger.Error($"{connName}.{serviceName} 需要连接到服务器,但找不到 {connName}");
return 0;
}
//找服务Id
var clientInfo = ClientInfos.Find(c => c.ConnName == connName && c.ServiceName == serviceName);
if (clientInfo == null)
{
//没有!!!!,失败!!!
logger.Error($"{connName}.{serviceName} 需要连接到服务器,但找不到 服务Id");
return 0;
}
clientInfo.ClientId = fObj.ID;
connaddr.conn = FObjSys.Current.Connect_to_Another_OBJSys(connaddr.ep, clientInfo.ClientId);
return clientInfo.ServiceId;
}
public void ReConnect(string connName, string addr)
{
//找到地址
var connaddr = ConnAddrs.Find(c => c.ConnName == connName);
if (connaddr == null)
{
//没有!!!!,失败!!!
logger.Error($"ReConnect({connaddr},{addr}), 不能找到 ConnAddr");
return;
}
if (connaddr.conn != null)
{
var conn = connaddr.conn;
if (!conn.RemoteEP.Equals(Misc.StringConverter.ToIPEndPoint(addr)))
{
//断开之前的连接
FObjSys.Current.Disconnect_to_Another_OBJSys(conn.RemoteEP, GetAllClientIds(connaddr.ConnName));
}
}
connaddr.conn = FObjSys.Current.Connect_to_Another_OBJSys(connaddr.ep, GetAllClientIds(connaddr.ConnName));
}
UInt32[] GetAllClientIds(string connName)
{
return ClientInfos.FindAll(c => c.ConnName == connName && c.ClientId != 0).Select(c => c.ClientId).ToArray();
}
string filename = "serviceManager.json";
public void Load()
{
if (File.Exists(filename))
{
try
{
string json = File.ReadAllText(filename);
JsonConvert.PopulateObject(json, this);
if (this.ConnAddrs == null)
this.ConnAddrs = new List<ConnAddr>();
if (this.ClientInfos == null)
this.ClientInfos = new List<ObjServiceClientInfo>();
}
catch
{
}
}
}
public void Save()
{
try
{
string json = JsonConvert.SerializeObject(this, Formatting.Indented);
File.WriteAllText(filename, json);
}
catch
{
}
}
}
public class ObjServiceClientInfo
{
/// <summary>
/// 连接器名称
/// </summary>
public string ConnName;
/// <summary>
/// 服务名称, 客户端 在 unity的名称
/// </summary>
public string ServiceName;
/// <summary>
/// 服务Id
/// </summary>
public UInt32 ServiceId;
[JsonIgnore]
public UInt32 ClientId;
}
public class ConnAddr
{
/// <summary>
/// 连接器名称
/// </summary>
public string ConnName;
/// <summary>
/// 设备地址
/// </summary>
public string Addr;
public IPEndPoint ep
{
get {
return Misc.StringConverter.ToIPEndPoint(Addr);
}
}
[JsonIgnore]
public TCPCConn conn;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ThickTcpUiInWindow
{
public class WarningReasonWindow: FLY.OBJComponents.Client.BufferWindow<FLY.OBJComponents.Common.FlyData_WarningHistory>
{
public WarningReasonWindow(FLY.OBJComponents.IService.IWarningService warningService, int size):
base(warningService.ReasonList, size)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Unity;
namespace FLY.UI.Module
{
public interface IUiModule2
{
/// <summary>
/// 控件标题
/// 它的值取决于culture
/// </summary>
string Title { get; }
/// <summary>
/// 控件类型
/// </summary>
ComponentType Type { get; }
/// <summary>
/// 只能有一个
/// </summary>
bool IsUnique { get; }
/// <summary>
/// 控件
/// 创建时,需要给它唯一ID,让加载自己的数据
/// </summary>
/// <param name="id">唯一ID</param>
/// <returns></returns>
FrameworkElement GetComponent(int id, IUnityContainer unityContainer);
/// <summary>
/// 控件缩略图,用于编辑界面时,大致看看
/// </summary>
/// <returns></returns>
FrameworkElement GetThumbnail();
/// <summary>
/// 给出全部控件ID, 控件自行删除没有的参数
/// </summary>
/// <param name="IDs"></param>
void MatchParam(int[] IDs);
}
[Flags]
public enum ComponentType
{
/// <summary>
/// 动态区
/// </summary>
DynArea,
/// <summary>
/// 图表区
/// </summary>
Graph,
/// <summary>
/// 参数设置页
/// </summary>
Menu
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment