public string FindAllProperties(PostalAdress p) { string ConsoleLog = null; PostalAdress po = POlog.GetObject(p.PCD); /*If Properties are searched this month ,no need to process again */ if (DateTime.Compare(po.SearchedProperties.AddMonths(1), DateTime.Now) >= 0 && po.SearchedProperties.Equals(new DateTime(0001, 1, 1)) == false) { ConsoleLog += "Already Searched this Postal Adress in this month\n"; return ConsoleLog; } else { ConsoleLog += "Valid Properties Searched\n"; string ScrappedString = null; using (WebClient webClientObj = new WebClient()) { try { ScrappedString = webClientObj.DownloadString("http://www.zoopla.co.uk/home-values/" + p.PCD); } catch (Exception e) { throw new Exception("Unable to Connect Zoople" + e.Message); } string b = "<a *?href=\"/property/(?<data>.*?)" + p.PCD.Replace(" ", "-").ToLower() + ".*?class=\"attrProperty\".*?>(?<data2>.*?)" + p.PCD.ToUpper() + "</a>"; string RequiredRegex = b; try { MatchCollection collection = Regex.Matches(ScrappedString, RequiredRegex); foreach (Match m in collection) { Property pobj = new Property(); pobj.SimpleAdress = m.Groups[2].Value.TrimEnd(); pobj.UrlAdress = @"C:\\Users\\jafar.baltidynamolog\\Documents\\Visual Studio 2010\\Projects\\Imagenary\\Imagenary\\bin\\" + m.Groups[2].Value.TrimEnd().Replace("\\\\", "\\").Replace(",", "") + "\\"; // log.Add(pobj, p.PCD); po.AddPropertyKey(pobj.SimpleAdress); ConsoleLog += "Property Addeds..." + pobj.SimpleAdress + "\n"; } } catch (ArgumentException ex) { throw new Exception("Exception while getting properties" + ex.Message); } } po.SearchedProperties = DateTime.Now; ConsoleLog += "PostalAdress Added ...\n"; POlog.Add(po); } return ConsoleLog; }
public string ReadExcelFileSingle(string fileName, string sheetName, string columnNames) { string pid = null; string ConsoleLog = null; KillProcesses("EXCEL"); string ConnectionString = GetConnectionString(fileName); using (OleDbConnection conn = new OleDbConnection(ConnectionString)) { cmd = new OleDbCommand(); cmd.Connection = conn; cmd.CommandText = "SELECT * FROM [" + sheetName + "] "; conn.Open(); var x = cmd.ExecuteReader(); while (x.Read()) { if (String.IsNullOrWhiteSpace(x[0].ToString()) == false) { string po = x["POSTCODE"].ToString().Replace(" ", ""); int length = po.Length; string postalcode = po.Insert(length - 3, " "); pid = x["ZOOPLA URL"].ToString(); if (PostalAdressObj.adressList.ContainsKey(pid) == false) { PostalAdressObj.Add(new PostalAdress() { PCD = postalcode, PID = pid }); } else { PostalAdressObj.adressList[pid].PCD = postalcode; } } } cmd = null; conn.Close(); } return(ConsoleLog); }
public void PrintAllValues() { PostalAdressLog log = PostalAdressLog.Create; if (ds.Tables[0] != null) { foreach (DataRow r in dt.Rows) { if (r != null && string.IsNullOrWhiteSpace(r[0].ToString()) == false) { string po = r[0].ToString(); if (log.adressList.ContainsKey(po)) { log.Add(new PostalAdress() { PCD = po }); } } } } }