Example #1
0
        public static void xmlparsetest()
        {
            DataFile      file = new DataFile("subjects.xml");
            ClassInfoList lst  = file.LoadClassInfo();

            Console.WriteLine(lst.Groups);
        }
Example #2
0
        public async void Navigated(string fromEndpoint, object data)
        {
            //DataFile file = new DataFile("subjects.xml");
            //classList = await file.LoadClassInfoAsync();

            string datapath = System.IO.Path.Combine(".", "Data");

            if (!System.IO.Directory.Exists(datapath))
            {
                System.IO.Directory.CreateDirectory(datapath);
            }

            manager = new DataManager(datapath);

            isContinuable.IsEnabled = false;

            Datas.Clear();
            foreach (var i in manager.GetFiles())
            {
                if (!i.IsValid)
                {
                    continue;
                }
                ClassInfoList infos = await i.LoadClassInfoAsync();

                //lst_databases.Items.Add(String.Format("{1} {2} ({0})", i.Info.Name, i.School, i.When));

                Datas.Add(i);
            }
        }
Example #3
0
        /// <summary>
        /// 직접입력받은 ClassInfo의 리스트를 해당 db에 저장한다.
        /// </summary>
        /// <param name="classes">ClassInfo의 리스트</param>
        public void SaveClassInfo(ClassInfoList classes, string filename)
        {
            XmlDocument xdoc = new XmlDocument();


            xdoc.InsertBefore(xdoc.CreateXmlDeclaration("1.0", "UTF-8", null), xdoc.DocumentElement);

            var root = xdoc.CreateElement("subjectdb");

            xdoc.AppendChild(root);

            var version = xdoc.CreateElement("version");

            version.InnerText = "1.0.0";
            root.AppendChild(version);

            var school = xdoc.CreateElement("school");

            school.InnerText = School;
            root.AppendChild(school);

            var when = xdoc.CreateElement("when");

            when.InnerText = When;
            root.AppendChild(when);

            var data = xdoc.CreateElement("data");

            root.AppendChild(data);

            foreach (var i in classes.Groups)
            {
                var group = xdoc.CreateElement("group");
                group.SetAttribute("name", i.Key);

                foreach (var j in i.Value)
                {
                    var subject = xdoc.CreateElement("subject");
                    //var name = xdoc.CreateElement("")
                }

                data.AppendChild(group);
            }



            xdoc.Save(filename);
        }
Example #4
0
        public async Task <ClassInfoList> LoadClassInfoAsync()
        {
            XmlDocument xdoc = await GetXmlDocumentAsync();


            var root = xdoc.SelectSingleNode("subjectdb");

            School = root["school"]?.InnerText;
            When   = root["when"]?.InnerText;



            ClassInfoList result = ParseData(root);

            infoListCache = result;

            return(result);
        }
Example #5
0
        private ClassInfoList ParseData(XmlNode xdoc)
        {
            ClassInfoList result = new ClassInfoList();



            var data = xdoc.SelectSingleNode("data");

            foreach (XmlNode groupnode in data.ChildNodes)
            {
                if (groupnode.Name == "group")
                {
                    string groupname = groupnode.Attributes.GetNamedItem("name").Value;
                    if (!result.Groups.ContainsKey(groupname))
                    {
                        result.Groups[groupname] = new List <ClassInfo>();
                    }


                    foreach (XmlNode subjectnode in groupnode.ChildNodes)
                    {
                        ClassInfo subject = new ClassInfo();

                        if (subjectnode["name"] == null)
                        {
                            throw new XmlException(string.Format("Subject doesn't have name in group '{0}'", groupname));
                        }

                        subject.Name = subjectnode["name"].InnerText;

                        subject.Professor = subjectnode["prof"]?.InnerText;



                        if (int.TryParse(subjectnode["grade"]?.InnerText, out int gradeval))
                        {
                            subject.Grade = gradeval;
                        }
                        else
                        {
                            subject.Grade = 0;
                        }


                        subject.Major = subjectnode["major"]?.InnerText;



                        if (int.TryParse(subjectnode["division"]?.InnerText, out int divval))
                        {
                            subject.Division = divval;
                        }
                        else
                        {
                            subject.Division = 0;
                        }

                        try
                        {
                            subject.Time = ParseTime(subjectnode["time"]);
                        }
                        catch (Exception)
                        {
                            throw new XmlException(string.Format("Invalid time format in subject {0}", subject.Name));
                        }



                        result.Groups[groupname].Add(subject);
                    }
                }
            }

            return(result);
        }