/// <summary> /// Adds history entry with specific key. /// </summary> /// <param name="key">Key to add to history entry.</param> protected override void Add(string key) { using (var model = new NCrawlerModel()) { var historyEntry = new CrawlHistory(); historyEntry.Key = key; historyEntry.GroupId = this.groupId; model.CrawlHistories.Add(historyEntry); model.SaveChanges(); } }
/// <summary> /// Push item in the queue. /// </summary> /// <param name="crawlerQueueEntry">Queue entry.</param> protected override void PushImpl(CrawlerQueueEntry crawlerQueueEntry) { using (var model = new NCrawlerModel()) { var entry = new CrawlQueue { GroupId = this.groupId, SerializedData = crawlerQueueEntry.ToJson(), }; model.CrawlQueues.Add(entry); model.SaveChanges(); } }
/// <summary> /// Pop item from the queue. /// </summary> /// <returns>Last item in the queue if present; null otherwise.</returns> protected override CrawlerQueueEntry PopImpl() { using (var model = new NCrawlerModel()) { var result = model.CrawlQueues.FirstOrDefault(q => q.GroupId == this.groupId); if (result.IsNull()) { return(null); } model.CrawlQueues.Remove(result); model.SaveChanges(); return(result.SerializedData.FromJson <CrawlerQueueEntry>()); } }
/// <summary> /// Pop item from the queue. /// </summary> /// <returns>Last item in the queue if present; null otherwise.</returns> protected override CrawlerQueueEntry PopImpl() { using (var model = new NCrawlerModel()) { CrawlQueue result = model.CrawlQueues.FirstOrDefault(q => q.GroupId == this.groupId); if (result.IsNull()) { return null; } model.CrawlQueues.Remove(result); model.SaveChanges(); return result.SerializedData.FromJson<CrawlerQueueEntry>(); } }