public static List<string> GetCachedNotePathList() { using (var dc = new MyDataContext()) { return (from img in dc.ImageTable select img.BelongedNotePath).Distinct().ToList(); } }
public void DeleteAllIfExist(List <string> ids) { if (null == ids) { throw new ArgumentNullException("ids"); } var isNoteChangedFlag = false; using (var dc = new MyDataContext()) { foreach (var id in ids) { var entity = dc.NoteTable.FirstOrDefault(n => n.Id == id); if (null == entity) { return; } dc.NoteTable.DeleteOnSubmit(entity); if (NoteDeleted != null) { NoteDeleted(entity); } isNoteChangedFlag = true; } dc.SafeSubmitChanges(); } if (isNoteChangedFlag) { if (NoteChanged != null) { NoteChanged(); } } }
public void AddIfNotExist(NoteEntity note) { if (null == note) { throw new ArgumentNullException("note"); } using (var dc = new MyDataContext()) { //var a = new System.IO.StringWriter(); //dc.Log = a; var entity = dc.NoteTable.FirstOrDefault(n => n.NotePath == note.NotePath); if (null != entity) { return; } ensureTitleIsNotEmpty(note); dc.NoteTable.InsertOnSubmit(note); dc.SafeSubmitChanges(); } //Debug.WriteLine(a); if (NoteCreated != null) { NoteCreated(note); } if (NoteChanged != null) { NoteChanged(); } }
public void AddIfNotExist(NoteEntity note) { if (null == note) { throw new ArgumentNullException("note"); } using (var dc = new MyDataContext()) { //var a = new System.IO.StringWriter(); //dc.Log = a; var entity = dc.NoteTable.FirstOrDefault(n => n.NotePath == note.NotePath); if (null != entity) return; ensureTitleIsNotEmpty(note); dc.NoteTable.InsertOnSubmit(note); dc.SafeSubmitChanges(); } //Debug.WriteLine(a); if (NoteCreated != null) { NoteCreated(note); } if (NoteChanged != null) { NoteChanged(); } }
public static List <string> GetCachedNotePathList() { using (var dc = new MyDataContext()) { return((from img in dc.ImageTable select img.BelongedNotePath).Distinct().ToList()); } }
/// <summary> /// 如果笔记存在,则将笔记删除。 /// </summary> /// <param name="id"></param> public void DeleteIfExist(string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException("id"); } using (var dc = new MyDataContext()) { var entity = dc.NoteTable.FirstOrDefault(n => n.Id == id); if (null == entity) { return; } dc.NoteTable.DeleteOnSubmit(entity); dc.SafeSubmitChanges(); if (NoteDeleted != null) { NoteDeleted(entity); } if (NoteChanged != null) { NoteChanged(); } } }
public void Clear() { using (var dc = new MyDataContext()) { dc.NotebookTable.DeleteAllOnSubmit(from e in dc.NotebookTable select e); dc.SafeSubmitChanges(); } }
public List <NotebookEntity> GetAllNotebook() { using (var dc = new MyDataContext()) { return(!dc.DatabaseExists() ? new List <NotebookEntity>() : dc.NotebookTable.ToList()); } }
public int GetTotalNotesNum() { using (var dc = new MyDataContext()) { return(!dc.DatabaseExists() ? 0 : Enumerable.Sum(dc.NotebookTable, notebook => notebook.NotesNum)); } }
public static void CreatetDatabaseIfNeeded() { using (var dc = new MyDataContext()) { if (dc.DatabaseExists()) return; dc.CreateDatabase(); Debug.WriteLine(DateTime.Now.ToLongTimeString() + " 数据库创建完成。"); } }
public int GetTotalNotesNum() { using (var dc = new MyDataContext()) { return !dc.DatabaseExists() ? 0 : Enumerable.Sum(dc.NotebookTable, notebook => notebook.NotesNum); } }
public List <NoteEntity> GetAllLocalCreatedNotes() { using (var dc = new MyDataContext()) { var entities = from n in dc.NoteTable where n.NoteStatus == NoteStatus.Added select n; return(entities.ToList()); } }
public List<NotebookEntity> GetAllNotebook() { using (var dc = new MyDataContext()) { return !dc.DatabaseExists() ? new List<NotebookEntity>() : dc.NotebookTable.ToList(); } }
public List <NoteEntity> GetAllNote() { using (var dc = new MyDataContext()) { var entities = from n in dc.NoteTable where n.NoteStatus != NoteStatus.Deleted orderby n.ModifyTime descending select n; return(entities.ToList()); } }
public static void DeleteDatabaseIfExists() { using (var dc = new MyDataContext()) { if (dc.DatabaseExists()) { dc.DeleteDatabase(); } Debug.WriteLine(DateTime.Now.ToLongTimeString() + " 数据库已被删除。"); } }
public static ImageEntity GetImageByLocalSavePath(string localSavePath) { if (string.IsNullOrEmpty(localSavePath)) { throw new ArgumentNullException("localSavePath"); } using (var dc = new MyDataContext()) { var entity = dc.ImageTable.FirstOrDefault(p => p.ImgLocalSavePath == localSavePath); return entity; } }
public static ImageEntity GetImageById(string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException("id"); } using (var dc = new MyDataContext()) { var entity = dc.ImageTable.FirstOrDefault(p => p.Id == id); return entity; } }
public static void CreatetDatabaseIfNeeded() { using (var dc = new MyDataContext()) { if (dc.DatabaseExists()) { return; } dc.CreateDatabase(); Debug.WriteLine(DateTime.Now.ToLongTimeString() + " 数据库创建完成。"); } }
public static ImageEntity GetImageByLocalSavePath(string localSavePath) { if (string.IsNullOrEmpty(localSavePath)) { throw new ArgumentNullException("localSavePath"); } using (var dc = new MyDataContext()) { var entity = dc.ImageTable.FirstOrDefault(p => p.ImgLocalSavePath == localSavePath); return(entity); } }
public static ImageEntity GetImageById(string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException("id"); } using (var dc = new MyDataContext()) { var entity = dc.ImageTable.FirstOrDefault(p => p.Id == id); return(entity); } }
public NoteEntity GetNoteByPath(string path) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } using (var dc = new MyDataContext()) { var entity = dc.NoteTable.FirstOrDefault(n => n.NotePath == path); return(entity); } }
public NoteEntity GetNoteById(string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException("id"); } using (var dc = new MyDataContext()) { var entity = dc.NoteTable.FirstOrDefault(n => n.Id == id); return(entity); } }
public static bool ImageExists(string imgNameWithoutExt, out ImageEntity img) { if (string.IsNullOrEmpty(imgNameWithoutExt)) { throw new ArgumentNullException("imgNameWithoutExt"); } using (var dc = new MyDataContext()) { img = dc.ImageTable.FirstOrDefault(p => p.ImgNameWithoutExt == imgNameWithoutExt); return(img != null); } }
public bool NoteExist(string path) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } using (var dc = new MyDataContext()) { var note = dc.NoteTable.FirstOrDefault(n => n.NotePath == path); return(note != null); } }
public List <NoteEntity> GetLocalCreatedNotes(string notebookName) { if (string.IsNullOrEmpty(notebookName)) { throw new ArgumentNullException("notebookName"); } using (var dc = new MyDataContext()) { var entities = from n in dc.NoteTable where n.NotebookName == notebookName && n.NoteStatus == NoteStatus.Added select n; return(entities.ToList()); } }
/// <summary> /// 删除悬空图片(没有笔记引用的图片)。 /// </summary> public static void DeleteNoRootImages() { using (var dc = new MyDataContext()) { if (!dc.DatabaseExists()) return; foreach (var img in dc.ImageTable) { if (NoteDao.Inst.NoteExist((img.BelongedNotePath))) continue; DeleteIfExist(img.Id); Debug.WriteLine("删除本地悬空图片:" + img.ImgLocalSavePath); } } }
public void Clear() { using (var dc = new MyDataContext()) { dc.NoteTable.DeleteAllOnSubmit(from e in dc.NoteTable select e); dc.SafeSubmitChanges(); } if (NoteCleared != null) { NoteCleared(); } if (NoteChanged != null) { NoteChanged(); } }
public List <NoteEntity> GetNotesByNotebookPath(string notebookPath) { if (string.IsNullOrEmpty(notebookPath)) { throw new ArgumentNullException("notebookPath"); } using (var dc = new MyDataContext()) { var entities = from n in dc.NoteTable where n.NotebookPath == notebookPath && n.NoteStatus != NoteStatus.Deleted orderby n.ModifyTime descending select n; return(entities.ToList()); } }
public void ModifyIfExist(NoteEntity entity) { if (null == entity) { throw new ArgumentNullException("entity"); } using (var dc = new MyDataContext()) { //var a = new System.IO.StringWriter(); //dc.Log = a; var note = dc.NoteTable.FirstOrDefault(n => n.Id == entity.Id); if (null == note) { Debug.WriteLine("ModifyIfExist::note is null."); return; } ensureTitleIsNotEmpty(entity); var oldNote = note.DeepClone(); note.NotePath = entity.NotePath; note.Title = entity.Title; note.CreateTime = entity.CreateTime; note.ModifyTime = entity.ModifyTime; note.Size = entity.Size; note.Source = entity.Source; note.NotebookName = entity.NotebookName; note.NotebookPath = entity.NotebookPath; note.Content = entity.Content; note.Author = entity.Author; note.NoteStatus = entity.NoteStatus; dc.SafeSubmitChanges(); //Debug.WriteLine(a); if (NoteModified != null) { NoteModified(oldNote, note); } if (NoteChanged != null) { NoteChanged(); } } }
/// <summary> /// 将笔记标记为已删除。 /// </summary> /// <param name="id"></param> public void MarkAsDeletedIfExist(string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException("id"); } using (var dc = new MyDataContext()) { var entity = dc.NoteTable.FirstOrDefault(n => n.Id == id); if (null == entity) { return; } entity.NoteStatus = NoteStatus.Deleted; dc.SafeSubmitChanges(); } }
public static void InsertIfNotExist(ImageEntity imgEntity) { if (null == imgEntity) { throw new ArgumentNullException("imgEntity"); } using (var dc = new MyDataContext()) { var entity = dc.ImageTable.FirstOrDefault(i => i.Id == imgEntity.Id); if (null != entity) { return; } dc.ImageTable.InsertOnSubmit(imgEntity); dc.SafeSubmitChanges(); } }
private static void DeleteIfExist(string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException("id"); } using (var dc = new MyDataContext()) { var entity = dc.ImageTable.FirstOrDefault(p => p.Id == id); if (null == entity) { return; } dc.ImageTable.DeleteOnSubmit(entity); dc.SafeSubmitChanges(); } }
public static void DeleteImageByBelongedNotePath(string belongedNotePath) { if (string.IsNullOrEmpty(belongedNotePath)) { throw new ArgumentNullException("belongedNotePath"); } using (var dc = new MyDataContext()) { var entities = from image in dc.ImageTable where image.BelongedNotePath.Equals(belongedNotePath) select image; foreach (var entity in entities) { dc.ImageTable.DeleteOnSubmit(entity); } dc.SafeSubmitChanges(); } }
public void ModifyOrAddIfNotExistsAll(List <Notebook> notebooks) { if (null == notebooks) { throw new ArgumentNullException("notebooks"); } using (var dc = new MyDataContext()) { foreach (var nb in notebooks) { var notebookEntity = dc.NotebookTable.FirstOrDefault(n => n.Path == nb.Path); if (null == notebookEntity) { var entity = new NotebookEntity(nb); dc.NotebookTable.InsertOnSubmit(entity); if (NotebookCreated != null) { NotebookCreated(entity); } } else { if (notebookEntity.Name == nb.Name && notebookEntity.Path == nb.Path && notebookEntity.NotesNum == nb.NotesNum && notebookEntity.CreateTime == nb.CreateTime && notebookEntity.ModifyTime == nb.ModifyTime) { continue; } notebookEntity.Name = nb.Name; notebookEntity.Path = nb.Path; notebookEntity.NotesNum = nb.NotesNum; notebookEntity.CreateTime = nb.CreateTime; notebookEntity.ModifyTime = nb.ModifyTime; if (NotebookModified != null) { NotebookModified(notebookEntity); } } } dc.SafeSubmitChanges(); } }
/// <summary> /// 删除悬空图片(没有笔记引用的图片)。 /// </summary> public static void DeleteNoRootImages() { using (var dc = new MyDataContext()) { if (!dc.DatabaseExists()) { return; } foreach (var img in dc.ImageTable) { if (NoteDao.Inst.NoteExist((img.BelongedNotePath))) { continue; } DeleteIfExist(img.Id); Debug.WriteLine("删除本地悬空图片:" + img.ImgLocalSavePath); } } }
public static void ModifyIfExist(ImageEntity entity) { if (null == entity) { throw new ArgumentNullException("entity"); } using (var dc = new MyDataContext()) { var pic = dc.ImageTable.FirstOrDefault(p => p.Id == entity.Id); if (null == pic) { return; } pic.ImgLocalSavePath = entity.ImgLocalSavePath; pic.BelongedNotePath = entity.BelongedNotePath; pic.ImgRemoteUrl = entity.ImgRemoteUrl; dc.SafeSubmitChanges(); } }
public void ModifyOrAddIfNotExistsAll(List<Notebook> notebooks) { if (null == notebooks) { throw new ArgumentNullException("notebooks"); } using (var dc = new MyDataContext()) { foreach (var nb in notebooks) { var notebookEntity = dc.NotebookTable.FirstOrDefault(n => n.Path == nb.Path); if (null == notebookEntity) { var entity = new NotebookEntity(nb); dc.NotebookTable.InsertOnSubmit(entity); if (NotebookCreated != null) { NotebookCreated(entity); } } else { if (notebookEntity.Name == nb.Name && notebookEntity.Path == nb.Path && notebookEntity.NotesNum == nb.NotesNum && notebookEntity.CreateTime == nb.CreateTime && notebookEntity.ModifyTime == nb.ModifyTime) continue; notebookEntity.Name = nb.Name; notebookEntity.Path = nb.Path; notebookEntity.NotesNum = nb.NotesNum; notebookEntity.CreateTime = nb.CreateTime; notebookEntity.ModifyTime = nb.ModifyTime; if (NotebookModified != null) { NotebookModified(notebookEntity); } } } dc.SafeSubmitChanges(); } }
public void BatchOperate(Dictionary<NoteBatchOperateEnum, List<NoteEntity>> dic) { if (null == dic) { throw new ArgumentNullException("dic"); } var isNoteChangedFlag = false; using (var dc = new MyDataContext()) { foreach (var noteEntity in dic[NoteBatchOperateEnum.Add]) { if (null == noteEntity) continue; var entity = dc.NoteTable.FirstOrDefault(n => n.NotePath == noteEntity.NotePath); if (null != entity) return; ensureTitleIsNotEmpty(noteEntity); dc.NoteTable.InsertOnSubmit(noteEntity); if (NoteCreated != null) { NoteCreated(noteEntity); } isNoteChangedFlag = true; } foreach (var noteEntity in dic[NoteBatchOperateEnum.Modify]) { var note = dc.NoteTable.FirstOrDefault(n => n.Id == noteEntity.Id); if (null == note) { return; } ensureTitleIsNotEmpty(noteEntity); var oldNote = note.DeepClone(); note.NotePath = noteEntity.NotePath; note.Title = noteEntity.Title; note.CreateTime = noteEntity.CreateTime; note.ModifyTime = noteEntity.ModifyTime; note.Size = noteEntity.Size; note.Source = noteEntity.Source; note.NotebookName = noteEntity.NotebookName; note.NotebookPath = noteEntity.NotebookPath; note.Content = noteEntity.Content; note.Author = noteEntity.Author; note.NoteStatus = noteEntity.NoteStatus; if (NoteModified != null) { NoteModified(oldNote, note); } isNoteChangedFlag = true; } foreach (var noteEntity in dic[NoteBatchOperateEnum.Delete]) { var entity = dc.NoteTable.FirstOrDefault(n => n.Id == noteEntity.Id); if (null == entity) return; dc.NoteTable.DeleteOnSubmit(entity); if (NoteDeleted != null) { NoteDeleted(entity); } isNoteChangedFlag = true; } dc.SafeSubmitChanges(); } if (isNoteChangedFlag) { if (NoteChanged != null) { NoteChanged(); } } }
public bool NoteExist(string path) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } using (var dc = new MyDataContext()) { var note = dc.NoteTable.FirstOrDefault(n => n.NotePath == path); return (note != null); } }
public static void InsertIfNotExist(ImageEntity imgEntity) { if (null == imgEntity) { throw new ArgumentNullException("imgEntity"); } using (var dc = new MyDataContext()) { var entity = dc.ImageTable.FirstOrDefault(i => i.Id == imgEntity.Id); if (null != entity) return; dc.ImageTable.InsertOnSubmit(imgEntity); dc.SafeSubmitChanges(); } }
/// <summary> /// 将笔记标记为已删除。 /// </summary> /// <param name="id"></param> public void MarkAsDeletedIfExist(string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException("id"); } using (var dc = new MyDataContext()) { var entity = dc.NoteTable.FirstOrDefault(n => n.Id == id); if (null == entity) return; entity.NoteStatus = NoteStatus.Deleted; dc.SafeSubmitChanges(); } }
public void BatchOperate(Dictionary <NoteBatchOperateEnum, List <NoteEntity> > dic) { if (null == dic) { throw new ArgumentNullException("dic"); } var isNoteChangedFlag = false; using (var dc = new MyDataContext()) { foreach (var noteEntity in dic[NoteBatchOperateEnum.Add]) { if (null == noteEntity) { continue; } var entity = dc.NoteTable.FirstOrDefault(n => n.NotePath == noteEntity.NotePath); if (null != entity) { return; } ensureTitleIsNotEmpty(noteEntity); dc.NoteTable.InsertOnSubmit(noteEntity); if (NoteCreated != null) { NoteCreated(noteEntity); } isNoteChangedFlag = true; } foreach (var noteEntity in dic[NoteBatchOperateEnum.Modify]) { var note = dc.NoteTable.FirstOrDefault(n => n.Id == noteEntity.Id); if (null == note) { return; } ensureTitleIsNotEmpty(noteEntity); var oldNote = note.DeepClone(); note.NotePath = noteEntity.NotePath; note.Title = noteEntity.Title; note.CreateTime = noteEntity.CreateTime; note.ModifyTime = noteEntity.ModifyTime; note.Size = noteEntity.Size; note.Source = noteEntity.Source; note.NotebookName = noteEntity.NotebookName; note.NotebookPath = noteEntity.NotebookPath; note.Content = noteEntity.Content; note.Author = noteEntity.Author; note.NoteStatus = noteEntity.NoteStatus; if (NoteModified != null) { NoteModified(oldNote, note); } isNoteChangedFlag = true; } foreach (var noteEntity in dic[NoteBatchOperateEnum.Delete]) { var entity = dc.NoteTable.FirstOrDefault(n => n.Id == noteEntity.Id); if (null == entity) { return; } dc.NoteTable.DeleteOnSubmit(entity); if (NoteDeleted != null) { NoteDeleted(entity); } isNoteChangedFlag = true; } dc.SafeSubmitChanges(); } if (isNoteChangedFlag) { if (NoteChanged != null) { NoteChanged(); } } }
public List<NoteEntity> GetNotesByNotebookPath(string notebookPath) { if (string.IsNullOrEmpty(notebookPath)) { throw new ArgumentNullException("notebookPath"); } using (var dc = new MyDataContext()) { var entities = from n in dc.NoteTable where n.NotebookPath == notebookPath && n.NoteStatus != NoteStatus.Deleted orderby n.ModifyTime descending select n; return entities.ToList(); } }
public List<NoteEntity> GetLocalCreatedNotes(string notebookName) { if (string.IsNullOrEmpty(notebookName)) { throw new ArgumentNullException("notebookName"); } using (var dc = new MyDataContext()) { var entities = from n in dc.NoteTable where n.NotebookName == notebookName && n.NoteStatus == NoteStatus.Added select n; return entities.ToList(); } }
public NoteEntity GetNoteById(string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException("id"); } using (var dc = new MyDataContext()) { var entity = dc.NoteTable.FirstOrDefault(n => n.Id == id); return entity; } }
public List<NoteEntity> GetAllLocalCreatedNotes() { using (var dc = new MyDataContext()) { var entities = from n in dc.NoteTable where n.NoteStatus == NoteStatus.Added select n; return entities.ToList(); } }
private static void DeleteIfExist(string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException("id"); } using (var dc = new MyDataContext()) { var entity = dc.ImageTable.FirstOrDefault(p => p.Id == id); if (null == entity) return; dc.ImageTable.DeleteOnSubmit(entity); dc.SafeSubmitChanges(); } }
/// <summary> /// 如果笔记存在,则将笔记删除。 /// </summary> /// <param name="id"></param> public void DeleteIfExist(string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException("id"); } using (var dc = new MyDataContext()) { var entity = dc.NoteTable.FirstOrDefault(n => n.Id == id); if (null == entity) return; dc.NoteTable.DeleteOnSubmit(entity); dc.SafeSubmitChanges(); if (NoteDeleted != null) { NoteDeleted(entity); } if (NoteChanged != null) { NoteChanged(); } } }
public void DeleteAllIfExist(List<string> ids) { if (null == ids) { throw new ArgumentNullException("ids"); } var isNoteChangedFlag = false; using (var dc = new MyDataContext()) { foreach (var id in ids) { var entity = dc.NoteTable.FirstOrDefault(n => n.Id == id); if (null == entity) return; dc.NoteTable.DeleteOnSubmit(entity); if (NoteDeleted != null) { NoteDeleted(entity); } isNoteChangedFlag = true; } dc.SafeSubmitChanges(); } if (isNoteChangedFlag) { if (NoteChanged != null) { NoteChanged(); } } }
public static bool ImageExists(string imgNameWithoutExt, out ImageEntity img) { if (string.IsNullOrEmpty(imgNameWithoutExt)) { throw new ArgumentNullException("imgNameWithoutExt"); } using (var dc = new MyDataContext()) { img = dc.ImageTable.FirstOrDefault(p => p.ImgNameWithoutExt == imgNameWithoutExt); return (img != null); } }
public NoteEntity GetNoteByPath(string path) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } using (var dc = new MyDataContext()) { var entity = dc.NoteTable.FirstOrDefault(n => n.NotePath == path); return entity; } }
public List<NoteEntity> GetAllNote() { using (var dc = new MyDataContext()) { var entities = from n in dc.NoteTable where n.NoteStatus != NoteStatus.Deleted orderby n.ModifyTime descending select n; return entities.ToList(); } }
public static void ModifyIfExist(ImageEntity entity) { if (null == entity) { throw new ArgumentNullException("entity"); } using (var dc = new MyDataContext()) { var pic = dc.ImageTable.FirstOrDefault(p => p.Id == entity.Id); if (null == pic) return; pic.ImgLocalSavePath = entity.ImgLocalSavePath; pic.BelongedNotePath = entity.BelongedNotePath; pic.ImgRemoteUrl = entity.ImgRemoteUrl; dc.SafeSubmitChanges(); } }