private void ChangePageTo(int index) { if (index <= 0) { return; } PageStockModels.Clear(); var temp = new List <StockModel>(StockModels.Skip((CurrentPageIndex - 1) * PageSize).Take(PageSize)); temp.ToList().ForEach(m => PageStockModels.Add(m)); }
/// <summary> /// 开始监控 /// </summary> private async void OnStart() { this.CanStart = false; StockModels.Clear(); PageStockModels.Clear(); _count = 0; this.TotalCrawledCount = 0; this.BigDealRemainCount = 0; this.QuickRemainCount = 0; StockModel.StaticIndex = 1; try { _configModel = ConfigJsonHelper.GetConfigModel(); Messenger.Default.Send(new StatusBarArgs(true, ResourceHelper.FindKey("StatusBar_Message_CheckingConfig")), StatusBarToken.UpdateStatus); bool isConfigUseful = await Task.Run(() => CheckConfig()); if (!isConfigUseful) { this.CanStart = true; return; } Messenger.Default.Send(new StatusBarArgs(true, ResourceHelper.FindKey("StatusBar_Message_FilteringStock")), StatusBarToken.UpdateStatus); List <string> monitorStocks = GetMonitorStocks(); if (monitorStocks == null) { this.CanStart = true; return; } if (!monitorStocks.Any()) { Messenger.Default.Send(new StatusBarArgs(true, ResourceHelper.FindKey("StatusBar_ConfigError_FilterNone")), StatusBarToken.UpdateStatus); this.CanStart = true; return; } CanStart = false; CanStop = true; WebProxy proxy = null; if (_configModel.IsUseProxy) { proxy = new WebProxy(_configModel.ProxyData.IP, _configModel.ProxyData.Port); } try { _iStockRealTimeDealCrawler?.StartCrawler(proxy, _configModel.ClawlerConfigData.QueryInterval, monitorStocks); } catch (ClawlerConfigException clawlerConfigException) { Messenger.Default.Send(new StatusBarArgs(true, clawlerConfigException.Message), StatusBarToken.UpdateStatus); await Task.Run(() => _iStockRealTimeDealCrawler?.StopCrawler()); this.CanStart = true; this.CanStop = false; return; } catch (Exception ex) { LogBuilder.Logger.Error("start crawler error.", ex); } if (false) { try { var stockAnalysisService = ServiceManager <StockTransactionModel> .Instance.GetStockAnalysisService(); _stockAnalysisService = stockAnalysisService; _stockAnalysisService.StockAnalysisResultUpdatedEvent += StockAnalysisService_StockAnalysisResultUpdatedEvent; _stockAnalysisService.RemainderCountUpdatedEvent += _stockAnalysisService_RemainderCountUpdatedEvent; _stockAnalysisService.StartAnalysis(new BigDealAnalysisStrategy(), _cacheBigDealAnalysisStrategy); } catch (StrategyConfigException strategyConfigException) { _stockAnalysisService.StockAnalysisResultUpdatedEvent -= StockAnalysisService_StockAnalysisResultUpdatedEvent; _stockAnalysisService.RemainderCountUpdatedEvent -= _stockAnalysisService_RemainderCountUpdatedEvent; _stockAnalysisService.StopAnalysis(); Messenger.Default.Send(new StatusBarArgs(true, strategyConfigException.Message), StatusBarToken.UpdateStatus); await Task.Run(() => _iStockRealTimeDealCrawler?.StopCrawler()); this.CanStart = true; this.CanStop = false; return; } catch (Exception ex) { LogBuilder.Logger.Error("start moniter BigOrderStrategy error.", ex); } } if (true) { try { var quickAnalysisService = ServiceManager <StockTransactionModelExtern> .Instance.GetStockAnalysisService(); _quickAnalysisService = quickAnalysisService; _quickAnalysisService.StockAnalysisResultUpdatedEvent += _quickAnalysisService_StockAnalysisResultUpdatedEvent; _quickAnalysisService.RemainderCountUpdatedEvent += _quickAnalysisService_RemainderCountUpdatedEvent; _quickAnalysisService.StartAnalysis(new QuickUpAnalysisStrategy(), _cacheQuickUpAnalysisStrategy); } catch (StrategyConfigException strategyConfigException) { _quickAnalysisService.StockAnalysisResultUpdatedEvent -= _quickAnalysisService_StockAnalysisResultUpdatedEvent; _quickAnalysisService.RemainderCountUpdatedEvent -= _quickAnalysisService_RemainderCountUpdatedEvent; _quickAnalysisService.StopAnalysis(); Messenger.Default.Send(new StatusBarArgs(true, strategyConfigException.Message), StatusBarToken.UpdateStatus); await Task.Run(() => _iStockRealTimeDealCrawler?.StopCrawler()); this.CanStart = true; this.CanStop = false; return; } catch (Exception ex) { LogBuilder.Logger.Error("start moniter RapidRiseStrategy error.", ex); } } MonitoringStockCount = monitorStocks.Count; Messenger.Default.Send(new StatusBarArgs(true, ResourceHelper.FindKey("StatusBar_Message_Monitoring")), StatusBarToken.UpdateStatus); } catch (Exception ex) { CanStart = true; CanStop = false; Messenger.Default.Send(new StatusBarArgs(true, string.Format(ResourceHelper.FindKey("StatusBar_Message_StartMonitorFailed"), ex.Message)), StatusBarToken.UpdateStatus); LogBuilder.Logger.Error("开始监控 - 失败", ex); } }