Beispiel #1
0
        private static ScheduledToastNotification GenerateAlarmNotification(MyRemind remind)
        {
            ToastContent content = new ToastContent()
            {
                Scenario = ToastScenario.Alarm,

                Visual = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                    {
                        Children =
                        {
                            new AdaptiveText()
                            {
                                Text = $"提醒: {remind.Title}"
                            },

                            new AdaptiveText()
                            {
                                Text = remind.Content
                            }
                        }
                    }
                },
                Actions = new ToastActionsSnoozeAndDismiss()//自动创建一个自动本地化的有延迟提醒时间间隔,贪睡和取消的按钮,贪睡时间由系统自动处理
            };

            return(new ScheduledToastNotification(content.GetXml(), remind.time)
            {
                Tag = GetTag(remind)
            });
        }
 public static string GetTag(MyRemind remind)
 {
     string temp = remind.Id_system.GetHashCode().ToString();
     id += temp + ",";
     // Tag needs to be 16 chars or less, so hash the Id
     return temp;
 }
        private static ScheduledToastNotification GenerateAlarmNotification(MyRemind remind)
        {
            ToastContent content = new ToastContent()
            {
                Scenario = ToastScenario.Alarm,

                Visual = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                    {
                        Children =
                                            {
                                                new AdaptiveText()
                                                {
                                                    Text = $"提醒: {remind.Title}"
                                                },

                                                new AdaptiveText()
                                                {
                                                    Text = remind.Content
                                                }
                                            }
                    }
                },
                Actions = new ToastActionsSnoozeAndDismiss()//自动创建一个自动本地化的有延迟提醒时间间隔,贪睡和取消的按钮,贪睡时间由系统自动处理
            };
            return new ScheduledToastNotification(content.GetXml(), remind.time)
            {
                Tag = GetTag(remind)
            };

        }
        private static void addNotification(MyRemind remind)
        {

            ScheduledToastNotification scheduledNotifi = GenerateAlarmNotification(remind);

            ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledNotifi);
        }
Beispiel #5
0
        public static string GetTag(MyRemind remind)
        {
            string temp = remind.Id_system.GetHashCode().ToString();

            id += temp + ",";
            // Tag needs to be 16 chars or less, so hash the Id
            return(temp);
        }
Beispiel #6
0
 public static void AddRemind(MyRemind remind)
 {
     remind.Id_system = Guid.NewGuid();
     //await Task.Run(delegate
     //{
     addNotification(remind);
     //});
 }
 public static void AddRemind(MyRemind remind)
 {
     remind.Id_system = Guid.NewGuid();
     //await Task.Run(delegate
     //{
     addNotification(remind);
     //});
 }
        public static List<KeyValuePair<string, string>> addRemind(MyRemind myRemind)
        {
            List<KeyValuePair<string, string>> paramList = new List<KeyValuePair<string, string>>();
            paramList.Add(new KeyValuePair<string, string>("stuNum", myRemind.StuNum));
            paramList.Add(new KeyValuePair<string, string>("idNum", myRemind.IdNum));
            string date = "[";

            for (int i = 0; i < myRemind.DateItems.Count; i++)
            {
                string dateJson = JsonConvert.SerializeObject(myRemind.DateItems[i]);
                date += $"{dateJson},";
            }
            date = date.Remove(date.Length - 1) + "]";

            paramList.Add(new KeyValuePair<string, string>("date", date));
            paramList.Add(new KeyValuePair<string, string>("title", myRemind.Title));
            paramList.Add(new KeyValuePair<string, string>("time", myRemind.Time));
            paramList.Add(new KeyValuePair<string, string>("content", myRemind.Content));
            return paramList;
        }
Beispiel #9
0
        public static List <KeyValuePair <string, string> > addRemind(MyRemind myRemind)
        {
            List <KeyValuePair <string, string> > paramList = new List <KeyValuePair <string, string> >();

            paramList.Add(new KeyValuePair <string, string>("stuNum", myRemind.StuNum));
            paramList.Add(new KeyValuePair <string, string>("idNum", myRemind.IdNum));
            string date = "[";

            for (int i = 0; i < myRemind.DateItems.Count; i++)
            {
                string dateJson = JsonConvert.SerializeObject(myRemind.DateItems[i]);
                date += $"{dateJson},";
            }
            date = date.Remove(date.Length - 1) + "]";

            paramList.Add(new KeyValuePair <string, string>("date", date));
            paramList.Add(new KeyValuePair <string, string>("title", myRemind.Title));
            paramList.Add(new KeyValuePair <string, string>("time", myRemind.Time));
            paramList.Add(new KeyValuePair <string, string>("content", myRemind.Content));
            return(paramList);
        }
        public static async Task<string> SyncAllRemind(MyRemind remind)
        {

            id = "";
            if (remind.Time != null)
            {
                int min = int.Parse(remind.Time) % 60;
                int hour = int.Parse(remind.Time) / 60;
                int day = hour / 24;
                TimeSpan beforeTime = new TimeSpan(day, hour, min, 0);


                List<SelectedWeekNum> weeklist = new List<SelectedWeekNum>();
                foreach (var item in remind.DateItems)
                {
                    var itemWeekList = item.Week.Split(',');
                    var itemClassList = int.Parse(item.Class);
                    var itemDayList = int.Parse(item.Day);
                    TimeSet classTime = new TimeSet();
                    classTime.Set(itemClassList);
                    for (int i = 0; i < itemWeekList.Count(); i++)
                    {
                        SelectedWeekNum swn = new SelectedWeekNum();
                        swn.SetWeekTime(int.Parse(itemWeekList[i]) - 1);

                        remind.time = swn.WeekNumOfMonday.AddDays(itemDayList) + classTime.Time - beforeTime;
                        if (remind.time.Ticks < DateTime.Now.Ticks)
                        {

                        }
                        else
                        {
                            AddRemind(remind);
                        }
                    }
                }
            }
            return id;
        }
