private static string GetConsultantInsertText(string firmID, Contact c)
 {
     string insert = string.Format(@"
                         INSERT INTO Consultant (Name, Title, Industry, Country, City, Email, Phone, BioPage, FirmID)
                         values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')
                 ", c.Name, c.Title, c.Industry, c.Country, c.City, c.Email, c.Phone, c.BioPage, firmID);
     return insert;
 }
Esempio n. 2
0
        public static bool ParseConsultants(MainViewModel vm, bool persistToDatabase)
        {
            var watch = new Stopwatch(); watch.Start();

            vm.LoadDoc();

            // page expertease
            vm.PageIndustry = string.Format("{0}", LookupQueryStringValue(vm, vm.Industries, "Expertise"));
            // page country
            vm.PageCountry = string.Format("{0}", LookupQueryStringValue(vm, vm.Countries, "Location"));
            // page city
            vm.PageCity = string.Format("{0}", LookupQueryStringValue(vm, vm.Cities, "Office"));
            // page number
            vm.PageNumber = string.IsNullOrEmpty(vm.QueryPairs["page"]) ? null : (int?)Int32.Parse(vm.QueryPairs["page"]);
            //  pages

            // page consultants
            var consultantElements = DomUtil.GetElementsByClass(vm.Doc, "td", "submain");
            if (consultantElements == null || consultantElements.Count() < 1)
                return false;

            var sb = new StringBuilder();
            var contacts = new List<Contact>();
            foreach (var consutlantElement in consultantElements) {
                var c = new Contact();
                c.Industry = vm.PageIndustry;
                c.Country = vm.PageCountry;
                c.City = vm.PageCity;
                c.Source = vm.GetHost();

                foreach (var e in consutlantElement.ChildNodes) {
                    var val = e.InnerText;
                    switch (e.Name) {

                        case "#text":
                            if (string.IsNullOrEmpty(c.Title))
                                c.Title = val;
                            break;
                        case "a":
                            if (val.Contains('@'))
                                c.Email = val;
                            else
                                c.Name = val;

                            if (e.Attributes["href"] != null && e.Attributes["href"].Value.IndexOf("/Bios") > -1)
                                c.BioPage = string.Format("http://{0}{1}", c.Source, e.Attributes["href"].Value.Substring(e.Attributes["href"].Value.IndexOf("/Bios")));
                            break;

                    }
                }
                sb.Append(c.ToString());
                sb.Append("\n");
                contacts.Add(c);
            }
            if (persistToDatabase)
                new ConsultantDataAccess().SaveConsultant(contacts);
            Task.Factory.StartNew(() => {
                vm.RetrieveStatus = string.Format("{0} retrieved in {1}:{2}", vm.Url, watch.Elapsed.Minutes, watch.Elapsed.Seconds);
                vm.PageConsultants = sb.ToString();
            });

            return true;
        }