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

修复 SyncPropServiceClient GetAllData是大包,很有机会先收到Push,最后再收到 GetAllData

parent e7b34840
......@@ -26,6 +26,19 @@ namespace FLY.OBJComponents.Client
/// </summary>
public bool IsInPushValue { get;protected set; }
/// <summary>
/// 同步完成
/// </summary>
public bool IsSynced { get; private set; }
/// <summary>
/// 缓存 发出 GetAllData指令,到收到回复 之间时段的 全部推送
/// </summary>
List<Dictionary<string, Dictionary<string, object>>> pushDataList = new List<Dictionary<string, Dictionary<string, object>>>();
/// <summary>
/// Add 函数, 添加的 objname, 必须等全部 都返回。 只要 addObjNameList.Count() 不为0, 也是要缓存 推送的
/// </summary>
List<string> addObjNameList = new List<string>();
public SyncPropServiceClient(UInt32 serverID, Dictionary<string, INotifyPropertyChanged> objnames)
{
......@@ -62,6 +75,11 @@ namespace FLY.OBJComponents.Client
ObjNames.Add(objname, obj);
//向服务器,只获取这个对象的数据
//暂停接收推送。。。。
IsSynced = false;
addObjNameList.Add(objname);
string json = JsonConvert.SerializeObject(objname);
FObjBase.FObjSys.Current.CallFunctionEx(mConn, mServerID, ID, SYNCPROP_OBJ_INTERFACE.CALL_GET_DATA,
Misc.Converter.StringToBytes(json));
......@@ -125,6 +143,9 @@ namespace FLY.OBJComponents.Client
{
mConn = from;
IsSynced = false;
pushDataList.Clear();
if (from.IsConnected)
{
CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
......@@ -134,8 +155,11 @@ namespace FLY.OBJComponents.Client
CurrObjSys.SenseConfigEx(mConn, mServerID, ID,
0xffffffff, SENSE_CONFIG.ADD);
}
}
public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
{
switch (infoid)
......@@ -144,10 +168,19 @@ namespace FLY.OBJComponents.Client
{
string json = Misc.Converter.BytesToString(infodata);
Dictionary<string, Dictionary<string, object>> DsDso = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, object>>>(json);
if (!IsSynced)
{
//还没同步完成,先缓存
pushDataList.Add(DsDso);
return;
}
IsInPushValue = true;
foreach (var Dso in DsDso)
{
INotifyPropertyChanged obj = ObjNames[Dso.Key] as INotifyPropertyChanged;
INotifyPropertyChanged obj = ObjNames[Dso.Key];
obj.PropertyChanged -= Data_PropertyChanged;
foreach (var dv in Dso.Value)
......@@ -162,12 +195,65 @@ namespace FLY.OBJComponents.Client
break;
}
}
/// <summary>
/// 处理全部 缓存的推送数据
/// </summary>
void DealPushDataList()
{
IsInPushValue = true;
for (int i = 0; i < pushDataList.Count(); i++)
{
var DsDso = pushDataList[i];
foreach (var Dso in DsDso)
{
INotifyPropertyChanged obj = ObjNames[Dso.Key];
obj.PropertyChanged -= Data_PropertyChanged;
foreach (var dv in Dso.Value)
{
PropertiesManager_JSON.SetValue(obj, dv.Key, dv.Value);
}
obj.PropertyChanged += Data_PropertyChanged;
}
}
IsInPushValue = false;
pushDataList.Clear();
}
public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState)
{
switch (funcid)
{
case SYNCPROP_OBJ_INTERFACE.CALL_GET_ALL_DATA:
{
//这个可能是大包来的,很慢,需要记录中途全部 push
string json = Misc.Converter.BytesToString(retdata);
//log.Debug("GetAllData:" +json);
Dictionary<string, Dictionary<string, object>> DsDso = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, object>>>(json);
IsInPushValue = true;
foreach (var Dso in DsDso)
{
if (ObjNames.ContainsKey(Dso.Key))
{
INotifyPropertyChanged obj = ObjNames[Dso.Key] as INotifyPropertyChanged;
obj.PropertyChanged -= Data_PropertyChanged;
foreach (var dv in Dso.Value)
{
PropertiesManager_JSON.SetValue(obj, dv.Key, dv.Value);
}
obj.PropertyChanged += Data_PropertyChanged;
}
}
IsInPushValue = false;
//完成同步
IsSynced = true;
//处理之前的推送事件
DealPushDataList();
}
break;
case SYNCPROP_OBJ_INTERFACE.CALL_GET_DATA:
{
string json = Misc.Converter.BytesToString(retdata);
Dictionary<string, Dictionary<string, object>> DsDso = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, object>>>(json);
......@@ -184,8 +270,19 @@ namespace FLY.OBJComponents.Client
}
obj.PropertyChanged += Data_PropertyChanged;
}
addObjNameList.Remove(Dso.Key);
}
IsInPushValue = false;
//全部接收完!!!
if (addObjNameList.Count() == 0)
{
//完成同步
IsSynced = true;
//处理之前的推送事件
DealPushDataList();
}
}
break;
}
......
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