示例#1
0
        private void biSimulation_ItemClick(object sender, ItemClickEventArgs e)
        {
            StrategyBase strategy = (StrategyBase)this.gridView1.GetFocusedRow();

            if (strategy == null)
            {
                XtraMessageBox.Show("No strategy selected.");
                return;
            }
            if (!strategy.SupportSimulation)
            {
                XtraMessageBox.Show("This strategy does not support simulation.");
                return;
            }

            StrategiesManager manager = new StrategiesManager();
            StrategyBase      cloned  = strategy.Clone();

            cloned.DemoMode = true;
            manager.Strategies.Add(cloned);

            this.siStatus.Caption = "<b>Loading data from exchanges...</b>";
            IOverlaySplashScreenHandle handle = SplashScreenManager.ShowOverlayForm(this);

            Application.DoEvents();
            manager.Initialize(new SimulationStrategyDataProvider());
            if (!manager.Start())
            {
                XtraMessageBox.Show("Error starting simulation! Please check log messages");
                return;
            }
            this.siStatus.Caption = "<b>Running simulation...</b>";
            Application.DoEvents();

            Stopwatch timer = new Stopwatch();

            timer.Start();
            int elapsedSeconds = 0;

            while (manager.Running)
            {
                if (timer.ElapsedMilliseconds / 1000 > elapsedSeconds)
                {
                    elapsedSeconds        = (int)(timer.ElapsedMilliseconds / 1000);
                    this.siStatus.Caption = string.Format("<b>Running simulation... {0} sec</b>", elapsedSeconds);
                    Application.DoEvents();
                }
            }
            SplashScreenManager.CloseOverlayForm(handle);
            this.siStatus.Caption = "<b>Simulation done.</b>";
            Application.DoEvents();
            StrategyConfigurationManager.Default.ShowData(cloned);
        }
        private void biEdit_ItemClick(object sender, ItemClickEventArgs e)
        {
            StrategyBase strategy = (StrategyBase)this.gridView1.GetFocusedRow();

            if (strategy == null)
            {
                XtraMessageBox.Show("No strategy selected for editing.");
                return;
            }
            StrategyBase cloned = strategy.Clone();

            if (!StrategyConfigurationManager.Default.EditStrategy(cloned))
            {
                return;
            }
            strategy.Assign(cloned);
            Manager.Save();
            this.gridView1.RefreshData();
        }
        private void biSimulation_ItemClick(object sender, ItemClickEventArgs e)
        {
            Stopped = false;
            StrategyBase strategy = (StrategyBase)this.gridView1.GetFocusedRow();

            if (strategy == null)
            {
                XtraMessageBox.Show("No strategy selected.");
                return;
            }
            if (!strategy.SupportSimulation)
            {
                XtraMessageBox.Show("This strategy does not support simulation.");
                return;
            }

            StrategiesManager manager = new StrategiesManager();

            manager.FileName = "SimulationStrategiesManager.xml";
            StrategyBase cloned = strategy.Clone();

            cloned.DemoMode = true;
            manager.Strategies.Add(cloned);

            this.siStatus.Caption = "<b>Loading data from exchanges...</b>";
            IOverlaySplashScreenHandle handle = SplashScreenManager.ShowOverlayForm(gridControl1);

            Application.DoEvents();
            SimulationStrategyDataProvider dataProvider = new SimulationStrategyDataProvider();

            dataProvider.DownloadProgressChanged += OnSimulationProviderDownloadProgressChanged;

            this.beSimulationProgress.EditValue  = 0;
            this.beSimulationProgress.Visibility = BarItemVisibility.Always;

            manager.Initialize(dataProvider);
            dataProvider.DownloadProgressChanged -= OnSimulationProviderDownloadProgressChanged;
            if (!manager.Start())
            {
                XtraMessageBox.Show("Error starting simulation! Please check log messages");
                return;
            }
            this.beSimulationProgress.EditValue  = 0;
            this.beSimulationProgress.Visibility = BarItemVisibility.Always;
            this.siStatus.Caption = "<b>Running simulation...</b>";
            Application.DoEvents();

            Stopwatch timer = new Stopwatch();

            timer.Start();
            int    elapsedSeconds = 0;
            double progress       = 0;

            while (manager.Running)
            {
                this.beSimulationProgress.EditValue = (int)(dataProvider.SimulationProgress * this.repositoryItemProgressBar1.Maximum);
                if (timer.ElapsedMilliseconds / 1000 > elapsedSeconds)
                {
                    elapsedSeconds        = (int)(timer.ElapsedMilliseconds / 1000);
                    this.siStatus.Caption = string.Format("<b>Running simulation... {0} sec</b>", elapsedSeconds);
                    Application.DoEvents();
                }
                if ((dataProvider.SimulationProgress - progress) >= 0.05)
                {
                    progress = dataProvider.SimulationProgress;
                    Application.DoEvents();
                }
            }
            this.beSimulationProgress.Visibility = BarItemVisibility.Never;
            SplashScreenManager.CloseOverlayForm(handle);
            manager.Save();
            this.siStatus.Caption = "<b>Simulation done.</b>";
            Application.DoEvents();
            //this.toastNotificationsManager1.ShowNotification("404ef86f-183c-4fea-960b-86f54e52ea76");
            StrategyConfigurationManager.Default.ShowData(cloned);
        }