예제 #1
0
        public static async void SyncRemind()
        {
            List <KeyValuePair <string, string> > paramList = new List <KeyValuePair <string, string> >();
            PasswordCredential user = null;
            var vault          = new PasswordVault();
            var credentialList = vault.FindAllByResource("ZSCY");

            if (credentialList.Count == 1)
            {
                credentialList[0].RetrievePassword();
                user = credentialList[0];
            }
            paramList.Add(new KeyValuePair <string, string>("stuNum", user.UserName));
            paramList.Add(new KeyValuePair <string, string>("idNum", user.Password));
            string content = "";

            try
            {
                content = await NetWork.httpRequest(@"http://hongyan.cqupt.edu.cn/cyxbsMobile/index.php/Home/Person/getTransaction", paramList);
            }
            catch (Exception x)
            {
                Debug.WriteLine(x.Message);
            }
            //相当于MyRemind
            GetRemindModel getRemid = new GetRemindModel();

            try
            {
                getRemid = JsonConvert.DeserializeObject <GetRemindModel>(content);
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.Message).ShowAsync();
            }

            List <string>   getRemindList_json = new List <string>();
            List <MyRemind> remindList         = new List <MyRemind>();

            #region 返回的json格式和添加的风格不一样,转换
            foreach (var item in getRemid.DataItems)
            {
                //getRemindList_json.Add(getRemid.DataItems[0].Id.ToString());
                MyRemind             mr  = new MyRemind();
                List <DateItemModel> dim = new List <DateItemModel>();
                //每个MyRemind的date
                foreach (var itemData in item.DateItems)
                {
                    DateItemModel dateitme = new DateItemModel();
                    string        week     = "";
                    foreach (var itemWeek in itemData.WeekItems)
                    {
                        week += itemWeek + ",";
                    }
                    week           = week.Remove(week.Length - 1);
                    dateitme.Class = itemData.Class.ToString();
                    dateitme.Day   = itemData.Day.ToString();
                    dateitme.Week  = week;
                    dim.Add(dateitme);
                }
                mr.Title     = item.Title;
                mr.Content   = item.Content;
                mr.DateItems = dim;
                mr.Time      = item.Time;
                mr.Id        = item.Id.ToString();
                remindList.Add(mr);
            }
            #endregion
            List <string> RemindTagList = new List <string>();
            RemindTagList = DatabaseMethod.ClearRemindItem() as List <string>;
            var notifier = ToastNotificationManager.CreateToastNotifier();
            if (RemindTagList != null)
            {
                for (int i = 0; i < RemindTagList.Count(); i++)
                {
                    var scheduledNotifs = notifier.GetScheduledToastNotifications()
                                          .Where(n => n.Tag.Equals(RemindTagList[i]));

                    // Remove all of those from the schedule
                    foreach (var n in scheduledNotifs)
                    {
                        notifier.RemoveFromSchedule(n);
                    }
                }
            }

            foreach (var remindItem in remindList)
            {
                string id = await SyncAllRemind(remindItem);

                DatabaseMethod.ToDatabase(remindItem.Id, JsonConvert.SerializeObject(remindItem), id);
            }
        }
예제 #2
0
        public static async void SyncRemind()
        {
            List<KeyValuePair<string, string>> paramList = new List<KeyValuePair<string, string>>();
            PasswordCredential user = null;
            var vault = new PasswordVault();
            var credentialList = vault.FindAllByResource("ZSCY");
            if (credentialList.Count == 1)
            {
                credentialList[0].RetrievePassword();
                user = credentialList[0];
            }
            paramList.Add(new KeyValuePair<string, string>("stuNum", user.UserName));
            paramList.Add(new KeyValuePair<string, string>("idNum", user.Password));
            string content = "";
            try
            {
                content = await NetWork.httpRequest(@"http://hongyan.cqupt.edu.cn/cyxbsMobile/index.php/Home/Person/getTransaction", paramList);
            }
            catch (Exception x)
            {

                Debug.WriteLine(x.Message);
            }
            //相当于MyRemind
            GetRemindModel getRemid = new GetRemindModel();


            try
            {
                getRemid = JsonConvert.DeserializeObject<GetRemindModel>(content);
            }
            catch (Exception e)
            {
                Debug.Write(e);
            }
            List<string> getRemindList_json = new List<string>();
            List<MyRemind> remindList = new List<MyRemind>();
            #region 返回的json格式和添加的风格不一样,转换
            foreach (var item in getRemid.DataItems)
            {
                //getRemindList_json.Add(getRemid.DataItems[0].Id.ToString());
                MyRemind mr = new MyRemind();
                List<DateItemModel> dim = new List<DateItemModel>();
                //每个MyRemind的date
                foreach (var itemData in item.DateItems)
                {
                    DateItemModel dateitme = new DateItemModel();
                    string week = "";
                    foreach (var itemWeek in itemData.WeekItems)
                    {
                        week += itemWeek + ",";
                    }
                    week = week.Remove(week.Length - 1);
                    dateitme.Class = itemData.Class.ToString();
                    dateitme.Day = itemData.Day.ToString();
                    dateitme.Week = week;
                    dim.Add(dateitme);
                }
                mr.Title = item.Title;
                mr.Content = item.Content;
                mr.DateItems = dim;
                mr.Time = item.Time;
                mr.Id = item.Id.ToString();
                remindList.Add(mr);

            }
            #endregion
            List<string> RemindTagList = new List<string>();
            RemindTagList = DatabaseMethod.ClearRemindItem() as List<string>;
            var notifier = ToastNotificationManager.CreateToastNotifier();
            if (RemindTagList != null)
            {

                for (int i = 0; i < RemindTagList.Count(); i++)
                {
                    var scheduledNotifs = notifier.GetScheduledToastNotifications()
                  .Where(n => n.Tag.Equals(RemindTagList[i]));

                    // Remove all of those from the schedule
                    foreach (var n in scheduledNotifs)
                    {
                        notifier.RemoveFromSchedule(n);
                    }
                }
            }

            foreach (var remindItem in remindList)
            {
                string id = await SyncAllRemind(remindItem);
                DatabaseMethod.ToDatabase(remindItem.Id, JsonConvert.SerializeObject(remindItem), id);
            }

        }