private void ViewIncrementIdentifier(object sender, EventArgs e) { try { IdController.Increment(_view.IncrementValue); ShowMessage($"ID инкрементирован на {_view.IncrementValue} и ID = {IdController.Identifier}"); } catch (Exception exception) { ShowError($"ќшибка: {exception.Message}"); } }
private void Increment(CancellationToken token) { //var stringA = TestHelper.LoadStringNumber("stringA.txt"); //var stringB = TestHelper.LoadStringNumber("stringB.txt"); string stringA; string stringB; TestHelper.GetRandomStringNumber((long)(1024 * 1024 * 1024 / 2), out stringA, out stringB); IdController.InitAlphaNumericIdentifier(_alphaNumericIdentifier); IdController.Increment(stringA, () => token.IsCancellationRequested); IdController.Increment(stringB, () => token.IsCancellationRequested); }
public void Test_Inrement(string id, string baseValue, string incrementValue, string resultId) { var sw = new Stopwatch(); sw.Start(); IdController.InitAlphaNumericIdentifier(_alphaNumericIdentifier); IdController.Increment(baseValue); IdController.Increment(incrementValue); sw.Stop(); Assert.AreEqual(resultId, IdController.Identifier); Console.WriteLine($"Numbers sum was done, Time: {sw.Elapsed}"); }
private void IncrementAction(string name, string incrementValue, CancellationToken token) { for (int i = 0; i < 1000; i++) { try { var sw = new Stopwatch(); sw.Start(); IdController.Increment(incrementValue, () => token.IsCancellationRequested); token.ThrowIfCancellationRequested(); Console.WriteLine($"{name} #{i} was done, Time: {sw.Elapsed}"); sw.Stop(); Thread.Sleep(100); } catch (Exception e) { Console.WriteLine($"Ошибка выполнения {name}"); Console.WriteLine(e); throw; } } }
public void Test_LoadAsyncTest() { var mre = new ManualResetEvent(false); Console.WriteLine("Test_LoadTest BEGIN"); var sw = new Stopwatch(); sw.Start(); var incrementValue = "922337203685477"; IdController.InitAlphaNumericIdentifier(_alphaNumericIdentifier); CancellationTokenSource cancelTokenSource = new CancellationTokenSource(); var tf = new TaskFactory(cancelTokenSource.Token); tf.StartNew(() => { try { Console.WriteLine($"Begin load stringNumber, Time: {sw.Elapsed}"); sw.Restart(); //string stringA = TestHelper.LoadStringNumber("stringA.txt"); //string stringB = TestHelper.LoadStringNumber("stringB.txt"); string stringA; string stringB; TestHelper.GetRandomStringNumber((long)(1024 * 1024 * 100), out stringA, out stringB); Console.WriteLine($"StringNumber loaded, Time: {sw.Elapsed}"); sw.Restart(); IdController.Increment(stringA); Console.WriteLine($"Increment valueA was done, Time: {sw.Elapsed}"); sw.Restart(); IdController.Increment(stringB); Console.WriteLine($"Increment valueB was done, Time: {sw.Elapsed}"); sw.Restart(); mre.Set(); } catch (Exception e) { Console.WriteLine(e); mre.Set(); } }, cancelTokenSource.Token); tf.StartNew(() => { IncrementAction("Increment1", incrementValue, cancelTokenSource.Token); }, cancelTokenSource.Token); tf.StartNew(() => { IncrementAction("Increment2", incrementValue, cancelTokenSource.Token); }, cancelTokenSource.Token); mre.WaitOne(); cancelTokenSource.Cancel(); sw.Stop(); Console.WriteLine($"Numbers sum was done, Time: {sw.Elapsed}"); Console.WriteLine("Test_LoadTest END"); }