Guest User

Untitled

a guest
Jan 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. #region Register
  2.  
  3. private void btnStartRegister_Click(object sender, EventArgs e)
  4. {
  5. if (backgroundWorker2.IsBusy)
  6. {
  7. btnStartRegister.Enabled = false;
  8. lblStatusOfaccMValue.Text = "Canceling...";
  9. backgroundWorker2.CancelAsync();
  10. }
  11. else
  12. {
  13. txtLogInRegister.Text = string.Empty;
  14. btnStartRegister.Text = "Cancel";
  15. lblUserCreatedCountValue.Text = "---";
  16. lblStatusOfaccMValue.Text = "Running...";
  17.  
  18. backgroundWorker2.RunWorkerAsync();
  19. }
  20. }
  21.  
  22. private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
  23. {
  24. backgroundWorker2.ReportProgress(Convert.ToInt32(0));
  25.  
  26. int UsersCount = int.Parse(txtUsersCount.Text);
  27. UsersCreatedCount_Step = 0;
  28. string path = Application.StartupPath;
  29. string accfilePath = path + @"acc.txt";
  30. string logfilePath = path + @"log.txt";
  31. string Ok_ip_port = string.Empty;
  32. string[] Separator = new string[] { "__" };
  33. int list_lines_acc_Current = -1;
  34.  
  35. string[] lines_acc = File.ReadAllLines(accfilePath);
  36. List<string> list_lines_acc = new List<string>(lines_acc);
  37. List<string> list_lines_acc_new = new List<string>(list_lines_acc);
  38.  
  39. foreach (string line_acc in list_lines_acc)
  40. {
  41. if (backgroundWorker2.CancellationPending)
  42. {
  43. e.Cancel = true;
  44. break;
  45. }
  46.  
  47. list_lines_acc_Current++;
  48. string[] line_acc_ar = line_acc.Split(Separator, StringSplitOptions.None);
  49. if (line_acc_ar.Length == 3)
  50. {
  51. string username = line_acc_ar[0];
  52. string password = line_acc_ar[1];
  53. string email = line_acc_ar[2];
  54. string[] email_ar = email.Split('@');
  55. email = email_ar[0] + "%40" + email_ar[1];
  56.  
  57.  
  58. list_lines_acc_new[list_lines_acc_Current] += "__" + txtSuffixURL.Text + "__" + txtServerNumber.Text + "__" + "127.0.0.1:2222";
  59.  
  60. try
  61. {
  62. bool[] RegisterMethod_res = RegisterMethod(bla bla bla);
  63. bool failed = RegisterMethod_res[0];
  64. bool world_full = RegisterMethod_res[1];
  65. if (!failed)
  66. {
  67. UsersCreatedCount_Step++;
  68. backgroundWorker2.ReportProgress(Convert.ToInt32(UsersCreatedCount_Step * (100.0 / UsersCount)));
  69. list_lines_acc_new[list_lines_acc_Current] += "__" + "Y";
  70. }
  71. else
  72. {
  73. if (world_full)
  74. {
  75. list_lines_acc_new[list_lines_acc_Current] += "__" + "N";
  76. e.Cancel = true;
  77. break;
  78. }
  79. else
  80. {
  81. list_lines_acc_new[list_lines_acc_Current] += "__" + "N";
  82. }
  83. }
  84.  
  85. File.WriteAllLines(accfilePath, list_lines_acc_new.ToArray());
  86. }
  87. catch (Exception ex)
  88. {
  89. list_lines_acc_new[list_lines_acc_Current] += "__" + "N";
  90.  
  91. File.WriteAllLines(accfilePath, list_lines_acc_new.ToArray());
  92. }
  93.  
  94. if (UsersCount == UsersCreatedCount_Step)
  95. {
  96. break;
  97. }
  98. }
  99. }
  100.  
  101. File.WriteAllLines(accfilePath, list_lines_acc_new.ToArray());
  102. }
  103.  
  104. private bool[] RegisterMethod()
  105. {
  106. bla bla bla
  107. ...
  108. ...
  109. return RegisterMethod_res;
  110. }
  111.  
  112. private void backgroundWorker2_ProgressChanged(object sender, ProgressChangedEventArgs e)
  113. {
  114. progressBar2.Value = e.ProgressPercentage;
  115. lblUserCreatedCountValue.Text = UsersCreatedCount_Step.ToString();
  116. }
  117.  
  118. private void backgroundWorker2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  119. {
  120. btnStartRegister.Text = "Start Register";
  121. btnStartRegister.Enabled = true;
  122.  
  123. if (e.Error != null)
  124. {
  125. MessageBox.Show(e.Error.Message);
  126. return;
  127. }
  128. if (e.Cancelled)
  129. {
  130. lblStatusOfaccMValue.Text = "Cancelled...";
  131. }
  132. else
  133. {
  134. lblStatusOfaccMValue.Text = "Completed";
  135. }
  136. }
  137.  
  138. #endregion
  139.  
  140. if (UsersCount == UsersCreatedCount_Step)
  141. {
  142. break;
  143. }
  144.  
  145. File.WriteAllLines(accfilePath, list_lines_acc_new.ToArray());
Add Comment
Please, Sign In to add comment