Beispiel #1
0
 private async Task InitialCate(LoginMode mode)
 {
     await CateVM.Refresh(mode);
 }
Beispiel #2
0
        /// <summary>
        /// 从云端同步所有待办事项
        /// </summary>
        /// <returns></returns>
        private async Task SyncAllToDos()
        {
            try
            {
                //没网络
                if (App.IsNoNetwork)
                {
                    //通知没有网络
                    ToastService.SendToast(ResourcesHelper.GetResString("NoNetworkHint"));
                    return;
                }
                if (App.IsInOfflineMode)
                {
                    return;
                }
                //加载滚动条
                IsLoading = Visibility.Visible;

                ToastService.SendToast(ResourcesHelper.GetResString("Syncing"));

                var isSyncOK = false;

                DispatcherTimer timer = new DispatcherTimer();
                timer.Interval = TimeSpan.FromSeconds(2);
                timer.Tick    += ((sendert, et) =>
                {
                    if (isSyncOK)
                    {
                        IsLoading = Visibility.Collapsed;
                        ToastService.SendToast(ResourcesHelper.GetResString("SyncSuccessfully"));
                    }
                    timer.Stop();
                });
                timer.Start();

                try
                {
                    await ReSendStagedToDos();

                    await CateVM.Refresh(LoginMode.Login);

                    var result = await CloudService.GetMyToDosAsync();

                    if (!string.IsNullOrEmpty(result.JsonSrc))
                    {
                        //获得无序的待办事项
                        var scheduleWithoutOrder = ToDo.ParseJsonToObs(result.JsonSrc);

                        //获得顺序列表
                        var orders = await CloudService.GetMyOrderAsync();

                        //排序
                        AllToDos = ToDo.GetSortedList(scheduleWithoutOrder, orders);

                        UpdateListByChangingSelectedCate();

                        await SerializerHelper.SerializerToJson <ObservableCollection <ToDo> >(AllToDos, SerializerFileNames.ToDoFileName);

                        isSyncOK = true;
                    }
                }
                catch (COMException)
                {
                    ToastService.SendToast(ResourcesHelper.GetResString("RequestError"));
                }
                finally
                {
                    IsLoading = Visibility.Collapsed;
                    if (!timer.IsEnabled)
                    {
                        ToastService.SendToast(ResourcesHelper.GetResString("SyncSuccessfully"));
                    }
                }

                //最后更新动态磁贴
                Messenger.Default.Send(new GenericMessage <ObservableCollection <ToDo> >(AllToDos), MessengerTokens.UpdateTile);
            }
            catch (Exception ex)
            {
                var task = Logger.LogAsync(ex);
            }
        }