public bool PostingAlreadySaved(Posting posting) { var query = conn.Table<Posting>().Where(v => v.Link.Equals(posting.Link)).ToListAsync().Result; if (query.Count > 0) return true; return false; }
public bool PostingAlreadySaved(Posting posting) { var query = conn.Table <Posting>().Where(v => v.Link.Equals(posting.Link)).ToListAsync().Result; if (query.Count > 0) { return(true); } return(false); }
public async Task<bool> DeletePostingAsync(Posting posting) { try { var result = await conn.DeleteAsync(posting).ConfigureAwait(continueOnCapturedContext: false); StatusMessage = string.Format("{0} dropped from database [Title: {1}]", result, posting.PostTitle); StatusCode = codes.ok; return true; } catch (Exception ex) { StatusMessage = string.Format("Failed to delete record: {0}, Error: {1}", posting.PostTitle, ex.Message); StatusCode = codes.bad; return false; } }
public async Task <bool> DeletePostingAsync(Posting posting) { try { var result = await conn.DeleteAsync(posting).ConfigureAwait(continueOnCapturedContext: false); StatusMessage = string.Format("{0} dropped from database [Title: {1}]", result, posting.PostTitle); StatusCode = codes.ok; return(true); } catch (Exception ex) { StatusMessage = string.Format("Failed to delete record: {0}, Error: {1}", posting.PostTitle, ex.Message); StatusCode = codes.bad; return(false); } }
private bool ParsePostings(XmlDocument xmldocument) { XmlNamespaceManager mgr = new XmlNamespaceManager(xmldocument.NameTable); mgr.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); mgr.AddNamespace("x", "http://purl.org/rss/1.0/"); XmlNodeList rssNodes = xmldocument.SelectNodes("//rdf:RDF/x:item", mgr); bool incremented = false; // Iterate through the items in the RSS file foreach (XmlNode rssNode in rssNodes) { string imageLink = "-1"; DateTime date = new DateTime(); foreach (XmlNode child in rssNode.ChildNodes) { if (child.Name == "enc:enclosure") { string pot = child.Attributes["resource"].Value; imageLink = pot != null ? pot : "-1"; } if (child.Name == "dc:date") { date = DateTime.Parse(child.InnerText); } } XmlNode rssSubNode = rssNode.SelectSingleNode("x:title", mgr); string title = rssSubNode != null ? rssSubNode.InnerText : ""; if (title.Length > 12 && title.Substring(title.Length - 12) == "<sup>2</sup>") { title = title.Remove(title.Length - 12); } rssSubNode = rssNode.SelectSingleNode("x:link", mgr); string link = rssSubNode != null ? rssSubNode.InnerText : ""; rssSubNode = rssNode.SelectSingleNode("x:description", mgr); string description = rssSubNode != null ? rssSubNode.InnerText : ""; if (title != null) { Posting posting = new Posting(); posting.PostTitle = System.Net.WebUtility.HtmlDecode(title); posting.Description = System.Net.WebUtility.HtmlDecode(description); posting.Link = link; posting.ImageLink = imageLink; posting.Date = date; lock (postings) { if (!postings.Exists(c => c.Link.Equals(posting.Link))) { if (WeeksOld != null && DateTime.Compare(date, DateTime.Today.AddDays(Convert.ToDouble(-7 * WeeksOld))) != -1) { postings.Add(posting); incremented = true; } else if (WeeksOld == null) { postings.Add(posting); incremented = true; } } else { Console.WriteLine("duplicate# " + dup); dup++; } } } } if (postings.Count >= 25 && postings.Count < MaxListings && incremented) { if (this.asyncLoadingPartlyComplete != null) this.asyncLoadingPartlyComplete(this, new EventArgs()); // System.Threading.Thread.Sleep(2000); get_craigslist_postings(String.Format("{1}&s={0}", pageCounter, this.query)); pageCounter += 25; } else { if (this.asyncLoadingComplete != null) this.asyncLoadingComplete(this, new EventArgs()); if (postings.Count == 0 && this.emptyPostingComplete != null) this.emptyPostingComplete(this, new EventArgs()); } return true; }