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); }
public List <string> GetCollectionNames() { LiteDB.LiteDatabase liteDatabase = new LiteDB.LiteDatabase(this.DbLite); List <string> lst = liteDatabase.GetCollectionNames().ToList(); liteDatabase.Dispose(); return(lst); }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { db.Dispose(); } disposedValue = true; } }
protected virtual void Dispose(bool disposing) { if (IsDisposed) { return; } if (disposing) { Database?.Dispose(); } IsDisposed = true; }
public static void Shutdown() { IsRunning = false; if (_winThread != null) { if (!_winThread.Join(TimeSpan.FromSeconds(10))) { Log.Error("StatsDB failed to shutdown in time"); } _winThread = null; } if (_database != null) { _database.Dispose(); } }
public void Dispose() { _liteDatabase?.Dispose(); }