Example #1
0
        public void RunTheBot(string username, string password)
        {
            pdfHandler.DeleteFile(webBrowser.downloadPath);
            Dictionary <int, int> matchFields = new Dictionary <int, int>();

            emailHandler.LoginAndNavigateToInbox(username, password);
            webBrowser.Click(WebElements.BtnInsuranceLabel);
            List <IWebElement> unreadMails = emailHandler.GetUnreadEmails();

            foreach (IWebElement item in unreadMails)
            {
                CustomerDetailsModel cModel = new CustomerDetailsModel();
                PolicyDetailsModel   pModel = new PolicyDetailsModel();
                webBrowser.ClickWithJavaScript(item.FindElement(By.CssSelector(WebElements.ChildElementUnreadEmails)));
                Dictionary <string, string> paths = emailHandler.DownloadAndGetFilePaths();
                //fileHandler.Open(paths.Values.ToList());

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                var statusFrom = new Status(paths.Values.ToList());
                Application.Run(statusFrom);

                foreach (KeyValuePair <string, string> path in paths)
                {
                    if (path.Value.Contains("Customer"))
                    {
                        cModel = GetPDFFromKYCForm(path.Value);
                    }
                    else
                    {
                        pModel = GetDetailsFromInsuranceCopy(path.Value);
                    }
                }
                matchFields = MatchingFields(cModel, pModel);

                string result = $"Using {paths.Keys.ToArray()[0]} and {paths.Keys.ToArray()[1]}, {matchFields.Keys.FirstOrDefault()} fields matching out of 22 fields and {matchFields.Values.FirstOrDefault()} are empty";
                // statusFrom.resultText = result;

                // fileHandler.Close("AcroRd32");
                webBrowser.Click(WebElements.BtnReply);
                webBrowser.EnterText(WebElements.TxtBoxReplyMessage, "Hello," + "\n" + result + "\nThank You\nReliance Bot");
                webBrowser.Click(WebElements.BtnSend);
                webBrowser.Pause(3);
                webBrowser.Click(WebElements.BtnInsuranceLabel);
                pdfHandler.DeleteFile(webBrowser.downloadPath);
            }
            webBrowser.Dispose();
        }
Example #2
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            pdfHandler.DeleteFile(webBrowser.downloadPath);
            Dictionary <int, int> matchFields = new Dictionary <int, int>();

            emailHandler.LoginAndNavigateToInbox("*****@*****.**", "Kartik1a$");
            webBrowser.Click(WebElements.BtnInsuranceLabel);
            List <IWebElement> unreadMails = emailHandler.GetUnreadEmails();

            UnreadmailCount = unreadMails.Count;
            foreach (IWebElement item in unreadMails)
            {
                count++;
                CustomerDetailsModel cModel = new CustomerDetailsModel();
                PolicyDetailsModel   pModel = new PolicyDetailsModel();
                webBrowser.ClickWithJavaScript(item.FindElement(By.CssSelector(WebElements.ChildElementUnreadEmails)));
                Dictionary <string, string> paths = emailHandler.DownloadAndGetFilePaths();
                Thread.Sleep(2000);
                isMinimize = false;
                backgroundWorker1.ReportProgress(1);
                myPaths = paths.Values.ToList();
                showPdf = true;
                backgroundWorker1.ReportProgress(1);

                CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
                CancellationToken       token = cancellationTokenSource.Token;
                Task task = Task.Run(() =>
                {
                    while (!token.IsCancellationRequested)
                    {
                        foreach (string status in statusValues)
                        {
                            Thread.Sleep(500);
                            statusText = status;
                            backgroundWorker1.ReportProgress(1);
                        }
                    }
                    //while (token.IsCancellationRequested)
                    //{
                    //    token.ThrowIfCancellationRequested();
                    //}
                }, token);

                //CancellationTokenSource tokenSource = new CancellationTokenSource();
                //CancellationToken token = tokenSource.Token;
                //Task t = Task.Run(() =>
                //  {
                //      foreach (string status in statusValues)
                //      {
                //          Thread.Sleep(500);
                //          statusText = status;
                //          backgroundWorker1.ReportProgress(1);
                //      }

                //  }, token);

                foreach (KeyValuePair <string, string> path in paths)
                {
                    if (path.Value.Contains("Customer"))
                    {
                        cModel = GetPDFFromKYCForm(path.Value);
                    }
                    else
                    {
                        pModel = GetDetailsFromInsuranceCopy(path.Value);
                    }
                }
                matchFields = MatchingFields(cModel, pModel);
                string result = $"Using {paths.Keys.ToArray()[0]} and {paths.Keys.ToArray()[1]}, {matchFields.Keys.FirstOrDefault()} fields matching out of 22 fields and {matchFields.Values.FirstOrDefault()} are empty";
                cancellationTokenSource.Cancel();
                task.Wait();
                // MessageBox.Show(result);
                statusText = result;
                backgroundWorker1.ReportProgress(1);
                Thread.Sleep(1000);
                isMinimize = true;
                backgroundWorker1.ReportProgress(1);
                // fileHandler.Close("AcroRd32");
                webBrowser.Click(WebElements.BtnReply);
                webBrowser.EnterText(WebElements.TxtBoxReplyMessage, "Hello," + "\n" + result + "\nThank You\nReliance Bot");
                webBrowser.Click(WebElements.BtnSend);
                webBrowser.Pause(3);
                webBrowser.Click(WebElements.BtnInsuranceLabel);
                pdfHandler.DeleteFile(webBrowser.downloadPath);
                Thread.Sleep(3000);
            }
            ServiceResult = "Completed";
            backgroundWorker1.ReportProgress(1);
            webBrowser.Dispose();
        }