コード例 #1
0
        private async void btnClearCache_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("确定要清理缓存?", "警告", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
            {
                return;
            }
            using (new WaitPopup("正在清理缓存", this))
            {
                await Task.Run(() =>
                {
                    Util.ClearImageCache();

                    var cachedNotePathList = ImageDao.GetCachedNotePathList();
                    if (null == cachedNotePathList)
                    {
                        return;
                    }
                    foreach (var notePath in cachedNotePathList)
                    {
                        var noteEntity = NoteDao.Inst.GetNoteByNotePath(notePath);
                        if (null == noteEntity)
                        {
                            continue;
                        }
                        noteEntity.Content = SyncCore.GetInst().ConvertImageLocalPathToRemoteUrl(noteEntity.Content);
                        NoteDao.Inst.ModifyIfExist(noteEntity);

                        ImageDao.DeleteImageByBelongedNotePath(noteEntity.NotePath);
                    }
                });
            }
            showCacheSize();
        }