Commit 9e6a0e4b authored by 潘栩锋's avatar 潘栩锋 🚴

优化 IPLCProxySystemService 直接使用 Reflect_ServiceClient 作为远程代理

添加 Reflect_ServiceClient 添加 数据改变时,判断是否服务器发送过来的数据
修改 SetPLCUpdatePlan 修改 接口 函数 的参数
parent 33cc7eba
...@@ -27,6 +27,12 @@ namespace FObjBase.Reflect ...@@ -27,6 +27,12 @@ namespace FObjBase.Reflect
/// 已经收到了 CALL_GetAllProperties, 全部属性都与服务器一致 /// 已经收到了 CALL_GetAllProperties, 全部属性都与服务器一致
/// </summary> /// </summary>
public bool IsSynced { get; private set; } public bool IsSynced { get; private set; }
/// <summary>
/// 当前 INotifyPropertyChanged 对象 引发了 PropertyChanged, 是由于 接收到数据导致的
/// </summary>
public bool IsInPushValue { get; protected set; }
class AnyEvent class AnyEvent
{ {
public string name; public string name;
...@@ -268,7 +274,7 @@ namespace FObjBase.Reflect ...@@ -268,7 +274,7 @@ namespace FObjBase.Reflect
void request_PUSH_PropertyChanged(Reflect_OBJ_INTERFACE.ReflectData rData) void request_PUSH_PropertyChanged(Reflect_OBJ_INTERFACE.ReflectData rData)
{ {
ignoreSet = true; ignoreSet = true;
IsInPushValue = true;
var node = COMMON.FindNode(rootNode, rData.name); var node = COMMON.FindNode(rootNode, rData.name);
if (node == null) if (node == null)
{ {
...@@ -280,7 +286,7 @@ namespace FObjBase.Reflect ...@@ -280,7 +286,7 @@ namespace FObjBase.Reflect
string json = rData.data.ToString(); string json = rData.data.ToString();
JsonConvert.PopulateObject(json, node.Obj); JsonConvert.PopulateObject(json, node.Obj);
IsInPushValue = false;
ignoreSet = false; ignoreSet = false;
} }
void request_PUSH_Event(Reflect_OBJ_INTERFACE.ReflectData rData) void request_PUSH_Event(Reflect_OBJ_INTERFACE.ReflectData rData)
......
...@@ -10,90 +10,33 @@ using System.Text; ...@@ -10,90 +10,33 @@ using System.Text;
namespace FLY.OBJComponents.Client namespace FLY.OBJComponents.Client
{ {
public class PLCProxySystemServiceClient : FObj, IPLCProxySystemService, IPropertyOpt public class PLCProxySystemServiceClient : FObjBase.Reflect.Reflect_SeviceClient, IPLCProxySystemService
{ {
public Dictionary<string, INotifyPropertyChanged> ObjNames { get; private set; } protected override Type InterfaceType => typeof(IPLCProxySystemService);
public bool IsConnected { get; private set; } = false;
SyncPropServiceClient syncPropServiceClient;
/// <summary> /// <summary>
/// 与PLC连接成功 /// 与PLC连接成功
/// </summary> /// </summary>
public bool IsConnectedWithPLC { get; set; } = false; public bool IsConnectedWithPLC { get; set; } = false;
public PLCProxySystemServiceClient(UInt32 serviceId) : base(serviceId) { }
public PLCProxySystemServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { }
IFConn mConn;
UInt32 mServerID;
public event PropertyChangedEventHandler PropertyChanged;
public PLCProxySystemServiceClient(UInt32 serverID, Dictionary<string, INotifyPropertyChanged> objnames)
{
mServerID = serverID;
ObjNames = objnames;
syncPropServiceClient = new SyncPropServiceClient(
serverID + 1,
new Dictionary<string, INotifyPropertyChanged> {
{".", this }
});
}
public UInt32[] GetIDs()
{
return new UInt32[] { ID,
syncPropServiceClient.ID
};
}
public override void ConnectNotify(IFConn from)
{
mConn = from;
IsConnected = from.IsConnected;
if (from.IsConnected)
{
CurrObjSys.SenseConfigEx(mConn, mServerID, ID,
0xffffffff, SENSE_CONFIG.ADD);
}
}
#region IPLCProxySystemService #region IPLCProxySystemService
public void FeedPlan(long planID) public void FeedPlan(long planID)
{ {
PLCOS_OBJ_INTERFACE.Pack_FeedPlanRequest pack = new PLCOS_OBJ_INTERFACE.Pack_FeedPlanRequest() Call(nameof(FeedPlan), new { planID });
{
planid = planID
};
string json = JsonConvert.SerializeObject(pack);
FObjSys.Current.CallFunctionEx(mConn, mServerID, ID,
PLCOS_OBJ_INTERFACE.CALL_FEED_PLAN, Misc.Converter.StringToBytes(json));
} }
public void RemovePlan(long planID) public void RemovePlan(long planID)
{ {
PLCOS_OBJ_INTERFACE.Pack_RemovePlanRequest pack = new PLCOS_OBJ_INTERFACE.Pack_RemovePlanRequest() Call(nameof(RemovePlan), new { planID });
{
planid = planID
};
string json = JsonConvert.SerializeObject(pack);
FObjSys.Current.CallFunctionEx(mConn, mServerID, ID,
PLCOS_OBJ_INTERFACE.CALL_REMOVE_PLAN, Misc.Converter.StringToBytes(json));
} }
public void SetPlan(string objname, IEnumerable<string> propertynames, long planID) public void SetPlan(string objname, IEnumerable<string> propertynames, long planID)
{ {
PLCOS_OBJ_INTERFACE.Pack_SetPlanRequest pack = new PLCOS_OBJ_INTERFACE.Pack_SetPlanRequest() Call(nameof(SetPlan), new { objname, propertynames, planID });
{
objname = objname,
propertyNames = propertynames,
planid = planID
};
string json = JsonConvert.SerializeObject(pack);
FObjSys.Current.CallFunctionEx(mConn, mServerID, ID,
PLCOS_OBJ_INTERFACE.CALL_SET_PLAN, Misc.Converter.StringToBytes(json));
} }
/// <summary> /// <summary>
...@@ -104,47 +47,8 @@ namespace FLY.OBJComponents.Client ...@@ -104,47 +47,8 @@ namespace FLY.OBJComponents.Client
/// <param name="planID">计划的编号,应该全局唯一,建议使用时间ticks</param> /// <param name="planID">计划的编号,应该全局唯一,建议使用时间ticks</param>
public void SetPlan(string objname, IEnumerable<string> propertynames, AsyncCBHandler asyncDelegate, object asyncContext) public void SetPlan(string objname, IEnumerable<string> propertynames, AsyncCBHandler asyncDelegate, object asyncContext)
{ {
PLCOS_OBJ_INTERFACE.Pack_SetPlan2Request pack = new PLCOS_OBJ_INTERFACE.Pack_SetPlan2Request() Call(nameof(SetPlan), new { objname, propertynames}, asyncDelegate, asyncContext);
{
objname = objname,
propertyNames = propertynames,
};
string json = JsonConvert.SerializeObject(pack);
FObjSys.Current.CallFunctionEx(mConn, mServerID, ID,
PLCOS_OBJ_INTERFACE.CALL_SET_PLAN2, Misc.Converter.StringToBytes(json), asyncDelegate, asyncContext);
} }
#endregion #endregion
public string[] GetSyncPropNames()
{
return new string[] {
nameof(IsConnectedWithPLC)
};
}
public string[] GetNoSyncPropNames()
{
return null;
}
public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, AsyncCBHandler asyncDelegate, object asyncContext)
{
switch (funcid)
{
case PLCOS_OBJ_INTERFACE.CALL_SET_PLAN2:
{
string json = Misc.Converter.BytesToString(retdata);
PLCOS_OBJ_INTERFACE.Pack_SetPlan2Reponse reponse = JsonConvert.DeserializeObject<PLCOS_OBJ_INTERFACE.Pack_SetPlan2Reponse>(json);
//SetPlanReponseHandler setPlanReponseHandler = (SetPlanReponseHandler)asyncDelegate;
asyncDelegate(asyncContext, reponse.planid);
//setPlanReponseHandler(reponse.planid, asyncContext);
}
break;
}
}
} }
} }
...@@ -16,14 +16,14 @@ namespace FLY.OBJComponents.Client ...@@ -16,14 +16,14 @@ namespace FLY.OBJComponents.Client
string objname; string objname;
IEnumerable<string> propertynames; IEnumerable<string> propertynames;
public SetPLCUpdatePlan(IPLCProxySystemService plsos, INotifyPropertyChanged obj, IEnumerable<string> propertynames) public SetPLCUpdatePlan(IPLCProxySystemService plsos, string objname, IEnumerable<string> propertynames)
{ {
PLCos = plsos; PLCos = plsos;
this.propertynames = propertynames; this.propertynames = propertynames;
this.objname = PLCos.ObjNames.First((kv) => kv.Value == obj).Key; this.objname = objname;// PLCos.ObjNames.First((kv) => kv.Value == obj).Key;
PLCos.PropertyChanged += PLCos_PropertyChanged;
timer = new DispatcherTimer()//120s 内必须再次注册 timer = new DispatcherTimer()//120s 内必须再次注册
{ {
...@@ -37,22 +37,42 @@ namespace FLY.OBJComponents.Client ...@@ -37,22 +37,42 @@ namespace FLY.OBJComponents.Client
} }
}; };
if (((PLCProxySystemServiceClient)PLCos).IsConnected) if(IsTimeToSetPlan())
{ {
PLCos.SetPlan( this.objname, this.propertynames, (asyncContext,retData) => PLCos.SetPlan(this.objname, this.propertynames, (asyncContext, retData) =>
{ {
long planid = (long)retData; long planid = (long)retData;
this.planid = planid; this.planid = planid;
timer.Start(); timer.Start();
}, null); }, null);
} }
} if (PLCos is PLCProxySystemServiceClient)
PLCos.PropertyChanged += PLCos_PropertyChanged;
}
bool IsTimeToSetPlan()
{
if (PLCos is PLCProxySystemServiceClient)
{
var _PLCos = PLCos as PLCProxySystemServiceClient;
if (_PLCos.IsConnected)
{
return true;
}
else {
return false;
}
}
else {
return true;
}
}
private void PLCos_PropertyChanged(object sender, PropertyChangedEventArgs e) private void PLCos_PropertyChanged(object sender, PropertyChangedEventArgs e)
{ {
if (e.PropertyName == "IsConnected") if (e.PropertyName == nameof(PLCProxySystemServiceClient.IsConnected))
{ {
if (((PLCProxySystemServiceClient)PLCos).IsConnected) var _PLCos = PLCos as PLCProxySystemServiceClient;
if (_PLCos.IsConnected)
{ {
PLCos.SetPlan(objname, propertynames, (asyncContext, retData) => PLCos.SetPlan(objname, propertynames, (asyncContext, retData) =>
{ {
......
...@@ -17,10 +17,6 @@ namespace FLY.OBJComponents.IService ...@@ -17,10 +17,6 @@ namespace FLY.OBJComponents.IService
/// 与PLC连接成功 /// 与PLC连接成功
/// </summary> /// </summary>
bool IsConnectedWithPLC { get; } bool IsConnectedWithPLC { get; }
/// <summary>
/// 对象名称
/// </summary>
Dictionary<string, INotifyPropertyChanged> ObjNames { get; }
/// <summary> /// <summary>
/// 设置更新计划 /// 设置更新计划
......
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