public static Task ProgressbarShow(this MetroWindow @object, Func <Task> action) { return(Task.Run(() => { @object.Dispatcher.Invoke(() => { var progress = new ProgressView { Owner = @object, Left = @object.Left / 2, Width = @object.Width / 2, Top = @object.Top / 2, Height = @object.Height / 2 }; progress.Loaded += (s, e) => { action().ContinueWith(task => { progress.Dispatcher.Invoke(() => { progress.Close(); }); }); }; progress.ShowDialog(); }); })); }
public MainWindow() { InitializeComponent(); Title = Title + $" {typeof(MainWindow).Assembly.GetName().Version}"; DependencyContainer.ComposeParts(this); #if DEBUG Log.Info("Running in debug mode"); #else Logger.Visibility = Visibility.Collapsed; #endif var dispatcher = Dispatcher.CurrentDispatcher; Func <(Action <string> show, Action <string> updateText, Action close)> createProgressingViewFunc = () => { var view = new ProgressView(); view.Owner = this; return(text => { view.TextToShow.Text = text; view.ShowDialog(); }, txt => { if (dispatcher.CheckAccess()) { view.TextToShow.Text = txt; } else { dispatcher.BeginInvoke((Action)(() => { view.TextToShow.Text = txt; })); } }, () => view.Close()); }; Action <Action <string, string, string> > createLoginViewFunc = loginAction => { var view = new LoginView { Owner = this }; var loginVm = new LoginViewModel(() => view.Close(), loginAction); view.DataContext = loginVm; view.ShowDialog(); }; _vm = new MainWindowsViewModel(createLoginViewFunc, createProgressingViewFunc); _vm.SetParentWindow(this); DataContext = _vm; Closing += OnClosing; Loaded += MainWindow_Loaded; Height = SystemParameters.PrimaryScreenHeight * 0.70; Width = Height * 1.5; }
public void Dispose() { _mainWindow.IsEnabled = true; _progressView.CanClose = true; _mainWindow.CanClose = true; _progressView.Close(); }
public void _progress_ProgressCompleted(object sender, EventArgs e) { _progressView.ViewModel.OperationName = "Starting..."; _progressView.ViewModel.ProgressPercentage = 0; _progressView.ViewModel.ProgressText = ""; _progressView.ViewModel.ProgressBarText = ""; ProgressReportingActive = false; ShowProgress = false; _progressView.Close(); }
private void UpdateFXCandles(object obj) { if (_updatingCandles) return; if (string.IsNullOrEmpty(_uiService.SelectedStrategyFilename)) { MessageBox.Show("Select strategy to update candles"); return; } var strategyType = StrategyHelper.CompileStrategy(_uiService.SelectedCodeText); if (strategyType == null) { MessageBox.Show("Unable to compile strategy"); return; } var strategy = (StrategyBase)Activator.CreateInstance(strategyType); _updatingCandles = true; var dispatcher = Dispatcher.CurrentDispatcher; var fxcm = _brokersService.Brokers.First(x => x.Name == "FXCM"); var timeframes = strategy.Timeframes.Union(new[] { Timeframe.M1 }).ToArray(); var markets = strategy.Markets; if (markets == null) { markets = StrategyBase.GetDefaultMarkets(); } var view = new ProgressView { Owner = Application.Current.MainWindow }; view.TextToShow.Text = "Updating candles"; Task.Run(() => { try { CandlesHelper.UpdateCandles( fxcm, _candleService, markets, timeframes, updateProgressAction: s => { _dispatcher.BeginInvoke((Action)(() => { view.TextToShow.Text = s; })); }); } catch (Exception ex) { Log.Error("Unable to update candles", ex); } dispatcher.Invoke(() => { view.Close(); MessageBox.Show("Updating candles complete"); _updatingCandles = false; }); }); view.ShowDialog(); }
public void Close() { view.Close(); }