예제 #1
0
        public void CallingIEForceCloseAfterIECloseShouldThrowAnExeption()
        {
            var ie = new IE();

            ie.Close();
            ie.ForceClose();
        }
예제 #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);
     }
 }
예제 #3
0
        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();
        }
예제 #4
0
        public void SaveImage(string filePath, string name)
        {
            string dirPath  = @"C:\Users\test01\Desktop\Images";
            string fileName = @"C:\Users\test01\Desktop\Images\" + name + ".jpg";

            if (File.Exists(fileName))
            {
                return;
            }

            try
            {
                ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;
                // Create a new directory
                DirectoryInfo imageDirectory = Directory.CreateDirectory(dirPath);
                Console.WriteLine($"Directory '{Path.GetFileName(dirPath)}' was created successfully in {Directory.GetParent(dirPath)}");

                // Image I'm trying to download from the web
                //string filePath = @"http://ilarge.lisimg.com/image/12056736/1080full-jessica-clements.jpg";

                using (WebClient _wc = new WebClient())
                {
                    _wc.DownloadFile(new Uri(filePath), fileName);
                    _wc.Dispose();
                }

                Console.WriteLine("\nFile successfully saved.");
            }

            catch (Exception e)
            {
                while (e != null)
                {
                    productItem.Close();
                    da.RecordDetailedErrorData(e, WebsiteID, 1);
                    Console.WriteLine(e.Message + " Line: 438");
                    isErrorred = true;

                    if (productItem != null)
                    {
                        productItem.ForceClose();
                    }
                }
            }

            if (System.Diagnostics.Debugger.IsAttached)
            {
                // Console.WriteLine("Press any key to continue . . .");
                // Console.ReadKey(true);
            }
        }
예제 #5
0
파일: IETests.cs 프로젝트: koshdim/KoWatIn
 public void CallingIEForceCloseAfterIECloseShouldThrowAnExeption()
 {
     var ie = new IE();
     ie.Close();
     ie.ForceClose();
 }
예제 #6
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     try { browser.Dispose();
           browser.ForceClose(); }
     catch { }
 }
예제 #7
0
        /// <summary>
        /// Performs authentication.
        /// </summary>
        private void EnsureAuth()
        {
            if (this.session != null && !this.session.Expired)
            {
                return;
            }

            try
            {
                using (var browser = new IE())
                {
                    var timer = new System.Diagnostics.Stopwatch();
                    timer.Start();

                    browser.AutoClose = true;
                    browser.GoTo(this.AuthUrl);

                    // Do autologin if needed.
                    if (this.AutoLogin && !browser.Url.ToLowerInvariant().Contains("access_token=") &&
                        !browser.Url.ToLowerInvariant().Contains("error="))
                    {
                        // Fill email password.
                        if (browser.TextField(Find.ByName("email")).Exists&&
                            browser.TextField(Find.ByName("pass")).Exists)
                        {
                            browser.TextField(Find.ByName("email")).Value = this.userEmail;
                            browser.TextField(Find.ByName("pass")).Value  = this.userPassword;
                            browser.Button("install_allow").Click();
                        }

                        // Accept application permissions.
                        if (browser.Button("install_allow").Exists)
                        {
                            browser.Button("install_allow").Click();
                        }

                        if (!browser.Url.ToLowerInvariant().Contains("access_token=") &&
                            !browser.Url.ToLowerInvariant().Contains("error="))
                        {
                            throw new AuthenticationException("Most likely wrong email\\password.");
                        }
                    }

                    // Wait for user to login.
                    if (!this.AutoLogin)
                    {
                        while (!browser.Url.ToLowerInvariant().Contains("access_token="))
                        {
                            System.Threading.Thread.Sleep(3000);
                        }
                    }

                    if (browser.Url.ToLowerInvariant().Contains("error="))
                    {
                        var error = Regex.Match(browser.Url, "error=(?<error>[^&$]*)", RegexOptions.IgnoreCase).Groups["error"].Value;
                        var desc  = Regex.Match(browser.Url, "error_description=(?<desc>[^&$]*)", RegexOptions.IgnoreCase).Groups["desc"].Value;
                        throw new AuthenticationException(
                                  string.Format(
                                      "Error: {0}\nDescription: {1}",
                                      HttpUtility.UrlDecode(error),
                                      HttpUtility.UrlDecode(desc)));
                    }

                    // Create auth session.
                    var token   = Regex.Match(browser.Url, "access_token=(?<token>[^&$]*)", RegexOptions.IgnoreCase).Groups["token"].Value;
                    var expires = int.Parse(Regex.Match(browser.Url, "expires_in=(?<expires>\\d+)", RegexOptions.IgnoreCase).Groups["expires"].Value);
                    var uid     = uint.Parse(Regex.Match(browser.Url, "user_id=(?<uid>\\d+)", RegexOptions.IgnoreCase).Groups["uid"].Value);

                    timer.Stop();
                    this.session = new AuthSession(uid, token, expires - (int)timer.Elapsed.TotalSeconds);

                    // Clears IE cache, all cookies (!) and kills IE process. Weird, I know :)
                    browser.ClearCache();
                    browser.ClearCookies();
                    browser.ForceClose();
                }
            }
            catch (AuthenticationException)
            {
                // WTF?! Browser closed? Wrong auth url?!
                throw;
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("Authentication failed.", ex);
            }
        }