Beispiel #11
0
        public static async Task <string> SyncAllRemind(MyRemind remind)
        {
            id = "";
            if (remind.Time != null)
            {
                int      min        = int.Parse(remind.Time) % 60;
                int      hour       = int.Parse(remind.Time) / 60;
                int      day        = hour / 24;
                TimeSpan beforeTime = new TimeSpan(day, hour, min, 0);


                List <SelectedWeekNum> weeklist = new List <SelectedWeekNum>();
                foreach (var item in remind.DateItems)
                {
                    var     itemWeekList  = item.Week.Split(',');
                    var     itemClassList = int.Parse(item.Class);
                    var     itemDayList   = int.Parse(item.Day);
                    TimeSet classTime     = new TimeSet();
                    classTime.Set(itemClassList);
                    for (int i = 0; i < itemWeekList.Count(); i++)
                    {
                        SelectedWeekNum swn = new SelectedWeekNum();
                        swn.SetWeekTime(int.Parse(itemWeekList[i]) - 1);

                        remind.time = swn.WeekNumOfMonday.AddDays(itemDayList) + classTime.Time - beforeTime;
                        if (remind.time.Ticks < DateTime.Now.Ticks)
                        {
                        }
                        else
                        {
                            AddRemind(remind);
                        }
                    }
                }
            }
            return(id);
        }
Beispiel #12
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            bool isLoad = false;
            PasswordCredential credential = null;
            var vault          = new PasswordVault();
            var credentialList = vault.FindAllByResource("ZSCY");

            if (credentialList.Count == 1)
            {
                credentialList[0].RetrievePassword();
                credential = credentialList[0];
            }
            try
            {
                var list = DatabaseMethod.ToModel();

                BackgroundTaskDeferral deferral1 = taskInstance.GetDeferral();
                if (list.Count > 0)
                {
                    //上传上次未上传的
                    foreach (var item in list)
                    {
                        if (item.Id == null)
                        {
                            string content = "";
                            isLoad = true;
                            MyRemind tempRemind = new MyRemind();
                            tempRemind        = JsonConvert.DeserializeObject <MyRemind>(item.json);
                            tempRemind.IdNum  = credential.Password;
                            tempRemind.StuNum = credential.UserName;
                            content           = await NetWork.httpRequest(@"http://hongyan.cqupt.edu.cn/cyxbsMobile/index.php/Home/Person/addTransaction", NetWork.addRemind(tempRemind));

                            Debug.WriteLine(content);

                            AddRemindReturn tempReturn = JsonConvert.DeserializeObject <AddRemindReturn>(content);
                            if (tempReturn.Status == 200)
                            {
                                string id = tempReturn.Id;
                                tempRemind.Id     = id;
                                tempRemind.IdNum  = null;
                                tempRemind.StuNum = null;
                                DatabaseMethod.EditDatabase(item.Num, id, JsonConvert.SerializeObject(tempRemind), item.Id_system);
                            }
                        }
                    }
                }

                deferral1.Complete();
                BackgroundTaskDeferral deferral2 = taskInstance.GetDeferral();
                if (isLoad)
                {
                }
                else
                {
                    RemindHelp.SyncRemind();
                }

                deferral2.Complete();
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #13
0
        private static void addNotification(MyRemind remind)
        {
            ScheduledToastNotification scheduledNotifi = GenerateAlarmNotification(remind);

            ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledNotifi);
        }
Beispiel #14
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);
            }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            bool isLoad = false;
            PasswordCredential credential = null;
            var vault = new PasswordVault();
            var credentialList = vault.FindAllByResource("ZSCY");
            if (credentialList.Count == 1)
            {
                credentialList[0].RetrievePassword();
                credential = credentialList[0];
            }
            try
            {
                var list = DatabaseMethod.ToModel();

                BackgroundTaskDeferral deferral1 = taskInstance.GetDeferral();
                foreach (var item in list)
                {

                    if (item.Id == null)
                    {
                        string content = "";
                        isLoad = true;
                        MyRemind tempRemind = new MyRemind();
                        tempRemind = JsonConvert.DeserializeObject<MyRemind>(item.json);
                        tempRemind.IdNum = credential.Password;
                        tempRemind.StuNum = credential.UserName;
                        content = await NetWork.httpRequest(@"http://hongyan.cqupt.edu.cn/cyxbsMobile/index.php/Home/Person/addTransaction", NetWork.addRemind(tempRemind));
                        Debug.WriteLine(content);

                        AddRemindReturn tempReturn = JsonConvert.DeserializeObject<AddRemindReturn>(content);
                        if (tempReturn.Status == 200)
                        {
                            string id = tempReturn.Id;
                            tempRemind.Id = id;
                            tempRemind.IdNum = null;
                            tempRemind.StuNum = null;
                            DatabaseMethod.EditDatabase(item.Num, id, JsonConvert.SerializeObject(tempRemind), item.Id_system);
                        }


                    }
                }

                deferral1.Complete();
                BackgroundTaskDeferral deferral2 = taskInstance.GetDeferral();
                if (isLoad)
                {

                }
                else
                {
                    RemindHelp.SyncRemind();
                }

                deferral2.Complete();
            }
            catch (Exception)
            {

                throw;
            }

        }
        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);
            }

        }