using FLY.Thick.Blowing.Common;
using FLY.Thick.Blowing.IService;
using FLY.Thick.Blowing.OBJ_INTERFACE;
using FObjBase;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FLY.Thick.Blowing.Client
{
public class BlowingFixProfileServiceClient : FObjServiceClient, IBlowingFixProfileService
{
public BlowingFixProfileServiceClient(UInt32 serviceId) : base(serviceId) { }
public BlowingFixProfileServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { }
#region IProfileService 接口
public BlowingFixProfileParam Param { get; } = new BlowingFixProfileParam();
///
/// 应用 & 保存
///
public void Apply()
{
string json = JsonConvert.SerializeObject(Param);
CurrObjSys.SetValueEx(mConn, mServerID, ID,
BLOWINGFIX_PROFILE_OBJ_INTERFACE.SET_PARAMS,
Misc.Converter.StringToBytes(json));
}
///
/// 获取产品列表, 返回类型为 List<string>
///
///
///
public void GetList(AsyncCBHandler AsyncDelegate, object AsyncState)
{
CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_GETLIST,
null,
AsyncDelegate, AsyncState);
}
///
/// 删除指定产品
///
///
public void Del(string productname)
{
string json = JsonConvert.SerializeObject(productname);
CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_DEL, Misc.Converter.StringToBytes(json));
}
///
/// 读取指定产品,返回类型为 ProfileParam
///
///
///
///
public void Read(string productname, AsyncCBHandler AsyncDelegate, object AsyncState)
{
string json = JsonConvert.SerializeObject(productname);
CurrObjSys.CallFunctionEx(mConn, mServerID, ID,
BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_READ,
Misc.Converter.StringToBytes(json),
AsyncDelegate, AsyncState);
}
#endregion
public override void ConnectNotify(IFConn from)
{
base.ConnectNotify(from);
if (from.IsConnected)
{
//获取所有数据,设置推送
CurrObjSys.GetValueEx(
mConn, mServerID, ID,
BLOWINGFIX_PROFILE_OBJ_INTERFACE.GET_PARAMS);
CurrObjSys.SenseConfigEx(
mConn, mServerID, ID,
0xffffffff,
SENSE_CONFIG.ADD);
}
}
public override void PushGetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
{
switch (memid)
{
case BLOWINGFIX_PROFILE_OBJ_INTERFACE.GET_PARAMS:
{
string json = Misc.Converter.BytesToString(infodata);
BlowingFixProfileParam p = JsonConvert.DeserializeObject(json);
Misc.PropertiesManager.CopyTo(p, Param);
}
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, uint magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState)
{
switch (funcid)
{
case BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_GETLIST:
{
string json = Misc.Converter.BytesToString(retdata);
List p = JsonConvert.DeserializeObject>(json);
((AsyncCBHandler)AsyncDelegate)(AsyncState, p);
}
break;
case BLOWINGFIX_PROFILE_OBJ_INTERFACE.CALL_READ:
{
string json = Misc.Converter.BytesToString(retdata);
BlowingFixProfileParam p = JsonConvert.DeserializeObject(json);
((AsyncCBHandler)AsyncDelegate)(AsyncState, p);
}
break;
}
}
}
}