Commit 33cc7eba authored by 潘栩锋's avatar 潘栩锋 🚴

优化 FObjSys的asyncDelegate 全部都为 AsyncCBHandler

优化 FLY.OBJComponents 匹配 FObjSys的asyncDelegate 的修改 改变
parent 66d3c2b1
...@@ -407,7 +407,7 @@ namespace FObjBase.Reflect ...@@ -407,7 +407,7 @@ namespace FObjBase.Reflect
pushInfoList.Clear(); pushInfoList.Clear();
} }
public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, object asyncDelegate, object asyncContext) public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, AsyncCBHandler asyncDelegate, object asyncContext)
{ {
switch (funcid) switch (funcid)
{ {
...@@ -427,7 +427,7 @@ namespace FObjBase.Reflect ...@@ -427,7 +427,7 @@ namespace FObjBase.Reflect
string json = Misc.Converter.BytesToString(retdata); string json = Misc.Converter.BytesToString(retdata);
var rData = JsonConvert.DeserializeObject<Reflect_OBJ_INTERFACE.ReflectData>(json); var rData = JsonConvert.DeserializeObject<Reflect_OBJ_INTERFACE.ReflectData>(json);
request_CALL_MethodInvoke(rData, (AsyncCBHandler)asyncDelegate, asyncContext); request_CALL_MethodInvoke(rData, asyncDelegate, asyncContext);
} }
break; break;
} }
......
...@@ -13,7 +13,7 @@ namespace FObjBase ...@@ -13,7 +13,7 @@ namespace FObjBase
} }
/// <summary> /// <summary>
/// 建议使用方法: /// 建议使用方法:
/// 做为客户端,都使用 FObjSys.Current 连接不同的客户端 /// 做为客户端,都使用 FObjSys.Current 连接不同的服务器
/// 做为服务器,当要提供2个Obj服务, 应该要使用 Currents[index] /// 做为服务器,当要提供2个Obj服务, 应该要使用 Currents[index]
/// 这套逻辑已经潜入到 每个 FObj 中, FObj.CurrObjSys, 就是对应的 Obj服务 /// 这套逻辑已经潜入到 每个 FObj 中, FObj.CurrObjSys, 就是对应的 Obj服务
/// </summary> /// </summary>
...@@ -323,7 +323,7 @@ namespace FObjBase ...@@ -323,7 +323,7 @@ namespace FObjBase
{ {
Transaction tran = ts.First(); Transaction tran = ts.First();
Transactions.Remove(tran); Transactions.Remove(tran);
PushCallFunction(s1, srcid, destid, magic, funcid, retdata, tran.AsyncDelegate, tran.AsyncState); PushCallFunction(s1, srcid, destid, magic, funcid, retdata, tran.AsyncDelegate, tran.AsyncContext);
} }
else else
{ {
...@@ -338,7 +338,7 @@ namespace FObjBase ...@@ -338,7 +338,7 @@ namespace FObjBase
{ {
PushAny(s1, destid, srcid, magic, infoid, funcid, retdata, null, null); PushAny(s1, destid, srcid, magic, infoid, funcid, retdata, null, null);
} }
void PushAny(IFConn s1, UInt32 destid, UInt32 srcid, UInt32 magic, UInt16 infoid, UInt16 funcid, byte[] retdata, object AsyncDelegate, object AsyncState) void PushAny(IFConn s1, UInt32 destid, UInt32 srcid, UInt32 magic, UInt16 infoid, UInt16 funcid, byte[] retdata, AsyncCBHandler asyncDelegate, object asyncContext)
{ {
if ((retdata != null) && (retdata.Length > Transaction.PackSize)) //参数太大,需要分包多次发送 if ((retdata != null) && (retdata.Length > Transaction.PackSize)) //参数太大,需要分包多次发送
{ {
...@@ -358,15 +358,15 @@ namespace FObjBase ...@@ -358,15 +358,15 @@ namespace FObjBase
Buf = (byte[])retdata.Clone(), Buf = (byte[])retdata.Clone(),
InfoId = infoid, InfoId = infoid,
FuncID = funcid, FuncID = funcid,
AsyncDelegate = AsyncDelegate, AsyncDelegate = asyncDelegate,
AsyncState = AsyncState AsyncContext = asyncContext
}; };
Transactions.Add(t); Transactions.Add(t);
SendBigSize(s1, destid, srcid, magic); SendBigSize(s1, destid, srcid, magic);
} }
else else
{ {
if (AsyncDelegate != null) if (asyncDelegate != null)
{ {
Transaction t = new Transaction() Transaction t = new Transaction()
{ {
...@@ -375,8 +375,8 @@ namespace FObjBase ...@@ -375,8 +375,8 @@ namespace FObjBase
Magic = magic, Magic = magic,
InfoId = infoid, InfoId = infoid,
FuncID = funcid, FuncID = funcid,
AsyncDelegate = AsyncDelegate, AsyncDelegate = asyncDelegate,
AsyncState = AsyncState AsyncContext = asyncContext
}; };
Transactions.Add(t); Transactions.Add(t);
} }
...@@ -599,9 +599,9 @@ namespace FObjBase ...@@ -599,9 +599,9 @@ namespace FObjBase
/// <param name="srcid">本地对象ID</param> /// <param name="srcid">本地对象ID</param>
/// <param name="funcid">函数ID</param> /// <param name="funcid">函数ID</param>
/// <param name="param">函数参数</param> /// <param name="param">函数参数</param>
/// <param name="AsyncDelegate">在其上调用异步调用的委托对象</param> /// <param name="asyncDelegate">在其上调用异步调用的委托对象</param>
/// <param name="AsyncState">作为 BeginInvoke 方法调用的最后一个参数而提供的对象</param> /// <param name="asyncContext">作为 BeginInvoke 方法调用的最后一个参数而提供的对象</param>
public UInt32 CallFunctionEx(IFConn s1, UInt32 destid, UInt32 srcid, UInt16 funcid, byte[] param, object AsyncDelegate, object AsyncState) public UInt32 CallFunctionEx(IFConn s1, UInt32 destid, UInt32 srcid, UInt16 funcid, byte[] param, AsyncCBHandler asyncDelegate, object asyncContext)
{ {
if (s1 == null) if (s1 == null)
return 0; return 0;
...@@ -609,15 +609,15 @@ namespace FObjBase ...@@ -609,15 +609,15 @@ namespace FObjBase
UInt32 magic = GetFreeMagic(); UInt32 magic = GetFreeMagic();
if (s1 is FConnLocal) if (s1 is FConnLocal)
{ {
if ((AsyncDelegate != null) || (AsyncState != null)) //需要返回参数!!! if ((asyncDelegate != null) || (asyncContext != null)) //需要返回参数!!!
{ {
Transaction t = new Transaction() Transaction t = new Transaction()
{ {
Conn = s1, Conn = s1,
SrcObjID = destid, SrcObjID = destid,
Magic = magic, Magic = magic,
AsyncDelegate = AsyncDelegate, AsyncDelegate = asyncDelegate,
AsyncState = AsyncState AsyncContext = asyncContext
}; };
Transactions.Add(t); Transactions.Add(t);
} }
...@@ -625,7 +625,7 @@ namespace FObjBase ...@@ -625,7 +625,7 @@ namespace FObjBase
return magic; return magic;
} }
PushAny(s1, destid, srcid, magic, Proto.INFO_CALL_FUNCTION, funcid, param, AsyncDelegate, AsyncState); PushAny(s1, destid, srcid, magic, Proto.INFO_CALL_FUNCTION, funcid, param, asyncDelegate, asyncContext);
return magic; return magic;
} }
...@@ -713,7 +713,7 @@ namespace FObjBase ...@@ -713,7 +713,7 @@ namespace FObjBase
if (tran.InfoId == Proto.INFO_PUSH_CALL_FUNCTION) if (tran.InfoId == Proto.INFO_PUSH_CALL_FUNCTION)
{ {
//如果是callfunction, 引发进度事件 //如果是callfunction, 引发进度事件
PushCallFunctionBigSizeStatus(conn, p.srcid, p.destid, p.magic, tran.FuncID, tran.Size, tran.Position, tran.AsyncState); PushCallFunctionBigSizeStatus(conn, p.srcid, p.destid, p.magic, tran.FuncID, tran.Size, tran.Position, tran.AsyncContext);
} }
...@@ -730,13 +730,13 @@ namespace FObjBase ...@@ -730,13 +730,13 @@ namespace FObjBase
if (tran.InfoId == Proto.INFO_PUSH_CALL_FUNCTION) if (tran.InfoId == Proto.INFO_PUSH_CALL_FUNCTION)
{ {
//如果是callfunction, 引发进度事件 //如果是callfunction, 引发进度事件
PushCallFunctionBigSizeStatus(conn, p.srcid, p.destid, p.magic, tran.FuncID, tran.Size, tran.Position, tran.AsyncState); PushCallFunctionBigSizeStatus(conn, p.srcid, p.destid, p.magic, tran.FuncID, tran.Size, tran.Position, tran.AsyncContext);
} }
switch (tran.InfoId) switch (tran.InfoId)
{ {
case Proto.INFO_PUSH_CALL_FUNCTION: case Proto.INFO_PUSH_CALL_FUNCTION:
PushCallFunction(conn, p.srcid, p.destid, p.magic, tran.FuncID, tran.Buf, tran.AsyncDelegate, tran.AsyncState); PushCallFunction(conn, p.srcid, p.destid, p.magic, tran.FuncID, tran.Buf, tran.AsyncDelegate, tran.AsyncContext);
break; break;
case Proto.INFO_PUSH_GET_VALUE: case Proto.INFO_PUSH_GET_VALUE:
PushGetValue(conn, p.srcid, p.destid, tran.FuncID, tran.Buf); PushGetValue(conn, p.srcid, p.destid, tran.FuncID, tran.Buf);
...@@ -1041,21 +1041,21 @@ namespace FObjBase ...@@ -1041,21 +1041,21 @@ namespace FObjBase
return; return;
destobj.PushGetValue(from, srcid, infoid, infodata); destobj.PushGetValue(from, srcid, infoid, infodata);
} }
void PushCallFunction(IFConn from, UInt32 srcid, UInt32 destid, UInt32 magic, UInt16 infoid, byte[] infodata, object AsyncDelegate, object AsyncState) void PushCallFunction(IFConn from, UInt32 srcid, UInt32 destid, UInt32 magic, UInt16 infoid, byte[] infodata, AsyncCBHandler asyncDelegate, object asyncContext)
{ {
IFObj destobj = Find(destid); IFObj destobj = Find(destid);
if (destobj == null) if (destobj == null)
return; return;
destobj.PushCallFunction(from, srcid, magic, infoid, infodata, AsyncDelegate, AsyncState); destobj.PushCallFunction(from, srcid, magic, infoid, infodata, asyncDelegate, asyncContext);
} }
void PushCallFunctionBigSizeStatus(IFConn from, UInt32 srcid, UInt32 destid, UInt32 magic, UInt16 infoid, int total_size, int download_size, object AsyncState) void PushCallFunctionBigSizeStatus(IFConn from, UInt32 srcid, UInt32 destid, UInt32 magic, UInt16 infoid, int total_size, int download_size, object asyncContext)
{ {
IFObj destobj = Find(destid); IFObj destobj = Find(destid);
if (destobj == null) if (destobj == null)
return; return;
destobj.PushCallFunctionBigSizeStatus(from, srcid, magic, infoid, total_size, download_size, AsyncState); destobj.PushCallFunctionBigSizeStatus(from, srcid, magic, infoid, total_size, download_size, asyncContext);
} }
int Process(IFConn from, UInt32 srcid, UInt32 destid, UInt32 magic, UInt16 info_no, byte[] infodata, out byte[] retdata) int Process(IFConn from, UInt32 srcid, UInt32 destid, UInt32 magic, UInt16 info_no, byte[] infodata, out byte[] retdata)
...@@ -1126,7 +1126,7 @@ namespace FObjBase ...@@ -1126,7 +1126,7 @@ namespace FObjBase
{ {
Transaction tran = ts.First(); Transaction tran = ts.First();
Transactions.Remove(tran);//用完,删除 Transactions.Remove(tran);//用完,删除
PushCallFunction(conn, p.srcid, p.destid, p.magic, pack.infoid, pack.infodata, tran.AsyncDelegate, tran.AsyncState); PushCallFunction(conn, p.srcid, p.destid, p.magic, pack.infoid, pack.infodata, tran.AsyncDelegate, tran.AsyncContext);
} }
else else
{ {
......
...@@ -54,9 +54,9 @@ namespace FObjBase ...@@ -54,9 +54,9 @@ namespace FObjBase
/// <param name="magic">交易号</param> /// <param name="magic">交易号</param>
/// <param name="funcid">功能ID</param> /// <param name="funcid">功能ID</param>
/// <param name="retdata">回复的数据</param> /// <param name="retdata">回复的数据</param>
/// <param name="AsyncDelegate">以前客户端调用CallFunction时,放入的函数指针</param> /// <param name="asyncDelegate">以前客户端调用CallFunction时,放入的函数指针</param>
/// <param name="AsyncState">以前客户端调用CallFunction时,放入的object</param> /// <param name="asyncContext">以前客户端调用CallFunction时,放入的object</param>
void PushCallFunction(IFConn from, UInt32 srcid, UInt32 magic, UInt16 funcid, byte[] retdata,object AsyncDelegate, object AsyncState); void PushCallFunction(IFConn from, UInt32 srcid, UInt32 magic, UInt16 funcid, byte[] retdata,AsyncCBHandler asyncDelegate, object asyncContext);
/// <summary> /// <summary>
/// 远端消息推送到本地 /// 远端消息推送到本地
...@@ -76,8 +76,8 @@ namespace FObjBase ...@@ -76,8 +76,8 @@ namespace FObjBase
/// <param name="funcid"></param> /// <param name="funcid"></param>
/// <param name="total_size"></param> /// <param name="total_size"></param>
/// <param name="download_size"></param> /// <param name="download_size"></param>
/// <param name="AsyncState"></param> /// <param name="asyncContext"></param>
void PushCallFunctionBigSizeStatus(IFConn from, UInt32 srcid, UInt32 magic, UInt16 funcid, int total_size, int download_size, object AsyncState); void PushCallFunctionBigSizeStatus(IFConn from, UInt32 srcid, UInt32 magic, UInt16 funcid, int total_size, int download_size, object asyncContext);
#endregion #endregion
#region Client->Server #region Client->Server
...@@ -177,9 +177,9 @@ namespace FObjBase ...@@ -177,9 +177,9 @@ namespace FObjBase
/// <param name="magic"></param> /// <param name="magic"></param>
/// <param name="funcid"></param> /// <param name="funcid"></param>
/// <param name="retdata"></param> /// <param name="retdata"></param>
/// <param name="AsyncDelegate"></param> /// <param name="asyncDelegate"></param>
/// <param name="AsyncState"></param> /// <param name="asyncContext"></param>
public virtual void PushCallFunction(IFConn from, uint srcid, UInt32 magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState) public virtual void PushCallFunction(IFConn from, uint srcid, UInt32 magic, ushort funcid, byte[] retdata, AsyncCBHandler asyncDelegate, object asyncContext)
{ {
} }
...@@ -203,8 +203,8 @@ namespace FObjBase ...@@ -203,8 +203,8 @@ namespace FObjBase
/// <param name="funcid"></param> /// <param name="funcid"></param>
/// <param name="total_size"></param> /// <param name="total_size"></param>
/// <param name="download_size"></param> /// <param name="download_size"></param>
/// <param name="AsyncState"></param> /// <param name="asyncContext"></param>
public virtual void PushCallFunctionBigSizeStatus(IFConn from, UInt32 srcid, UInt32 magic, UInt16 funcid, int total_size, int download_size, object AsyncState) public virtual void PushCallFunctionBigSizeStatus(IFConn from, UInt32 srcid, UInt32 magic, UInt16 funcid, int total_size, int download_size, object asyncContext)
{ {
} }
......
...@@ -93,9 +93,9 @@ namespace FObjBase ...@@ -93,9 +93,9 @@ namespace FObjBase
/// <param name="srcid">本地对象ID</param> /// <param name="srcid">本地对象ID</param>
/// <param name="funcid">函数ID</param> /// <param name="funcid">函数ID</param>
/// <param name="param">函数参数</param> /// <param name="param">函数参数</param>
/// <param name="AsyncDelegate">在其上调用异步调用的委托对象</param> /// <param name="asyncDelegate">在其上调用异步调用的委托对象</param>
/// <param name="AsyncState">作为 BeginInvoke 方法调用的最后一个参数而提供的对象</param> /// <param name="asyncContext">作为 BeginInvoke 方法调用的最后一个参数而提供的对象</param>
UInt32 CallFunctionEx(IFConn s1, UInt32 destid, UInt32 srcid, UInt16 funcid, byte[] param, object AsyncDelegate, object AsyncState); UInt32 CallFunctionEx(IFConn s1, UInt32 destid, UInt32 srcid, UInt16 funcid, byte[] param, AsyncCBHandler asyncDelegate, object asyncContext);
/// <summary> /// <summary>
/// 向远端CallFunction /// 向远端CallFunction
......
...@@ -42,12 +42,12 @@ namespace FObjBase ...@@ -42,12 +42,12 @@ namespace FObjBase
/// <summary> /// <summary>
/// callfunction 返回时, 异步回调函数 /// callfunction 返回时, 异步回调函数
/// </summary> /// </summary>
public object AsyncDelegate; public AsyncCBHandler AsyncDelegate;
/// <summary> /// <summary>
/// callfunction 返回时, 异步状态 /// callfunction 返回时, 异步状态
/// </summary> /// </summary>
public object AsyncState; public object AsyncContext;
/// <summary> /// <summary>
/// 动作号 /// 动作号
...@@ -105,7 +105,7 @@ namespace FObjBase ...@@ -105,7 +105,7 @@ namespace FObjBase
Buf = null; Buf = null;
Size = -1; Size = -1;
Position = 0; Position = 0;
if ((AsyncDelegate == null) && (AsyncState == null)) if ((AsyncDelegate == null) && (AsyncContext == null))
{ {
return true; return true;
} }
......
...@@ -105,7 +105,7 @@ namespace FLY.OBJComponents.Client ...@@ -105,7 +105,7 @@ namespace FLY.OBJComponents.Client
} }
} }
public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState) public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, AsyncCBHandler asyncDelegate, object asyncContext)
{ {
switch (funcid) switch (funcid)
{ {
...@@ -114,7 +114,7 @@ namespace FLY.OBJComponents.Client ...@@ -114,7 +114,7 @@ namespace FLY.OBJComponents.Client
{ {
string json = Misc.Converter.BytesToString(retdata); string json = Misc.Converter.BytesToString(retdata);
GetRecordReponse<T> p = JsonConvert.DeserializeObject<GetRecordReponse<T>>(json); GetRecordReponse<T> p = JsonConvert.DeserializeObject<GetRecordReponse<T>>(json);
((AsyncCBHandler)AsyncDelegate)(AsyncState, p); asyncDelegate?.Invoke(asyncContext, p);
} }
break; break;
} }
......
...@@ -102,7 +102,7 @@ namespace FLY.OBJComponents.Client ...@@ -102,7 +102,7 @@ namespace FLY.OBJComponents.Client
/// <param name="objname">对象名</param> /// <param name="objname">对象名</param>
/// <param name="propertynames">属性名</param> /// <param name="propertynames">属性名</param>
/// <param name="planID">计划的编号,应该全局唯一,建议使用时间ticks</param> /// <param name="planID">计划的编号,应该全局唯一,建议使用时间ticks</param>
public void SetPlan(string objname, IEnumerable<string> propertynames, SetPlanReponseHandler setPlanReponse, object context) public void SetPlan(string objname, IEnumerable<string> propertynames, AsyncCBHandler asyncDelegate, object asyncContext)
{ {
PLCOS_OBJ_INTERFACE.Pack_SetPlan2Request pack = new PLCOS_OBJ_INTERFACE.Pack_SetPlan2Request() PLCOS_OBJ_INTERFACE.Pack_SetPlan2Request pack = new PLCOS_OBJ_INTERFACE.Pack_SetPlan2Request()
{ {
...@@ -113,7 +113,7 @@ namespace FLY.OBJComponents.Client ...@@ -113,7 +113,7 @@ namespace FLY.OBJComponents.Client
string json = JsonConvert.SerializeObject(pack); string json = JsonConvert.SerializeObject(pack);
FObjSys.Current.CallFunctionEx(mConn, mServerID, ID, FObjSys.Current.CallFunctionEx(mConn, mServerID, ID,
PLCOS_OBJ_INTERFACE.CALL_SET_PLAN2, Misc.Converter.StringToBytes(json), setPlanReponse, context); PLCOS_OBJ_INTERFACE.CALL_SET_PLAN2, Misc.Converter.StringToBytes(json), asyncDelegate, asyncContext);
} }
#endregion #endregion
...@@ -129,7 +129,7 @@ namespace FLY.OBJComponents.Client ...@@ -129,7 +129,7 @@ namespace FLY.OBJComponents.Client
return null; return null;
} }
public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState) public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, AsyncCBHandler asyncDelegate, object asyncContext)
{ {
switch (funcid) switch (funcid)
{ {
...@@ -137,10 +137,10 @@ namespace FLY.OBJComponents.Client ...@@ -137,10 +137,10 @@ namespace FLY.OBJComponents.Client
{ {
string json = Misc.Converter.BytesToString(retdata); string json = Misc.Converter.BytesToString(retdata);
PLCOS_OBJ_INTERFACE.Pack_SetPlan2Reponse reponse = JsonConvert.DeserializeObject<PLCOS_OBJ_INTERFACE.Pack_SetPlan2Reponse>(json); PLCOS_OBJ_INTERFACE.Pack_SetPlan2Reponse reponse = JsonConvert.DeserializeObject<PLCOS_OBJ_INTERFACE.Pack_SetPlan2Reponse>(json);
SetPlanReponseHandler setPlanReponseHandler = (SetPlanReponseHandler)AsyncDelegate; //SetPlanReponseHandler setPlanReponseHandler = (SetPlanReponseHandler)asyncDelegate;
asyncDelegate(asyncContext, reponse.planid);
setPlanReponseHandler(reponse.planid, AsyncState); //setPlanReponseHandler(reponse.planid, asyncContext);
} }
break; break;
} }
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Misc;
using System.ComponentModel;
using FObjBase;
namespace FLY.Thick.RemoteHistory
{
public class RemoteHistorySerivceClient : FObj, IRemoteHistory
{
IFConn mConn = null;
UInt32 mServerID;
public bool IsConnected;
#region IHistory<T> 成员
private int currdays = 0;
/// <summary>
/// 当前保存的数据天数
/// </summary>
public int CurrDays
{
get { return currdays; }
protected set
{
if (currdays != value)
{
currdays = value;
NotifyPropertyChanged("CurrDays");
}
}
}
private int keeyday;
/// <summary>
/// 数据能保存的天数
/// </summary>
public int KeeyDay
{
get
{
return keeyday;
}
set
{
if (value <= 0)
value = 1;
if (keeyday != value)
{
keeyday = value;
NotifyPropertyChanged("KeeyDay");
}
}
}
private int saverows;
/// <summary>
/// 多少行保存一次
/// </summary>
public int SaveRows
{
get
{
return saverows;
}
set
{
if (saverows != value)
{
saverows = value;
NotifyPropertyChanged("SaveRows");
}
}
}
private int currrows;
/// <summary>
/// 当前总行数
/// </summary>
public int CurrRows
{
get
{
return currrows;
}
protected set
{
if (currrows != value)
{
currrows = value;
NotifyPropertyChanged("CurrRows");
}
}
}
private string currpath = null;
public string CurrPath
{
get
{
return currpath;
}
protected set
{
if (currpath != value)
{
currpath = value;
NotifyPropertyChanged("CurrPath");
}
}
}
#endregion
public RemoteHistorySerivceClient(UInt32 serverid)
{
mServerID = serverid;
}
public void Apply()
{
REMOTEHISTORY_OBJ_INTERFACE.Pack_Params p
= new REMOTEHISTORY_OBJ_INTERFACE.Pack_Params()
{
keeyday = KeeyDay,
saverows = SaveRows
};
CurrObjSys.SetValueEx(
mConn, mServerID, ID,
REMOTEHISTORY_OBJ_INTERFACE.SET_PARAMS, p.ToBytes());
}
public void Flush()
{
CurrObjSys.CallFunctionEx(
mConn, mServerID, ID,
REMOTEHISTORY_OBJ_INTERFACE.CALL_FLUSH, null);
}
public void GetPaths(DateTime dt_begin, DateTime dt_end, string profilename, GetPathsReponseHandler return_func, object state)
{
REMOTEHISTORY_OBJ_INTERFACE.Pack_GetPathsRequest p = new REMOTEHISTORY_OBJ_INTERFACE.Pack_GetPathsRequest()
{
dt_begin = dt_begin,
dt_end = dt_end,
profilename = profilename
};
CurrObjSys.CallFunctionEx(
mConn, mServerID, ID,
REMOTEHISTORY_OBJ_INTERFACE.CALL_GETPATHS, p.ToBytes(), return_func, state);
}
/// <summary>
/// 获取根目录
/// </summary>
public void GetRootPath(GetRootPathReponseHandler return_func, object state)
{
CurrObjSys.CallFunctionEx(
mConn, mServerID, ID,
REMOTEHISTORY_OBJ_INTERFACE.CALL_GETROOTPATH, null, return_func, state);
}
#region INotifyPropertyChanged 成员
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(string propertyname)
{
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyname));
}
#endregion
public override void Dispose()
{
//获取所有数据,设置推送
CurrObjSys.ObjRemove(this, mConn);
}
public override void ConnectNotify(IFConn from)
{
mConn = from;
IsConnected = from.IsConnected;
if (from.IsConnected)
{
//获取所有数据,设置推送
CurrObjSys.GetValueEx(
mConn, mServerID, ID,
REMOTEHISTORY_OBJ_INTERFACE.GET_PARAMS);
CurrObjSys.GetValueEx(
mConn, mServerID, ID,
REMOTEHISTORY_OBJ_INTERFACE.GET_STATE);
CurrObjSys.SenseConfigEx(
mConn, mServerID, ID, 0xffffffff,
SENSE_CONFIG.ADD);
}
}
public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
{
switch (memid)
{
case REMOTEHISTORY_OBJ_INTERFACE.GET_PARAMS:
{
REMOTEHISTORY_OBJ_INTERFACE.Pack_Params p = new REMOTEHISTORY_OBJ_INTERFACE.Pack_Params();
if (p.TryParse(infodata))
{
KeeyDay = p.keeyday;
SaveRows = p.saverows;
}
} break;
case REMOTEHISTORY_OBJ_INTERFACE.GET_STATE:
{
REMOTEHISTORY_OBJ_INTERFACE.Pack_State p = new REMOTEHISTORY_OBJ_INTERFACE.Pack_State();
if (p.TryParse(infodata))
{
CurrRows = p.currrows;
CurrPath = p.currpath;
CurrDays = p.currdays;
}
} break;
}
}
public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
{
PushGetValue(from, srcid, infoid, infodata);
}
public override void PushCallFunction(IFConn from, uint srcid, UInt32 magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState)
{
switch (funcid)
{
case REMOTEHISTORY_OBJ_INTERFACE.CALL_GETPATHS:
{
REMOTEHISTORY_OBJ_INTERFACE.Pack_GetPathsResponse p = new REMOTEHISTORY_OBJ_INTERFACE.Pack_GetPathsResponse();
if (!p.TryParse(retdata))
return;
GetPathsReponseHandler func = (GetPathsReponseHandler)AsyncDelegate;
func(p.paths, AsyncState);
}break;
case REMOTEHISTORY_OBJ_INTERFACE.CALL_GETROOTPATH:
{
REMOTEHISTORY_OBJ_INTERFACE.Pack_GetRootPathResponse p = new REMOTEHISTORY_OBJ_INTERFACE.Pack_GetRootPathResponse();
if (!p.TryParse(retdata))
return;
GetRootPathReponseHandler func = (GetRootPathReponseHandler)AsyncDelegate;
func(p.rootpath, AsyncState);
}break;
}
}
}
}
...@@ -39,8 +39,9 @@ namespace FLY.OBJComponents.Client ...@@ -39,8 +39,9 @@ namespace FLY.OBJComponents.Client
if (((PLCProxySystemServiceClient)PLCos).IsConnected) if (((PLCProxySystemServiceClient)PLCos).IsConnected)
{ {
PLCos.SetPlan( this.objname, this.propertynames, (planid, context) => PLCos.SetPlan( this.objname, this.propertynames, (asyncContext,retData) =>
{ {
long planid = (long)retData;
this.planid = planid; this.planid = planid;
timer.Start(); timer.Start();
}, null); }, null);
...@@ -53,8 +54,9 @@ namespace FLY.OBJComponents.Client ...@@ -53,8 +54,9 @@ namespace FLY.OBJComponents.Client
{ {
if (((PLCProxySystemServiceClient)PLCos).IsConnected) if (((PLCProxySystemServiceClient)PLCos).IsConnected)
{ {
PLCos.SetPlan(objname, propertynames, (planid, context) => PLCos.SetPlan(objname, propertynames, (asyncContext, retData) =>
{ {
long planid = (long)retData;
this.planid = planid; this.planid = planid;
timer.Start(); timer.Start();
}, null); }, null);
......
...@@ -223,7 +223,7 @@ namespace FLY.OBJComponents.Client ...@@ -223,7 +223,7 @@ namespace FLY.OBJComponents.Client
pushDataList.Clear(); pushDataList.Clear();
} }
public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState) public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, AsyncCBHandler asyncDelegate, object asyncContext)
{ {
switch (funcid) switch (funcid)
{ {
...@@ -238,7 +238,7 @@ namespace FLY.OBJComponents.Client ...@@ -238,7 +238,7 @@ namespace FLY.OBJComponents.Client
{ {
if (ObjNames.ContainsKey(Dso.Key)) if (ObjNames.ContainsKey(Dso.Key))
{ {
INotifyPropertyChanged obj = ObjNames[Dso.Key] as INotifyPropertyChanged; INotifyPropertyChanged obj = ObjNames[Dso.Key];
obj.PropertyChanged -= Data_PropertyChanged; obj.PropertyChanged -= Data_PropertyChanged;
foreach (var dv in Dso.Value) foreach (var dv in Dso.Value)
{ {
......
...@@ -52,7 +52,6 @@ ...@@ -52,7 +52,6 @@
<Compile Include="Client\BufferServiceClient.cs" /> <Compile Include="Client\BufferServiceClient.cs" />
<Compile Include="Client\JsonDistServiceClient.cs" /> <Compile Include="Client\JsonDistServiceClient.cs" />
<Compile Include="Client\PLCProxySystemServiceClient.cs" /> <Compile Include="Client\PLCProxySystemServiceClient.cs" />
<Compile Include="Client\RemoteHistorySerivceClient.cs" />
<Compile Include="Client\SetPLCUpdatePlan.cs" /> <Compile Include="Client\SetPLCUpdatePlan.cs" />
<Compile Include="Client\SyncPropServiceClient.cs" /> <Compile Include="Client\SyncPropServiceClient.cs" />
<Compile Include="Client\WarningSystem2ServiceClient.cs" /> <Compile Include="Client\WarningSystem2ServiceClient.cs" />
......
using System; using FObjBase;
using FObjBase.Reflect;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
...@@ -34,7 +36,8 @@ namespace FLY.OBJComponents.IService ...@@ -34,7 +36,8 @@ namespace FLY.OBJComponents.IService
/// <param name="objname">对象名</param> /// <param name="objname">对象名</param>
/// <param name="propertynames">属性名</param> /// <param name="propertynames">属性名</param>
/// <param name="planID">计划的编号,应该全局唯一,建议使用时间ticks</param> /// <param name="planID">计划的编号,应该全局唯一,建议使用时间ticks</param>
void SetPlan(string objname, IEnumerable<string> propertynames, SetPlanReponseHandler setPlanReponse, object context); [Call(typeof(long))]
void SetPlan(string objname, IEnumerable<string> propertynames, AsyncCBHandler asyncDelegate, object asyncContext);
/// <summary> /// <summary>
/// 更新计划持续,如果不喂狗,120s后停止更新数据 /// 更新计划持续,如果不喂狗,120s后停止更新数据
...@@ -48,6 +51,4 @@ namespace FLY.OBJComponents.IService ...@@ -48,6 +51,4 @@ namespace FLY.OBJComponents.IService
/// <param name="planID"></param> /// <param name="planID"></param>
void RemovePlan(long planID); void RemovePlan(long planID);
} }
public delegate void SetPlanReponseHandler(long planid, object context);
} }
...@@ -47,9 +47,10 @@ namespace FLY.OBJComponents.Server.OBJProxy ...@@ -47,9 +47,10 @@ namespace FLY.OBJComponents.Server.OBJProxy
{ {
string json = Misc.Converter.BytesToString(infodata); string json = Misc.Converter.BytesToString(infodata);
PLCOS_OBJ_INTERFACE.Pack_SetPlan2Request pack = JsonConvert.DeserializeObject<PLCOS_OBJ_INTERFACE.Pack_SetPlan2Request>(json); PLCOS_OBJ_INTERFACE.Pack_SetPlan2Request pack = JsonConvert.DeserializeObject<PLCOS_OBJ_INTERFACE.Pack_SetPlan2Request>(json);
plcos.SetPlan(pack.objname, pack.propertyNames, (planid, context) => plcos.SetPlan(pack.objname, pack.propertyNames, (asyncContext, retData) =>
{ {
ConnContext conn = context as ConnContext; ConnContext conn = asyncContext as ConnContext;
long planid = (long)retData;
PLCOS_OBJ_INTERFACE.Pack_SetPlan2Reponse p = new PLCOS_OBJ_INTERFACE.Pack_SetPlan2Reponse() { planid = planid }; PLCOS_OBJ_INTERFACE.Pack_SetPlan2Reponse p = new PLCOS_OBJ_INTERFACE.Pack_SetPlan2Reponse() { planid = planid };
string s = JsonConvert.SerializeObject(p); string s = JsonConvert.SerializeObject(p);
CurrObjSys.PushCallFunctionEx(conn.from, srcid, ID, magic, funcid, Misc.Converter.StringToBytes(s)); CurrObjSys.PushCallFunctionEx(conn.from, srcid, ID, magic, funcid, Misc.Converter.StringToBytes(s));
......
...@@ -8,6 +8,7 @@ using FLY.Modbus; ...@@ -8,6 +8,7 @@ using FLY.Modbus;
using System.Windows.Threading; using System.Windows.Threading;
using System.IO; using System.IO;
using Newtonsoft.Json; using Newtonsoft.Json;
using FObjBase;
namespace FLY.OBJComponents.Server namespace FLY.OBJComponents.Server
{ {
...@@ -281,11 +282,11 @@ namespace FLY.OBJComponents.Server ...@@ -281,11 +282,11 @@ namespace FLY.OBJComponents.Server
/// <param name="objname">对象名称</param> /// <param name="objname">对象名称</param>
/// <param name="propertynames"></param> /// <param name="propertynames"></param>
/// <param name="planID">计划的编号,应该全局唯一,建议使用时间ticks</param> /// <param name="planID">计划的编号,应该全局唯一,建议使用时间ticks</param>
public void SetPlan(string objname, IEnumerable<string> propertynames, SetPlanReponseHandler reponseHandler, object context) public void SetPlan(string objname, IEnumerable<string> propertynames, AsyncCBHandler asyncDelegate, object asyncContext)
{ {
long planID = GetFreePlanID(); long planID = GetFreePlanID();
SetPlan(objname, propertynames, planID); SetPlan(objname, propertynames, planID);
reponseHandler(planID, context); asyncDelegate?.Invoke(asyncContext, planID);
} }
/// <summary> /// <summary>
/// 更新计划持续,如果不喂狗,20s后停止更新数据 /// 更新计划持续,如果不喂狗,20s后停止更新数据
......
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