Exemplo n.º 1
0
        /// <summary>
        /// 从云端同步所有待办事项
        /// </summary>
        /// <returns></returns>
        private async Task SyncAllToDos()
        {
            try
            {
                //没网络
                if (App.IsNoNetwork)
                {
                    //通知没有网络
                    Messenger.Default.Send(new GenericMessage <string>(ResourcesHelper.GetString("NoNetworkHint")), MessengerTokens.ToastToken);
                    return;
                }

                //加载滚动条
                IsLoading = Visibility.Visible;

                DispatcherTimer timer = new DispatcherTimer();
                timer.Interval = TimeSpan.FromSeconds(3.2);
                timer.Tick    += ((sendert, et) =>
                {
                    IsLoading = Visibility.Collapsed;
                });
                timer.Start();

                var result = await PostHelper.GetMySchedules(LocalSettingHelper.GetValue("sid"));

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

                    //获得顺序列表
                    var orders = await PostHelper.GetMyOrder(LocalSettingHelper.GetValue("sid"));

                    //排序
                    MyToDos = ToDo.SetOrderByString(scheduleWithoutOrder, orders);

                    ChangeDisplayCateList(SelectedCate);

                    Messenger.Default.Send(new GenericMessage <string>(ResourcesHelper.GetString("SyncSuccessfully")), MessengerTokens.ToastToken);

                    await SerializerHelper.SerializerToJson <ObservableCollection <ToDo> >(MyToDos, SerializerFileNames.ToDoFileName, true);
                }


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