Exemple #1
0
        private static void Chat(WebClient client, string path)
        {
            using (File.Create(path))
            {
            }

            using (var browser = new IE("http://widget.chatvdvoem.ru/iframe?mode=production&height=600"))
            {
                browser.Link(Find.ById("chat_start")).Click();

                var lastAnswer = string.Empty;
                var answer = string.Empty;

                while (true)
                {
                    var i = 0;

                    while (string.Equals(lastAnswer, answer,
                        StringComparison.InvariantCultureIgnoreCase))
                    {
                        Thread.Sleep(7000);

                        i++;

                        if (i > 4)
                        {
                            browser.ForceClose();
                            return;
                        }

                        var froms = browser.Elements.Filter(p => p.ClassName == "messageFrom");

                        if (froms.Count == 0)
                            continue;

                        answer = froms.Last().Text;

                        answer = answer.Substring(6);
                    }

                    lastAnswer = answer;

                    if (BlackListed(answer))
                        break;

                    var question = GetAnswer(client, answer);

                    File.AppendAllLines(path, new[] { answer, question });

                    browser.TextField(Find.ByName("text")).TypeText(question);

                    Thread.Sleep(2000);

                    browser.Button(Find.ById("text_send")).Click();
                }

                browser.ForceClose();
            }
        }
