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

把 JSONDIST 改为 使用 object.reflect

parent b115f761
......@@ -83,7 +83,7 @@ namespace FLY.OBJComponents.Client
private void BufferWindow_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Size")
if (e.PropertyName == nameof(Size))
{
if (Size < 10)
Size = 10;
......@@ -91,11 +91,11 @@ namespace FLY.OBJComponents.Client
updatePageInfo();
GetWindow();
}
else if (e.PropertyName == "WindowID")
else if (e.PropertyName == nameof(WindowID))
{
updatePageInfo();
}
else if (e.PropertyName == "IsKeepNewest")
else if (e.PropertyName == nameof(IsKeepNewest))
{
}
......@@ -130,8 +130,8 @@ namespace FLY.OBJComponents.Client
private void Buffer_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if ((e.PropertyName == "Count") ||
(e.PropertyName == "NewestID"))
if ((e.PropertyName == nameof(Buffer.Count)) ||
(e.PropertyName == nameof(Buffer.NewestID)))
{
updatePageInfo();
}
......
......@@ -11,89 +11,32 @@ using System.Threading.Tasks;
namespace FLY.OBJComponents.Client
{
public class JsonDistServiceClient : FObjServiceClient, IJsonDistService
public class JsonDistServiceClient : FObjBase.Reflect.Reflect_SeviceClient, IJsonDistService
{
public event JsonDistValueChangedEventHandler ValueChanged;
protected override Type InterfaceType => typeof(IJsonDistService);
public JsonDistServiceClient(UInt32 serviceId) : base(serviceId) { }
public JsonDistServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { }
public void GetValue(string key, AsyncCBHandler asyncCB, object asyncContext)
{
var request = new JSONDIST_OBJ_INTERFACE.Pack_CallGetValueRequest()
{
key = key
};
string json = JsonConvert.SerializeObject(request);
public event EventHandler ValueChanged;
CurrObjSys.CallFunctionEx(mConn, mServerID, ID, JSONDIST_OBJ_INTERFACE.CALL_GetValue,
Misc.Converter.StringToBytes(json),
asyncCB, asyncContext
);
}
public void SetValue(string key, JObject value)
public void Trigger_ValueChanged(JsonDistValueChangedEventArgs e)
{
var request = new JSONDIST_OBJ_INTERFACE.Pack_CallSetValueRequest()
{
key = key,
value = value
};
string json = JsonConvert.SerializeObject(request);
CurrObjSys.CallFunctionEx(mConn, mServerID, ID, JSONDIST_OBJ_INTERFACE.CALL_SetValue,
Misc.Converter.StringToBytes(json)
);
ValueChanged?.Invoke(this, e);
}
public override void Dispose()
public void GetValue(string key, AsyncCBHandler asyncDelegate, object asyncContext)
{
CurrObjSys.ObjRemove(
this, mConn);
Call(nameof(GetValue), new { key }, asyncDelegate, asyncContext);
}
public override void ConnectNotify(IFConn from)
{
base.ConnectNotify(from);
if (from.IsConnected)
{
CurrObjSys.SenseConfigEx(
mConn, mServerID, ID,
0xffffffff,
SENSE_CONFIG.ADD);
}
}
public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
{
switch (infoid)
{
case JSONDIST_OBJ_INTERFACE.PUSH_ValueChanged:
{
string json = Misc.Converter.BytesToString(infodata);
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<JsonDistValueValueChangedEventArgs>(json);
ValueChanged?.Invoke(this, new JsonDistValueValueChangedEventArgs() { key = p.key });
} break;
}
}
public override void PushCallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] retdata, object asyncDelegate, object asyncContext)
public void SetValue(string key, JObject value)
{
switch (funcid)
{
case JSONDIST_OBJ_INTERFACE.CALL_GetValue:
{
string json = Misc.Converter.BytesToString(retdata);
var p = JsonConvert.DeserializeObject<DistCell>(json);
((AsyncCBHandler)asyncDelegate)(asyncContext, p);
} break;
}
Call(nameof(SetValue), new { key, value });
}
}
}
......@@ -68,14 +68,12 @@
<Compile Include="IService\IRemoteHistory.cs" />
<Compile Include="IService\IWarningService.cs" />
<Compile Include="OBJ_INTERFACE\BUFFER_OBJ_INTERFACE.cs" />
<Compile Include="OBJ_INTERFACE\JSONDIST_OBJ_INTERFACE.cs" />
<Compile Include="OBJ_INTERFACE\PLCOS_OBJ_INTERFACE.cs" />
<Compile Include="OBJ_INTERFACE\REMOTEHISTORY_OBJ_INTERFACE.cs" />
<Compile Include="OBJ_INTERFACE\SYNCPROP_OBJ_INTERFACE.cs" />
<Compile Include="OBJ_INTERFACE\WARNING_OBJ_INTERFACE.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Server.OBJProxy\Buffer_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\JsonDist_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\PLCProxySystem_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\RemoteHistory_OBJProxy.cs" />
<Compile Include="Server.OBJProxy\SyncProp_OBJProxy.cs" />
......@@ -101,6 +99,10 @@
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Project.FLY.FObjSys\FObjBaseReflect\FObjBase.Reflect.csproj">
<Project>{15f40c32-d546-4b2a-8d80-b3ddbcdaa690}</Project>
<Name>FObjBase.Reflect</Name>
</ProjectReference>
<ProjectReference Include="..\..\Project.FLY.FObjSys\FObjSys\FObjBase.csproj">
<Project>{abfe87d4-b692-4ae9-a8c0-1f470b8acbb8}</Project>
<Name>FObjBase</Name>
......
......@@ -44,17 +44,17 @@ namespace FLY.OBJComponents.IService
/// </summary>
/// <param name="last_id">最后的ID</param>
/// <param name="count">数量</param>
/// <param name="asyncCB">回调</param>
/// <param name="asyncDelegate">回调</param>
/// <param name="asyncContext">回调里面的上下文</param>
void GetRecord(int last_id, int count, AsyncCBHandler asyncCB, object asyncContext);
void GetRecord(int last_id, int count, AsyncCBHandler asyncDelegate, object asyncContext);
/// <summary>
/// 获取最新的N个数据
/// </summary>
/// <param name="count">数量</param>
/// <param name="asyncCB">回调</param>
/// <param name="asyncDelegate">回调</param>
/// <param name="asyncContext">回调里面的上下文</param>
void GetRecord(int count, AsyncCBHandler asyncCB, object asyncContext);
void GetRecord(int count, AsyncCBHandler asyncDelegate, object asyncContext);
}
public class GetRecordReponse<T>
{
......
using FObjBase;
using FObjBase.Reflect;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
......@@ -11,10 +12,16 @@ namespace FLY.OBJComponents.IService
{
public interface IJsonDistService
{
void GetValue(string key, AsyncCBHandler asyncCB, object asyncContext);
[Call(typeof(DistCell))]
void GetValue(string key, AsyncCBHandler asyncDelegate, object asyncContext);
void SetValue(string key, JObject value);
event JsonDistValueChangedEventHandler ValueChanged;
//event JsonDistValueChangedEventHandler ValueChanged;
[Push(typeof(JsonDistValueChangedEventArgs))]
event EventHandler ValueChanged;
}
public class DistCell
{
......@@ -27,9 +34,9 @@ namespace FLY.OBJComponents.IService
}
}
public delegate void JsonDistValueChangedEventHandler(object sender, JsonDistValueValueChangedEventArgs e);
public delegate void JsonDistValueChangedEventHandler(object sender, JsonDistValueChangedEventArgs e);
public class JsonDistValueValueChangedEventArgs
public class JsonDistValueChangedEventArgs: EventArgs
{
public string key;
}
......
using FLY.OBJComponents.IService;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FLY.OBJComponents.OBJ_INTERFACE
{
public class JSONDIST_OBJ_INTERFACE
{
#region Pack
public class Pack_CallGetValueRequest
{
public string key;
}
public class Pack_CallGetValueReponse
{
public DistCell distCell;
}
public class Pack_CallSetValueRequest
{
public string key;
public JObject value;
}
#endregion
#region SetValue
#endregion
#region GetValue
#endregion
#region PushMsg
/// <summary>
/// JsonDistValueValueChangedEventArgs
/// </summary>
public const UInt16 PUSH_ValueChanged = 0;
#endregion
#region Call
/// <summary>
/// request:Pack_CallGetValueRequest
/// reponse:Pack_CallGetValueReponse
/// </summary>
public const UInt16 CALL_GetValue = 1;
/// <summary>
/// request:Pack_CallSetValueRequest
/// reponse:null
/// </summary>
public const UInt16 CALL_SetValue = 2;
#endregion
}
}
using FLY.OBJComponents.IService;
using FLY.OBJComponents.OBJ_INTERFACE;
using FObjBase;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FLY.OBJComponents.Server.OBJProxy
{
public class JsonDist_OBJProxy : FObj
{
IJsonDistService jsonDist;
public JsonDist_OBJProxy(int objsys_idx, UInt32 id, IJsonDistService jsonDist)
: base(objsys_idx)
{
ID = id;
this.jsonDist = jsonDist;
this.jsonDist.ValueChanged += JsonDist_ValueChanged;
}
private void JsonDist_ValueChanged(object sender, JsonDistValueValueChangedEventArgs e)
{
string j = JsonConvert.SerializeObject(e);
CurrObjSys.PushObjInfoEx(
this, JSONDIST_OBJ_INTERFACE.PUSH_ValueChanged,
Misc.Converter.StringToBytes(j));
}
public override void CallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] infodata)
{
switch (funcid)
{
case JSONDIST_OBJ_INTERFACE.CALL_GetValue:
{
string json = Misc.Converter.BytesToString(infodata);
var request = JsonConvert.DeserializeObject< JSONDIST_OBJ_INTERFACE.Pack_CallGetValueRequest> (json);
jsonDist.GetValue(request.key,
(asyncContext, retData) =>
{
string j = JsonConvert.SerializeObject(retData);
CurrObjSys.PushCallFunctionEx(
from,
srcid, ID,
magic, funcid, Misc.Converter.StringToBytes(j));
}, null);
}
break;
case JSONDIST_OBJ_INTERFACE.CALL_SetValue:
{
string json = Misc.Converter.BytesToString(infodata);
var request = JsonConvert.DeserializeObject<JSONDIST_OBJ_INTERFACE.Pack_CallSetValueRequest>(json);
jsonDist.SetValue(request.key, request.value);
}
break;
}
}
}
}
......@@ -126,13 +126,13 @@ namespace FLY.OBJComponents.Server
/// </summary>
/// <param name="last_id">最后的ID</param>
/// <param name="count">数量</param>
/// <param name="asyncCB">回调</param>
/// <param name="asyncDelegate">回调</param>
/// <param name="asyncContext">回调里面的上下文</param>
public async void GetRecord(int last_id, int count, AsyncCBHandler asyncCB, object asyncContext)
public async void GetRecord(int last_id, int count, AsyncCBHandler asyncDelegate, object asyncContext)
{
if (Count == 0)
{
asyncCB(asyncContext, new GetRecordReponse<TLc>()
asyncDelegate(asyncContext, new GetRecordReponse<TLc>()
{
LastID = 0,
Items = null
......@@ -152,7 +152,7 @@ namespace FLY.OBJComponents.Server
}
reponse.Items = lcs;
asyncCB(asyncContext, reponse);
asyncDelegate(asyncContext, reponse);
});
}
......@@ -161,11 +161,11 @@ namespace FLY.OBJComponents.Server
/// 获取最新的N个数据
/// </summary>
/// <param name="count">数量</param>
/// <param name="asyncCB">回调</param>
/// <param name="asyncDelegate">回调</param>
/// <param name="asyncContext">回调里面的上下文</param>
public void GetRecord(int count, AsyncCBHandler asyncCB, object asyncContext)
public void GetRecord(int count, AsyncCBHandler asyncDelegate, object asyncContext)
{
GetRecord(NewestID, count, asyncCB, asyncContext);
GetRecord(NewestID, count, asyncDelegate, asyncContext);
}
}
......@@ -277,13 +277,13 @@ namespace FLY.OBJComponents.Server
/// </summary>
/// <param name="last_id">最后的ID</param>
/// <param name="count">数量</param>
/// <param name="asyncCB">回调</param>
/// <param name="asyncDelegate">回调</param>
/// <param name="asyncContext">回调里面的上下文</param>
public async void GetRecord(int last_id, int count, AsyncCBHandler asyncCB, object asyncContext)
public async void GetRecord(int last_id, int count, AsyncCBHandler asyncDelegate, object asyncContext)
{
if (Count == 0)
{
asyncCB(asyncContext, new GetRecordReponse<TDb>()
asyncDelegate(asyncContext, new GetRecordReponse<TDb>()
{
LastID = 0,
Items = null
......@@ -297,7 +297,7 @@ namespace FLY.OBJComponents.Server
var dbs = dbTable.Find($"ORDER BY ID LIMIT {last_id - count + 1},{count}");
reponse.LastID = last_id;
reponse.Items = dbs;
asyncCB(asyncContext, reponse);
asyncDelegate(asyncContext, reponse);
});
}
......@@ -308,9 +308,9 @@ namespace FLY.OBJComponents.Server
/// <param name="count">数量</param>
/// <param name="asyncCB">回调</param>
/// <param name="asyncContext">回调里面的上下文</param>
public void GetRecord(int count, AsyncCBHandler asyncCB, object asyncContext)
public void GetRecord(int count, AsyncCBHandler asyncDelegate, object asyncContext)
{
GetRecord(NewestID, count, asyncCB, asyncContext);
GetRecord(NewestID, count, asyncDelegate, asyncContext);
}
}
}
......@@ -18,7 +18,7 @@ namespace FLY.OBJComponents.Server
public class JsonDist : IJsonDistService
{
public event JsonDistValueChangedEventHandler ValueChanged;
public event EventHandler ValueChanged;
List<DistCell> cells = new List<DistCell>();
......@@ -28,10 +28,10 @@ namespace FLY.OBJComponents.Server
}
public void GetValue(string key, AsyncCBHandler asyncCB, object asyncContext)
public void GetValue(string key, AsyncCBHandler asyncDelegate, object asyncContext)
{
var distCell = cells.Find(c => c.Key == key);
asyncCB(asyncContext, distCell);
asyncDelegate(asyncContext, distCell);
}
public void SetValue(string key, JObject value)
......@@ -51,7 +51,7 @@ namespace FLY.OBJComponents.Server
distCell.Time = DateTime.Now;
distCell.Value = value;
}
ValueChanged?.Invoke(this, new JsonDistValueValueChangedEventArgs() { key = key });
ValueChanged?.Invoke(this, new JsonDistValueChangedEventArgs() { key = key });
Save();
}
......
......@@ -60,7 +60,7 @@ namespace FLY.Thick.Base.UI
private void ObjServiceClient_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsConnected")
if (e.PropertyName == nameof(FObjServiceClient.IsConnected))
{
var objServiceClient = sender as FObjServiceClient;
if (objServiceClient.IsConnected)
......@@ -70,16 +70,17 @@ namespace FLY.Thick.Base.UI
}
}
}
private void JsonDist_ValueChanged(object sender, JsonDistValueValueChangedEventArgs e)
private void JsonDist_ValueChanged(object sender, EventArgs _e)
{
if (e.key == JSONDIST_KEY)
var e = _e as JsonDistValueChangedEventArgs;
if (e.key == JSONDIST_KEY)
{
fetch_db();
}
}
void check_db()
{
if (DbDefault == null)
......
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