1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using FLY.OBJComponents.Common;
using FLY.OBJComponents.IService;
using FLY.OBJComponents.OBJ_INTERFACE;
using FLY.Thick.RemoteHistory;
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 Buffer_OBJProxy<T> : FObj
{
const int MARKNO_PUSH_STATUS = 1;
const int MARKNO_PUSH_PARAMS = 2;
IBuffer<T> buffer;
public Buffer_OBJProxy(int objsys_idx, UInt32 id, IBuffer<T> buffer)
: base(objsys_idx)
{
ID = id;
this.buffer = buffer;
buffer.BufferChanged += Buffer_BufferChanged;
buffer.PropertyChanged += Buffer_PropertyChanged;
}
private void Buffer_BufferChanged(object sender, NotifyBufferChangedEventArgs<T> e)
{
string j = JsonConvert.SerializeObject(e);
CurrObjSys.PushObjInfoEx(
this, BUFFER_OBJ_INTERFACE.PUSH_BUFFERCHANGED,
Misc.Converter.StringToBytes(j));
}
private void Buffer_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if ((e.PropertyName == "NewestID") ||
(e.PropertyName == "Count"))
{
FObjBase.PollModule.Current.Poll_JustOnce(() =>
{
byte[] buf;
GetValue(null, 0, BUFFER_OBJ_INTERFACE.GET_STATUS, out buf);
CurrObjSys.PushObjInfoEx(
this, BUFFER_OBJ_INTERFACE.GET_STATUS,
buf);
}, this, MARKNO_PUSH_STATUS);
}
if (e.PropertyName == "Capacity")
{
FObjBase.PollModule.Current.Poll_JustOnce(() =>
{
byte[] buf;
GetValue(null, 0, BUFFER_OBJ_INTERFACE.GET_PARAMS, out buf);
CurrObjSys.PushObjInfoEx(
this, BUFFER_OBJ_INTERFACE.GET_PARAMS,
buf);
}, this, MARKNO_PUSH_PARAMS);
}
}
public override void SetValue(IFConn from, uint srcid, ushort memid, byte[] infodata)
{
switch (memid)
{
case BUFFER_OBJ_INTERFACE.SET_PARAMS:
{
string json = Misc.Converter.BytesToString(infodata);
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<BUFFER_OBJ_INTERFACE.Pack_Params>(json);
buffer.Capacity = p.capcity;
}
break;
}
}
public override void GetValue(IFConn from, uint srcid, ushort memid, out byte[] infodata)
{
switch (memid)
{
case BUFFER_OBJ_INTERFACE.GET_PARAMS:
{
var p = new BUFFER_OBJ_INTERFACE.Pack_Params()
{
capcity = buffer.Capacity
};
string json = JsonConvert.SerializeObject(p);
infodata = Misc.Converter.StringToBytes(json);
}
break;
case BUFFER_OBJ_INTERFACE.GET_STATUS:
{
var p = new BUFFER_OBJ_INTERFACE.Pack_Status()
{
newestId = buffer.NewestID,
count = buffer.Count
};
string json = JsonConvert.SerializeObject(p);
infodata = Misc.Converter.StringToBytes(json);
}
break;
default:
infodata = null;
break;
}
}
public override void CallFunction(IFConn from, uint srcid, uint magic, ushort funcid, byte[] infodata)
{
switch (funcid)
{
case BUFFER_OBJ_INTERFACE.CALL_GETRECORD:
{
string json = Misc.Converter.BytesToString(infodata);
BUFFER_OBJ_INTERFACE.Pack_GetRecordRequest request = JsonConvert.DeserializeObject<BUFFER_OBJ_INTERFACE.Pack_GetRecordRequest>(json);
buffer.GetRecord(request.last_id, request.count,
(asyncContext, retData) =>
{
ConnContext connContext = asyncContext as ConnContext;
string j = JsonConvert.SerializeObject(retData);
CurrObjSys.PushCallFunctionEx(
connContext.from,
connContext.srcid, ID,
connContext.magic, BUFFER_OBJ_INTERFACE.CALL_GETRECORD, Misc.Converter.StringToBytes(j));
}, new ConnContext(from, srcid, magic));
}
break;
case BUFFER_OBJ_INTERFACE.CALL_GETRECORD_NEWEST:
{
string json = Misc.Converter.BytesToString(infodata);
BUFFER_OBJ_INTERFACE.Pack_GetRecordNewestRequest request = JsonConvert.DeserializeObject<BUFFER_OBJ_INTERFACE.Pack_GetRecordNewestRequest>(json);
buffer.GetRecord(request.count,
(asyncContext, retData) =>
{
ConnContext connContext = asyncContext as ConnContext;
GetRecordReponse<T> reponse = retData as GetRecordReponse<T>;
string j = JsonConvert.SerializeObject(reponse);
CurrObjSys.PushCallFunctionEx(
connContext.from,
connContext.srcid, ID,
connContext.magic, funcid, Misc.Converter.StringToBytes(j));
}, new ConnContext(from, srcid, magic));
}
break;
case BUFFER_OBJ_INTERFACE.CALL_RESET:
{
buffer.Reset();
}break;
}
}
}
}