Ejemplo n.º 1
0
 private static void OnSyncNoteChanged(WaitPopup wp, NoteSyncEventArgs noteSyncEventArgs)
 {
     wp.SafeInvoke(() => wp.SetTip(noteSyncEventArgs.SyncedNoteCount + "/" + noteSyncEventArgs.TotalNoteCount));
 }
Ejemplo n.º 2
0
        private async Task loadNote()
        {
            using (var waitPopup = new WaitPopup("正在加载笔记", this))
            {
                try
                {
                    tbTitle.Text = NoteEntity.Title;
                    tbNotebook.Text = NoteEntity.NotebookName;

                    if (NoteUtil.NeedCache(NoteEntity.Content))
                    {
                        if (Util.IsNetworkAvailable())
                        {
                            waitPopup.SetTip("正在下载图片");
                            NoteEntity.Content = await SyncCore.GetInst().DownloadImageToLocalAsync(NoteEntity.NotePath, NoteEntity.Content, (count, totalCount) =>
                            {
                                waitPopup.SetTip("正在下载图片:" + count + "/" + totalCount);
                            });
                            NoteDao.Inst.ModifyIfExist(NoteEntity);

                            ContentWebBrowser.NavigateToString(NoteEntity.Content);
                        }
                        else
                        {
                            Toast.Prompt("额,网络不可用,图片未能下载!");
                        }
                    }
                    else
                    {
                        ContentWebBrowser.NavigateToString(NoteEntity.Content);
                    }
                }
                catch (Exception ex)
                {
                    LoggerFactory.GetLogger().Error("", ex);
                    Toast.Prompt("额,发生不可预知的错误,请稍后重试!");
                }
            }
        }
Ejemplo n.º 3
0
 private async void OnSyncAppbarButtonClicked(object sender, EventArgs e)
 {
     try
     {
         var pivotItem = MainPivot.SelectedItem as PivotItem;
         if (null == pivotItem) return;
         if (pivotItem.Name == null) return;
         switch ((pivotItem.Name))
         {
             case "NoteListPivotItem":
                 using (var waitPopup = new WaitPopup("正在同步笔记中", this))
                 {
                     if (NotebookList.SelectedNotebook != null)
                     {
                         SyncCore.GetInst().SyncNoteChanged += (noteSyncEventArgs) =>
                             {
                                 OnSyncNoteChanged(waitPopup, noteSyncEventArgs);
                             };
                         await SyncCore.GetInst().SyncNotebookNotesAsync(NotebookList.SelectedNotebook.Name,
                             NotebookList.SelectedNotebook.Path, (type, msg) =>
                             {
                                 switch (type)
                                 {
                                     case SyncCompletedType.All:
                                         Toast.Prompt("笔记同步完成");
                                         break;
                                     case SyncCompletedType.AddedNote:
                                         waitPopup.SafeInvoke(() => waitPopup.SetTip(msg.ToString()));
                                         break;
                                     case SyncCompletedType.Failed:
                                         Toast.Prompt("额,同步笔记失败,请稍后重试!");
                                         LoggerFactory.GetLogger().Error("同步笔记失败", (Exception)msg);
                                         break;
                                 }
                             });
                         // 取消事件订阅
                         SyncCore.GetInst().SyncNoteChanged -= (noteSyncEventArgs) =>
                         {
                             OnSyncNoteChanged(waitPopup, noteSyncEventArgs);
                         };
                     }
                     else
                     {
                         Toast.Prompt("额,没有选择任何笔记本欸!");
                     }
                 }
                 break;
             case "NotebookPivotItem":
                 using (new WaitPopup("正在同步笔记本列表", this))
                 {
                     await NotebookList.SycnNotebooksAsync();
                     NotebookList.SetSelectedNotebook(NotebookList.GetDefaultSelectedNotebook());
                 }
                 break;
         }
     }
     catch (Exception ex)
     {
         LoggerFactory.GetLogger().Error("同步发生错误", ex);
         Toast.Prompt("额,发生不可预知的错误,请稍后重试!");
     }
 }