Advertisement
Guest User

Untitled

a guest
Dec 24th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. using OpenQA.Selenium;
  18. using OpenQA.Selenium.Firefox;
  19. using OpenQA.Selenium.Support.UI;
  20.  
  21. namespace Selenium
  22. {
  23. /// <summary>
  24. /// Interaction logic for MainWindow.xaml
  25. /// </summary>
  26. public partial class MainWindow : Window
  27. {
  28. public MainWindow()
  29. {
  30.  
  31. //
  32. InitializeComponent();
  33. }
  34.  
  35. private void LogAction(string s)
  36. {
  37. //this.Log.Dispatcher.BeginInvoke(
  38. // () => { },
  39. // System.Windows.Threading.DispatcherPriority.Background
  40. // );
  41. }
  42.  
  43. private void RestartDevice()
  44. {
  45. //Ust.I.Device = "HID\\VID_3938&PID_1031&COL01";
  46. //Ust.Zapisz();
  47.  
  48. System.Diagnostics.Process process = new System.Diagnostics.Process();
  49. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
  50. ///startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
  51. startInfo.RedirectStandardError = true;
  52. startInfo.RedirectStandardOutput = true;
  53. startInfo.UseShellExecute = false;
  54. startInfo.FileName = "dmgr.exe";
  55. startInfo.Arguments = $"restart \"{Ust.I.Device}\"";
  56. process.StartInfo = startInfo;
  57. process.Start();
  58. process.WaitForExit();
  59. //MessageBox.Show(process.StandardError.ReadToEnd());
  60. //MessageBox.Show(process.StandardOutput.ReadToEnd());
  61.  
  62. //string strCmdText;
  63. //strCmdText = $"restart \"{Ust.I.Device}\"";
  64. //System.Diagnostics.Process.Start("dmgr.exe", strCmdText);
  65. }
  66.  
  67.  
  68. private void Button_Click(object sender, RoutedEventArgs e)
  69. {
  70. int ipCounter = 0;
  71. int generalCounter = 0;
  72.  
  73. var users = User.GetUsers();
  74. LogAction($"Rozpoczęto pracę - pobrano {users.Count} kont");
  75.  
  76. foreach (var user in users)
  77. {
  78. ChangeIPIfNeeded(ref ipCounter);
  79. LogAction($"{++generalCounter}/{users.Count} - {user.Login}");
  80. JoinApp(user);
  81. }
  82.  
  83. //RestartDevice();
  84. }
  85.  
  86.  
  87. private void ChangeIPIfNeeded(ref int count)
  88. {
  89. if(count == Ust.I.IPCount)
  90. {
  91. RestartDevice();
  92. count = 0;
  93. }
  94. else
  95. {
  96. count++;
  97. }
  98. }
  99.  
  100. private string JoinApp(User user)
  101. {
  102. try
  103. {
  104. using (IWebDriver driver = new FirefoxDriver())
  105. {
  106. driver.Navigate().GoToUrl("https://www.facebook.com/login.php");
  107. IWebElement query = driver.FindElement(By.Name("email"));
  108. query.SendKeys(user.Login);
  109.  
  110. query = driver.FindElement(By.Name("pass"));
  111. query.SendKeys(user.Pass);
  112. query.Submit();
  113.  
  114. driver.Navigate().GoToUrl(Ust.I.AppJoin);
  115.  
  116. var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3));
  117.  
  118. query = wait.Until(c => c.FindElement(By.Name("__CONFIRM__")));
  119. query.Click();
  120.  
  121. query = wait.Until(c => c.FindElement(By.XPath("//div[@data-name=\"audience[0][value]\"]")));
  122. query.Click();
  123.  
  124. query = wait.Until(c => c.FindElement(By.XPath("//ul[@class=\"uiMenuInner\"]/li[1]")));
  125. query.Click();
  126.  
  127. query = wait.Until(c => c.FindElement(By.Name("__CONFIRM__")));
  128. query.Click();
  129.  
  130. query = wait.Until(ExpectedConditions.ElementToBeClickable(By.Name("__CONFIRM__")));
  131. //query = wait.Until(c => c.FindElement(By.Name("__CONFIRM__")));
  132. query.Click();
  133.  
  134. var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3));
  135.  
  136. driver.Navigate().GoToUrl(Ust.I.AppToken);
  137.  
  138. if(Ust.I.DoubleRefresh) {
  139. driver.Navigate().GoToUrl(Ust.I.AppToken);
  140. }
  141.  
  142. query = wait.Until(c => c.FindElement(By.XPath("//form[@action=\"/tools/debug/\"]//input[@type=\"text\"]")));
  143. Debug.WriteLine(query.GetAttribute("value"));
  144.  
  145. return query.GetAttribute("value");
  146. //data-name="audience[0][value]"
  147. ////ul[@class="uiMenuInner"]/li[1]
  148. ////form[@action="/tools/debug/"]//input[@type="text"]
  149. }
  150. }
  151. catch (Exception EX)
  152. {
  153. MessageBox.Show(EX.ToString());
  154. return "";
  155. }
  156. }
  157. }
  158.  
  159. public class User
  160. {
  161. public string Login { get; set; }
  162. public string Pass { get; set; }
  163.  
  164. public static List<User> GetUsers()
  165. {
  166. var users = new List<User>();
  167.  
  168. using(var reader = new StreamReader("konta.txt"))
  169. {
  170. while(reader.EndOfStream == false)
  171. {
  172. var line = reader.ReadLine();
  173. if (string.IsNullOrEmpty(line)) continue;
  174. var data = line.Split(new char[] { '|' });
  175. var user = new User
  176. {
  177. Login = data[0],
  178. Pass = data[1]
  179. };
  180. users.Add(user);
  181. }
  182. }
  183.  
  184. return users;
  185. }
  186. }
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement