コード例 #1
0
ファイル: SyncCore.cs プロジェクト: ciker/WPYoudaonNote
        private NoteEntity modifyNote(NoteSync noteSync, Note serverNote, NoteEntity findLocalNote, Dictionary <NoteBatchOperateEnum, List <NoteEntity> > dic = null)
        {
            findLocalNote.NotePath     = noteSync.NotePath;
            findLocalNote.Title        = serverNote.Title;
            findLocalNote.CreateTime   = serverNote.CreateTime;
            findLocalNote.ModifyTime   = serverNote.ModifyTime;
            findLocalNote.Size         = serverNote.Size;
            findLocalNote.Source       = serverNote.Source;
            findLocalNote.NotebookPath = noteSync.NotebookPath;
            findLocalNote.Content      = DownloadImageToLocalAsync(noteSync.NotePath, serverNote.Content).Result;
            findLocalNote.Author       = serverNote.Author;
            findLocalNote.NotebookName = noteSync.NotebookName;
            findLocalNote.NoteStatus   = NoteStatus.Normal;
            if (null == dic)
            {
                NoteDao.Inst.ModifyIfExist(findLocalNote);
            }
            else
            {
                if (null != findLocalNote)
                {
                    dic[NoteBatchOperateEnum.Modify].Add(findLocalNote);
                }
            }

            return(findLocalNote);
        }
コード例 #2
0
ファイル: SyncCore.cs プロジェクト: ciker/WPYoudaonNote
        private NoteEntity modifyNote(NoteSync noteSync, Note serverNote, NoteEntity findLocalNote, Dictionary<NoteBatchOperateEnum, List<NoteEntity>> dic = null)
        {
            findLocalNote.NotePath = noteSync.NotePath;
            findLocalNote.Title = serverNote.Title;
            findLocalNote.CreateTime = serverNote.CreateTime;
            findLocalNote.ModifyTime = serverNote.ModifyTime;
            findLocalNote.Size = serverNote.Size;
            findLocalNote.Source = serverNote.Source;
            findLocalNote.NotebookPath = noteSync.NotebookPath;
            findLocalNote.Content = DownloadImageToLocalAsync(noteSync.NotePath, serverNote.Content).Result;
            findLocalNote.Author = serverNote.Author;
            findLocalNote.NotebookName = noteSync.NotebookName;
            findLocalNote.NoteStatus = NoteStatus.Normal;
            if (null == dic)
            {
                NoteDao.Inst.ModifyIfExist(findLocalNote);
            }
            else
            {
                if (null != findLocalNote)
                {
                    dic[NoteBatchOperateEnum.Modify].Add(findLocalNote);
                }
            }

            return findLocalNote;
        }
コード例 #3
0
ファイル: SyncCore.cs プロジェクト: ciker/WPYoudaonNote
        private NoteEntity syncNote(NoteSync noteSync, Dictionary<NoteBatchOperateEnum, List<NoteEntity>> dic = null)
        {
            var serverNote = _api.GetNote(noteSync.NotePath);
            var findLocalNote = NoteListCache.GetNoteByPath(noteSync.NotebookPath, noteSync.NotePath);
            if (null != findLocalNote) // 本地有这篇笔记
            {
                if (serverNote.ModifyTime > findLocalNote.ModifyTime) // 服务端的笔记比本地上次同步过的新
                {
                    switch (findLocalNote.NoteStatus)
                    {
                        case NoteStatus.Normal:
                            return modifyNote(noteSync, serverNote, findLocalNote, dic);
                        case NoteStatus.Deleted:
                            deleteNote(findLocalNote, dic);
                            break;
                        case NoteStatus.Modified:
                            // 把本地的笔记备份一份新的,并标记为新增加的
                            var newNoteEntity = new NoteEntity
                            {
                                Title = "冲突 - " + findLocalNote.Title,
                                Content = findLocalNote.Content,
                                Author = findLocalNote.Author,
                                Source = findLocalNote.Source,
                                Size = findLocalNote.Size,
                                NotebookName = findLocalNote.NotebookName,
                                NotebookPath = findLocalNote.NotebookPath,
                                CreateTime = findLocalNote.CreateTime,
                                ModifyTime = findLocalNote.ModifyTime,
                                NoteStatus = NoteStatus.Added
                            };
                            if (null == dic) // 操作单篇笔记
                            {
                                NoteDao.Inst.AddIfNotExist(newNoteEntity);
                            }
                            else
                            {
                                if (null != newNoteEntity)
                                {
                                    dic[NoteBatchOperateEnum.Add].Add(newNoteEntity);
                                }
                            }

                            // 将服务端的更新到本地
                            return modifyNote(noteSync, serverNote, findLocalNote, dic);
                    }
                }
                else // 本地上次同步过的笔记比服务端的新
                {
                    switch (findLocalNote.NoteStatus)
                    {
                        case NoteStatus.Modified:
                            var content = ConvertImageLocalPathToRemoteUrl(findLocalNote.Content);
                            _api.UpdateNote(findLocalNote.NotePath, content, findLocalNote.Source, findLocalNote.Author, findLocalNote.Title);
                            // 为了获取到笔记在服务器端的更新时间,不得不重新获取笔记。不能用本地的时间是因为不同的客户端的时间可能不一样
                            var newNote = _api.GetNote(findLocalNote.NotePath);
                            findLocalNote.NoteStatus = NoteStatus.Normal;
                            findLocalNote.ModifyTime = newNote.ModifyTime;
                            if (null == dic) // 操作单篇笔记
                            {
                                NoteDao.Inst.ModifyIfExist(findLocalNote);
                            }
                            else
                            {
                                if (null != findLocalNote)
                                {
                                    dic[NoteBatchOperateEnum.Modify].Add(findLocalNote);
                                }
                            }
                            return findLocalNote;
                        case NoteStatus.Deleted:
                            deleteNote(findLocalNote, dic);
                            break;
                    }
                }
            }
            else // 本地没有这篇笔记,直接同步到本地
            {
                var entity = new NoteEntity(serverNote, noteSync.NotePath, noteSync.NotebookName, noteSync.NotebookPath);
                if (null == dic) // 操作单篇笔记
                {
                    NoteDao.Inst.AddIfNotExist(entity);
                }
                else
                {
                    if (null != entity)
                    {
                        dic[NoteBatchOperateEnum.Add].Add(entity);
                    }
                }
                return entity;
            }
            return null;
        }
