AllDateScaler.cs 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529
  1. using Microsoft.VisualBasic.CompilerServices;
  2. using MuchInfo.Chart.Data.Interfaces;
  3. using MuchInfo.Chart.WPF.Primitives.Interfaces;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. namespace MuchInfo.Chart.WPF.Primitives
  8. {
  9. public class AllDateScaler : IDateScaler
  10. {
  11. #region Fields
  12. /// <summary>
  13. /// 是否是外汇
  14. /// </summary>
  15. private bool _isForex;
  16. private Chart _chart;
  17. private IList<ILineDataPoint> _dataSource;
  18. /// <summary>
  19. /// 设置当前时间间隔如 5Y 3Y 3M Today...
  20. /// </summary>
  21. private string _desiredChartLength;
  22. private Dictionary<DateTime, int> _dictionary;
  23. /// <summary>
  24. /// 结束日期
  25. /// </summary>
  26. private DateTime _endDateTime;
  27. /// <summary>
  28. /// 最后一个数据索引
  29. /// </summary>
  30. private int _endIndex;
  31. private IList<IDateDataPoint> _extraDataPoints;
  32. /// <summary>
  33. /// 数据节点列表
  34. /// </summary>
  35. private IList<IDateDataPoint> _fullDataPoints;
  36. /// <summary>
  37. /// FutureSplitPercent
  38. /// 左右分割线
  39. /// </summary>
  40. private float _futureSplitPercent;
  41. private bool _hasNonEODDates;
  42. /// <summary>
  43. /// 数据节点总长度
  44. /// </summary>
  45. private int _length;
  46. /// <summary>
  47. /// 时间间隔下的第一个数据索引 >=5
  48. /// </summary>
  49. private int _numBars;
  50. /// <summary>
  51. /// 左边纵坐标引起的位移
  52. /// </summary>
  53. private double _offset;
  54. /// <summary>
  55. /// 时间线,如1分钟线、2分钟线...
  56. /// </summary>
  57. private TimeSpan _timeSpan;
  58. #endregion Fields
  59. #region Constructors
  60. public AllDateScaler(Chart chart)
  61. {
  62. this._chart = chart;
  63. this._dictionary = new Dictionary<DateTime, int>();
  64. this._endDateTime = DateTime.MaxValue;
  65. this._desiredChartLength = "";
  66. this._endIndex = 0;
  67. //numBars为矩形柱间距,矩形柱数量实际要-1
  68. this._numBars = _chart.RecordCountInternal - 1;
  69. //左右分割线-决定右边空出位置
  70. this._futureSplitPercent = 0.0f;//0.1f;
  71. this._hasNonEODDates = false;
  72. this._isForex = false;
  73. }
  74. #endregion Constructors
  75. #region Properties
  76. #region Public Properties
  77. public string DesiredChartLength
  78. {
  79. get
  80. {
  81. return this._desiredChartLength;
  82. }
  83. set
  84. {
  85. this._desiredChartLength = value;
  86. this.OnScalerPropertyChanged();
  87. }
  88. }
  89. public DateTime DesiredEndDate
  90. {
  91. get
  92. {
  93. return this._endDateTime;
  94. }
  95. set
  96. {
  97. bool flag = DateTime.Compare(this._endDateTime, value) != 0;
  98. if (flag)
  99. {
  100. this._endDateTime = value;
  101. this.OnScalerPropertyChanged();
  102. }
  103. }
  104. }
  105. public int EndDateIndex
  106. {
  107. get
  108. {
  109. return this._endIndex;
  110. }
  111. set
  112. {
  113. _endIndex = value;
  114. }
  115. }
  116. /// <summary>
  117. /// 最后一个数据索引
  118. /// </summary>
  119. public int EndIndex
  120. {
  121. get
  122. {
  123. return this._endIndex;
  124. }
  125. }
  126. public float FutureSplitPercent
  127. {
  128. get
  129. {
  130. return this._futureSplitPercent;
  131. }
  132. set
  133. {
  134. bool flag = (double)value > 0.9;
  135. if (flag)
  136. {
  137. this._futureSplitPercent = value;
  138. }
  139. else
  140. {
  141. flag = (value < 0f);
  142. if (flag)
  143. {
  144. this._futureSplitPercent = 0f;
  145. }
  146. else
  147. {
  148. this._futureSplitPercent = value;
  149. }
  150. }
  151. this.OnScalerPropertyChanged();
  152. }
  153. }
  154. public int IndexOfLastDataDate
  155. {
  156. get
  157. {
  158. bool flag = this._dataSource != null && this._dataSource.Count > 0;
  159. checked
  160. {
  161. int result;
  162. if (flag)
  163. {
  164. result = this.IndexFromDate(this._dataSource[this._dataSource.Count - 1].Date);
  165. }
  166. else
  167. {
  168. result = this._fullDataPoints == null ? 0 : this._fullDataPoints.Count - 1;
  169. }
  170. return result;
  171. }
  172. }
  173. }
  174. /// <summary>
  175. /// 时间间隔下的第一个数据索引(时间轴节点间的间距) >=5
  176. /// </summary>
  177. public int NumBars
  178. {
  179. get
  180. {
  181. return this._numBars;
  182. }
  183. set
  184. {
  185. bool flag = this._numBars != value;
  186. if (flag)
  187. {
  188. //numBars为矩形柱间距,矩形柱数量实际要-1
  189. var minBarsCount = _chart.MinRecordCountInternal - 1;
  190. var maxBarsCount = _chart.MaxRecordCountInternal - 1;
  191. this._numBars = value;
  192. flag = (this._numBars < minBarsCount);
  193. if (flag)
  194. {
  195. this._numBars = minBarsCount;
  196. }
  197. //限制滑块滑动显示数据范围
  198. _numBars = (this._numBars < minBarsCount) ? minBarsCount
  199. : ((this._numBars > maxBarsCount) ? maxBarsCount : _numBars);
  200. //最小值为4
  201. _numBars = Math.Max(4, _numBars);
  202. this._desiredChartLength = "";
  203. this.OnScalerPropertyChanged();
  204. }
  205. }
  206. }
  207. public int StartDateIndex
  208. {
  209. get
  210. {
  211. return Math.Max(0, checked(this._endIndex - this._numBars));
  212. }
  213. set
  214. {
  215. _endIndex = value;
  216. }
  217. }
  218. #endregion Public Properties
  219. #endregion Properties
  220. #region Methods
  221. #region Public Methods
  222. public int BinaryIndexSearch(DateTime aDate, int MinIndex)
  223. {
  224. int i = MinIndex;
  225. //int num = this.EndIndex;
  226. //大于原始数据最大的取原始最大
  227. var originalEndIndex = _dataSource.Count - 1;
  228. var num = _endIndex > originalEndIndex ? originalEndIndex : _endIndex;
  229. bool flag = false;
  230. bool flag2 = DateTime.Compare(aDate, this.DateValue(num)) > 0;
  231. checked
  232. {
  233. int result;
  234. if (flag2)
  235. {
  236. result = -1;
  237. }
  238. else
  239. {
  240. flag2 = this._dictionary.ContainsKey(aDate);
  241. int num2 = 0;
  242. if (flag2)
  243. {
  244. flag = true;
  245. num2 = this._dictionary[aDate];
  246. }
  247. else
  248. {
  249. while (i < num)
  250. {
  251. flag2 = (num - i > 60);
  252. if (flag2)
  253. {
  254. num2 = (int)Math.Round(unchecked((double)i + (double)checked(num - i) / 20.0));
  255. }
  256. else
  257. {
  258. num2 = (int)Math.Round((double)(i + num) / 2.0);
  259. }
  260. flag2 = (DateTime.Compare(aDate, this.DateValue(num2)) > 0);
  261. if (flag2)
  262. {
  263. i = num2 + 1;
  264. }
  265. else
  266. {
  267. flag2 = (DateTime.Compare(aDate, this.DateValue(num2)) < 0);
  268. if (!flag2)
  269. {
  270. flag = true;
  271. break;
  272. }
  273. num = num2 - 1;
  274. }
  275. }
  276. }
  277. flag2 = flag;
  278. int num3;
  279. if (flag2)
  280. {
  281. num3 = num2;
  282. }
  283. else
  284. {
  285. flag2 = (DateTime.Compare(this.DateValue(i), aDate) == 0);
  286. if (flag2)
  287. {
  288. num3 = i;
  289. }
  290. else
  291. {
  292. flag2 = (DateTime.Compare(this.DateValue(i), aDate) < 0);
  293. if (flag2)
  294. {
  295. num3 = i + 1;
  296. }
  297. else
  298. {
  299. flag2 = (DateTime.Compare(this.DateValue(i), aDate) > 0);
  300. if (flag2)
  301. {
  302. num3 = i;
  303. }
  304. else
  305. {
  306. num3 = num2 - 1;
  307. }
  308. }
  309. }
  310. }
  311. result = num3;
  312. }
  313. return result;
  314. }
  315. }
  316. public int Count()
  317. {
  318. bool flag = this._fullDataPoints == null;
  319. int result;
  320. if (flag)
  321. {
  322. result = 0;
  323. }
  324. else
  325. {
  326. result = this._fullDataPoints.Count;
  327. }
  328. return result;
  329. }
  330. /// <summary>
  331. /// Dates the contains.
  332. /// </summary>
  333. /// <param name="date">The date.</param>
  334. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  335. public bool DateContains(DateTime date)
  336. {
  337. return _dictionary.Keys.Contains(date);
  338. }
  339. public DateTime DateFromX(double aX)
  340. {
  341. checked
  342. {
  343. var result = new DateTime();
  344. try
  345. {
  346. bool flag = !(this._fullDataPoints != null && this._fullDataPoints.Count != 0 && this._endIndex != this.StartDateIndex);
  347. if (flag)
  348. {
  349. var dateTime = new DateTime(1900, 1, 1);
  350. result = dateTime;
  351. }
  352. else
  353. {
  354. //通过x取日期时去掉左边纵坐标的宽度
  355. double num = (aX - _offset) / (double)this.WidthWithBarBuffer();
  356. int num2 = (int)Math.Round((double)unchecked((float)this.StartDateIndex + (float)checked(this._endIndex - this.StartDateIndex) * num));
  357. flag = (num2 >= 0 && num2 < this._fullDataPoints.Count);
  358. if (flag)
  359. {
  360. result = this._fullDataPoints[num2].Date;
  361. }
  362. //else
  363. //{
  364. // DateTime dateTime2 = MarketDates.DateFromMarketDateId((int)Math.Round((double)unchecked((float)this.AllDateScaler_718 + num * (float)checked(this.AllDateScaler_719 - this.AllDateScaler_718))), this.isForex);
  365. // flag = (this.AllDateScaler_716.Days < 1);
  366. // if (flag)
  367. // {
  368. // result = dateTime2;
  369. // }
  370. // else
  371. // {
  372. // result = dateTime2.Date;
  373. // }
  374. //}
  375. }
  376. }
  377. catch (Exception ex)
  378. {
  379. throw ex;
  380. }
  381. return result;
  382. }
  383. }
  384. public DateTime DateValue(int aIndex)
  385. {
  386. if (this._fullDataPoints == null || !this._fullDataPoints.Any()) return default(DateTime);
  387. var flag = aIndex >= 0 && aIndex < this._fullDataPoints.Count;
  388. return flag ? this._fullDataPoints[aIndex].Date : default(DateTime);
  389. }
  390. public bool DateVisible(DateTime aDate)
  391. {
  392. var allDateScaler = this._fullDataPoints;
  393. //只有一条数据直接返回true
  394. if (allDateScaler == null || allDateScaler.Count == 1) return true;
  395. bool flag = true;
  396. if (allDateScaler.Count != 0)
  397. {
  398. if (this._endIndex != this.StartDateIndex)
  399. {
  400. flag = false;
  401. }
  402. }
  403. bool result;
  404. if (flag)
  405. {
  406. result = false;
  407. }
  408. else
  409. {
  410. flag = true;
  411. if (this.StartDateIndex >= 0 && this.EndIndex >= 0)
  412. {
  413. if (this.StartDateIndex < allDateScaler.Count)
  414. {
  415. if (this.EndIndex < allDateScaler.Count)
  416. {
  417. flag = false;
  418. }
  419. }
  420. }
  421. if (flag)
  422. {
  423. result = false;
  424. }
  425. else
  426. {
  427. //大于原始数据最大的取原始最大
  428. var originalEndIndex = _dataSource.Count - 1;
  429. var endIndex = _endIndex > originalEndIndex ? originalEndIndex : _endIndex;
  430. //修复第一条不可见Bug:重新变成>=
  431. flag = (DateTime.Compare(aDate, allDateScaler[this.StartDateIndex].Date) >= 0
  432. && DateTime.Compare(aDate, allDateScaler[endIndex].Date) <= 0);
  433. result = flag;
  434. }
  435. }
  436. return result;
  437. }
  438. /// <summary>
  439. /// 数据间的间隔
  440. /// </summary>
  441. /// <returns></returns>
  442. public double DistanceBetweenDates()
  443. {
  444. bool flag = this._fullDataPoints == null;
  445. double result;
  446. if (flag)
  447. {
  448. result = 0f;
  449. }
  450. else
  451. {
  452. flag = (this._fullDataPoints.Count > 0 && this._endIndex != this.StartDateIndex);
  453. if (flag)
  454. {
  455. result = ((double)this._length * (1.0 / (double)checked(this._endIndex - this.StartDateIndex + 1)));
  456. }
  457. else
  458. {
  459. result = 0f;
  460. }
  461. }
  462. return result;
  463. }
  464. /// <summary>
  465. /// Firsts the visible index from data.
  466. /// </summary>
  467. /// <param name="data">The data.</param>
  468. /// <returns>System.Int32.</returns>
  469. public int FirstVisibleIndexFromData(IList<ILineDataPoint> data)
  470. {
  471. if (this._fullDataPoints == null || !this._fullDataPoints.Any()) return 0;
  472. var startTime = this._fullDataPoints[this.StartDateIndex].Date;
  473. var dataPoint = data.FirstOrDefault(z => z.Date >= startTime);
  474. if (dataPoint == null) return 0;
  475. var result = data.IndexOf(dataPoint);
  476. return result == -1 ? 0 : result;
  477. }
  478. public bool HasNonEODDates()
  479. {
  480. return this._hasNonEODDates;
  481. }
  482. public int IndexFromDate(DateTime aDate)
  483. {
  484. bool flag = this._dictionary.ContainsKey(aDate);
  485. int result;
  486. if (flag)
  487. {
  488. result = this._dictionary[aDate];
  489. }
  490. else
  491. {
  492. result = -100;
  493. }
  494. return result;
  495. }
  496. /// <summary>
  497. /// Lasts the visible index from data.
  498. /// </summary>
  499. /// <param name="data">The data.</param>
  500. /// <returns>System.Int32.</returns>
  501. public int LastVisibleIndexFromData(IList<ILineDataPoint> data)
  502. {
  503. if (this._fullDataPoints == null || !this._fullDataPoints.Any()) return 0;
  504. var endTime = this._fullDataPoints[this.EndDateIndex].Date;
  505. var dataPoint = data.FirstOrDefault(z => z.Date >= endTime);
  506. if (dataPoint == null) return data.Count - 1;
  507. var result = data.IndexOf(dataPoint);
  508. return result == -1 ? 0 : result;
  509. }
  510. public DateTime OriginalDateFromX(double aX)
  511. {
  512. if (_dataSource == null || !_dataSource.Any()) return default(DateTime);
  513. var count = this._dataSource.Count;
  514. if (this._dataSource != null && count != 0 && this._endIndex != this.StartDateIndex && this.WidthWithBarBuffer() != 0)
  515. {
  516. double num = (aX - _offset) / (double)this.WidthWithBarBuffer();
  517. var num2 = (int)Math.Round(this.StartDateIndex + (this._endIndex - this.StartDateIndex) * num);
  518. if (num2 < 0)
  519. {
  520. return _dataSource.Min(z => z.Date);
  521. }
  522. if (num2 >= count - 1)
  523. {
  524. return _dataSource.Max(z => z.Date);
  525. }
  526. return this._dataSource[num2].Date;
  527. }
  528. return new DateTime(1900, 1, 1);
  529. }
  530. public DateTime OriginalDateFromX(double aX, int offSet)
  531. {
  532. if (_dataSource == null || !_dataSource.Any()) return default(DateTime);
  533. var count = this._dataSource.Count;
  534. if (this._dataSource != null && count != 0 &&
  535. this._endIndex != this.StartDateIndex && this.WidthWithBarBuffer() != 0)
  536. {
  537. //通过x取日期时去掉左边纵坐标的宽度
  538. double num = (aX - _offset) / (double)this.WidthWithBarBuffer();
  539. var num2 = (int)Math.Round(this.StartDateIndex + (this._endIndex - this.StartDateIndex) * num) + offSet;
  540. if (num2 < 0) return _dataSource.Min(z => z.Date);
  541. if (num2 >= count - 1) return _dataSource.Max(z => z.Date);
  542. //修复第一条不可见Bug:n+1->n
  543. return this._dataSource[num2].Date;
  544. }
  545. return new DateTime(1900, 1, 1);
  546. }
  547. public DateTime OriginalDateValue(int aIndex)
  548. {
  549. if (_dataSource == null || !_dataSource.Any()) return default(DateTime);
  550. bool flag = aIndex >= 0 && aIndex < this._dataSource.Count;
  551. DateTime result;
  552. if (flag)
  553. {
  554. result = this._dataSource[aIndex].Date;
  555. }
  556. else
  557. {
  558. result = this._dataSource.Max(z => z.Date);
  559. }
  560. return result;
  561. }
  562. public float PercentFromDate(DateTime aDate)
  563. {
  564. bool flag = this._dictionary.ContainsKey(aDate);
  565. checked
  566. {
  567. float result = 0;
  568. if (flag)
  569. {
  570. int num = this._dictionary[aDate];
  571. result = (float)((double)(num - this.StartDateIndex) / (double)(this._endIndex - this.StartDateIndex));
  572. }
  573. //else
  574. //{
  575. // int num2 = MarketDates.MarketDateId(aDate, this.isForex);
  576. // result = (float)((double)(num2 - this.AllDateScaler_718) / (double)(this.AllDateScaler_719 - this.AllDateScaler_718));
  577. //}
  578. return result;
  579. }
  580. }
  581. public float PercentFromIndex(int aIndex)
  582. {
  583. bool flag = this._endIndex != this.StartDateIndex;
  584. float result = 0f;
  585. if (flag)
  586. {
  587. result = (float)checked((double)(aIndex - this.StartDateIndex) / (double)(this._endIndex - this.StartDateIndex));
  588. }
  589. return result;
  590. }
  591. public void SetDates(IList<ILineDataPoint> data, TimeSpan aTimeFrame, bool isForex)
  592. {
  593. this._isForex = isForex;
  594. this._timeSpan = aTimeFrame;
  595. this._dataSource = data;
  596. this.OnScalerPropertyChanged();
  597. }
  598. /// <summary>
  599. /// 设置滑动块的总长度
  600. /// </summary>
  601. /// <param name="width">绘图区宽度</param>
  602. /// <param name="offset">左边纵坐标引起的位移</param>
  603. public void SetPlotInfo(int width, float offset)
  604. {
  605. this._length = width;
  606. this._offset = offset;
  607. }
  608. public int WidthWithBarBuffer()
  609. {
  610. checked
  611. {
  612. //修复第一条不可见Bug:*0.3->* 1.3
  613. int num = (int)Math.Round(unchecked((double)this._length - (double)this.DistanceBetweenDates() * 1.3));
  614. num--;
  615. bool flag = num < 0;
  616. if (flag)
  617. {
  618. num = 0;
  619. }
  620. return num;
  621. }
  622. }
  623. public float XforDate(DateTime aDate)
  624. {
  625. bool flag = !(this._fullDataPoints != null && this._fullDataPoints.Count != 0 && this._endIndex != this.StartDateIndex);
  626. float result = 0;
  627. if (flag)
  628. {
  629. result = -1000f;
  630. }
  631. else
  632. {
  633. //var item = aDate;
  634. //if (_chart.CycleType == CycleType.TimeSharing)
  635. //{
  636. // item = _dictionary.Keys.FirstOrDefault(z => z.Date == aDate.Date && z.Hour == aDate.Hour && z.Minute == aDate.Minute);
  637. // flag = this._dictionary.ContainsKey(item);
  638. //}
  639. //else
  640. //{
  641. flag = this._dictionary.ContainsKey(aDate);
  642. //}
  643. if (flag)
  644. {
  645. //修复第一条不可见Bug:因为要右移1/2 DistanceBetweenDates(),,所以num +1
  646. int num = this._dictionary[aDate] + 1;
  647. result = (float)((double)this.WidthWithBarBuffer() * checked((double)(num - this.StartDateIndex) / (double)(this._endIndex - this.StartDateIndex)));
  648. result -= (float)(DistanceBetweenDates() / 2);
  649. }
  650. else
  651. {
  652. var a = string.Empty;
  653. //int num2 = MarketDates.MarketDateId(aDate, this.isForex);
  654. //result = (float)((double)this.WidthWithBarBuffer() * checked((double)(num2 - this.AllDateScaler_718) / (double)(this.AllDateScaler_719 - this.AllDateScaler_718)));
  655. }
  656. }
  657. return result;
  658. }
  659. #endregion Public Methods
  660. #region Private Methods
  661. /// <summary>
  662. /// 根据最后一天返回当前所设置时间间隔的第一天
  663. /// </summary>
  664. /// <param name="endDate"></param>
  665. /// <returns></returns>
  666. private DateTime GetCurrentFirstDate(DateTime endDate)
  667. {
  668. bool flag = endDate.Ticks == 0L;
  669. checked
  670. {
  671. var result = new DateTime();
  672. if (flag)
  673. {
  674. result = endDate;
  675. }
  676. else
  677. {
  678. string allDateScaler_ = this._desiredChartLength;
  679. flag = allDateScaler_.Equals("5Y");
  680. if (flag)
  681. {
  682. result = endDate.AddYears(-5);
  683. }
  684. else
  685. {
  686. flag = (Operators.CompareString(allDateScaler_, "1Y", false) == 0);
  687. if (flag)
  688. {
  689. result = endDate.AddYears(-1);
  690. }
  691. else
  692. {
  693. flag = (Operators.CompareString(allDateScaler_, "YTD", false) == 0);
  694. if (flag)
  695. {
  696. DateTime dateTime = new DateTime(endDate.Year, 1, 1);
  697. result = dateTime;
  698. }
  699. else
  700. {
  701. flag = (Operators.CompareString(allDateScaler_, "6M", false) == 0);
  702. if (flag)
  703. {
  704. result = endDate.AddMonths(-6);
  705. }
  706. else
  707. {
  708. flag = (Operators.CompareString(allDateScaler_, "3M", false) == 0);
  709. if (flag)
  710. {
  711. result = endDate.AddMonths(-3);
  712. }
  713. else
  714. {
  715. flag = (Operators.CompareString(allDateScaler_, "1M", false) == 0);
  716. if (flag)
  717. {
  718. result = endDate.AddMonths(-1);
  719. }
  720. else
  721. {
  722. flag = (Operators.CompareString(allDateScaler_, "1W", false) == 0);
  723. if (flag)
  724. {
  725. result = endDate.AddDays(-7.0);
  726. }
  727. else
  728. {
  729. flag = (Operators.CompareString(allDateScaler_, "1D", false) == 0);
  730. if (flag)
  731. {
  732. int num = 1;
  733. flag = this._isForex;
  734. DateTime dateTime2;
  735. if (flag)
  736. {
  737. dateTime2 = endDate.AddDays(-1.0);
  738. while (dateTime2.DayOfWeek == (DayOfWeek)6 && num < 3)
  739. {
  740. dateTime2 = dateTime2.AddDays(-1.0);
  741. num++;
  742. }
  743. }
  744. else
  745. {
  746. dateTime2 = endDate.AddDays(-1.0);
  747. while (true)
  748. {
  749. if (!Conversions.ToBoolean(num < 3))
  750. {
  751. goto IL_28E;
  752. }
  753. //if (!Conversions.ToBoolean(dateTime2.DayOfWeek == (DayOfWeek)6 || dateTime2.DayOfWeek == 0) && !Conversions.ToBoolean(MarketDates.IsWholeDayHoliday(dateTime2, this.isForex)))
  754. //{
  755. // goto IL_28E;
  756. //}
  757. if (!Conversions.ToBoolean(dateTime2.DayOfWeek == (DayOfWeek)6 || dateTime2.DayOfWeek == 0))
  758. {
  759. goto IL_28E;
  760. }
  761. object arg_294_0 = true;
  762. IL_294:
  763. if (!Conversions.ToBoolean(arg_294_0))
  764. {
  765. break;
  766. }
  767. dateTime2 = dateTime2.AddDays(-1.0);
  768. num++;
  769. continue;
  770. IL_28E:
  771. arg_294_0 = false;
  772. goto IL_294;
  773. }
  774. }
  775. result = dateTime2;
  776. }
  777. else
  778. {
  779. flag = (Operators.CompareString(allDateScaler_, "Today", false) == 0);
  780. if (flag)
  781. {
  782. DateTime dateTime = new DateTime(endDate.Year, endDate.Month, endDate.Day);
  783. result = dateTime;
  784. }
  785. }
  786. }
  787. }
  788. }
  789. }
  790. }
  791. }
  792. }
  793. }
  794. return result;
  795. }
  796. }
  797. private List<IDateDataPoint> GetDayExtrDataPoints(DateTime aStartDate, int numToAdd)
  798. {
  799. var list = new List<IDateDataPoint>();
  800. DateTime dateTime = aStartDate.Date;
  801. checked
  802. {
  803. if (this._isForex)
  804. {
  805. while (list.Count < numToAdd)
  806. {
  807. do
  808. {
  809. dateTime = dateTime.Add(this._timeSpan);
  810. }
  811. while (dateTime.DayOfWeek == (DayOfWeek)6);
  812. var allDateScaler_ = new AllDateScaler.DateDataPoint(dateTime);
  813. if (this._dataSource == null || this._dataSource.Count == 0)
  814. {
  815. goto IL_9D;
  816. }
  817. if (DateTime.Compare(this._dataSource[this._dataSource.Count - 1].Date, dateTime) < 0)
  818. {
  819. goto IL_9D;
  820. }
  821. bool arg_9E_0 = false;
  822. IL_9E:
  823. var flag = arg_9E_0;
  824. if (flag)
  825. {
  826. list.Add(allDateScaler_);
  827. }
  828. continue;
  829. IL_9D:
  830. arg_9E_0 = true;
  831. goto IL_9E;
  832. }
  833. }
  834. else
  835. {
  836. while (list.Count < numToAdd)
  837. {
  838. //do
  839. //{
  840. // dateTime = dateTime.Add(this.AllDateScaler_716);
  841. //}
  842. //while (Conversions.ToBoolean((Conversions.ToBoolean(dateTime.DayOfWeek == (DayOfWeek)6 || dateTime.DayOfWeek == 0) || Conversions.ToBoolean(MarketDates.IsWholeDayHoliday(dateTime, this.isForex))) ? true : false));
  843. do
  844. {
  845. dateTime = dateTime.Add(this._timeSpan);
  846. }
  847. while (dateTime.DayOfWeek == (DayOfWeek)6 || dateTime.DayOfWeek == 0);
  848. var allDateScaler_2 = new AllDateScaler.DateDataPoint(dateTime);
  849. if (this._dataSource == null || this._dataSource.Count == 0)
  850. {
  851. goto IL_173;
  852. }
  853. if (DateTime.Compare(this._dataSource[this._dataSource.Count - 1].Date, dateTime) < 0)
  854. {
  855. goto IL_173;
  856. }
  857. bool arg_174_0 = false;
  858. IL_174:
  859. var flag = arg_174_0;
  860. if (flag)
  861. {
  862. list.Add(allDateScaler_2);
  863. }
  864. continue;
  865. IL_173:
  866. arg_174_0 = true;
  867. goto IL_174;
  868. }
  869. }
  870. return list;
  871. }
  872. }
  873. /// <summary>
  874. /// Gets the extra data points.
  875. /// </summary>
  876. /// <returns>List{IDateDataPoint}.</returns>
  877. private List<IDateDataPoint> GetExtraDataPoints()
  878. {
  879. bool flag = this._futureSplitPercent > 0f && this._dataSource != null && this._dataSource.Count > 1;
  880. checked
  881. {
  882. List<IDateDataPoint> result;
  883. if (flag)
  884. {
  885. DateTime aStartDate = this._dataSource[this._dataSource.Count - 2].Date.Add(this._timeSpan);
  886. int numToAdd = (int)Math.Round((double)unchecked((float)this.NumBars * this._futureSplitPercent));
  887. flag = (this._timeSpan.Days < 1);
  888. if (flag)
  889. {
  890. result = this.GetlessThenDayExtraDataPoints(aStartDate, numToAdd);
  891. }
  892. else
  893. {
  894. flag = (this._timeSpan.Days == 255);
  895. if (flag)
  896. {
  897. aStartDate = this._dataSource[this._dataSource.Count - 1].Date;
  898. result = this.GetYearExtraDataPoints(aStartDate, numToAdd);
  899. }
  900. else
  901. {
  902. flag = (this._timeSpan.Days == 120);
  903. if (flag)
  904. {
  905. aStartDate = this._dataSource[this._dataSource.Count - 1].Date;
  906. result = this.GetQuarterDataExtraPoints(aStartDate, numToAdd);
  907. }
  908. else
  909. {
  910. flag = (this._timeSpan.Days == 30);
  911. if (flag)
  912. {
  913. aStartDate = this._dataSource[this._dataSource.Count - 1].Date;
  914. result = this.GetMonthExtraDataPoints(aStartDate, numToAdd);
  915. }
  916. else
  917. {
  918. flag = (this._timeSpan.Days == 5);
  919. if (flag)
  920. {
  921. aStartDate = this._dataSource[this._dataSource.Count - 1].Date;
  922. result = this.GetWeekExtraDataPoints(aStartDate, numToAdd);
  923. }
  924. else
  925. {
  926. result = this.GetDayExtrDataPoints(aStartDate, numToAdd);
  927. }
  928. }
  929. }
  930. }
  931. }
  932. }
  933. else
  934. {
  935. result = null;
  936. }
  937. return result;
  938. }
  939. }
  940. /// <summary>
  941. /// Gets the last contains.
  942. /// </summary>
  943. /// <param name="date">The date.</param>
  944. /// <returns>System.Int32.</returns>
  945. private int GetLastContainsValue(DateTime date)
  946. {
  947. if (_dictionary == null || !_dictionary.Any()) return 0;
  948. foreach (var keyPair in _dictionary)
  949. {
  950. if (keyPair.Key >= date) return keyPair.Value;
  951. }
  952. return 0;
  953. }
  954. private List<IDateDataPoint> GetlessThenDayExtraDataPoints(DateTime aStartDate, int numToAdd)
  955. {
  956. var list = new List<IDateDataPoint>();
  957. bool flag = this._isForex;
  958. checked
  959. {
  960. if (flag)
  961. {
  962. DateTime aDate = aStartDate.AddSeconds((double)(-1 * aStartDate.Second));
  963. while (list.Count < numToAdd)
  964. {
  965. aDate = aDate.Add(this._timeSpan);
  966. flag = (aDate.DayOfWeek == (DayOfWeek)6);
  967. if (!flag)
  968. {
  969. if (aDate.DayOfWeek != (DayOfWeek)5)
  970. {
  971. goto IL_B8;
  972. }
  973. TimeSpan arg_B1_0 = aDate.TimeOfDay;
  974. TimeSpan timeSpan = new TimeSpan(17, 0, 0);
  975. if (!(arg_B1_0 > timeSpan))
  976. {
  977. goto IL_B8;
  978. }
  979. bool arg_BC_0 = true;
  980. IL_BC:
  981. flag = arg_BC_0;
  982. if (flag)
  983. {
  984. aDate = aDate.Date.AddDays(2.0).AddHours(17.0);
  985. goto IL_13A;
  986. }
  987. if (aDate.DayOfWeek != 0)
  988. {
  989. goto IL_116;
  990. }
  991. TimeSpan arg_10F_0 = aDate.TimeOfDay;
  992. timeSpan = new TimeSpan(17, 0, 0);
  993. if (!(arg_10F_0 < timeSpan))
  994. {
  995. goto IL_116;
  996. }
  997. bool arg_11A_0 = true;
  998. IL_11A:
  999. flag = arg_11A_0;
  1000. if (flag)
  1001. {
  1002. aDate = aDate.Date.AddHours(17.0);
  1003. goto IL_13A;
  1004. }
  1005. goto IL_13A;
  1006. IL_116:
  1007. arg_11A_0 = false;
  1008. goto IL_11A;
  1009. IL_B8:
  1010. arg_BC_0 = false;
  1011. goto IL_BC;
  1012. }
  1013. aDate = aDate.Date.AddDays(1.0).AddHours(17.0);
  1014. IL_13A:
  1015. var allDateScaler_ = new AllDateScaler.DateDataPoint(aDate);
  1016. list.Add(allDateScaler_);
  1017. }
  1018. }
  1019. else
  1020. {
  1021. DateTime aDate2 = aStartDate.AddSeconds((double)(-1 * aStartDate.Second));
  1022. TimeSpan timeSpan2 = new TimeSpan(16, 0, 0);
  1023. TimeSpan timeSpan3 = new TimeSpan(9, 30, 0);
  1024. TimeSpan timeSpan4 = new TimeSpan(16, 0, 0);
  1025. TimeSpan timeSpan5 = new TimeSpan(9, 30, 0);
  1026. //MarketDates.HolidayItem holidayItem = MarketDates.GetHoliday(aDate2, this.isForex);
  1027. //flag = (holidayItem != null && holidayItem.WholeDay);
  1028. //if (flag)
  1029. //{
  1030. // holidayItem = null;
  1031. //}
  1032. while (list.Count < numToAdd)
  1033. {
  1034. aDate2 = aDate2.Add(this._timeSpan);
  1035. flag = true;// (holidayItem == null);
  1036. if (flag)
  1037. {
  1038. timeSpan4 = timeSpan2;
  1039. timeSpan5 = timeSpan3;
  1040. }
  1041. //else
  1042. //{
  1043. // timeSpan4 = holidayItem.CloseTime;
  1044. // timeSpan5 = holidayItem.OpenTime;
  1045. //}
  1046. while (true)
  1047. {
  1048. if (aDate2.TimeOfDay > timeSpan4 || aDate2.DayOfWeek == (DayOfWeek)6)
  1049. {
  1050. goto IL_2C4;
  1051. }
  1052. if (aDate2.DayOfWeek == 0)
  1053. {
  1054. goto IL_2C4;
  1055. }
  1056. bool arg_2C5_0 = false;
  1057. IL_2C5:
  1058. if (!arg_2C5_0)
  1059. {
  1060. break;
  1061. }
  1062. //if (!Conversions.ToBoolean((Conversions.ToBoolean(arg_2C5_0) || Conversions.ToBoolean(MarketDates.IsWholeDayHoliday(aDate2, this.isForex))) ? true : false))
  1063. //{
  1064. // break;
  1065. //}
  1066. aDate2 = aDate2.Date.AddDays(1.0).Add(timeSpan3).Add(this._timeSpan);
  1067. //holidayItem = MarketDates.GetHoliday(aDate2, this.isForex);
  1068. //flag = (holidayItem != null && holidayItem.WholeDay);
  1069. //if (flag)
  1070. //{
  1071. // holidayItem = null;
  1072. //}
  1073. //flag = (holidayItem == null);
  1074. if (flag)
  1075. {
  1076. timeSpan4 = timeSpan2;
  1077. timeSpan5 = timeSpan3;
  1078. }
  1079. //else
  1080. //{
  1081. // timeSpan4 = holidayItem.CloseTime;
  1082. // timeSpan5 = holidayItem.OpenTime;
  1083. //}
  1084. continue;
  1085. IL_2C4:
  1086. arg_2C5_0 = true;
  1087. goto IL_2C5;
  1088. }
  1089. flag = (aDate2.TimeOfDay >= timeSpan5);
  1090. if (flag)
  1091. {
  1092. AllDateScaler.DateDataPoint allDateScaler_2 = new AllDateScaler.DateDataPoint(aDate2);
  1093. list.Add(allDateScaler_2);
  1094. }
  1095. }
  1096. }
  1097. return list;
  1098. }
  1099. }
  1100. private List<IDateDataPoint> GetMonthExtraDataPoints(DateTime aStartDate, int NumToAdd)
  1101. {
  1102. var list = new List<IDateDataPoint>();
  1103. DateTime aDate = aStartDate.Date;
  1104. checked
  1105. {
  1106. if (this._isForex)
  1107. {
  1108. while (list.Count < NumToAdd)
  1109. {
  1110. aDate = new DateTime(aDate.Year, aDate.Month, 1);
  1111. aDate = aDate.AddMonths(1);
  1112. aDate = aDate.AddDays((double)(DateTime.DaysInMonth(aDate.Year, aDate.Month) - 1));
  1113. while (aDate.DayOfWeek == (DayOfWeek)6)
  1114. {
  1115. aDate = aDate.AddDays(-1.0);
  1116. }
  1117. AllDateScaler.DateDataPoint allDateScaler_2 = new AllDateScaler.DateDataPoint(aDate);
  1118. list.Add(allDateScaler_2);
  1119. }
  1120. }
  1121. else
  1122. {
  1123. while (list.Count < NumToAdd)
  1124. {
  1125. aDate = new DateTime(aDate.Year, aDate.Month, 1);
  1126. aDate = aDate.AddMonths(1);
  1127. aDate = aDate.AddDays((double)(DateTime.DaysInMonth(aDate.Year, aDate.Month) - 1));
  1128. //while (Conversions.ToBoolean((Conversions.ToBoolean(aDate.DayOfWeek == (DayOfWeek)6 || aDate.DayOfWeek == 0) || Conversions.ToBoolean(MarketDates.IsWholeDayHoliday(aDate, this.isForex))) ? true : false))
  1129. //{
  1130. // aDate = aDate.AddDays(-1.0);
  1131. //}
  1132. while (aDate.DayOfWeek == (DayOfWeek)6 || aDate.DayOfWeek == 0)
  1133. {
  1134. aDate = aDate.AddDays(-1.0);
  1135. }
  1136. AllDateScaler.DateDataPoint allDateScaler_3 = new AllDateScaler.DateDataPoint(aDate);
  1137. list.Add(allDateScaler_3);
  1138. }
  1139. }
  1140. return list;
  1141. }
  1142. }
  1143. private List<IDateDataPoint> GetQuarterDataExtraPoints(DateTime aStartDate, int NumToAdd)
  1144. {
  1145. var list = new List<IDateDataPoint>();
  1146. DateTime aDate = aStartDate.Date;
  1147. while (aDate.Month % 3 != 0)
  1148. {
  1149. aDate = aDate.AddMonths(1);
  1150. }
  1151. bool allDateScaler_ = this._isForex;
  1152. if (allDateScaler_)
  1153. {
  1154. while (list.Count < NumToAdd)
  1155. {
  1156. aDate = aDate.AddMonths(3);
  1157. aDate = new DateTime(aDate.Year, aDate.Month, DateTime.DaysInMonth(aDate.Year, aDate.Month));
  1158. while (aDate.DayOfWeek == (DayOfWeek)6)
  1159. {
  1160. aDate = aDate.AddDays(-1.0);
  1161. }
  1162. AllDateScaler.DateDataPoint allDateScaler_2 = new AllDateScaler.DateDataPoint(aDate);
  1163. list.Add(allDateScaler_2);
  1164. }
  1165. }
  1166. else
  1167. {
  1168. while (list.Count < NumToAdd)
  1169. {
  1170. aDate = aDate.AddMonths(3);
  1171. aDate = new DateTime(aDate.Year, aDate.Month, DateTime.DaysInMonth(aDate.Year, aDate.Month));
  1172. //while (Conversions.ToBoolean((Conversions.ToBoolean(aDate.DayOfWeek == (DayOfWeek)6 || aDate.DayOfWeek == 0) || Conversions.ToBoolean(MarketDates.IsWholeDayHoliday(aDate, this.isForex))) ? true : false))
  1173. //{
  1174. // aDate = aDate.AddDays(-1.0);
  1175. //}
  1176. while (aDate.DayOfWeek == (DayOfWeek)6 || aDate.DayOfWeek == 0)
  1177. {
  1178. aDate = aDate.AddDays(-1.0);
  1179. }
  1180. AllDateScaler.DateDataPoint allDateScaler_3 = new AllDateScaler.DateDataPoint(aDate);
  1181. list.Add(allDateScaler_3);
  1182. }
  1183. }
  1184. return list;
  1185. }
  1186. private List<IDateDataPoint> GetWeekExtraDataPoints(DateTime aStartDate, int numToAdd)
  1187. {
  1188. var list = new List<IDateDataPoint>();
  1189. DateTime aDate = aStartDate.Date;
  1190. while (aDate.DayOfWeek != (DayOfWeek)5)
  1191. {
  1192. aDate = aDate.AddDays(1.0);
  1193. }
  1194. if (_isForex)
  1195. {
  1196. while (list.Count < numToAdd)
  1197. {
  1198. aDate = aDate.AddDays(7.0);
  1199. AllDateScaler.DateDataPoint allDateScaler_2 = new AllDateScaler.DateDataPoint(aDate);
  1200. list.Add(allDateScaler_2);
  1201. while (aDate.DayOfWeek != (DayOfWeek)5)
  1202. {
  1203. aDate = aDate.AddDays(1.0);
  1204. }
  1205. }
  1206. }
  1207. else
  1208. {
  1209. while (list.Count < numToAdd)
  1210. {
  1211. aDate = aDate.AddDays(7.0);
  1212. //while (Conversions.ToBoolean(MarketDates.IsWholeDayHoliday(aDate, this.isForex)))
  1213. //{
  1214. // aDate = aDate.AddDays(-1.0);
  1215. //}
  1216. AllDateScaler.DateDataPoint allDateScaler_3 = new AllDateScaler.DateDataPoint(aDate);
  1217. list.Add(allDateScaler_3);
  1218. while (aDate.DayOfWeek != (DayOfWeek)5)
  1219. {
  1220. aDate = aDate.AddDays(1.0);
  1221. }
  1222. }
  1223. }
  1224. return list;
  1225. }
  1226. private List<IDateDataPoint> GetYearExtraDataPoints(DateTime aStartDate, int numToAdd)
  1227. {
  1228. var list = new List<IDateDataPoint>();
  1229. DateTime aDate = aStartDate.Date;
  1230. bool allDateScaler_ = this._isForex;
  1231. checked
  1232. {
  1233. if (allDateScaler_)
  1234. {
  1235. while (list.Count < numToAdd)
  1236. {
  1237. aDate = new DateTime(aDate.Year + 1, 12, DateTime.DaysInMonth(aDate.Year + 1, 12));
  1238. while (aDate.DayOfWeek == (DayOfWeek)6)
  1239. {
  1240. aDate = aDate.AddDays(-1.0);
  1241. }
  1242. AllDateScaler.DateDataPoint allDateScaler_2 = new AllDateScaler.DateDataPoint(aDate);
  1243. list.Add(allDateScaler_2);
  1244. }
  1245. }
  1246. else
  1247. {
  1248. while (list.Count < numToAdd)
  1249. {
  1250. aDate = new DateTime(aDate.Year + 1, 12, DateTime.DaysInMonth(aDate.Year + 1, 12));
  1251. //while (Conversions.ToBoolean((Conversions.ToBoolean(aDate.DayOfWeek == (DayOfWeek)6 || aDate.DayOfWeek == 0) || Conversions.ToBoolean(MarketDates.IsWholeDayHoliday(aDate, this.isForex))) ? true : false))
  1252. //{
  1253. // aDate = aDate.AddDays(-1.0);
  1254. //}
  1255. while (aDate.DayOfWeek == (DayOfWeek)6 || aDate.DayOfWeek == 0)
  1256. {
  1257. aDate = aDate.AddDays(-1.0);
  1258. }
  1259. AllDateScaler.DateDataPoint allDateScaler_3 = new AllDateScaler.DateDataPoint(aDate);
  1260. list.Add(allDateScaler_3);
  1261. }
  1262. }
  1263. return list;
  1264. }
  1265. }
  1266. private void OnScalerPropertyChanged()
  1267. {
  1268. var list = new List<IDateDataPoint>();
  1269. var flag = (this._dataSource != null && this._dataSource.Any());
  1270. if (flag)
  1271. {
  1272. list.AddRange(_dataSource.Cast<IDateDataPoint>());
  1273. }
  1274. this._extraDataPoints = this.GetExtraDataPoints();
  1275. flag = (this._extraDataPoints != null);
  1276. if (flag)
  1277. {
  1278. list.AddRange(_extraDataPoints);
  1279. }
  1280. flag = (list.Count > 0 && list.Count < 3);
  1281. checked
  1282. {
  1283. if (flag)
  1284. {
  1285. try
  1286. {
  1287. int i = 3 - list.Count;
  1288. DateTime aDate = list[0].Date;
  1289. while (i > 0)
  1290. {
  1291. i--;
  1292. //使用Add代替Insert,否则DataVisible会判断出错
  1293. //aDate = aDate.Subtract(this._timeSpan);
  1294. //list.Insert(0, new AllDateScaler.DateDataPoint(aDate));
  1295. aDate = aDate.Add(this._timeSpan);
  1296. list.Add(new AllDateScaler.DateDataPoint(aDate));
  1297. }
  1298. }
  1299. catch (Exception ex)
  1300. {
  1301. throw ex;
  1302. }
  1303. }
  1304. this._fullDataPoints = list;
  1305. var dictionary = new Dictionary<DateTime, int>();
  1306. this._hasNonEODDates = false;
  1307. flag = (this._fullDataPoints != null);
  1308. if (flag)
  1309. {
  1310. var timeSpan = new TimeSpan(16, 0, 0);
  1311. int num = this._fullDataPoints.Count - 1;
  1312. int num2 = 0;
  1313. while (true)
  1314. {
  1315. int num3 = num;
  1316. if (num2 > num3)
  1317. {
  1318. break;
  1319. }
  1320. DateTime dateTime = this._fullDataPoints[num2].Date;
  1321. flag = (!this._hasNonEODDates && dateTime.TimeOfDay != timeSpan);
  1322. if (flag)
  1323. {
  1324. this._hasNonEODDates = true;
  1325. }
  1326. dictionary[dateTime] = num2;
  1327. num2++;
  1328. }
  1329. flag = (DateTime.Compare(this._endDateTime, DateTime.MaxValue) == 0);
  1330. if (flag)
  1331. {
  1332. this._endIndex = this._fullDataPoints.Count - 1;
  1333. }
  1334. else
  1335. {
  1336. int num4 = this._fullDataPoints.Count - 1;
  1337. while (true)
  1338. {
  1339. int num3 = 0;
  1340. if (num4 < num3)
  1341. {
  1342. goto IL_272;
  1343. }
  1344. flag = (DateTime.Compare(this._fullDataPoints[num4].Date, this._endDateTime) <= 0);
  1345. if (flag)
  1346. {
  1347. break;
  1348. }
  1349. num4 += -1;
  1350. }
  1351. this._endIndex = num4;
  1352. IL_272:
  1353. flag = (this._endIndex < this._numBars);
  1354. if (flag)
  1355. {
  1356. this._endIndex = this._numBars;
  1357. }
  1358. flag = (this._endIndex > this._fullDataPoints.Count - 1);
  1359. if (flag)
  1360. {
  1361. this._endIndex = this._fullDataPoints.Count - 1;
  1362. }
  1363. }
  1364. flag = (this._dataSource != null && this._dataSource.Count > 0
  1365. && !string.IsNullOrWhiteSpace(this.DesiredChartLength) &&
  1366. DateTime.Compare(this._endDateTime, DateTime.MaxValue) == 0);
  1367. if (flag)
  1368. {
  1369. DateTime dateTime2 = this.GetCurrentFirstDate(this._dataSource[this._dataSource.Count - 1].Date);
  1370. int num5 = 0;
  1371. int num6 = this.EndIndex;
  1372. while (true)
  1373. {
  1374. if (num6 < 0)
  1375. {
  1376. break;
  1377. }
  1378. num5++;
  1379. flag = (DateTime.Compare(this._fullDataPoints[num6].Date, dateTime2) < 0);
  1380. if (flag)
  1381. {
  1382. break;
  1383. }
  1384. num6 += -1;
  1385. }
  1386. flag = (num5 < _chart.MinRecordCountInternal);
  1387. if (flag)
  1388. {
  1389. num5 = _chart.MinRecordCountInternal;
  1390. }
  1391. this._numBars = num5;
  1392. }
  1393. }
  1394. else
  1395. {
  1396. this._endIndex = 0;
  1397. }
  1398. this._dictionary = dictionary;
  1399. }
  1400. }
  1401. #endregion Private Methods
  1402. #endregion Methods
  1403. #region Nested Types
  1404. private class DateDataPoint : IDateDataPoint
  1405. {
  1406. #region Constructors
  1407. public DateDataPoint(DateTime aDate)
  1408. {
  1409. this.Date = aDate;
  1410. }
  1411. #endregion Constructors
  1412. #region Properties
  1413. #region Public Properties
  1414. public DateTime Date
  1415. {
  1416. get;
  1417. set;
  1418. }
  1419. #endregion Public Properties
  1420. #endregion Properties
  1421. }
  1422. #endregion Nested Types
  1423. }
  1424. }