示例#1
0
 public static List<string> GetCachedNotePathList()
 {
     using (var dc = new MyDataContext())
     {
         return (from img in dc.ImageTable select img.BelongedNotePath).Distinct().ToList();
     }
 }
示例#2
0
        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();
                }
            }
        }
示例#3
0
        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();
            }
        }
示例#4
0
        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();
            }
        }
示例#5
0
 public static List <string> GetCachedNotePathList()
 {
     using (var dc = new MyDataContext())
     {
         return((from img in dc.ImageTable select img.BelongedNotePath).Distinct().ToList());
     }
 }
示例#6
0
        /// <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();
                }
            }
        }
示例#7
0
 public void Clear()
 {
     using (var dc = new MyDataContext())
     {
         dc.NotebookTable.DeleteAllOnSubmit(from e in dc.NotebookTable select e);
         dc.SafeSubmitChanges();
     }
 }
示例#8
0
 public void Clear()
 {
     using (var dc = new MyDataContext())
     {
         dc.NotebookTable.DeleteAllOnSubmit(from e in dc.NotebookTable select e);
         dc.SafeSubmitChanges();
     }
 }
示例#9
0
 public List <NotebookEntity> GetAllNotebook()
 {
     using (var dc = new MyDataContext())
     {
         return(!dc.DatabaseExists()
             ? new List <NotebookEntity>()
             : dc.NotebookTable.ToList());
     }
 }
示例#10
0
 public int GetTotalNotesNum()
 {
     using (var dc = new MyDataContext())
     {
         return(!dc.DatabaseExists()
             ? 0
             : Enumerable.Sum(dc.NotebookTable, notebook => notebook.NotesNum));
     }
 }
示例#11
0
 public static void CreatetDatabaseIfNeeded()
 {
     using (var dc = new MyDataContext())
     {
         if (dc.DatabaseExists()) return;
         dc.CreateDatabase();
         Debug.WriteLine(DateTime.Now.ToLongTimeString() + " 数据库创建完成。");
     }
 }
示例#12
0
 public int GetTotalNotesNum()
 {
     using (var dc = new MyDataContext())
     {
         return !dc.DatabaseExists()
             ? 0
             : Enumerable.Sum(dc.NotebookTable, notebook => notebook.NotesNum);
     }
 }
示例#13
0
 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());
     }
 }
示例#14
0
        public List<NotebookEntity> GetAllNotebook()
        {
            using (var dc = new MyDataContext())
            {
                return !dc.DatabaseExists()
                    ? new List<NotebookEntity>()
                    : dc.NotebookTable.ToList();

            }
        }
示例#15
0
 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());
     }
 }
示例#16
0
 public static void DeleteDatabaseIfExists()
 {
     using (var dc = new MyDataContext())
     {
         if (dc.DatabaseExists())
         {
             dc.DeleteDatabase();
         }
         Debug.WriteLine(DateTime.Now.ToLongTimeString() + " 数据库已被删除。");
     }
 }
示例#17
0
 public static void DeleteDatabaseIfExists()
 {
     using (var dc = new MyDataContext())
     {
         if (dc.DatabaseExists())
         {
             dc.DeleteDatabase();
         }
         Debug.WriteLine(DateTime.Now.ToLongTimeString() + " 数据库已被删除。");
     }
 }
示例#18
0
 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;
     }
 }
示例#19
0
 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;
     }
 }
示例#20
0
 public static void CreatetDatabaseIfNeeded()
 {
     using (var dc = new MyDataContext())
     {
         if (dc.DatabaseExists())
         {
             return;
         }
         dc.CreateDatabase();
         Debug.WriteLine(DateTime.Now.ToLongTimeString() + " 数据库创建完成。");
     }
 }
示例#21
0
 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);
     }
 }
示例#22
0
 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);
     }
 }
示例#23
0
 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);
     }
 }
示例#24
0
 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);
     }
 }
示例#25
0
 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);
     }
 }
示例#26
0
        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);
            }
        }
示例#27
0
 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());
     }
 }
示例#28
0
        /// <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);
                }
            }
        }
示例#29
0
 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();
     }
 }
示例#30
0
        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());
            }
        }
示例#31
0
        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();
                }
            }
        }
示例#32
0
 /// <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();
     }
 }
示例#33
0
 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();
     }
 }
示例#34
0
 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();
     }
 }
示例#35
0
        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();
            }
        }
示例#36
0
        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();
            }
        }
示例#37
0
        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();
            }
        }
示例#38
0
        /// <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);
                }
            }
        }
示例#39
0
        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();
            }
        }
示例#40
0
        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();
            }
        }
示例#41
0
        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();
                }
            }
        }
示例#42
0
        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);
            }
        }
示例#43
0
 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();
     }
 }
示例#44
0
 /// <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();
     }
 }
示例#45
0
        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();
                }
            }
        }
示例#46
0
        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();
                }
            }
        }
示例#47
0
        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();
            }
        }
示例#48
0
 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();
     }
 }
示例#49
0
 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;
     }
 }
示例#50
0
 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();
     }
 }
示例#51
0
 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();
     }
 }
示例#52
0
        /// <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();
                }
            }
        }
示例#53
0
        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();
                }
            }
        }
示例#54
0
 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();
     }
 }
示例#55
0
 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);
     }
 }
示例#56
0
 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;
     }
 }
示例#57
0
 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();
     }
 }
示例#58
0
        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();
            }
        }