private static void noteCreated(NoteEntity newNoteEntity) { var belongNotebookPath = newNoteEntity.NotebookPath; lock (LockObj) { NoteCollection noteCollection; if (NoteCollectionDict.TryGetValue(belongNotebookPath, out noteCollection)) { var flag = false; for (var i = 0; i < noteCollection.Count; i++) { if (noteCollection[i].ModifyTime >= newNoteEntity.ModifyTime) { continue; } noteCollection.Insert(i, newNoteEntity); flag = true; break; } if (!flag) { noteCollection.Add(newNoteEntity); } } else { noteCollection = new NoteCollection { newNoteEntity }; NoteCollectionDict.Add(belongNotebookPath, noteCollection); } } }
public static NoteCollection GetNoteCollection(string notebookPath) { if (string.IsNullOrEmpty(notebookPath)) { throw new ArgumentNullException("notebookPath"); } lock (LockObj) { NoteCollection noteCollection; if (!NoteCollectionDict.TryGetValue(notebookPath, out noteCollection)) { noteCollection = new NoteCollection(NoteDao.Inst.GetNotesByNotebookPath(notebookPath)); NoteCollectionDict.Add(notebookPath, noteCollection); } noteCollection.Sort(n => n.ModifyTime, ListSortDirection.Descending); return(noteCollection); } }
private static void initNoteListDictAsync() { Task.Run(() => { var notebooks = NotebookDao.Inst.GetAllNotebook(); if (null == notebooks) { return; } foreach (var nb in notebooks) { var noteCollection = new NoteCollection(NoteDao.Inst.GetNotesByNotebookPath(nb.Path)); lock (LockObj) { if (!NoteCollectionDict.ContainsKey(nb.Path)) { NoteCollectionDict.Add(nb.Path, noteCollection); } } } }); }