Ejemplo n.º 1
0
 public void Adicionar(int CandidateId, string nota)
 {
     using (grouponjobsdevEntities context = new grouponjobsdevEntities())
     {
         Candidate_Note note = new Candidate_Note();
         note.CandidateId = CandidateId;
         note.Nota = nota;
         context.Candidate_Note.AddObject(note);
         context.SaveChanges();
     }
 }
Ejemplo n.º 2
0
        private void navigate()
        {
            string FirstName = "";
            string LastName = "";
            string EMailDecoded = "";
            string ResumeDecoded = "";
            string Rating = "";
            string Disposition = "";
            string WorkFlowDecoded = "";
            string CityDecoded = "";
            int RatingId = 0;
            int DispositionId = 0;
            int requisitionInitialId;
            int countRequisitions;
            int inicio = int.Parse(txtInicio.Text);
            int fim = int.Parse(txtFim.Text);
            bool hasnotes = true;
            string[] messages = new string[100];
            int contador = inicio;
            int totalId = 0;
            try
            {

                bool erro = false;
                using (grouponjobsdevEntities context = new grouponjobsdevEntities())
                {
                    countRequisitions = context.Requisitions.Count();
                    requisitionInitialId = context.Requisitions.Select(r => r.RequisitionId).First();
                }

                for (int l = inicio; contador <= fim; l++)
                {
                    string RequisitionLink = "";
                    erro = true;
                    hasnotes = true;
                    try
                    {
                        totalId = requisitionInitialId + contador;
                        using (grouponjobsdevEntities context = new grouponjobsdevEntities())
                        {
                            RequisitionLink = context.Requisitions.Where(r => r.RequisitionId == totalId).Select(r => r.RequisitionLink).First();
                        }
                        browserJobVite.Navigate(new Uri("https://hire.jobvite.com/Hiring/" + RequisitionLink));
                        while (browserJobVite.ReadyState != WebBrowserReadyState.Complete)
                        {
                            Application.DoEvents();
                        }

                        if (RequisitionLink != "")
                        {

                            foreach (HtmlElement e in browserJobVite.Document.GetElementsByTagName("a"))
                            {
                                if (e.GetAttribute("classname") == "jv-redirectCandidate")
                                {
                                    e.InvokeMember("Click");
                                    break;
                                }
                            }

                            while (browserJobVite.ReadyState != WebBrowserReadyState.Complete)
                            {
                                Application.DoEvents();
                            }
                            iMax = ContagemCandidatos();
                            //MessageBox.Show(iMax.ToString());
                            //MessageBox.Show(RequisitionLink);
                            erro = false;
                        }
                        contador++;
                    }
                    catch (Exception ex)
                    {

                        erro = true;
                    }

                    for (int n = 0; n < iMax; n++)
                    {
                        while (browserJobVite.ReadyState != WebBrowserReadyState.Complete)
                        {
                            Application.DoEvents();
                        }

                        if (erro == false)
                        {
                            hasnotes = true;
                            source.LoadHtml(browserJobVite.DocumentText);
                            foreach (HtmlNode TitleHeader in source.DocumentNode.SelectNodes("//span[@id=\"TitleHeader\"]"))
                            {
                                string TitleHeaderDecoded = System.Net.WebUtility.HtmlDecode(TitleHeader.InnerText);
                                string[] nameSplit = TitleHeaderDecoded.Split(' ');
                                FirstName = nameSplit[0];
                                LastName = concatenaLastName(nameSplit);
                                txtLog.Text = txtLog.Text + FirstName + " " + LastName + Environment.NewLine;
                            }
                            foreach (HtmlNode WorkFlow in source.DocumentNode.SelectNodes("//span[@id=\"candidateStatus\"]"))
                            {
                                WorkFlowDecoded = System.Net.WebUtility.HtmlDecode(WorkFlow.InnerText);
                                txtLog.Text = txtLog.Text + WorkFlowDecoded + Environment.NewLine;
                            }
                            foreach (HtmlNode EMail in source.DocumentNode.SelectNodes("//span[@id=\"Email\"]"))
                            {
                                EMailDecoded = System.Net.WebUtility.HtmlDecode(EMail.InnerText);
                                txtLog.Text = txtLog.Text + EMailDecoded + Environment.NewLine;
                            }
                            foreach (HtmlNode Resume in source.DocumentNode.SelectNodes("//span[@id=\"Resume\"]"))
                            {
                                ResumeDecoded = Resume.InnerText;
                                txtLog.Text = txtLog.Text + ResumeDecoded + Environment.NewLine;
                            }
                            foreach (HtmlNode City in source.DocumentNode.SelectNodes("//span[@id=\"City\"]"))
                            {
                                CityDecoded = System.Net.WebUtility.HtmlDecode(City.InnerText);
                                //txtLog.Text = txtLog.Text + "Cidade: " + CityDecoded + Environment.NewLine;
                            }
                            int z = 0;
                            try
                            {
                                foreach (HtmlNode Notes in source.DocumentNode.SelectNodes("//span[@id=\"msgSpan0\"]/table/tr/td"))
                                {
                                    if (!string.IsNullOrEmpty(Notes.InnerText))
                                    {
                                        messages[z] = Notes.InnerText;
                                        z++;
                                    }
                                }
                            }
                            catch
                            {
                                hasnotes = false;
                            }

                            //teste de dropdown list

                            var menus = source.DocumentNode.Descendants("select");
                            int k = 0;
                            string[] ddlvalues = new string[3];
                            foreach (var element in menus)
                            {
                                ddlvalues[k] = AddMenuElement(element);
                                k++;
                            }
                            switch (ddlvalues[1])
                            {
                                case "5601":
                                    ddlvalues[1] = "Não avaliado";
                                    break;
                                case "5602":
                                    ddlvalues[1] = "Não qualificado";
                                    break;
                                case "5604":
                                    ddlvalues[1] = "Talvez";
                                    break;
                                case "5605":
                                    ddlvalues[1] = "Bom";
                                    break;
                                case "5606":
                                    ddlvalues[1] = "Preferido";
                                    break;
                                case "5607":
                                    ddlvalues[1] = "Super qualificado";
                                    break;
                                case "5608":
                                    ddlvalues[1] = "Sem interesse";
                                    break;
                            }

                            switch (ddlvalues[2])
                            {
                                case "F3SaVfwK":
                                    ddlvalues[2] = "Não avaliado";
                                    break;
                                case "FCLaVfwc":
                                    ddlvalues[2] = "Fora do Perfil";
                                    break;
                                case "FDLaVfwd":
                                    ddlvalues[2] = "Abordado e Fora do Perfil";
                                    break;
                                case "FELaVfwe":
                                    ddlvalues[2] = "Entrevistado e Fora do Perfil";
                                    break;
                                case "FFLaVfwf":
                                    ddlvalues[2] = "Entrevista Groupon";
                                    break;
                                case "FGLaVfwg":
                                    ddlvalues[2] = "Em Avaliação";
                                    break;
                                case "FcSaVfwT":
                                    ddlvalues[2] = "Sem interesse";
                                    break;
                                case "FHLaVfwh":
                                    ddlvalues[2] = "Proposta";
                                    break;
                                case "FILaVfwi":
                                    ddlvalues[2] = "Rejeitou Proposta";
                                    break;
                                case "FJLaVfwj":
                                    ddlvalues[2] = "Contratado!";
                                    break;
                            }
                            Rating = ddlvalues[1];
                            Disposition = ddlvalues[2];
                            int CityId = 5508;
                            using (grouponjobsdevEntities context = new grouponjobsdevEntities())
                            {
                                Candidate_Log log = new Candidate_Log();
                                try
                                {
                                    RatingId = context.Candidate_Rating.Where(cr => cr.Name == Rating).Select(cr => cr.RatingId).First();
                                }
                                catch (Exception ex)
                                {
                                    RatingId = 1;
                                    log.Adicionar(FirstName + " " + LastName, "Rating", Rating, ex.Message);
                                }
                                try
                                {
                                    DispositionId = context.Candidate_Disposition.Where(cd => cd.Name == Disposition).Select(cd => cd.DispositionId).First();
                                }

                                catch (Exception ex)
                                {
                                    DispositionId = 3;
                                    log.Adicionar(FirstName + " " + LastName, "Disposition", Disposition, ex.Message);
                                }
                                try
                                {
                                    CityId = context.Cities.Where(c => c.Name == CityDecoded).Select(c => c.CityId).First();
                                }
                                catch (Exception ex)
                                {

                                    log.Adicionar(FirstName + " " + LastName, "City", CityDecoded, ex.Message);
                                }

                                try
                                {
                                    JobsCrawler.DAL.Candidate cand = new JobsCrawler.DAL.Candidate();
                                    cand.Adicionar(FirstName, LastName, RatingId, DispositionId, totalId, ResumeDecoded, WorkFlowDecoded, CityId);
                                }
                                catch (Exception ex)
                                {
                                }
                                if (hasnotes == true)
                                {
                                    try
                                    {
                                        foreach (string Nota in messages)
                                        {
                                            if (!string.IsNullOrEmpty(Nota))
                                            {
                                                Candidate_Note note = new Candidate_Note();
                                                int CandidateId;
                                                CandidateId = context.Candidates.Where(c => c.FirstName == FirstName && c.LastName == LastName).Select(c => c.CandidateId).First();
                                                note.Adicionar(CandidateId, Nota);
                                            }
                                        }
                                    }
                                    catch
                                    {
                                    }

                                }

                            }

                            browserJobVite.Navigate(new Uri("https://hire.jobvite.com/Hiring/ViewCandidate.aspx?v=14&id=" + (n + 1)));
                        }

                    }
                }

            }
            catch (Exception ex)
            {
                txtLog.Text = ex.ToString();
            }
        }