private static void OnSyncNoteChanged(WaitPopup wp, NoteSyncEventArgs noteSyncEventArgs) { wp.SafeInvoke(() => wp.SetTip(noteSyncEventArgs.SyncedNoteCount + "/" + noteSyncEventArgs.TotalNoteCount)); }
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("额,发生不可预知的错误,请稍后重试!"); } }