private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { //update ui once worker complete his work mDebug = false; mDebugWait = false; mDoStep = false; RunComplete?.Invoke(this, EventArgs.Empty); System.Windows.MessageBox.Show("Расчет окончен!", MainWindowViewModel.PROGRAM_CAPTION, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information); }
public override UpdateResult Update() { var arenaInfo = _gameDataProvider.GetArenaInfo(); if (arenaInfo == null) { return(UpdateResult.Continue); } var numCards = arenaInfo.Deck.Cards.Sum(x => x.Count); if (numCards == MaxDeckSize) { if (_prevSlot == MaxDeckSize) { OnCardPicked(arenaInfo); } DeckComplete?.Invoke(new ArenaDeckComlpeteEventArgs(arenaInfo)); if (arenaInfo.Rewards?.Any() ?? false) { RunComplete?.Invoke(new ArenaRunCompleteEventArgs(arenaInfo)); } return(UpdateResult.Break); } if (HasChanged(arenaInfo, arenaInfo.CurrentSlot)) { var choices = _gameDataProvider.GetDraftChoices(); if (choices == null || choices.Length == 0) { return(UpdateResult.Continue); } if (arenaInfo.CurrentSlot > _prevSlot) { if (ChoicesHaveChanged(choices) || _sameChoices) { _sameChoices = false; ChoicesChanged?.Invoke(new ArenaChoicesChangedEventArgs(choices, arenaInfo.Deck)); } else { _sameChoices = true; return(UpdateResult.Continue); } } if (_prevSlot == 0 && arenaInfo.CurrentSlot == 1) { OnHeroPicked(arenaInfo); } else if (_prevSlot > 0 && arenaInfo.CurrentSlot > _prevSlot) { OnCardPicked(arenaInfo); } _prevSlot = arenaInfo.CurrentSlot; _prevInfo = arenaInfo; _prevChoices = choices; } return(UpdateResult.Continue); }
/// <summary> /// Metoda vyzkouší dešifrovat několik textů a po skončení zavolá /// předanou metodu runComplete s argumentem počet nalezených neshod. /// Metoda funguje paralelně, testovací kód je spouštěn v tolika /// vláknech, kolik má počítač jader. /// </summary> /// <param name="cipher">Šifra, nad kterou budeme Unit test provádět</param> /// <param name="crackMehod">Identifikátor útočící metody.</param> /// <param name="count">Počet textů, které chceme zkoušet.</param> /// <param name="runComplete">Jaká akce má být provedena po dokončení testu.</param> /// <param name="progressBar">Do kterého progressBaru chceme zobrazovat průběh</param> public static void Test(Cipher cipher, int crackMehod, int count, RunComplete runComplete) { threads = coresInComputer; Thread thread; errors = 0; coresInComputer.Times(i => { thread = new Thread(() => DoTest(cipher, crackMehod, count, i, runComplete)); thread.IsBackground = true; thread.Priority = 0; thread.Start(); }); }
/// <summary> /// Provádí samotný test dešifrování. /// </summary> /// <param name="cipher">Šifra, nad kterou budeme Unit test provádět</param> /// <param name="crackMehod">Identifikátor útočící metody.</param> /// <param name="count">Počet textů, které chceme zkoušet.</param> /// <param name="start">Index prvního testovaného řetězce</param> /// <param name="runComplete">Jaká akce má být provedena po dokončení testu.</param> /// <param name="progressBar">Do kterého progressBaru chceme zobrazovat průběh</param> private static void DoTest(Cipher cipher, int crackMehod, int count, int start, RunComplete runComplete) { int errorsCounter = 0; string[] testStrings = File.ReadAllText(Storage.StatsFolderPath + Storage.TextsFile + ".czech.txt") .ToLower() .Split('\n') .Select(x => x.Filter(y => TextAnalysis.IsEnglishLetter(y))) .Where(x => x.Length >= 500) .Select(x => x.ToCharArray().Take(500).ToList().Implode("")) .Where(x => x.Length > 0) .Take(count) .ToArray(); //File.WriteAllText("delky.txt", testStrings.ToList().Select(x => x.Length).ToList().Implode("\n")); List<string> keys; string opentext = string.Empty; string ciphertext; for (int i = start; i < testStrings.Length; i += coresInComputer) { ciphertext = cipher.Encrypt(testStrings[i], cipher.RandomKey()); try { keys = cipher.Crack(ciphertext, crackMehod, Storage.Languages.czech); opentext = cipher.Decrypt(ciphertext, keys[0]); } catch (CryptanalysisCore.Exceptions.MatchNotFound) { errorsCounter++; } if (opentext != testStrings[i]) errorsCounter++; } /* * Atomicky přičteme počet zjištěných neshod, snížíme počet běžících vláken * o jedničku a následně zjistíme, jestli je toto vlákno poslední běžící vlákno. */ lock (incrementResultsLock) { errors += errorsCounter; threads--; if (threads == 0) { runComplete(errors, count); } } }
internal void OnArenaRunComplete(ArenaRunCompleteEventArgs args) { Update(args.Info); State = ArenaState.Complete; RunComplete?.Invoke(args); }
private void OnPlugInRunComplete(IChoAbortableAsyncResult result) { _isRunning = false; RunComplete.Raise(this, new ChoEventArgs <IChoAbortableAsyncResult>(result)); }
/// <summary> /// Provádí samotný test dešifrování. /// </summary> /// <param name="cipher">Šifra, nad kterou budeme Unit test provádět</param> /// <param name="crackMehod">Identifikátor útočící metody.</param> /// <param name="count">Počet textů, které chceme zkoušet.</param> /// <param name="start">Index prvního testovaného řetězce</param> /// <param name="runComplete">Jaká akce má být provedena po dokončení testu.</param> /// <param name="progressBar">Do kterého progressBaru chceme zobrazovat průběh</param> private static void DoTest(Cipher cipher, int crackMehod, int count, int start, RunComplete runComplete, System.Windows.Forms.ProgressBar progressBar) { int errorsCounter = 0; string[] testStrings = texts.Where(x => x.Length >= 500) .Select(x => x.ToCharArray().Take(500).ToList().Implode("")) .Where(x => x.Length > 0) .Take(count) .ToArray(); List<string> keys; string opentext = string.Empty; string ciphertext; for (int i = start; i < testStrings.Length; i += coresInComputer) { ciphertext = cipher.Encrypt(testStrings[i], cipher.RandomKey()); try { keys = cipher.Crack(ciphertext, crackMehod, Storage.Languages.czech); opentext = cipher.Decrypt(ciphertext, keys[0]); } catch (CryptanalysisCore.Exceptions.MatchNotFound) { errorsCounter++; } if (opentext != testStrings[i]) errorsCounter++; if (progressBar != null) { Action incrementProgressBar = () => progressBar.Value++; if (progressBar.InvokeRequired) progressBar.Invoke(incrementProgressBar); else incrementProgressBar(); } } /* * Atomicky přičteme počet zjištěných neshod, snížíme počet běžících vláken * o jedničku a následně zjistíme, jestli je toto vlákno poslední běžící vlákno. */ lock (incrementResultsLock) { errors += errorsCounter; threads--; if (threads == 0) { runComplete(errors, count); if (progressBar != null) { Action zeroProgressBar = () => progressBar.Value = 0; if (progressBar.InvokeRequired) progressBar.Invoke(zeroProgressBar); else zeroProgressBar(); } } } }
/// <summary> /// Metoda vyzkouší dešifrovat několik textů a po skončení zavolá /// předanou metodu runComplete s argumentem počet nalezených neshod. /// Metoda funguje paralelně, testovací kód je spouštěn v tolika /// vláknech, kolik má počítač jader. /// </summary> /// <param name="cipher">Šifra, nad kterou budeme Unit test provádět</param> /// <param name="crackMehod">Identifikátor útočící metody.</param> /// <param name="count">Počet textů, které chceme zkoušet.</param> /// <param name="runComplete">Jaká akce má být provedena po dokončení testu.</param> public static void Test(Cipher cipher, int crackMehod, int count, RunComplete runComplete) { Test(cipher, crackMehod, count, runComplete, null); }
/// <summary> /// Metoda vyzkouší dešifrovat několik textů a po skončení zavolá /// předanou metodu runComplete s argumentem počet nalezených neshod. /// Metoda funguje paralelně, testovací kód je spouštěn v tolika /// vláknech, kolik má počítač jader. /// </summary> /// <param name="cipher">Šifra, nad kterou budeme Unit test provádět</param> /// <param name="crackMehod">Identifikátor útočící metody.</param> /// <param name="count">Počet textů, které chceme zkoušet.</param> /// <param name="runComplete">Jaká akce má být provedena po dokončení testu.</param> /// <param name="progressBar">Do kterého progressBaru chceme zobrazovat průběh</param> public static void Test(Cipher cipher, int crackMehod, int count, RunComplete runComplete, System.Windows.Forms.ProgressBar progressBar) { threads = coresInComputer; Thread thread; if(progressBar != null) progressBar.Maximum = count; errors = 0; coresInComputer.Times(i => { thread = new Thread(() => DoTest(cipher, crackMehod, count, i, runComplete, progressBar)); thread.IsBackground = true; thread.Priority = 0; thread.Start(); }); }