This repository has been archived by the owner on Jun 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathQuikDDE.cs
196 lines (191 loc) · 5.5 KB
/
QuikDDE.cs
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
namespace QuikDDE
{
using System;
using System.IO;
using System.Text;
using NDde.Server;
using QuikDDE;
public class DdeData : EventArgs
{
private xlTable _xlData;
private string _topicname;
private string _item;
public DdeData(byte[] data, string topicname, string itemname) : base()
{
this._xlData = new xlTable(data);
this._item = itemname;
this._topicname = topicname;
}
public xlTable DataTable
{
get
{
return this._xlData;
}
}
public string TopicName
{
get
{
string str;
str = !(!(this._topicname[0] == '[')) ? this._topicname.Substring(1, this._topicname.LastIndexOf(']') - 1) : this._topicname;
return str;
}
}
public string ItemName
{
get
{
return this._item;
}
}
}
public class ddesrv : DdeServer
{
public ddesrv(string service) : base(service)
{
}
public override void Register()
{
base.Register();
}
public override void Unregister()
{
base.Unregister();
}
protected override DdeServer.PokeResult OnPoke(DdeConversation conversation, string item, byte[] data, int format)
{
StreamWriter streamWriter = new StreamWriter("ddedatalength.txt", true);
streamWriter.WriteLine(string.Concat("Data length: ", data.Length.ToString()));
streamWriter.Close();
FileStream fileStream = new FileStream("ddedata.txt", FileMode.Append);
fileStream.Write(data, 0, data.Length);
fileStream.Dispose();
Data(new DdeData(data, conversation.Topic, item));
return DdeServer.PokeResult.Processed;
}
protected virtual void Data(DdeData e)
{
if (!(OnPokeData == null))
{
OnPokeData(this, e);
}
}
public delegate void DdeEventHandler(object sender, DdeData e);
public event ddesrv.DdeEventHandler OnPokeData;
}
public class xlTable
{
private int _rows;
private int _cols;
private string[,] _table;
public xlTable(byte[] data) : base()
{
Update(data, 0);
}
public xlTable(byte[] data, int StartIndex) : base()
{
Update(data, StartIndex);
}
private void Update(byte[] data, int _StartIndx)
{
int i;
int i1;
int i2;
int i3;
int i6;
bool bl;
i = _StartIndx;
i1 = 0;
i2 = 0;
i3 = 0;
i6 = 0;
while ((i < data.Length))
{
switch (data[i])
{
case 0:
i++;
break;
case 1:
i3 = data[i + 2];
i6 = i + 4;
while ((i6 < (i3 + i6)))
{
string[,][i1, i2] = BitConverter.ToDouble(data, i6).ToString();
i2++;
bl = !(i2 == this._cols);
if (!bl)
{
i1++;
i2 = 0;
}
i6 += 8;
}
i = i6 + i3;
break;
case 2:
i3 = data[i + 2];
i6 = i + 4;
while ((i6 < (i6 + i3)))
{
string[,][i1, i2] = Encoding.Default.GetString(data, i6 + 1, data[i6]);
i2++;
bl = !(i2 == this._cols);
if (!bl)
{
i1++;
i2 = 0;
}
i6 += data[i6];
i6++;
}
i = i6 + i3;
break;
case 16:
i3 = data[2];
this._rows = data[4];
this._cols = data[6];
this._table = new string[this._rows, this._cols];
i = 8;
break;
}
}
}
private enum DataType
{
Empty = 0,
Table = 16,
Float = 1,
String = 2,
Bool = 3,
Error = 4,
Blank = 5,
Int = 6,
Skip = 7,
}
public int RowsCount
{
get
{
return this._rows;
}
}
public int ColsCount
{
get
{
return this._cols;
}
}
public string this[int RowID, int ColID]
{
get
{
string str;
str = !((ColID >= this._cols ? false : RowID < this._rows)) ? null : string[,][RowID, ColID];
return str;
}
}
}
}