Exemple #2
0
 /// <summary>
 /// Closes the given IE instance.
 /// </summary>
 /// <param name="ieInstance">The IE instance to be closed.</param>
 public static void CloseIEInstance(IE ieInstance)
 {
     if (ieInstance != null)
     {
         ieInstance.ForceClose();
         Thread.Sleep(2000);
     }
 }
 public ResultWindow(int timeLimit , string idProblem)
     : this()
 {
     this.timeLimit = timeLimit;
     this.idProblem = idProblem;
     Process process = new Process();
     process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
     process.StartInfo.CreateNoWindow = true;
     process.StartInfo.UseShellExecute = false;
     process.StartInfo.FileName = "cmd";
     process.StartInfo.Arguments =
         string.Format("/C \"\"{0}\" < \"{1}\" > \"{2}\"\"",
         Properties.Settings.Default.FileExec,
         Properties.Settings.Default.FileInput,
         Properties.Settings.Default.FileOutput);
     process.Start();
     if (!process.WaitForExit(timeLimit * 1000))
         process.Kill();
     if (process.ExitCode != 0)
     {
         runtime.Visibility = Visibility.Visible;
         return;
     }
     timeExec.Content = process.TotalProcessorTime.Milliseconds / 1000f + "s";
     try
     {
         textInput = File.ReadAllText(Properties.Settings.Default.FileInput);
         textOutput = File.ReadAllText(Properties.Settings.Default.FileOutput);
         textOutput = textOutput.Replace("\r\n", "\n");
         //Settings.MakeNewIeInstanceVisible = false;
         WatiN.Core.Settings.Instance.AutoMoveMousePointerToTopLeft = false;
         browser = new IE(prefix + idProblem);
         TextField inputField = browser.TextField(Find.ById("edit-input-data"));
         WatiN.Core.Button buttonSubmit = browser.Button(Find.ById("edit-output"));
         inputField.Value = textInput;
         buttonSubmit.Click();
         browser.WaitForComplete();
         string result = browser.Html;
         int begin = result.IndexOf("<pre>") + 5;
         textCorrect = result.Substring(begin, result.IndexOf("</pre>") - begin);
         File.WriteAllText(Properties.Settings.Default.FileCorrect, textCorrect);
         if (textOutput != textCorrect)
             incorrect.Visibility = Visibility.Visible;
         else
             accepted.Visibility = Visibility.Visible;
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     browser.ForceClose();
 }
        static void Main(string[] args)
        {
            AES aes = new AES();

            //grab from the appSettings
            string username = AES.Decrypt(ConfigurationManager.AppSettings["username"]);
            string password = AES.Decrypt(ConfigurationManager.AppSettings["password"]);
            string shoreTelDirectorLogin = AES.Decrypt(ConfigurationManager.AppSettings["ShoreTelDirectorLogin"]);
            string shoreTelUserList = AES.Decrypt(ConfigurationManager.AppSettings["ShoreTelUserList"]);

            //nav to url
            IE myIE = new IE(shoreTelDirectorLogin);

            //sign in
            myIE.TextField(Find.ByName("login")).TypeText(username);
            myIE.TextField(Find.ByName("password")).TypeText(password);
            myIE.Button(Find.ByName("SUBMIT1")).Click();

            //nav to url containing userList
            IE myIE3 = new IE(shoreTelUserList);

            //change recPerPage to 3000 to ensure we grab all extensions
            myIE3.SelectList(Find.ById("RecPerPage")).Option("3000").Select();

            var userListTable = myIE3.Table(Find.By("_t", "Users"));

            //create/overwrite javascript file
            string jspath = @"C:\SendShoreTelUsersHome.js";
            File.Create(jspath).Close();
            StreamWriter sw = new StreamWriter(jspath);

            //Prepare the ports!
            sw.WriteLine("var ports = new ActiveXObject('ShoreBusDS.Ports');");

            //writing go home line for each extension
            foreach (var tableRow in userListTable.TableRows)
            {
                //sample text layout of each tr.Text: " Zac Glenn Headquarters Executives Personal 7777 7777 AB77 77 Zac Glenn Home "
                if (!string.IsNullOrEmpty(tableRow.Text))
                {
                    Match match = Regex.Match(tableRow.Text, @"\d{4}");
                    string extension = match.Value;

                    if (!string.IsNullOrEmpty(extension))
                    {
                        sw.WriteLine("ports.UserGoHome('" + extension + "');");
                    }
                }
            }
            //close file connection because exceptions arise that the file is already in use etc
            sw.Close();

            //create your cmd process to execute js file using wscript
            Process process = new Process();
            process.StartInfo.FileName = "wscript.exe";
            process.StartInfo.WorkingDirectory = @"c:\";
            process.StartInfo.Arguments = "SendShoreTelUsersHome.js";
            process.Start();

            //close everything we opened
            myIE.ForceClose();
        }
Exemple #5
0
        private static void Up(string linkToArticle)
        {
            using (var browser = new IE("http://diesel.elcat.kg/"))
            {
                browser.WaitForComplete();
                var logon = browser.Link(Find.ByText("Вход"));
                if (logon.Exists)
                {
                    logon.Click();
                    browser.WaitForComplete();
                    var userName = browser.TextField(Find.ByName("UserName"));
                    var password = browser.TextField(Find.ByName("PassWord"));
                    userName.Value = ConfigurationManager.AppSettings["Login"];
                    password.Value = ConfigurationManager.AppSettings["Password"];
                    Button submitButton = browser.Button(Find.ByName("submit"));
                    submitButton.Click();
                    browser.WaitForComplete(5);
                }

                browser.GoTo(linkToArticle);
                browser.WaitForComplete();
                if (browser.Spans.Any(_ => _.ClassName == "pagelink"))
                {
                    browser.GoTo(browser.Spans
                                        .Where(_ => _.ClassName == "pagelink")
                                        .Skip(1)
                                        .Last().Links.First().GetAttributeValue("href"));
                    browser.WaitForComplete();
                }

                var upPosts = browser.Divs
                    .Where(_ => !string.IsNullOrEmpty(_.Id) && _.Id.Contains("post-"))
                    .Where(_ => _.Text.Trim().ToLower() == UpWord.ToLower())
                    .ToList();

                upPosts.ForEach(_ => DeletePost(_, browser));

                var fastReplyArea = browser.TextField(Find.ById("fast-reply_textarea"));
                fastReplyArea.Value = UpWord;
                var sendButton = browser.Button(Find.ByName("submit"));
                sendButton.Click();
                browser.ForceClose();
            }
        }
Exemple #6
0
        static void Main(string[] args)
        {
            IE  ie;

            string url = args[0];
            int scriptId = System.Int16.Parse(args[1]);

            switch (scriptId)
            {
                case 1:
                    {
                        ie = new IE(url);
                        ie.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ShowMaximized);
                        Thread.Sleep(3000);
                        ie.ForceClose();
                    }; break;
                case 2:
                    {
                        Settings.HighLightElement = true;
                        Settings.AutoMoveMousePointerToTopLeft = false;
                        Settings.MakeNewIe8InstanceNoMerge = true;
                        Settings.AttachToBrowserTimeOut = 60;
                        Settings.WaitForCompleteTimeOut = 60;
                        Settings.WaitUntilExistsTimeOut = 300;
                        Settings.AutoCloseDialogs = true;
                        ie = new IE(url, false);
                        ie.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ShowMaximized);
                        Thread.Sleep(3000);
                        ie.ForceClose();
                    }; break;
                case 3:
                    {
                        Settings.HighLightElement = true;
                        Settings.AutoMoveMousePointerToTopLeft = false;
                        Settings.MakeNewIe8InstanceNoMerge = true;
                        Settings.AttachToBrowserTimeOut = 60;
                        Settings.WaitForCompleteTimeOut = 60;
                        Settings.WaitUntilExistsTimeOut = 300;
                        Settings.AutoCloseDialogs = true;
                        ie = new IE(false);
                        ie.GoTo(url);
                        ie.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ShowMaximized);
                        Thread.Sleep(3000);
                        ie.ForceClose();
                    }; break;
                case 4:
                    {
                        Settings.HighLightElement = true;
                        Settings.AutoMoveMousePointerToTopLeft = false;
                        Settings.MakeNewIe8InstanceNoMerge = true;
                        Settings.AttachToBrowserTimeOut = 60;
                        Settings.WaitForCompleteTimeOut = 60;
                        Settings.WaitUntilExistsTimeOut = 300;
                        Settings.AutoCloseDialogs = true;
                        ie = new IE(true);
                        ie.GoTo(url);
                        ie.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ShowMaximized);
                        Thread.Sleep(3000);
                        ie.ForceClose();
                    }; break;
            }
            /*Settings.HighLightElement = true;
            Settings.AutoMoveMousePointerToTopLeft = false;
            Settings.MakeNewIe8InstanceNoMerge = true;
            //Settings.AttachToIETimeOut = 60;
            Settings.AutoCloseDialogs = true;
            Settings.WaitForCompleteTimeOut = 60;
            Settings.WaitUntilExistsTimeOut = 300;
            ie = new IE(true);
            ie.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ShowMaximized);
            ie.AutoClose = true;
            Thread.Sleep(3000);*/
        }