using LiteDB; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tango.PPC.Common.Resume { public class JobResumeDB : IDisposable { private LiteDatabase _db; private ILiteCollection _collection; private static Lazy _default = new Lazy(() => new JobResumeDB()); public static JobResumeDB Default { get { return _default.Value; } } private JobResumeDB() { Init(); } private void Init() { String dbFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "Job Resume v2"); Directory.CreateDirectory(dbFolder); _db = new LiteDatabase($"Filename={Path.Combine(dbFolder, "job_resume.db")};connection=shared"); _collection = _db.GetCollection("JobResume"); } public void Update(JobResumeModel model) { _collection.Update(model); } public void Add(JobResumeModel model) { _collection.Insert(model); } public List GetAll() { return _collection.FindAll().ToList(); } public JobResumeModel Get(String jobGuild) { return _collection.FindOne(x => x.JobGuid == jobGuild); } public void Delete(JobResumeModel model) { _collection.Delete(model.JobGuid); } public void Delete(String jobGuid) { _collection.Delete(jobGuid); } ~JobResumeDB() { Dispose(); } public void Dispose() { try { _db?.Dispose(); } catch { } } } }