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

            }
        }
Ejemplo n.º 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());
     }
 }
Ejemplo n.º 16
0
 public static void DeleteDatabaseIfExists()
 {
     using (var dc = new MyDataContext())
     {
         if (dc.DatabaseExists())
         {
             dc.DeleteDatabase();
         }
         Debug.WriteLine(DateTime.Now.ToLongTimeString() + " 数据库已被删除。");
     }
 }
Ejemplo n.º 17
0
 public static void DeleteDatabaseIfExists()
 {
     using (var dc = new MyDataContext())
     {
         if (dc.DatabaseExists())
         {
             dc.DeleteDatabase();
         }
         Debug.WriteLine(DateTime.Now.ToLongTimeString() + " 数据库已被删除。");
     }
 }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 20
0
 public static void CreatetDatabaseIfNeeded()
 {
     using (var dc = new MyDataContext())
     {
         if (dc.DatabaseExists())
         {
             return;
         }
         dc.CreateDatabase();
         Debug.WriteLine(DateTime.Now.ToLongTimeString() + " 数据库创建完成。");
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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());
     }
 }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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());
            }
        }
Ejemplo n.º 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();
                }
            }
        }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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();
                }
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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();
                }
            }
        }
Ejemplo n.º 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();
                }
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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();
                }
            }
        }
Ejemplo n.º 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();
                }
            }
        }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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();
            }
        }