Пример #1
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();
            }
        }
Пример #2
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();
                }
            }
        }
Пример #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 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();
                }
            }
        }
Пример #5
0
 public void Clear()
 {
     using (var dc = new MyDataContext())
     {
         dc.NotebookTable.DeleteAllOnSubmit(from e in dc.NotebookTable select e);
         dc.SafeSubmitChanges();
     }
 }
Пример #6
0
 public void Clear()
 {
     using (var dc = new MyDataContext())
     {
         dc.NotebookTable.DeleteAllOnSubmit(from e in dc.NotebookTable select e);
         dc.SafeSubmitChanges();
     }
 }
Пример #7
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();
     }
 }
Пример #8
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();
                }
            }
        }
Пример #9
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();
     }
 }
Пример #10
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();
     }
 }
Пример #11
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();
     }
 }
Пример #12
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();
            }
        }
Пример #13
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();
            }
        }
Пример #14
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();
            }
        }
Пример #15
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();
            }
        }
Пример #16
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();
                }
            }
        }
Пример #17
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();
                }
            }
        }
Пример #18
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();
     }
 }
Пример #19
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();
                }
            }
        }
Пример #20
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();
                }
            }
        }
Пример #21
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();
     }
 }
Пример #22
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();
                }
            }
        }
Пример #23
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();
            }
        }
Пример #24
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();
     }
 }
Пример #25
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();
            }
        }
Пример #26
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();
     }
 }