当前位置: 首页>>代码示例>>C#>>正文


C# SortedDictionary.SafeAdd方法代码示例

本文整理汇总了C#中SortedDictionary.SafeAdd方法的典型用法代码示例。如果您正苦于以下问题:C# SortedDictionary.SafeAdd方法的具体用法?C# SortedDictionary.SafeAdd怎么用?C# SortedDictionary.SafeAdd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SortedDictionary的用法示例。


在下文中一共展示了SortedDictionary.SafeAdd方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Download_OnClick

        private void Download_OnClick(object sender, RoutedEventArgs e)
        {
            var year = SelectedYear;
            var from = From.Value ?? year.Days.First();
            var to = (To.Value ?? year.Days.Last()).EndOfDay();
            var trader = SelectedTrader;
            var tf = SelectedTimeFrame;

            var seriesSet = _securityCtrls
                .Where(pair => pair.Key.SelectedSecurity != null)
                .Select(pair => Tuple.Create(new CandleSeries(typeof(TimeFrameCandle), pair.Key.SelectedSecurity, tf), pair.Value))
                .ToArray();

            BusyIndicator.BusyContent = "Подготовка данных...";
            BusyIndicator.IsBusy = true;

            _candles.Clear();

            var trades = new Dictionary<Security, Dictionary<DateTimeOffset, Tuple<MyTrade[], MyTrade>>>();

            var worker = new BackgroundWorker { WorkerReportsProgress = true };

            worker.DoWork += (o, ea) =>
            {
                foreach (var series in seriesSet)
                {
                    var security = series.Item1.Security;
                    var candleStorage = _dataRegistry.GetCandleStorage(series.Item1, format: StorageFormats.Csv);
                    var secCandles = _candles.SafeAdd(security);

                    secCandles.Clear();
                    secCandles.AddRange(candleStorage.Load(from, to));

                    var candlesDatesCache = _candlesDates.SafeAdd(Tuple.Create(security, tf), k => new DatesCache(Path.Combine(((LocalMarketDataDrive)candleStorage.Drive.Drive).GetSecurityPath(security.ToSecurityId()), "{0}min_date.bin".Put((int)tf.TotalMinutes))));

                    var minCandleDate = candlesDatesCache.MinValue;
                    var maxCandleDate = candlesDatesCache.MaxValue;

                    if (from >= minCandleDate && to <= maxCandleDate)
                        continue;

                    var finamFrom = from;
                    var finamTo = to;

                    if (maxCandleDate != null && finamFrom >= minCandleDate && finamFrom <= maxCandleDate)
                        finamFrom = maxCandleDate.Value + TimeSpan.FromDays(1);

                    if (minCandleDate != null && finamTo >= minCandleDate && finamTo <= maxCandleDate)
                        finamTo = minCandleDate.Value - TimeSpan.FromDays(1);

                    if (finamTo <= finamFrom)
                        continue;

                    worker.ReportProgress(1, Tuple.Create(security, finamFrom, finamTo));

                    var newCandles = (tf.Ticks == 1
                        ? finamFrom.Range(finamTo, TimeSpan.FromDays(1)).SelectMany(day => _finamHistorySource.GetTrades(security, day, day)).ToEx().ToCandles<TimeFrameCandle>(tf)
                        : _finamHistorySource.GetCandles(security, tf, finamFrom, finamTo)
                        ).ToArray();

                    candleStorage.Save(newCandles);

                    foreach (var date in newCandles.Select(c => c.OpenTime.Date).Distinct())
                        candlesDatesCache.Add(date);

                    candlesDatesCache.Save();

                    // TODO
                    secCandles.AddRange(newCandles);
                }

                var traderDrive = new LocalMarketDataDrive(trader);
                var traderStorage = _traderStorages.SafeAdd(trader, key => new StorageRegistry { DefaultDrive = traderDrive });

                foreach (var series in seriesSet)
                {
                    var security = series.Item1.Security;

                    var olStorage = traderStorage.GetOrderLogStorage(security, format: StorageFormats.Csv);
                    var tradeDatesCache = _tradesDates.SafeAdd(trader, k => new DatesCache(Path.Combine(traderDrive.Path, "dates.bin")));

                    var secTrades = from
                        .Range(to, TimeSpan.FromDays(1))
                        .Intersect(year.Days)
                        .SelectMany(date =>
                        {
                            if (olStorage.Dates.Contains(date))
                                return olStorage.Load(date);

                            if (tradeDatesCache.Contains(date))
                                return Enumerable.Empty<OrderLogItem>();

                            worker.ReportProgress(2, date);

                            var loadedTrades = year.GetTrades(_securityStorage, trader, date);

                            var dateTrades = Enumerable.Empty<OrderLogItem>();

                            foreach (var group in loadedTrades.GroupBy(t => t.Order.Security))
                            {
//.........这里部分代码省略.........
开发者ID:akovbovich,项目名称:AlgoTools,代码行数:101,代码来源:MainWindow.xaml.cs


注:本文中的SortedDictionary.SafeAdd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。