コード例 #1
0
ファイル: Model.cs プロジェクト: zixing131/Friday-UWP
            public static async Task <ObservableCollection <CourseModel> > GetCourse(string yaer = null, string term = null)
            {
                string filename = "course_";

                if (yaer == null)
                {
                    filename = filename + MD5.GetMd5String(UserManager.UserData.beginYear.ToString() + UserManager.UserData.term.ToString());
                }
                else
                {
                    filename = filename + MD5.GetMd5String(yaer + term);
                }
                var CourseFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Course", CreationCollisionOption.OpenIfExists);

                var CourseFile = await CourseFolder.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists);

                var json = await FileIO.ReadTextAsync(CourseFile);

                ObservableCollection <CourseModel> CourseList;

                if (json == "")
                {
                    CourseList = null;
                }
                else
                {
                    CourseList = Data.Json.DataContractJsonDeSerialize <ObservableCollection <CourseModel> >(json);
                }
                if (CourseList == null)
                {
                    CourseList = new ObservableCollection <CourseModel>();
                }
                return(CourseList);
            }
コード例 #2
0
ファイル: Model.cs プロジェクト: zixing131/Friday-UWP
            public static async Task <CourseModel> GetCourse(int day, int section, string yaer = null, string term = null)
            {
                string filename = "course_";

                if (yaer == null)
                {
                    filename = filename + MD5.GetMd5String(UserManager.UserData.beginYear.ToString() + UserManager.UserData.term.ToString());
                }
                else
                {
                    filename = filename + MD5.GetMd5String(yaer + term);
                }
                var CourseFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Course", CreationCollisionOption.OpenIfExists);

                var CourseFile = await CourseFolder.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists);

                var json = await FileIO.ReadTextAsync(CourseFile);

                ObservableCollection <CourseModel> CourseList;

                if (json == "")
                {
                    CourseList = null;
                }
                else
                {
                    CourseList = Data.Json.DataContractJsonDeSerialize <ObservableCollection <CourseModel> >(json);
                }
                if (CourseList == null)
                {
                    return(null);
                }
                else
                {
                    CourseModel result = null;
                    foreach (var item in CourseList)
                    {
                        if (item.day == day && (item.sectionStart <= section && section <= item.sectionEnd))
                        {
                            result = item;
                        }
                    }
                    return(result);
                }
            }
コード例 #3
0
ファイル: Model.cs プロジェクト: zixing131/Friday-UWP
            public static async Task SaveCourse(ObservableCollection <CourseModel> CourseList, string yaer = null, string term = null)
            {
                string filename = "course_";

                if (yaer == null)
                {
                    filename = filename + MD5.GetMd5String(UserManager.UserData.beginYear.ToString() + UserManager.UserData.term.ToString());
                }
                else
                {
                    filename = filename + MD5.GetMd5String(yaer + term);
                }
                var CourseFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Course", CreationCollisionOption.OpenIfExists);

                var CourseFile = await CourseFolder.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists);

                await FileIO.WriteTextAsync(CourseFile, Data.Json.ToJsonData(CourseList));
            }
コード例 #4
0
ファイル: Model.cs プロジェクト: joyhooei/Friday-UWP
            public static async Task <CourseModel> GetCourse(int day, int section, string yaer = null, string term = null, string week = null)
            {
                string filename = "course_";

                if (yaer == null)
                {
                    filename = filename + MD5.GetMd5String(UserManager.UserData.beginYear.ToString() + UserManager.UserData.term.ToString());
                }
                else
                {
                    filename = filename + MD5.GetMd5String(yaer + term);
                }


                var CourseFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Course", CreationCollisionOption.OpenIfExists);

                var CourseFile = await CourseFolder.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists);

                var json = await FileIO.ReadTextAsync(CourseFile);

                ObservableCollection <CourseModel> CourseList;

                if (json == "")
                {
                    CourseList = null;
                }
                else
                {
                    CourseList = Data.Json.DataContractJsonDeSerialize <ObservableCollection <CourseModel> >(json);
                }
                if (CourseList == null)
                {
                    return(null);
                }
                else
                {
                    CourseModel result = null;

                    var resultList = new List <CourseModel>();
                    foreach (var item in CourseList)
                    {
                        if (item.day == day && (item.sectionStart <= section && section <= item.sectionEnd))
                        {
                            resultList.Add(item);
                            result = item;
                        }
                    }

                    var isWeekValid = int.TryParse(week, out int _week);


                    if (resultList.Count > 1 && isWeekValid)
                    {
                        foreach (var item in resultList)
                        {
                            var weeks = item.smartPeriod.Split(' ');

                            if (Array.IndexOf(weeks, week) >= 0)
                            {
                                result = item;
                                break;
                            }
                        }
                    }



                    return(result);
                }
            }