| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529 |
- using Microsoft.VisualBasic.CompilerServices;
- using MuchInfo.Chart.Data.Interfaces;
- using MuchInfo.Chart.WPF.Primitives.Interfaces;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace MuchInfo.Chart.WPF.Primitives
- {
- public class AllDateScaler : IDateScaler
- {
- #region Fields
- /// <summary>
- /// 是否是外汇
- /// </summary>
- private bool _isForex;
- private Chart _chart;
- private IList<ILineDataPoint> _dataSource;
- /// <summary>
- /// 设置当前时间间隔如 5Y 3Y 3M Today...
- /// </summary>
- private string _desiredChartLength;
- private Dictionary<DateTime, int> _dictionary;
- /// <summary>
- /// 结束日期
- /// </summary>
- private DateTime _endDateTime;
- /// <summary>
- /// 最后一个数据索引
- /// </summary>
- private int _endIndex;
- private IList<IDateDataPoint> _extraDataPoints;
- /// <summary>
- /// 数据节点列表
- /// </summary>
- private IList<IDateDataPoint> _fullDataPoints;
- /// <summary>
- /// FutureSplitPercent
- /// 左右分割线
- /// </summary>
- private float _futureSplitPercent;
- private bool _hasNonEODDates;
- /// <summary>
- /// 数据节点总长度
- /// </summary>
- private int _length;
- /// <summary>
- /// 时间间隔下的第一个数据索引 >=5
- /// </summary>
- private int _numBars;
- /// <summary>
- /// 左边纵坐标引起的位移
- /// </summary>
- private double _offset;
- /// <summary>
- /// 时间线,如1分钟线、2分钟线...
- /// </summary>
- private TimeSpan _timeSpan;
- #endregion Fields
- #region Constructors
- public AllDateScaler(Chart chart)
- {
- this._chart = chart;
- this._dictionary = new Dictionary<DateTime, int>();
- this._endDateTime = DateTime.MaxValue;
- this._desiredChartLength = "";
- this._endIndex = 0;
- //numBars为矩形柱间距,矩形柱数量实际要-1
- this._numBars = _chart.RecordCountInternal - 1;
- //左右分割线-决定右边空出位置
- this._futureSplitPercent = 0.0f;//0.1f;
- this._hasNonEODDates = false;
- this._isForex = false;
- }
- #endregion Constructors
- #region Properties
- #region Public Properties
- public string DesiredChartLength
- {
- get
- {
- return this._desiredChartLength;
- }
- set
- {
- this._desiredChartLength = value;
- this.OnScalerPropertyChanged();
- }
- }
- public DateTime DesiredEndDate
- {
- get
- {
- return this._endDateTime;
- }
- set
- {
- bool flag = DateTime.Compare(this._endDateTime, value) != 0;
- if (flag)
- {
- this._endDateTime = value;
- this.OnScalerPropertyChanged();
- }
- }
- }
- public int EndDateIndex
- {
- get
- {
- return this._endIndex;
- }
- set
- {
- _endIndex = value;
- }
- }
- /// <summary>
- /// 最后一个数据索引
- /// </summary>
- public int EndIndex
- {
- get
- {
- return this._endIndex;
- }
- }
- public float FutureSplitPercent
- {
- get
- {
- return this._futureSplitPercent;
- }
- set
- {
- bool flag = (double)value > 0.9;
- if (flag)
- {
- this._futureSplitPercent = value;
- }
- else
- {
- flag = (value < 0f);
- if (flag)
- {
- this._futureSplitPercent = 0f;
- }
- else
- {
- this._futureSplitPercent = value;
- }
- }
- this.OnScalerPropertyChanged();
- }
- }
- public int IndexOfLastDataDate
- {
- get
- {
- bool flag = this._dataSource != null && this._dataSource.Count > 0;
- checked
- {
- int result;
- if (flag)
- {
- result = this.IndexFromDate(this._dataSource[this._dataSource.Count - 1].Date);
- }
- else
- {
- result = this._fullDataPoints == null ? 0 : this._fullDataPoints.Count - 1;
- }
- return result;
- }
- }
- }
- /// <summary>
- /// 时间间隔下的第一个数据索引(时间轴节点间的间距) >=5
- /// </summary>
- public int NumBars
- {
- get
- {
- return this._numBars;
- }
- set
- {
- bool flag = this._numBars != value;
- if (flag)
- {
- //numBars为矩形柱间距,矩形柱数量实际要-1
- var minBarsCount = _chart.MinRecordCountInternal - 1;
- var maxBarsCount = _chart.MaxRecordCountInternal - 1;
- this._numBars = value;
- flag = (this._numBars < minBarsCount);
- if (flag)
- {
- this._numBars = minBarsCount;
- }
- //限制滑块滑动显示数据范围
- _numBars = (this._numBars < minBarsCount) ? minBarsCount
- : ((this._numBars > maxBarsCount) ? maxBarsCount : _numBars);
- //最小值为4
- _numBars = Math.Max(4, _numBars);
- this._desiredChartLength = "";
- this.OnScalerPropertyChanged();
- }
- }
- }
- public int StartDateIndex
- {
- get
- {
- return Math.Max(0, checked(this._endIndex - this._numBars));
- }
- set
- {
- _endIndex = value;
- }
- }
- #endregion Public Properties
- #endregion Properties
- #region Methods
- #region Public Methods
- public int BinaryIndexSearch(DateTime aDate, int MinIndex)
- {
- int i = MinIndex;
- //int num = this.EndIndex;
- //大于原始数据最大的取原始最大
- var originalEndIndex = _dataSource.Count - 1;
- var num = _endIndex > originalEndIndex ? originalEndIndex : _endIndex;
- bool flag = false;
- bool flag2 = DateTime.Compare(aDate, this.DateValue(num)) > 0;
- checked
- {
- int result;
- if (flag2)
- {
- result = -1;
- }
- else
- {
- flag2 = this._dictionary.ContainsKey(aDate);
- int num2 = 0;
- if (flag2)
- {
- flag = true;
- num2 = this._dictionary[aDate];
- }
- else
- {
- while (i < num)
- {
- flag2 = (num - i > 60);
- if (flag2)
- {
- num2 = (int)Math.Round(unchecked((double)i + (double)checked(num - i) / 20.0));
- }
- else
- {
- num2 = (int)Math.Round((double)(i + num) / 2.0);
- }
- flag2 = (DateTime.Compare(aDate, this.DateValue(num2)) > 0);
- if (flag2)
- {
- i = num2 + 1;
- }
- else
- {
- flag2 = (DateTime.Compare(aDate, this.DateValue(num2)) < 0);
- if (!flag2)
- {
- flag = true;
- break;
- }
- num = num2 - 1;
- }
- }
- }
- flag2 = flag;
- int num3;
- if (flag2)
- {
- num3 = num2;
- }
- else
- {
- flag2 = (DateTime.Compare(this.DateValue(i), aDate) == 0);
- if (flag2)
- {
- num3 = i;
- }
- else
- {
- flag2 = (DateTime.Compare(this.DateValue(i), aDate) < 0);
- if (flag2)
- {
- num3 = i + 1;
- }
- else
- {
- flag2 = (DateTime.Compare(this.DateValue(i), aDate) > 0);
- if (flag2)
- {
- num3 = i;
- }
- else
- {
- num3 = num2 - 1;
- }
- }
- }
- }
- result = num3;
- }
- return result;
- }
- }
- public int Count()
- {
- bool flag = this._fullDataPoints == null;
- int result;
- if (flag)
- {
- result = 0;
- }
- else
- {
- result = this._fullDataPoints.Count;
- }
- return result;
- }
- /// <summary>
- /// Dates the contains.
- /// </summary>
- /// <param name="date">The date.</param>
- /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
- public bool DateContains(DateTime date)
- {
- return _dictionary.Keys.Contains(date);
- }
- public DateTime DateFromX(double aX)
- {
- checked
- {
- var result = new DateTime();
- try
- {
- bool flag = !(this._fullDataPoints != null && this._fullDataPoints.Count != 0 && this._endIndex != this.StartDateIndex);
- if (flag)
- {
- var dateTime = new DateTime(1900, 1, 1);
- result = dateTime;
- }
- else
- {
- //通过x取日期时去掉左边纵坐标的宽度
- double num = (aX - _offset) / (double)this.WidthWithBarBuffer();
- int num2 = (int)Math.Round((double)unchecked((float)this.StartDateIndex + (float)checked(this._endIndex - this.StartDateIndex) * num));
- flag = (num2 >= 0 && num2 < this._fullDataPoints.Count);
- if (flag)
- {
- result = this._fullDataPoints[num2].Date;
- }
- //else
- //{
- // DateTime dateTime2 = MarketDates.DateFromMarketDateId((int)Math.Round((double)unchecked((float)this.AllDateScaler_718 + num * (float)checked(this.AllDateScaler_719 - this.AllDateScaler_718))), this.isForex);
- // flag = (this.AllDateScaler_716.Days < 1);
- // if (flag)
- // {
- // result = dateTime2;
- // }
- // else
- // {
- // result = dateTime2.Date;
- // }
- //}
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- return result;
- }
- }
- public DateTime DateValue(int aIndex)
- {
- if (this._fullDataPoints == null || !this._fullDataPoints.Any()) return default(DateTime);
- var flag = aIndex >= 0 && aIndex < this._fullDataPoints.Count;
- return flag ? this._fullDataPoints[aIndex].Date : default(DateTime);
- }
- public bool DateVisible(DateTime aDate)
- {
- var allDateScaler = this._fullDataPoints;
- //只有一条数据直接返回true
- if (allDateScaler == null || allDateScaler.Count == 1) return true;
- bool flag = true;
- if (allDateScaler.Count != 0)
- {
- if (this._endIndex != this.StartDateIndex)
- {
- flag = false;
- }
- }
- bool result;
- if (flag)
- {
- result = false;
- }
- else
- {
- flag = true;
- if (this.StartDateIndex >= 0 && this.EndIndex >= 0)
- {
- if (this.StartDateIndex < allDateScaler.Count)
- {
- if (this.EndIndex < allDateScaler.Count)
- {
- flag = false;
- }
- }
- }
- if (flag)
- {
- result = false;
- }
- else
- {
- //大于原始数据最大的取原始最大
- var originalEndIndex = _dataSource.Count - 1;
- var endIndex = _endIndex > originalEndIndex ? originalEndIndex : _endIndex;
- //修复第一条不可见Bug:重新变成>=
- flag = (DateTime.Compare(aDate, allDateScaler[this.StartDateIndex].Date) >= 0
- && DateTime.Compare(aDate, allDateScaler[endIndex].Date) <= 0);
- result = flag;
- }
- }
- return result;
- }
- /// <summary>
- /// 数据间的间隔
- /// </summary>
- /// <returns></returns>
- public double DistanceBetweenDates()
- {
- bool flag = this._fullDataPoints == null;
- double result;
- if (flag)
- {
- result = 0f;
- }
- else
- {
- flag = (this._fullDataPoints.Count > 0 && this._endIndex != this.StartDateIndex);
- if (flag)
- {
- result = ((double)this._length * (1.0 / (double)checked(this._endIndex - this.StartDateIndex + 1)));
- }
- else
- {
- result = 0f;
- }
- }
- return result;
- }
- /// <summary>
- /// Firsts the visible index from data.
- /// </summary>
- /// <param name="data">The data.</param>
- /// <returns>System.Int32.</returns>
- public int FirstVisibleIndexFromData(IList<ILineDataPoint> data)
- {
- if (this._fullDataPoints == null || !this._fullDataPoints.Any()) return 0;
- var startTime = this._fullDataPoints[this.StartDateIndex].Date;
- var dataPoint = data.FirstOrDefault(z => z.Date >= startTime);
- if (dataPoint == null) return 0;
- var result = data.IndexOf(dataPoint);
- return result == -1 ? 0 : result;
- }
- public bool HasNonEODDates()
- {
- return this._hasNonEODDates;
- }
- public int IndexFromDate(DateTime aDate)
- {
- bool flag = this._dictionary.ContainsKey(aDate);
- int result;
- if (flag)
- {
- result = this._dictionary[aDate];
- }
- else
- {
- result = -100;
- }
- return result;
- }
- /// <summary>
- /// Lasts the visible index from data.
- /// </summary>
- /// <param name="data">The data.</param>
- /// <returns>System.Int32.</returns>
- public int LastVisibleIndexFromData(IList<ILineDataPoint> data)
- {
- if (this._fullDataPoints == null || !this._fullDataPoints.Any()) return 0;
- var endTime = this._fullDataPoints[this.EndDateIndex].Date;
- var dataPoint = data.FirstOrDefault(z => z.Date >= endTime);
- if (dataPoint == null) return data.Count - 1;
- var result = data.IndexOf(dataPoint);
- return result == -1 ? 0 : result;
- }
- public DateTime OriginalDateFromX(double aX)
- {
- if (_dataSource == null || !_dataSource.Any()) return default(DateTime);
- var count = this._dataSource.Count;
- if (this._dataSource != null && count != 0 && this._endIndex != this.StartDateIndex && this.WidthWithBarBuffer() != 0)
- {
- double num = (aX - _offset) / (double)this.WidthWithBarBuffer();
- var num2 = (int)Math.Round(this.StartDateIndex + (this._endIndex - this.StartDateIndex) * num);
- if (num2 < 0)
- {
- return _dataSource.Min(z => z.Date);
- }
- if (num2 >= count - 1)
- {
- return _dataSource.Max(z => z.Date);
- }
- return this._dataSource[num2].Date;
- }
- return new DateTime(1900, 1, 1);
- }
- public DateTime OriginalDateFromX(double aX, int offSet)
- {
- if (_dataSource == null || !_dataSource.Any()) return default(DateTime);
- var count = this._dataSource.Count;
- if (this._dataSource != null && count != 0 &&
- this._endIndex != this.StartDateIndex && this.WidthWithBarBuffer() != 0)
- {
- //通过x取日期时去掉左边纵坐标的宽度
- double num = (aX - _offset) / (double)this.WidthWithBarBuffer();
- var num2 = (int)Math.Round(this.StartDateIndex + (this._endIndex - this.StartDateIndex) * num) + offSet;
- if (num2 < 0) return _dataSource.Min(z => z.Date);
- if (num2 >= count - 1) return _dataSource.Max(z => z.Date);
- //修复第一条不可见Bug:n+1->n
- return this._dataSource[num2].Date;
- }
- return new DateTime(1900, 1, 1);
- }
- public DateTime OriginalDateValue(int aIndex)
- {
- if (_dataSource == null || !_dataSource.Any()) return default(DateTime);
- bool flag = aIndex >= 0 && aIndex < this._dataSource.Count;
- DateTime result;
- if (flag)
- {
- result = this._dataSource[aIndex].Date;
- }
- else
- {
- result = this._dataSource.Max(z => z.Date);
- }
- return result;
- }
- public float PercentFromDate(DateTime aDate)
- {
- bool flag = this._dictionary.ContainsKey(aDate);
- checked
- {
- float result = 0;
- if (flag)
- {
- int num = this._dictionary[aDate];
- result = (float)((double)(num - this.StartDateIndex) / (double)(this._endIndex - this.StartDateIndex));
- }
- //else
- //{
- // int num2 = MarketDates.MarketDateId(aDate, this.isForex);
- // result = (float)((double)(num2 - this.AllDateScaler_718) / (double)(this.AllDateScaler_719 - this.AllDateScaler_718));
- //}
- return result;
- }
- }
- public float PercentFromIndex(int aIndex)
- {
- bool flag = this._endIndex != this.StartDateIndex;
- float result = 0f;
- if (flag)
- {
- result = (float)checked((double)(aIndex - this.StartDateIndex) / (double)(this._endIndex - this.StartDateIndex));
- }
- return result;
- }
- public void SetDates(IList<ILineDataPoint> data, TimeSpan aTimeFrame, bool isForex)
- {
- this._isForex = isForex;
- this._timeSpan = aTimeFrame;
- this._dataSource = data;
- this.OnScalerPropertyChanged();
- }
- /// <summary>
- /// 设置滑动块的总长度
- /// </summary>
- /// <param name="width">绘图区宽度</param>
- /// <param name="offset">左边纵坐标引起的位移</param>
- public void SetPlotInfo(int width, float offset)
- {
- this._length = width;
- this._offset = offset;
- }
- public int WidthWithBarBuffer()
- {
- checked
- {
- //修复第一条不可见Bug:*0.3->* 1.3
- int num = (int)Math.Round(unchecked((double)this._length - (double)this.DistanceBetweenDates() * 1.3));
- num--;
- bool flag = num < 0;
- if (flag)
- {
- num = 0;
- }
- return num;
- }
- }
- public float XforDate(DateTime aDate)
- {
- bool flag = !(this._fullDataPoints != null && this._fullDataPoints.Count != 0 && this._endIndex != this.StartDateIndex);
- float result = 0;
- if (flag)
- {
- result = -1000f;
- }
- else
- {
- //var item = aDate;
- //if (_chart.CycleType == CycleType.TimeSharing)
- //{
- // item = _dictionary.Keys.FirstOrDefault(z => z.Date == aDate.Date && z.Hour == aDate.Hour && z.Minute == aDate.Minute);
- // flag = this._dictionary.ContainsKey(item);
- //}
- //else
- //{
- flag = this._dictionary.ContainsKey(aDate);
- //}
- if (flag)
- {
- //修复第一条不可见Bug:因为要右移1/2 DistanceBetweenDates(),,所以num +1
- int num = this._dictionary[aDate] + 1;
- result = (float)((double)this.WidthWithBarBuffer() * checked((double)(num - this.StartDateIndex) / (double)(this._endIndex - this.StartDateIndex)));
- result -= (float)(DistanceBetweenDates() / 2);
- }
- else
- {
- var a = string.Empty;
- //int num2 = MarketDates.MarketDateId(aDate, this.isForex);
- //result = (float)((double)this.WidthWithBarBuffer() * checked((double)(num2 - this.AllDateScaler_718) / (double)(this.AllDateScaler_719 - this.AllDateScaler_718)));
- }
- }
- return result;
- }
- #endregion Public Methods
- #region Private Methods
- /// <summary>
- /// 根据最后一天返回当前所设置时间间隔的第一天
- /// </summary>
- /// <param name="endDate"></param>
- /// <returns></returns>
- private DateTime GetCurrentFirstDate(DateTime endDate)
- {
- bool flag = endDate.Ticks == 0L;
- checked
- {
- var result = new DateTime();
- if (flag)
- {
- result = endDate;
- }
- else
- {
- string allDateScaler_ = this._desiredChartLength;
- flag = allDateScaler_.Equals("5Y");
- if (flag)
- {
- result = endDate.AddYears(-5);
- }
- else
- {
- flag = (Operators.CompareString(allDateScaler_, "1Y", false) == 0);
- if (flag)
- {
- result = endDate.AddYears(-1);
- }
- else
- {
- flag = (Operators.CompareString(allDateScaler_, "YTD", false) == 0);
- if (flag)
- {
- DateTime dateTime = new DateTime(endDate.Year, 1, 1);
- result = dateTime;
- }
- else
- {
- flag = (Operators.CompareString(allDateScaler_, "6M", false) == 0);
- if (flag)
- {
- result = endDate.AddMonths(-6);
- }
- else
- {
- flag = (Operators.CompareString(allDateScaler_, "3M", false) == 0);
- if (flag)
- {
- result = endDate.AddMonths(-3);
- }
- else
- {
- flag = (Operators.CompareString(allDateScaler_, "1M", false) == 0);
- if (flag)
- {
- result = endDate.AddMonths(-1);
- }
- else
- {
- flag = (Operators.CompareString(allDateScaler_, "1W", false) == 0);
- if (flag)
- {
- result = endDate.AddDays(-7.0);
- }
- else
- {
- flag = (Operators.CompareString(allDateScaler_, "1D", false) == 0);
- if (flag)
- {
- int num = 1;
- flag = this._isForex;
- DateTime dateTime2;
- if (flag)
- {
- dateTime2 = endDate.AddDays(-1.0);
- while (dateTime2.DayOfWeek == (DayOfWeek)6 && num < 3)
- {
- dateTime2 = dateTime2.AddDays(-1.0);
- num++;
- }
- }
- else
- {
- dateTime2 = endDate.AddDays(-1.0);
- while (true)
- {
- if (!Conversions.ToBoolean(num < 3))
- {
- goto IL_28E;
- }
- //if (!Conversions.ToBoolean(dateTime2.DayOfWeek == (DayOfWeek)6 || dateTime2.DayOfWeek == 0) && !Conversions.ToBoolean(MarketDates.IsWholeDayHoliday(dateTime2, this.isForex)))
- //{
- // goto IL_28E;
- //}
- if (!Conversions.ToBoolean(dateTime2.DayOfWeek == (DayOfWeek)6 || dateTime2.DayOfWeek == 0))
- {
- goto IL_28E;
- }
- object arg_294_0 = true;
- IL_294:
- if (!Conversions.ToBoolean(arg_294_0))
- {
- break;
- }
- dateTime2 = dateTime2.AddDays(-1.0);
- num++;
- continue;
- IL_28E:
- arg_294_0 = false;
- goto IL_294;
- }
- }
- result = dateTime2;
- }
- else
- {
- flag = (Operators.CompareString(allDateScaler_, "Today", false) == 0);
- if (flag)
- {
- DateTime dateTime = new DateTime(endDate.Year, endDate.Month, endDate.Day);
- result = dateTime;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return result;
- }
- }
- private List<IDateDataPoint> GetDayExtrDataPoints(DateTime aStartDate, int numToAdd)
- {
- var list = new List<IDateDataPoint>();
- DateTime dateTime = aStartDate.Date;
- checked
- {
- if (this._isForex)
- {
- while (list.Count < numToAdd)
- {
- do
- {
- dateTime = dateTime.Add(this._timeSpan);
- }
- while (dateTime.DayOfWeek == (DayOfWeek)6);
- var allDateScaler_ = new AllDateScaler.DateDataPoint(dateTime);
- if (this._dataSource == null || this._dataSource.Count == 0)
- {
- goto IL_9D;
- }
- if (DateTime.Compare(this._dataSource[this._dataSource.Count - 1].Date, dateTime) < 0)
- {
- goto IL_9D;
- }
- bool arg_9E_0 = false;
- IL_9E:
- var flag = arg_9E_0;
- if (flag)
- {
- list.Add(allDateScaler_);
- }
- continue;
- IL_9D:
- arg_9E_0 = true;
- goto IL_9E;
- }
- }
- else
- {
- while (list.Count < numToAdd)
- {
- //do
- //{
- // dateTime = dateTime.Add(this.AllDateScaler_716);
- //}
- //while (Conversions.ToBoolean((Conversions.ToBoolean(dateTime.DayOfWeek == (DayOfWeek)6 || dateTime.DayOfWeek == 0) || Conversions.ToBoolean(MarketDates.IsWholeDayHoliday(dateTime, this.isForex))) ? true : false));
- do
- {
- dateTime = dateTime.Add(this._timeSpan);
- }
- while (dateTime.DayOfWeek == (DayOfWeek)6 || dateTime.DayOfWeek == 0);
- var allDateScaler_2 = new AllDateScaler.DateDataPoint(dateTime);
- if (this._dataSource == null || this._dataSource.Count == 0)
- {
- goto IL_173;
- }
- if (DateTime.Compare(this._dataSource[this._dataSource.Count - 1].Date, dateTime) < 0)
- {
- goto IL_173;
- }
- bool arg_174_0 = false;
- IL_174:
- var flag = arg_174_0;
- if (flag)
- {
- list.Add(allDateScaler_2);
- }
- continue;
- IL_173:
- arg_174_0 = true;
- goto IL_174;
- }
- }
- return list;
- }
- }
- /// <summary>
- /// Gets the extra data points.
- /// </summary>
- /// <returns>List{IDateDataPoint}.</returns>
- private List<IDateDataPoint> GetExtraDataPoints()
- {
- bool flag = this._futureSplitPercent > 0f && this._dataSource != null && this._dataSource.Count > 1;
- checked
- {
- List<IDateDataPoint> result;
- if (flag)
- {
- DateTime aStartDate = this._dataSource[this._dataSource.Count - 2].Date.Add(this._timeSpan);
- int numToAdd = (int)Math.Round((double)unchecked((float)this.NumBars * this._futureSplitPercent));
- flag = (this._timeSpan.Days < 1);
- if (flag)
- {
- result = this.GetlessThenDayExtraDataPoints(aStartDate, numToAdd);
- }
- else
- {
- flag = (this._timeSpan.Days == 255);
- if (flag)
- {
- aStartDate = this._dataSource[this._dataSource.Count - 1].Date;
- result = this.GetYearExtraDataPoints(aStartDate, numToAdd);
- }
- else
- {
- flag = (this._timeSpan.Days == 120);
- if (flag)
- {
- aStartDate = this._dataSource[this._dataSource.Count - 1].Date;
- result = this.GetQuarterDataExtraPoints(aStartDate, numToAdd);
- }
- else
- {
- flag = (this._timeSpan.Days == 30);
- if (flag)
- {
- aStartDate = this._dataSource[this._dataSource.Count - 1].Date;
- result = this.GetMonthExtraDataPoints(aStartDate, numToAdd);
- }
- else
- {
- flag = (this._timeSpan.Days == 5);
- if (flag)
- {
- aStartDate = this._dataSource[this._dataSource.Count - 1].Date;
- result = this.GetWeekExtraDataPoints(aStartDate, numToAdd);
- }
- else
- {
- result = this.GetDayExtrDataPoints(aStartDate, numToAdd);
- }
- }
- }
- }
- }
- }
- else
- {
- result = null;
- }
- return result;
- }
- }
- /// <summary>
- /// Gets the last contains.
- /// </summary>
- /// <param name="date">The date.</param>
- /// <returns>System.Int32.</returns>
- private int GetLastContainsValue(DateTime date)
- {
- if (_dictionary == null || !_dictionary.Any()) return 0;
- foreach (var keyPair in _dictionary)
- {
- if (keyPair.Key >= date) return keyPair.Value;
- }
- return 0;
- }
- private List<IDateDataPoint> GetlessThenDayExtraDataPoints(DateTime aStartDate, int numToAdd)
- {
- var list = new List<IDateDataPoint>();
- bool flag = this._isForex;
- checked
- {
- if (flag)
- {
- DateTime aDate = aStartDate.AddSeconds((double)(-1 * aStartDate.Second));
- while (list.Count < numToAdd)
- {
- aDate = aDate.Add(this._timeSpan);
- flag = (aDate.DayOfWeek == (DayOfWeek)6);
- if (!flag)
- {
- if (aDate.DayOfWeek != (DayOfWeek)5)
- {
- goto IL_B8;
- }
- TimeSpan arg_B1_0 = aDate.TimeOfDay;
- TimeSpan timeSpan = new TimeSpan(17, 0, 0);
- if (!(arg_B1_0 > timeSpan))
- {
- goto IL_B8;
- }
- bool arg_BC_0 = true;
- IL_BC:
- flag = arg_BC_0;
- if (flag)
- {
- aDate = aDate.Date.AddDays(2.0).AddHours(17.0);
- goto IL_13A;
- }
- if (aDate.DayOfWeek != 0)
- {
- goto IL_116;
- }
- TimeSpan arg_10F_0 = aDate.TimeOfDay;
- timeSpan = new TimeSpan(17, 0, 0);
- if (!(arg_10F_0 < timeSpan))
- {
- goto IL_116;
- }
- bool arg_11A_0 = true;
- IL_11A:
- flag = arg_11A_0;
- if (flag)
- {
- aDate = aDate.Date.AddHours(17.0);
- goto IL_13A;
- }
- goto IL_13A;
- IL_116:
- arg_11A_0 = false;
- goto IL_11A;
- IL_B8:
- arg_BC_0 = false;
- goto IL_BC;
- }
- aDate = aDate.Date.AddDays(1.0).AddHours(17.0);
- IL_13A:
- var allDateScaler_ = new AllDateScaler.DateDataPoint(aDate);
- list.Add(allDateScaler_);
- }
- }
- else
- {
- DateTime aDate2 = aStartDate.AddSeconds((double)(-1 * aStartDate.Second));
- TimeSpan timeSpan2 = new TimeSpan(16, 0, 0);
- TimeSpan timeSpan3 = new TimeSpan(9, 30, 0);
- TimeSpan timeSpan4 = new TimeSpan(16, 0, 0);
- TimeSpan timeSpan5 = new TimeSpan(9, 30, 0);
- //MarketDates.HolidayItem holidayItem = MarketDates.GetHoliday(aDate2, this.isForex);
- //flag = (holidayItem != null && holidayItem.WholeDay);
- //if (flag)
- //{
- // holidayItem = null;
- //}
- while (list.Count < numToAdd)
- {
- aDate2 = aDate2.Add(this._timeSpan);
- flag = true;// (holidayItem == null);
- if (flag)
- {
- timeSpan4 = timeSpan2;
- timeSpan5 = timeSpan3;
- }
- //else
- //{
- // timeSpan4 = holidayItem.CloseTime;
- // timeSpan5 = holidayItem.OpenTime;
- //}
- while (true)
- {
- if (aDate2.TimeOfDay > timeSpan4 || aDate2.DayOfWeek == (DayOfWeek)6)
- {
- goto IL_2C4;
- }
- if (aDate2.DayOfWeek == 0)
- {
- goto IL_2C4;
- }
- bool arg_2C5_0 = false;
- IL_2C5:
- if (!arg_2C5_0)
- {
- break;
- }
- //if (!Conversions.ToBoolean((Conversions.ToBoolean(arg_2C5_0) || Conversions.ToBoolean(MarketDates.IsWholeDayHoliday(aDate2, this.isForex))) ? true : false))
- //{
- // break;
- //}
- aDate2 = aDate2.Date.AddDays(1.0).Add(timeSpan3).Add(this._timeSpan);
- //holidayItem = MarketDates.GetHoliday(aDate2, this.isForex);
- //flag = (holidayItem != null && holidayItem.WholeDay);
- //if (flag)
- //{
- // holidayItem = null;
- //}
- //flag = (holidayItem == null);
- if (flag)
- {
- timeSpan4 = timeSpan2;
- timeSpan5 = timeSpan3;
- }
- //else
- //{
- // timeSpan4 = holidayItem.CloseTime;
- // timeSpan5 = holidayItem.OpenTime;
- //}
- continue;
- IL_2C4:
- arg_2C5_0 = true;
- goto IL_2C5;
- }
- flag = (aDate2.TimeOfDay >= timeSpan5);
- if (flag)
- {
- AllDateScaler.DateDataPoint allDateScaler_2 = new AllDateScaler.DateDataPoint(aDate2);
- list.Add(allDateScaler_2);
- }
- }
- }
- return list;
- }
- }
- private List<IDateDataPoint> GetMonthExtraDataPoints(DateTime aStartDate, int NumToAdd)
- {
- var list = new List<IDateDataPoint>();
- DateTime aDate = aStartDate.Date;
- checked
- {
- if (this._isForex)
- {
- while (list.Count < NumToAdd)
- {
- aDate = new DateTime(aDate.Year, aDate.Month, 1);
- aDate = aDate.AddMonths(1);
- aDate = aDate.AddDays((double)(DateTime.DaysInMonth(aDate.Year, aDate.Month) - 1));
- while (aDate.DayOfWeek == (DayOfWeek)6)
- {
- aDate = aDate.AddDays(-1.0);
- }
- AllDateScaler.DateDataPoint allDateScaler_2 = new AllDateScaler.DateDataPoint(aDate);
- list.Add(allDateScaler_2);
- }
- }
- else
- {
- while (list.Count < NumToAdd)
- {
- aDate = new DateTime(aDate.Year, aDate.Month, 1);
- aDate = aDate.AddMonths(1);
- aDate = aDate.AddDays((double)(DateTime.DaysInMonth(aDate.Year, aDate.Month) - 1));
- //while (Conversions.ToBoolean((Conversions.ToBoolean(aDate.DayOfWeek == (DayOfWeek)6 || aDate.DayOfWeek == 0) || Conversions.ToBoolean(MarketDates.IsWholeDayHoliday(aDate, this.isForex))) ? true : false))
- //{
- // aDate = aDate.AddDays(-1.0);
- //}
- while (aDate.DayOfWeek == (DayOfWeek)6 || aDate.DayOfWeek == 0)
- {
- aDate = aDate.AddDays(-1.0);
- }
- AllDateScaler.DateDataPoint allDateScaler_3 = new AllDateScaler.DateDataPoint(aDate);
- list.Add(allDateScaler_3);
- }
- }
- return list;
- }
- }
- private List<IDateDataPoint> GetQuarterDataExtraPoints(DateTime aStartDate, int NumToAdd)
- {
- var list = new List<IDateDataPoint>();
- DateTime aDate = aStartDate.Date;
- while (aDate.Month % 3 != 0)
- {
- aDate = aDate.AddMonths(1);
- }
- bool allDateScaler_ = this._isForex;
- if (allDateScaler_)
- {
- while (list.Count < NumToAdd)
- {
- aDate = aDate.AddMonths(3);
- aDate = new DateTime(aDate.Year, aDate.Month, DateTime.DaysInMonth(aDate.Year, aDate.Month));
- while (aDate.DayOfWeek == (DayOfWeek)6)
- {
- aDate = aDate.AddDays(-1.0);
- }
- AllDateScaler.DateDataPoint allDateScaler_2 = new AllDateScaler.DateDataPoint(aDate);
- list.Add(allDateScaler_2);
- }
- }
- else
- {
- while (list.Count < NumToAdd)
- {
- aDate = aDate.AddMonths(3);
- aDate = new DateTime(aDate.Year, aDate.Month, DateTime.DaysInMonth(aDate.Year, aDate.Month));
- //while (Conversions.ToBoolean((Conversions.ToBoolean(aDate.DayOfWeek == (DayOfWeek)6 || aDate.DayOfWeek == 0) || Conversions.ToBoolean(MarketDates.IsWholeDayHoliday(aDate, this.isForex))) ? true : false))
- //{
- // aDate = aDate.AddDays(-1.0);
- //}
- while (aDate.DayOfWeek == (DayOfWeek)6 || aDate.DayOfWeek == 0)
- {
- aDate = aDate.AddDays(-1.0);
- }
- AllDateScaler.DateDataPoint allDateScaler_3 = new AllDateScaler.DateDataPoint(aDate);
- list.Add(allDateScaler_3);
- }
- }
- return list;
- }
- private List<IDateDataPoint> GetWeekExtraDataPoints(DateTime aStartDate, int numToAdd)
- {
- var list = new List<IDateDataPoint>();
- DateTime aDate = aStartDate.Date;
- while (aDate.DayOfWeek != (DayOfWeek)5)
- {
- aDate = aDate.AddDays(1.0);
- }
- if (_isForex)
- {
- while (list.Count < numToAdd)
- {
- aDate = aDate.AddDays(7.0);
- AllDateScaler.DateDataPoint allDateScaler_2 = new AllDateScaler.DateDataPoint(aDate);
- list.Add(allDateScaler_2);
- while (aDate.DayOfWeek != (DayOfWeek)5)
- {
- aDate = aDate.AddDays(1.0);
- }
- }
- }
- else
- {
- while (list.Count < numToAdd)
- {
- aDate = aDate.AddDays(7.0);
- //while (Conversions.ToBoolean(MarketDates.IsWholeDayHoliday(aDate, this.isForex)))
- //{
- // aDate = aDate.AddDays(-1.0);
- //}
- AllDateScaler.DateDataPoint allDateScaler_3 = new AllDateScaler.DateDataPoint(aDate);
- list.Add(allDateScaler_3);
- while (aDate.DayOfWeek != (DayOfWeek)5)
- {
- aDate = aDate.AddDays(1.0);
- }
- }
- }
- return list;
- }
- private List<IDateDataPoint> GetYearExtraDataPoints(DateTime aStartDate, int numToAdd)
- {
- var list = new List<IDateDataPoint>();
- DateTime aDate = aStartDate.Date;
- bool allDateScaler_ = this._isForex;
- checked
- {
- if (allDateScaler_)
- {
- while (list.Count < numToAdd)
- {
- aDate = new DateTime(aDate.Year + 1, 12, DateTime.DaysInMonth(aDate.Year + 1, 12));
- while (aDate.DayOfWeek == (DayOfWeek)6)
- {
- aDate = aDate.AddDays(-1.0);
- }
- AllDateScaler.DateDataPoint allDateScaler_2 = new AllDateScaler.DateDataPoint(aDate);
- list.Add(allDateScaler_2);
- }
- }
- else
- {
- while (list.Count < numToAdd)
- {
- aDate = new DateTime(aDate.Year + 1, 12, DateTime.DaysInMonth(aDate.Year + 1, 12));
- //while (Conversions.ToBoolean((Conversions.ToBoolean(aDate.DayOfWeek == (DayOfWeek)6 || aDate.DayOfWeek == 0) || Conversions.ToBoolean(MarketDates.IsWholeDayHoliday(aDate, this.isForex))) ? true : false))
- //{
- // aDate = aDate.AddDays(-1.0);
- //}
- while (aDate.DayOfWeek == (DayOfWeek)6 || aDate.DayOfWeek == 0)
- {
- aDate = aDate.AddDays(-1.0);
- }
- AllDateScaler.DateDataPoint allDateScaler_3 = new AllDateScaler.DateDataPoint(aDate);
- list.Add(allDateScaler_3);
- }
- }
- return list;
- }
- }
- private void OnScalerPropertyChanged()
- {
- var list = new List<IDateDataPoint>();
- var flag = (this._dataSource != null && this._dataSource.Any());
- if (flag)
- {
- list.AddRange(_dataSource.Cast<IDateDataPoint>());
- }
- this._extraDataPoints = this.GetExtraDataPoints();
- flag = (this._extraDataPoints != null);
- if (flag)
- {
- list.AddRange(_extraDataPoints);
- }
- flag = (list.Count > 0 && list.Count < 3);
- checked
- {
- if (flag)
- {
- try
- {
- int i = 3 - list.Count;
- DateTime aDate = list[0].Date;
- while (i > 0)
- {
- i--;
- //使用Add代替Insert,否则DataVisible会判断出错
- //aDate = aDate.Subtract(this._timeSpan);
- //list.Insert(0, new AllDateScaler.DateDataPoint(aDate));
- aDate = aDate.Add(this._timeSpan);
- list.Add(new AllDateScaler.DateDataPoint(aDate));
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- this._fullDataPoints = list;
- var dictionary = new Dictionary<DateTime, int>();
- this._hasNonEODDates = false;
- flag = (this._fullDataPoints != null);
- if (flag)
- {
- var timeSpan = new TimeSpan(16, 0, 0);
- int num = this._fullDataPoints.Count - 1;
- int num2 = 0;
- while (true)
- {
- int num3 = num;
- if (num2 > num3)
- {
- break;
- }
- DateTime dateTime = this._fullDataPoints[num2].Date;
- flag = (!this._hasNonEODDates && dateTime.TimeOfDay != timeSpan);
- if (flag)
- {
- this._hasNonEODDates = true;
- }
- dictionary[dateTime] = num2;
- num2++;
- }
- flag = (DateTime.Compare(this._endDateTime, DateTime.MaxValue) == 0);
- if (flag)
- {
- this._endIndex = this._fullDataPoints.Count - 1;
- }
- else
- {
- int num4 = this._fullDataPoints.Count - 1;
- while (true)
- {
- int num3 = 0;
- if (num4 < num3)
- {
- goto IL_272;
- }
- flag = (DateTime.Compare(this._fullDataPoints[num4].Date, this._endDateTime) <= 0);
- if (flag)
- {
- break;
- }
- num4 += -1;
- }
- this._endIndex = num4;
- IL_272:
- flag = (this._endIndex < this._numBars);
- if (flag)
- {
- this._endIndex = this._numBars;
- }
- flag = (this._endIndex > this._fullDataPoints.Count - 1);
- if (flag)
- {
- this._endIndex = this._fullDataPoints.Count - 1;
- }
- }
- flag = (this._dataSource != null && this._dataSource.Count > 0
- && !string.IsNullOrWhiteSpace(this.DesiredChartLength) &&
- DateTime.Compare(this._endDateTime, DateTime.MaxValue) == 0);
- if (flag)
- {
- DateTime dateTime2 = this.GetCurrentFirstDate(this._dataSource[this._dataSource.Count - 1].Date);
- int num5 = 0;
- int num6 = this.EndIndex;
- while (true)
- {
- if (num6 < 0)
- {
- break;
- }
- num5++;
- flag = (DateTime.Compare(this._fullDataPoints[num6].Date, dateTime2) < 0);
- if (flag)
- {
- break;
- }
- num6 += -1;
- }
- flag = (num5 < _chart.MinRecordCountInternal);
- if (flag)
- {
- num5 = _chart.MinRecordCountInternal;
- }
- this._numBars = num5;
- }
- }
- else
- {
- this._endIndex = 0;
- }
- this._dictionary = dictionary;
- }
- }
- #endregion Private Methods
- #endregion Methods
- #region Nested Types
- private class DateDataPoint : IDateDataPoint
- {
- #region Constructors
- public DateDataPoint(DateTime aDate)
- {
- this.Date = aDate;
- }
- #endregion Constructors
- #region Properties
- #region Public Properties
- public DateTime Date
- {
- get;
- set;
- }
- #endregion Public Properties
- #endregion Properties
- }
- #endregion Nested Types
- }
- }
|