DrawingToolInfo.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. using System;
  2. using System.IO;
  3. namespace MuchInfo.Chart.Data
  4. {
  5. /// <summary>
  6. /// Class DrawingToolInfo
  7. /// </summary>
  8. public class DrawingToolInfo
  9. {
  10. public long DrawingID;
  11. public Guid DrawingGUID;
  12. public int ContactID;
  13. public int? SymbolID;
  14. public string Symbol;
  15. public DateTime Created;
  16. public DateTime Updated;
  17. public long? TimeFrame;
  18. public Guid? ScaleGUID;
  19. public short? DrawType;
  20. public DateTime? P1Date;
  21. public float? P1Val;
  22. public DateTime? P2Date;
  23. public float? P2Val;
  24. public DateTime? P3Date;
  25. public float? P3Val;
  26. public int? Color1;
  27. public int? Color2;
  28. public bool? Bool1;
  29. public bool? Bool2;
  30. public string XML;
  31. public bool isDeleted;
  32. public bool DrawOnAllSymbols;
  33. public short CreatedIn;
  34. public short LastEditedIn;
  35. public string ChartID;
  36. public DrawingToolInfo()
  37. {
  38. this.Created = DateTime.Now;
  39. this.Updated = DateTime.Now;
  40. this.isDeleted = false;
  41. this.DrawOnAllSymbols = false;
  42. this.CreatedIn = 1;
  43. this.LastEditedIn = 1;
  44. }
  45. public DrawingToolInfo Copy()
  46. {
  47. var memoryStream = new MemoryStream();
  48. DrawingToolInfo result;
  49. try
  50. {
  51. while (true)
  52. {
  53. BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
  54. try
  55. {
  56. while (true)
  57. {
  58. BinaryReader binaryReader = new BinaryReader(memoryStream);
  59. try
  60. {
  61. this.toBytes(binaryWriter);
  62. memoryStream.Position = (0L);
  63. result = DrawingToolInfo.fromBytes(binaryReader);
  64. return result;
  65. }
  66. finally
  67. {
  68. bool flag = binaryReader != null;
  69. if (flag)
  70. {
  71. binaryReader.Dispose();
  72. }
  73. }
  74. }
  75. }
  76. finally
  77. {
  78. bool flag = binaryWriter != null;
  79. if (flag)
  80. {
  81. binaryWriter.Dispose();
  82. }
  83. }
  84. }
  85. }
  86. finally
  87. {
  88. bool flag = memoryStream != null;
  89. if (flag)
  90. {
  91. memoryStream.Dispose();
  92. }
  93. }
  94. //return result;
  95. }
  96. public Guid OriginalScaleGUID()
  97. {
  98. if (!string.IsNullOrEmpty(ChartID) && this.ChartID.StartsWith("ORIGSCALEGUID|"))
  99. {
  100. return new Guid(this.ChartID.Substring("ORIGSCALEGUID|".Length));
  101. }
  102. return Guid.Empty;
  103. }
  104. public static DrawingToolInfo fromBytes(BinaryReader read)
  105. {
  106. bool flag = read.ReadByte() == 1;
  107. DrawingToolInfo result;
  108. if (flag)
  109. {
  110. var drawingToolInfo = new DrawingToolInfo();
  111. drawingToolInfo.DrawingID = read.ReadInt64();
  112. drawingToolInfo.DrawingGUID = new Guid(read.ReadBytes(16));
  113. drawingToolInfo.ContactID = read.ReadInt32();
  114. flag = (read.ReadByte() == 1);
  115. if (flag)
  116. {
  117. drawingToolInfo.SymbolID = read.ReadInt32();
  118. }
  119. drawingToolInfo.Symbol = read.ReadString();
  120. drawingToolInfo.Created = new DateTime(read.ReadInt64());
  121. drawingToolInfo.Updated = new DateTime(read.ReadInt64());
  122. flag = (read.ReadByte() == 1);
  123. if (flag)
  124. {
  125. drawingToolInfo.TimeFrame = read.ReadInt64();
  126. }
  127. flag = (read.ReadByte() == 1);
  128. if (flag)
  129. {
  130. DrawingToolInfo arg_E5_0 = drawingToolInfo;
  131. Guid guid = new Guid(read.ReadBytes(16));
  132. arg_E5_0.ScaleGUID = guid;
  133. }
  134. flag = (read.ReadByte() == 1);
  135. if (flag)
  136. {
  137. drawingToolInfo.DrawType = read.ReadInt16();
  138. }
  139. flag = (read.ReadByte() == 1);
  140. if (flag)
  141. {
  142. DrawingToolInfo arg_12E_0 = drawingToolInfo;
  143. DateTime dateTime = new DateTime(read.ReadInt64());
  144. arg_12E_0.P1Date = dateTime;
  145. }
  146. flag = (read.ReadByte() == 1);
  147. if (flag)
  148. {
  149. drawingToolInfo.P1Val = read.ReadSingle();
  150. }
  151. flag = (read.ReadByte() == 1);
  152. if (flag)
  153. {
  154. DrawingToolInfo arg_177_0 = drawingToolInfo;
  155. DateTime dateTime = new DateTime(read.ReadInt64());
  156. arg_177_0.P2Date = dateTime;
  157. }
  158. flag = (read.ReadByte() == 1);
  159. if (flag)
  160. {
  161. drawingToolInfo.P2Val = read.ReadSingle();
  162. }
  163. flag = (read.ReadByte() == 1);
  164. if (flag)
  165. {
  166. DrawingToolInfo arg_1C0_0 = drawingToolInfo;
  167. DateTime dateTime = new DateTime(read.ReadInt64());
  168. arg_1C0_0.P3Date = dateTime;
  169. }
  170. flag = (read.ReadByte() == 1);
  171. if (flag)
  172. {
  173. drawingToolInfo.P3Val = read.ReadSingle();
  174. }
  175. flag = (read.ReadByte() == 1);
  176. if (flag)
  177. {
  178. drawingToolInfo.Color1 = read.ReadInt32();
  179. }
  180. flag = (read.ReadByte() == 1);
  181. if (flag)
  182. {
  183. drawingToolInfo.Color2 = read.ReadInt32();
  184. }
  185. flag = (read.ReadByte() == 1);
  186. if (flag)
  187. {
  188. drawingToolInfo.Bool1 = read.ReadBoolean();
  189. }
  190. flag = (read.ReadByte() == 1);
  191. if (flag)
  192. {
  193. drawingToolInfo.Bool2 = read.ReadBoolean();
  194. }
  195. flag = (read.ReadByte() == 1);
  196. if (flag)
  197. {
  198. drawingToolInfo.XML = read.ReadString();
  199. }
  200. drawingToolInfo.isDeleted = read.ReadBoolean();
  201. drawingToolInfo.DrawOnAllSymbols = read.ReadBoolean();
  202. drawingToolInfo.CreatedIn = read.ReadInt16();
  203. drawingToolInfo.LastEditedIn = read.ReadInt16();
  204. flag = (read.ReadByte() == 1);
  205. if (flag)
  206. {
  207. drawingToolInfo.ChartID = read.ReadString();
  208. }
  209. result = drawingToolInfo;
  210. }
  211. else
  212. {
  213. result = null;
  214. }
  215. return result;
  216. }
  217. public void toBytes(BinaryWriter write)
  218. {
  219. write.Write(1);
  220. write.Write(this.DrawingID);
  221. write.Write(this.DrawingGUID.ToByteArray());
  222. write.Write(this.ContactID);
  223. bool flag = this.SymbolID.HasValue;
  224. if (flag)
  225. {
  226. write.Write(1);
  227. write.Write(this.SymbolID.Value);
  228. }
  229. else
  230. {
  231. write.Write(0);
  232. }
  233. write.Write(this.Symbol);
  234. write.Write(this.Created.Ticks);
  235. write.Write(this.Updated.Ticks);
  236. flag = this.TimeFrame.HasValue;
  237. if (flag)
  238. {
  239. write.Write(1);
  240. write.Write(this.TimeFrame.Value);
  241. }
  242. else
  243. {
  244. write.Write(0);
  245. }
  246. flag = this.ScaleGUID.HasValue;
  247. if (flag)
  248. {
  249. write.Write(1);
  250. write.Write(this.ScaleGUID.Value.ToByteArray());
  251. }
  252. else
  253. {
  254. write.Write(0);
  255. }
  256. flag = this.DrawType.HasValue;
  257. if (flag)
  258. {
  259. write.Write(1);
  260. write.Write(this.DrawType.Value);
  261. }
  262. else
  263. {
  264. write.Write(0);
  265. }
  266. flag = this.P1Date.HasValue;
  267. if (flag)
  268. {
  269. write.Write(1);
  270. write.Write(this.P1Date.Value.Ticks);
  271. }
  272. else
  273. {
  274. write.Write(0);
  275. }
  276. flag = this.P1Val.HasValue;
  277. if (flag)
  278. {
  279. write.Write(1);
  280. write.Write(this.P1Val.Value);
  281. }
  282. else
  283. {
  284. write.Write(0);
  285. }
  286. flag = this.P2Date.HasValue;
  287. if (flag)
  288. {
  289. write.Write(1);
  290. write.Write(this.P2Date.Value.Ticks);
  291. }
  292. else
  293. {
  294. write.Write(0);
  295. }
  296. flag = this.P2Val.HasValue;
  297. if (flag)
  298. {
  299. write.Write(1);
  300. write.Write(this.P2Val.Value);
  301. }
  302. else
  303. {
  304. write.Write(0);
  305. }
  306. flag = this.P3Date.HasValue;
  307. if (flag)
  308. {
  309. write.Write(1);
  310. write.Write(this.P3Date.Value.Ticks);
  311. }
  312. else
  313. {
  314. write.Write(0);
  315. }
  316. flag = this.P3Val.HasValue;
  317. if (flag)
  318. {
  319. write.Write(1);
  320. write.Write(this.P3Val.Value);
  321. }
  322. else
  323. {
  324. write.Write(0);
  325. }
  326. flag = this.Color1.HasValue;
  327. if (flag)
  328. {
  329. write.Write(1);
  330. write.Write(this.Color1.Value);
  331. }
  332. else
  333. {
  334. write.Write(0);
  335. }
  336. flag = this.Color2.HasValue;
  337. if (flag)
  338. {
  339. write.Write(1);
  340. write.Write(this.Color2.Value);
  341. }
  342. else
  343. {
  344. write.Write(0);
  345. }
  346. flag = this.Bool1.HasValue;
  347. if (flag)
  348. {
  349. write.Write(1);
  350. write.Write(this.Bool1.Value);
  351. }
  352. else
  353. {
  354. write.Write(0);
  355. }
  356. flag = this.Bool2.HasValue;
  357. if (flag)
  358. {
  359. write.Write(1);
  360. write.Write(this.Bool2.Value);
  361. }
  362. else
  363. {
  364. write.Write(0);
  365. }
  366. if (!string.IsNullOrEmpty(this.XML))
  367. {
  368. write.Write(1);
  369. write.Write(this.XML);
  370. }
  371. else
  372. {
  373. write.Write(0);
  374. }
  375. write.Write(this.isDeleted);
  376. write.Write(this.DrawOnAllSymbols);
  377. write.Write(this.CreatedIn);
  378. write.Write(this.LastEditedIn);
  379. if (string.IsNullOrEmpty(this.ChartID))
  380. {
  381. write.Write(1);
  382. write.Write(this.ChartID);
  383. }
  384. else
  385. {
  386. write.Write(0);
  387. }
  388. }
  389. }
  390. }