コード例 #4
0
ファイル: SyncCore.cs プロジェクト: ciker/WPYoudaonNote
 private async Task<NoteEntity> syncNoteAsync(NoteSync noteSync, Dictionary<NoteBatchOperateEnum, List<NoteEntity>> dic =null)
 {
     return await Task.Run(() => syncNote(noteSync, dic));
 }
コード例 #5
0
ファイル: SyncCore.cs プロジェクト: ciker/WPYoudaonNote
        private NoteEntity syncNote(NoteSync noteSync, Dictionary <NoteBatchOperateEnum, List <NoteEntity> > dic = null)
        {
            var serverNote    = _api.GetNote(noteSync.NotePath);
            var findLocalNote = NoteListCache.GetNoteByPath(noteSync.NotebookPath, noteSync.NotePath);

            if (null != findLocalNote)                                // 本地有这篇笔记
            {
                if (serverNote.ModifyTime > findLocalNote.ModifyTime) // 服务端的笔记比本地上次同步过的新
                {
                    switch (findLocalNote.NoteStatus)
                    {
                    case NoteStatus.Normal:
                        return(modifyNote(noteSync, serverNote, findLocalNote, dic));

                    case NoteStatus.Deleted:
                        deleteNote(findLocalNote, dic);
                        break;

                    case NoteStatus.Modified:
                        // 把本地的笔记备份一份新的,并标记为新增加的
                        var newNoteEntity = new NoteEntity
                        {
                            Title        = "冲突 - " + findLocalNote.Title,
                            Content      = findLocalNote.Content,
                            Author       = findLocalNote.Author,
                            Source       = findLocalNote.Source,
                            Size         = findLocalNote.Size,
                            NotebookName = findLocalNote.NotebookName,
                            NotebookPath = findLocalNote.NotebookPath,
                            CreateTime   = findLocalNote.CreateTime,
                            ModifyTime   = findLocalNote.ModifyTime,
                            NoteStatus   = NoteStatus.Added
                        };
                        if (null == dic)     // 操作单篇笔记
                        {
                            NoteDao.Inst.AddIfNotExist(newNoteEntity);
                        }
                        else
                        {
                            if (null != newNoteEntity)
                            {
                                dic[NoteBatchOperateEnum.Add].Add(newNoteEntity);
                            }
                        }

                        // 将服务端的更新到本地
                        return(modifyNote(noteSync, serverNote, findLocalNote, dic));
                    }
                }
                else // 本地上次同步过的笔记比服务端的新
                {
                    switch (findLocalNote.NoteStatus)
                    {
                    case NoteStatus.Modified:
                        var content = ConvertImageLocalPathToRemoteUrl(findLocalNote.Content);
                        _api.UpdateNote(findLocalNote.NotePath, content, findLocalNote.Source, findLocalNote.Author, findLocalNote.Title);
                        // 为了获取到笔记在服务器端的更新时间,不得不重新获取笔记。不能用本地的时间是因为不同的客户端的时间可能不一样
                        var newNote = _api.GetNote(findLocalNote.NotePath);
                        findLocalNote.NoteStatus = NoteStatus.Normal;
                        findLocalNote.ModifyTime = newNote.ModifyTime;
                        if (null == dic)     // 操作单篇笔记
                        {
                            NoteDao.Inst.ModifyIfExist(findLocalNote);
                        }
                        else
                        {
                            if (null != findLocalNote)
                            {
                                dic[NoteBatchOperateEnum.Modify].Add(findLocalNote);
                            }
                        }
                        return(findLocalNote);

                    case NoteStatus.Deleted:
                        deleteNote(findLocalNote, dic);
                        break;
                    }
                }
            }
            else // 本地没有这篇笔记,直接同步到本地
            {
                var entity = new NoteEntity(serverNote, noteSync.NotePath, noteSync.NotebookName, noteSync.NotebookPath);
                if (null == dic) // 操作单篇笔记
                {
                    NoteDao.Inst.AddIfNotExist(entity);
                }
                else
                {
                    if (null != entity)
                    {
                        dic[NoteBatchOperateEnum.Add].Add(entity);
                    }
                }
                return(entity);
            }
            return(null);
        }
コード例 #6
0
ファイル: SyncCore.cs プロジェクト: ciker/WPYoudaonNote
 private async Task <NoteEntity> syncNoteAsync(NoteSync noteSync, Dictionary <NoteBatchOperateEnum, List <NoteEntity> > dic = null)
 {
     return(await Task.Run(() => syncNote(noteSync, dic)));
 }