| 1 | using Core.Models; |
| 2 | using Core.Models.Db; |
| 3 | using System; |
| 4 | using System.Collections.Generic; |
| 5 | using System.Data.Entity; |
| 6 | using System.Data.SQLite; |
| 7 | using System.Diagnostics; |
| 8 | using System.IO; |
| 9 | using System.Linq; |
| 10 | using System.Text; |
| 11 | using System.Threading.Tasks; |
| 12 | |
| 13 | namespace Core.Librarys.SQLite |
| 14 | { |
| 15 | public class TaiDbContext : DbContext |
| 16 | { |
| 17 | ///<summary> |
| 18 | /// |
| 19 | ///</summary> |
| 20 | public DbSet<DailyLogModel> DailyLog { get; set; } |
| 21 | ///<summary> |
| 22 | /// |
| 23 | ///</summary> |
| 24 | public DbSet<HoursLogModel> HoursLog { get; set; } |
| 25 | public DbSet<AppModel> App { get; set; } |
| 26 | ///<summary> |
| 27 | /// |
| 28 | ///</summary> |
| 29 | public DbSet<CategoryModel> Categorys { get; set; } |
| 30 | ///<summary> |
| 31 | /// |
| 32 | ///</summary> |
| 33 | public DbSet<WebSiteModel> WebSites { get; set; } |
| 34 | ///<summary> |
| 35 | /// |
| 36 | ///</summary> |
| 37 | public DbSet<WebSiteCategoryModel> WebSiteCategories { get; set; } |
| 38 | ///<summary> |
| 39 | /// |
| 40 | ///</summary> |
| 41 | public DbSet<WebBrowseLogModel> WebBrowserLogs { get; set; } |
| 42 | ///<summary> |
| 43 | /// |
| 44 | ///</summary> |
| 45 | public DbSet<WebUrlModel> WebUrls { get; set; } |
| 46 | |
| 47 | private static string _dbFilePath = Path.Combine(FileHelper.GetRootDirectory(), "Data", "data.db"); |
| 48 | public TaiDbContext() |
| 49 | : base(new SQLiteConnection() |
| 50 | { |
| 51 | ConnectionString = $"Data Source={_dbFilePath}", |
| 52 | BusyTimeout = 60 |
| 53 | }, true) |
| 54 | { |
| 55 | DbConfiguration.SetConfiguration(new SQLiteConfiguration()); |
| 56 | } |
| 57 | |
| 58 | protected override void OnModelCreating(DbModelBuilder modelBuilder) |
| 59 | { |
| 60 | var model = modelBuilder.Build(Database.Connection); |
| 61 | new SQLiteBuilder(model).SelfCheck(); |
| 62 | } |
| 63 | |
| 64 | public void SelfCheck() |
| 65 | { |
| 66 | Database.ExecuteSqlCommand("select count(*) from sqlite_master where type='table' and name='tai'"); |
| 67 | } |
| 68 | } |
| 69 | } |