private void queue_ContentChanged(object sender, QueueChangedEventArgs <QueueModel> args) { if (args.Action == QueueChangedActionEnum.Enqueue) { pool.QueueWorkItem(() => { try { QueueModel qm; if (queue.Dequeue(out qm)) { var result = NodeVisitor.Cooperater.GetResult(qm.Url); if (result != null) { var cm = new ContentModel(); cm.FeedId = qm.FeedId; cm.Url = qm.Url; cm.Metas = result.Metas; cm.CDate = DateTime.Now; var connectString = string.Format(@"LiteDb/Content/{0}.db", DateTime.Now.ToString("yyyyMM")); var storage = new LiteDbStorage(connectString, "contents"); if (storage.Insert(cm) == -1) { File.AppendAllText(path + @"\" + EncryptHelper.GetMD5Hash(qm.Url) + ".json", JsonConvert.SerializeObject(cm)); } } } } catch { //save failed } }); } }
public bool SaveContent([FromBody] ContentModel content, string shard = "") { try { if (string.IsNullOrEmpty(shard)) { shard = DateTime.Now.ToString("yyyyMM"); } var storage = new LiteDbStorage(@"LiteDb/Content/" + shard + ".db", "contents"); return(storage.Insert(content) != -1); } catch { return(false); } }