public void SaveRankModel(Dictionary <string, RankModel> dict) { System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); LiteDB.LiteDatabase liteDatabase = new LiteDB.LiteDatabase(this.DbLite); LiteDB.LiteCollection <RankModel> liteCollection = liteDatabase.GetCollection <RankModel>("博客园排行"); int count = 0; foreach (KeyValuePair <string, RankModel> itemRank in dict) { count++; LiteDB.BsonValue bsonValue = new LiteDB.BsonValue(itemRank.Value.Url); RankModel model = liteCollection.FindById(bsonValue); if (model == null) { bsonValue = liteCollection.Insert(itemRank.Value); } else { } } liteDatabase.Dispose(); stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed); }
public async void SaveBlogModel(List <BlogModel> blogModels, string collectionName) { System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); LiteDB.LiteDatabase liteDatabase = new LiteDB.LiteDatabase(this.DbLite); LiteDB.LiteCollection <BlogModel> liteCollection = liteDatabase.GetCollection <BlogModel>(collectionName.RepleaceBrackets()); int count = 0; foreach (BlogModel blogModel in blogModels) { count++; LiteDB.BsonValue bsonValue = new LiteDB.BsonValue(blogModel.PostUrl); BlogModel model = liteCollection.FindById(bsonValue); if (model == null) { blogModel.HtmlContent = await this.Get(blogModel.PostUrl); blogModel.HtmlContent = blogModel.HtmlContent?.RepleaceBrackets()?.Sub(); bsonValue = liteCollection.Insert(blogModel); } else { } } liteDatabase.Dispose(); stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed); }