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 /// /// 是否是外汇 /// private bool _isForex; private Chart _chart; private IList _dataSource; /// /// 设置当前时间间隔如 5Y 3Y 3M Today... /// private string _desiredChartLength; private Dictionary _dictionary; /// /// 结束日期 /// private DateTime _endDateTime; /// /// 最后一个数据索引 /// private int _endIndex; private IList _extraDataPoints; /// /// 数据节点列表 /// private IList _fullDataPoints; /// /// FutureSplitPercent /// 左右分割线 /// private float _futureSplitPercent; private bool _hasNonEODDates; /// /// 数据节点总长度 /// private int _length; /// /// 时间间隔下的第一个数据索引 >=5 /// private int _numBars; /// /// 左边纵坐标引起的位移 /// private double _offset; /// /// 时间线,如1分钟线、2分钟线... /// private TimeSpan _timeSpan; #endregion Fields #region Constructors public AllDateScaler(Chart chart) { this._chart = chart; this._dictionary = new Dictionary(); 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; } } /// /// 最后一个数据索引 /// 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; } } } /// /// 时间间隔下的第一个数据索引(时间轴节点间的间距) >=5 /// 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; } /// /// Dates the contains. /// /// The date. /// true if XXXX, false otherwise 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; } /// /// 数据间的间隔 /// /// 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; } /// /// Firsts the visible index from data. /// /// The data. /// System.Int32. public int FirstVisibleIndexFromData(IList 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; } /// /// Lasts the visible index from data. /// /// The data. /// System.Int32. public int LastVisibleIndexFromData(IList 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 data, TimeSpan aTimeFrame, bool isForex) { this._isForex = isForex; this._timeSpan = aTimeFrame; this._dataSource = data; this.OnScalerPropertyChanged(); } /// /// 设置滑动块的总长度 /// /// 绘图区宽度 /// 左边纵坐标引起的位移 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 /// /// 根据最后一天返回当前所设置时间间隔的第一天 /// /// /// 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 GetDayExtrDataPoints(DateTime aStartDate, int numToAdd) { var list = new List(); 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; } } /// /// Gets the extra data points. /// /// List{IDateDataPoint}. private List GetExtraDataPoints() { bool flag = this._futureSplitPercent > 0f && this._dataSource != null && this._dataSource.Count > 1; checked { List 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; } } /// /// Gets the last contains. /// /// The date. /// System.Int32. 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 GetlessThenDayExtraDataPoints(DateTime aStartDate, int numToAdd) { var list = new List(); 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 GetMonthExtraDataPoints(DateTime aStartDate, int NumToAdd) { var list = new List(); 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 GetQuarterDataExtraPoints(DateTime aStartDate, int NumToAdd) { var list = new List(); 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 GetWeekExtraDataPoints(DateTime aStartDate, int numToAdd) { var list = new List(); 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 GetYearExtraDataPoints(DateTime aStartDate, int numToAdd) { var list = new List(); 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(); var flag = (this._dataSource != null && this._dataSource.Any()); if (flag) { list.AddRange(_dataSource.Cast()); } 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(); 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 } }