Beispiel #1
0
        public static Lessons GetLessons(string group, int timestart, JsnDec codedic)
        {
            int timefinish = timestart + 86400;

            group = codedic.groups.FirstOrDefault(x => x.Value == group).Key;
            string reguest  = $"http://services.tsi.lv/schedule/api/service.asmx/GetLocalizedEvents?from={timestart}&to={timefinish}&teachers=&rooms=&groups={group}&lang=%27ru%27";
            string response = Getresponse(reguest);

            response = response.Replace("(", "");
            response = response.Replace(")", "");
            var  jser = new JavaScriptSerializer();
            Jsn1 dic  = jser.Deserialize <Jsn1>(response);
            Jsn2 dic2 = jser.Deserialize <Jsn2>(dic.d);

            return(new Lessons(dic2, codedic, timestart));
        }
Beispiel #2
0
        public Lessons(Jsn2 jsn2, JsnDec codedic, int timestart)
        {
            LessonCount = jsn2.events.values.Count;
            timestamp   = timestart;
            //if (LessonCount != 0)
            {
                lessons = new Lesson[LessonCount];
                for (int i = 0; i < LessonCount; i++)
                {
                    lessons[i] = new Lesson();
                }


                for (int i = 0; i < LessonCount; i++)
                {
                    int      timeStampTemp = (int)jsn2.events.values.ElementAt(i).ElementAt(0);
                    DateTime dateTimeTemp  = new DateTime();
                    dateTimeTemp    = dateTimeTemp.AddSeconds(timeStampTemp);
                    lessons[i].time = $"{dateTimeTemp.Hour}:{dateTimeTemp.Minute}";
                    lessons[i].time = lessons[i].time.Replace(":0", ":00");

                    try
                    {
                        lessons[i].room    = codedic.rooms[((object[])jsn2.events.values.ElementAt(i).ElementAt(1))[0].ToString()];
                        lessons[i].groups  = codedic.groups[((object[])jsn2.events.values.ElementAt(i).ElementAt(2))[0].ToString()];
                        lessons[i].teacher = codedic.teachers[jsn2.events.values.ElementAt(i).ElementAt(3).ToString()];
                    }
                    catch (Exception)
                    {
                    }
                    lessons[i].name = (string)jsn2.events.values.ElementAt(i).ElementAt(4);

                    if (lessons[i].name.Length > 49)
                    {
                        lessons[i].name = lessons[i].name.Substring(0, 49) + ".";
                    }

                    lessons[i].comment = (string)jsn2.events.values.ElementAt(i).ElementAt(5);
                    lessons[i].cclass  = (string)jsn2.events.values.ElementAt(i).ElementAt(6);

                    lessons[i].teacher += "  " + lessons[i].comment;
                }
            }
        }