Exemplo n.º 1
0
        public static PolicyDetailsModel GetDetailsFromInsuranceCopy(string path)
        {
            var client  = new RestClient("https://cognitiveservicesprodfun.azurewebsites.net/api/Insurancepolicy/extract?code=D5LEk84GbaOqP1jenKZq6HVrBXVXeKkxeJDPVqoth0WAfYnPJNUlLA==");
            var request = new RestRequest(Method.POST);

            request.AddParameter("Content-Type", "multipart/form-data");
            request.AddFile("file", path, "application/pdf");
            IRestResponse response = client.Execute(request);

            PolicyDetailsModel pModel = JsonConvert.DeserializeObject <PolicyDetailsModel>(response.Content);

            return(pModel);
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
        public Dictionary <int, int> MatchingFields(CustomerDetailsModel cModel, PolicyDetailsModel pModel)
        {
            int i = 0;
            int j = 0;

            foreach (var item in cModel.GetType().GetProperties())
            {
                if (item.PropertyType == typeof(string))
                {
                    string value = (string)item.GetValue(cModel);
                    if (string.IsNullOrEmpty(value))
                    {
                        j++;
                    }
                }
            }

            i += Convert.ToInt32(FuzzyMatch(cModel.InsuredName, pModel.Insured) >= 0.7);
            i += Convert.ToInt32(FuzzyMatch(cModel.PolicyNumber, pModel.Number) == 1);
            i += Convert.ToInt32(FuzzyMatch(cModel.Address, pModel.Address) >= 0.7);
            i += Convert.ToInt32(FuzzyMatch(cModel.Phone, pModel.Phone) >= 0.8);
            i += Convert.ToInt32(FuzzyMatch(cModel.Email, pModel.Email) >= 0.8);
            i += Convert.ToInt32(FuzzyMatch(cModel.RegistrationNumber, pModel.RegistrationNumber) == 1);
            i += Convert.ToInt32(FuzzyMatch(cModel.EngineNumber, pModel.EngineNumber) >= 0.8);
            i += Convert.ToInt32(FuzzyMatch(cModel.Chassis, pModel.Chassis) >= 0.8);
            i += Convert.ToInt32(FuzzyMatch(cModel.Make_Model, pModel.Make) >= 0.8);
            i += Convert.ToInt32(FuzzyMatch(cModel.TypeOfBody, pModel.TypeOfBody) >= 0.8);
            i += Convert.ToInt32(FuzzyMatch(cModel.YearOfManufacture, pModel.YearOfManufacturing) == 1);
            i += Convert.ToInt32(FuzzyMatch(cModel.SeatingCapacity, pModel.SeatingCapacity) == 1);
            i += Convert.ToInt32(FuzzyMatch(cModel.PreviousPolicyYear, string.Empty) == 1);
            i += Convert.ToInt32(FuzzyMatch(cModel.PreviousPolicyCompanyName, pModel.CompanyName) >= 0.7);
            i += Convert.ToInt32(FuzzyMatch(cModel.VehicleCategory, pModel.VehicleCategory) >= 0.8);
            i += Convert.ToInt32(FuzzyMatch(cModel.VehicleSubCategory, string.Empty) == 1);
            i += Convert.ToInt32(FuzzyMatch(cModel.PreviousPolicyRED, pModel.PreviousPolicyRED) == 1);
            i += Convert.ToInt32(FuzzyMatch(cModel.Salutation, pModel.Salutation) == 1);
            i += Convert.ToInt32(FuzzyMatch(cModel.Hypothecation, pModel.Hypothecation) >= 0.7);
            i += Convert.ToInt32(FuzzyMatch(cModel.RTO, pModel.RTO) >= 0.8);
            i += Convert.ToInt32(FuzzyMatch(cModel.NCB, pModel.NCB) == 1);

            Dictionary <int, int> result = new Dictionary <int, int>();

            result.Add(i, j);
            return(result);
        }
Exemplo n.º 4
0
        public static Dictionary <string, string> GetFilePaths(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();
            Dictionary <string, string> paths       = new Dictionary <string, string>();

            foreach (IWebElement item in unreadMails)
            {
                CustomerDetailsModel cModel = new CustomerDetailsModel();
                PolicyDetailsModel   pModel = new PolicyDetailsModel();
                webBrowser.ClickWithJavaScript(item.FindElement(By.CssSelector(WebElements.ChildElementUnreadEmails)));
                paths = emailHandler.DownloadAndGetFilePaths();
            }
            return(paths);
        }
Exemplo n.º 5
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();
        }