public SetProgress ( double value ) : void | ||
value | double | The percentage to set as the value. |
Résultat | void |
/// <summary> /// Runs CanEnable asynchronously multiple times until successful, cancelled or max tries reached /// </summary> /// <param name="dialog"></param> /// <returns></returns> public Task<bool> CanEnableAsync(ProgressDialogController dialog) { return Task.Run(() => { for (var tries = 1; tries <= 10; tries++) { // Dialog interaction if (dialog != null) { // Stop if cancelled by user if (dialog.IsCanceled) { dialog.SetIndeterminate(); return false; } // Updated progress to indicate how much tries are left dialog.SetProgress(0.1*tries); } if (CanEnable()) { dialog?.SetIndeterminate(); return true; } Thread.Sleep(2000); } dialog?.SetIndeterminate(); return false; }); }
public string CreateXmlDb(List<MagicCard> listOfCards, ProgressDialogController dialogController) { var curCard = 0; var totalCards = listOfCards.Count; foreach (var distinctSet in listOfCards.DistinctBy(o => o.Set)) { var enumerable = listOfCards.Where(op => op.Set == distinctSet.Set && op.PathOfCardImage.Contains("original")).DistinctBy(o => o.Name); foreach (var distinctCard in enumerable) { var cardElement = _xmlfile.CreateElement("card"); AddChildElementAndValue(cardElement, _util.GetVariableName(() => distinctCard.Name), distinctCard.Name); AddChildElementAndValue(cardElement, _util.GetVariableName(() => distinctCard.Set), distinctCard.Set); AddChildElementAndValue(cardElement, _util.GetVariableName(() => distinctCard.PathOfCardImage), distinctCard.PathOfCardImage); var phashesElement = _xmlfile.CreateElement("phashes"); foreach (var magicCard in listOfCards.Where(o => o.Name == distinctCard.Name && o.Set == distinctSet.Set)) { foreach (var phash in magicCard.PHashes) { AddChildElementAndValue(phashesElement, "phash", phash.ToString()); } } cardElement.AppendChild(phashesElement); _rootNode.AppendChild(cardElement); curCard++; dialogController.SetProgress((double)curCard / totalCards); dialogController.SetMessage("Creating a Simple Database of all those pHashes: " + curCard + "/" + totalCards); } } SaveXmlFile(); return Path.GetFullPath(XmlDbPath); }
private void ParseStatement(XElement xml, ProgressDialogController progress, DBContext context, bool skipLastDateCheck) { const int totalActions = 12; progress.SetProgress(1.0 / totalActions); ParseSecuritiesInfo(xml, context); string accountId = xml.Attribute("accountId").Value; Account account = context.Accounts.First(x => x.AccountId == accountId); DateTime lastDate = context.CashTransactions.Any(x => x.AccountID == account.ID) ? context.CashTransactions.Max(x => x.TransactionDate) : new DateTime(1, 1, 1); progress.SetProgress(2.0 / totalActions); ParseCashTransactions(xml, context, skipLastDateCheck, lastDate, account); progress.SetProgress(3.0 / totalActions); ParseCFDCharges(xml, context, skipLastDateCheck, lastDate, account); progress.SetProgress(4.0 / totalActions); ParseOrders(xml, context, skipLastDateCheck, account); progress.SetProgress(5.0 / totalActions); ParseExecutions(xml, context, skipLastDateCheck, account); progress.SetProgress(6.0 / totalActions); ParseEquitySummaries(xml, context, account); progress.SetProgress(7.0 / totalActions); ParseOpenPositions(xml, context, account); progress.SetProgress(8.0 / totalActions); ParseFXRates(xml, context); progress.SetProgress(9.0 / totalActions); ParsePriorPeriodPositions(xml, context, skipLastDateCheck, account); progress.SetProgress(10.0 / totalActions); ParseOpenDividendAccruals(xml, context, account); progress.SetProgress(11.0 / totalActions); ParseFXPositions(xml, context, account); progress.SetProgress(12.0 / totalActions); ParseFXTransactions(xml, context, skipLastDateCheck, account); }
private static async Task CleanUpGameFiles(ProgressDialogController controller) { var count = 0; int gamesCount; var lockMe = new object(); var options = new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }; await Task.Run(() => { var games = DeckStatsList.Instance.DeckStats.SelectMany(x => x.Games).Concat(DefaultDeckStats.Instance.DeckStats.SelectMany(x => x.Games)).ToList(); gamesCount = games.Count; Parallel.ForEach(games, options, (game, loopState) => { if(controller.IsCanceled) { loopState.Stop(); return; } if(game.OpponentCards.Any()) return; var oppCards = GetOpponentDeck(game); if(oppCards.Any()) game.SetOpponentCards(oppCards); game.DeleteGameFile(); lock(lockMe) { controller.SetProgress(1.0 * ++count / gamesCount); } }); }); DeckStatsList.Save(); DefaultDeckStats.Save(); if(!controller.IsCanceled) { try { Directory.Delete(GamesDir, true); } catch(Exception e) { Log.Error(e); } } }
private async void PerformanceDay_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (!initialized) return; else { if (PerformanceDay.SelectedItem != null) { var selectedItem = (DateTime)PerformanceDay.SelectedItem; IsEnabled = false; _controller = await mainWindow.ShowProgressAsync("Performances", "Loading..."); _controller.SetIndeterminate(); await Task.Factory.StartNew(() => { ufoVM.LoadPerformancesOfDay(selectedItem); }); await _controller.CloseAsync(); IsEnabled = true; _controller.SetProgress(1); } } }
public void ComputePHashes(string selectedPath, ProgressDialogController dialogController) { ListOfMagicCards.Clear(); //read images in resources Util.TraverseTree(@"H:\Compy Sci\MTG-Scanner\MTG-Scanner\Resources\Card Images", ListOfMagicCards); //Util.TraverseTree(selectedPath, ListOfMagicCards); //Util.TraverseTree(selectedPath, ListOfMagicCards); //compute hashes var curCard = 0; var totalCards = ListOfMagicCards.Count; Parallel.ForEach(ListOfMagicCards, card => { var hash = Util.ComputePHash(card); card.PHashes.Add(hash); curCard++; dialogController.SetProgress((double)curCard / totalCards); dialogController.SetMessage("pHashing real hard! Finished: " + curCard + "/" + totalCards); }); }
private static Task DownloadFile(string uri, string filename, MetroWindow window, ProgressDialogController controller) { return Task.Run(() => { WebClient client = new WebClient(); client.DownloadProgressChanged += async (sender, e) => { double bytesIn = double.Parse(e.BytesReceived.ToString()); double totalBytes = double.Parse(e.TotalBytesToReceive.ToString()); double percentage = bytesIn / totalBytes * 100; try { await window.Dispatcher.InvokeAsync(() => { controller.SetProgress(int.Parse(Math.Truncate(percentage).ToString())); }); } catch { } }; client.DownloadFileCompleted += async (sender, e) => { await controller.CloseAsync(); client.Dispose(); }; client.DownloadFileAsync(new Uri(uri), Environment.CurrentDirectory + filename); }); }
public async System.Threading.Tasks.Task<bool> GetTaskTherd() { var metroWindow = (Application.Current.MainWindow as MetroWindow); metroWindow.MetroDialogOptions.ColorScheme = MetroDialogColorScheme.Theme; controller = await metroWindow.ShowProgressAsync("Идет обновление задач", "В данный момент идет обновления задач"); BackgroundWorker worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; controller.SetProgress(0); worker.DoWork += worker_DoWork; worker.RunWorkerCompleted += BackgroundWorker_RunWorkerCompleted; isRunAnalize = true; worker.RunWorkerAsync(this); return true; }
private async void Button_Click(object sender, RoutedEventArgs e) { var button = sender as Button; var buttonCmdParam = button.CommandParameter; var command = button.Tag as ICommand; IsEnabled = false; _controller = await mainWindow.ShowProgressAsync("EMail", "Sending..."); _controller.SetIndeterminate(); await Task.Factory.StartNew(() => { // Execute command in tag if (button != null) { if (command != null) command.Execute(buttonCmdParam); } return true; }); await _controller.CloseAsync(); IsEnabled = true; await mainWindow.ShowMessageAsync("EMail", "EMails were sent successfully!"); _controller.SetProgress(1); }
private async void ExportEventSummaryToCSV(int? count = null) { Telemetry.TrackEvent(TelemetryCategory.Export, Telemetry.TelemetryEvent.Export.Summary); var saveDialog = new SaveFileDialog(); saveDialog.AddExtension = true; saveDialog.FileName = "band_export.csv"; saveDialog.DefaultExt = ".csv"; var result = saveDialog.ShowDialog(); if (result == true) { _summaryExportProgressDialog = await ((MetroWindow)(Window.GetWindow(this))).ShowProgressAsync("Exporting Data", "..."); _summaryExportProgressDialog.SetCancelable(true); // TODO: this needs to be implemented. No event? _summaryExportProgressDialog.SetProgress(0); var progressIndicator = new Progress<BandCloudExportProgress>(ReportSummaryExportProgress); await BandCloudManager.Instance.ExportEventsSummaryToCSV(count, ExportSettings, saveDialog.FileName, progressIndicator); _summaryExportProgressDialog.CloseAsync(); if (ExportSettings.OpenFileAfterExport) { Process.Start(saveDialog.FileName); } SaveExportSettings(); } }
internal static async Task<int> FixOppNameAndClass(List<GameStats> games, ProgressDialogController controller) { var count = 0; var fixCount = 0; var gamesCount = games.Count; var lockMe = new object(); var options = new ParallelOptions {MaxDegreeOfParallelism = Environment.ProcessorCount}; await Task.Run(() => { Parallel.ForEach(games, options, (game, loopState) => { if(controller.IsCanceled) { loopState.Stop(); return; } List<ReplayKeyPoint> replay; try { replay = ReplayReader.LoadReplay(game.ReplayFile); } catch { return; } var last = replay.LastOrDefault(); if(last == null) return; var opponent = last.Data.FirstOrDefault(x => x.IsOpponent); if(opponent == null) return; var incremented = false; if(game.OpponentName != opponent.Name) { game.OpponentName = opponent.Name; Interlocked.Increment(ref fixCount); incremented = true; } var heroEntityId = opponent.GetTag(GAME_TAG.HERO_ENTITY); var entity = last.Data.FirstOrDefault(x => x.Id == heroEntityId); if(entity != null) { string hero; if(CardIds.HeroIdDict.TryGetValue(entity.CardId ?? "", out hero) && game.OpponentHero != hero) { game.OpponentHero = hero; if(!incremented) Interlocked.Increment(ref fixCount); } } lock(lockMe) { controller.SetProgress(1.0 * ++count / gamesCount); } }); }); return fixCount; }
private async void btnLogin_Click(object sender, RoutedEventArgs e) { var email = txtEMail.Text; var pwd = txtPwd.Password; if (string.IsNullOrEmpty(email) && string.IsNullOrEmpty(pwd)) { txtError.Text = "Please enter a EMail and a Password!"; return; } else if (string.IsNullOrEmpty(pwd)) { txtError.Text = "Please enter a Password"; return; } else if (string.IsNullOrEmpty(email)) { txtError.Text = "Please enter a EMail"; return; } txtError.Text = ""; IsEnabled = false; _controller = await this.ShowProgressAsync("Logging in...", "Authenticating..."); _controller.SetIndeterminate(); var result = await Task.Factory.StartNew(() => { return commander.AuthenticateUser(email, pwd); }); txtPwd.Password = ""; await _controller.CloseAsync(); IsEnabled = true; if (result == true) { await this.ShowMessageAsync("Authenticated", "Login success!"); MainWindow mainWindow = new MainWindow(); mainWindow.Show(); Close(); } else { txtError.Text = "Combination of EMail and Password is incorrect!"; } _controller.SetProgress(1); }
public void SetProgress(double value) { _controller.SetProgress(value); }