Esempio n. 1
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(ConstantPool.AccessToken))
            {
                NavigationService.Navigate(new Uri("/Views/AuthorizeView.xaml", UriKind.Relative));
                return;
            }

            if (_isNewPage == false)
            {
                // 从新建页面返回
                var savedNotebook = Util.ReadLastSelectedNotebook();
                if (null != savedNotebook && null != NotebookList.SelectedNotebook)
                {
                    if (savedNotebook.Path != NotebookList.SelectedNotebook.Path)
                    {
                        NotebookList.SetSelectedNotebook(savedNotebook);
                    }
                }
                return;
            }

            InitNotebookList();

            if (ConstantPool.AutoSendErrorReport)
            {
                Util.SendErrorReportAsync();
            }

            _isNewPage = false;
        }
Esempio n. 2
0
        private void InitNotebookList()
        {
            NotebookList.NotebookSelectionChanged += () =>
            {
                if (null == NotebookList.SelectedNotebook)
                {
                    return;
                }
                NoteList.UpdateBind(NotebookList.SelectedNotebook);
                NoteListPivotItem.Header = new TextBlock
                {
                    Text       = NotebookList.SelectedNotebook.Name,
                    FontFamily = new System.Windows.Media.FontFamily("Microsoft YaHei"),
                    FontSize   = 40,
                    Margin     = new Thickness(0, 10, 0, 0),
                    Foreground = new SolidColorBrush(Colors.Black)
                };
                MainPivot.SelectedItem = NoteListPivotItem;
            };

            NotebookList.SetSelectedNotebook(NotebookList.GetDefaultSelectedNotebook());
        }
Esempio 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("额,发生不可预知的错误,请稍后重试!");
            }
        }
 private void NotebookList_Loaded(object sender, RoutedEventArgs e)
 {
     Notebook = NotebookList.FindNotebookEntity(_notebookPath);
     NotebookList.SetSelectedNotebook(Notebook);
 }