コード例 #1
0
 public static void UpdateLessonsInfo(Local.SavedEntity entity, List <Local.LessonInfo> lessonsInfo)
 {
     Local.TimetableInfo timetable = GetTimetableLocal(entity);
     timetable.LessonsInfo = lessonsInfo;
     UpdateTimetableLocal(timetable);
     Device.BeginInvokeOnMainThread(() =>
     {
         MessagingCenter.Send(Application.Current, MessageTypes.LessonSettingsChanged, entity);
     });
 }
コード例 #2
0
        public static List <Local.TimetableInfo> GetTimetableLocal(params Local.SavedEntity[] entities)
        {
            var timetables = new List <Local.TimetableInfo>();

            if (entities == null)
            {
                return(timetables);
            }
            foreach (Local.SavedEntity entity in entities)
            {
                Local.TimetableInfo timetableInfo = Serialisation.FromJsonFile <Local.TimetableInfo>(FilePath.SavedTimetable(entity.Type, entity.ID));
                if (timetableInfo == null)
                {
                    continue;
                }
                timetables.Add(timetableInfo);
            }
            return(timetables);
        }
コード例 #3
0
        public static Local.TimetableInfo GetTimetableFromCist(Local.SavedEntity entity, DateTime dateStart, DateTime dateEnd)
        {
            if (SettingsRepository.CheckCistTimetableUpdateRights(entity).Count == 0)
            {
                return(null);
            }

            using (var client = new WebClient
            {
                Encoding = Encoding.GetEncoding("Windows-1251")
            })
            {
                try
                {
                    Local.TimetableInfo timetable = GetTimetableLocal(entity);

                    // Getting events
                    Uri    uri         = new Uri(Urls.CistEntityTimetableUrl(entity.Type, entity.ID, dateStart, dateEnd));
                    string responseStr = client.DownloadString(uri);
                    responseStr = responseStr.Replace("&amp;", "&");
                    responseStr = responseStr.Replace("\"events\":[\n]}]", "\"events\": []");
                    Cist.Timetable cistTimetable = Serialisation.FromJson <Cist.Timetable>(responseStr);

                    // Updating timetable information
                    if (timetable == null)
                    {
                        timetable = new Local.TimetableInfo(entity);
                    }
                    timetable.Events = cistTimetable.Events.Select(ev =>
                    {
                        Local.Event localEvent = MapConfig.Map <Cist.Event, Local.Event>(ev);
                        localEvent.Lesson      = MapConfig.Map <Cist.Lesson, Local.Lesson>(cistTimetable.Lessons.First(l => l.Id == ev.LessonId));
                        localEvent.Type        = MapConfig.Map <Cist.EventType, Local.EventType>(cistTimetable.EventTypes.First(et => et.Id == ev.TypeId));
                        localEvent.Teachers    = cistTimetable.Teachers
                                                 .Where(t => ev.TeacherIds.Contains(t.Id))
                                                 .DistinctBy(t => t.ShortName.Replace('ї', 'i'))
                                                 .Select(t => MapConfig.Map <Cist.Teacher, Local.Teacher>(t))
                                                 .ToList();
                        localEvent.Groups = cistTimetable.Groups
                                            .Where(g => ev.GroupIds.Contains(g.Id))
                                            .Select(g => MapConfig.Map <Cist.Group, Local.Group>(g))
                                            .ToList();
                        return(localEvent);
                    }).ToList();

                    // Updating LastUpdated for saved groups
                    List <Local.SavedEntity> AllSavedEntities = UniversityEntitiesRepository.GetSaved();
                    foreach (Local.SavedEntity savedEntity in AllSavedEntities.Where(e => e == entity))
                    {
                        savedEntity.LastUpdated = DateTime.Now;
                    }
                    UniversityEntitiesRepository.UpdateSaved(AllSavedEntities);

                    // Saving timetables
                    UpdateTimetableLocal(timetable);
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        MessagingCenter.Send(Application.Current, MessageTypes.TimetableUpdated, entity);
                    });

                    return(timetable);
                }
                catch (Exception ex)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        ex.Data.Add("Entity", $"{entity.Type} {entity.Name} ({entity.ID})");
                        ex.Data.Add("From", dateStart.ToString("dd.MM.yyyy"));
                        ex.Data.Add("To", dateEnd.ToString("dd.MM.yyyy"));
                        MessagingCenter.Send(Application.Current, MessageTypes.ExceptionOccurred, ex);
                    });
                }
            }
            return(null);
        }
コード例 #4
0
 private static void UpdateTimetableLocal(Local.TimetableInfo newTimetable)
 {
     Serialisation.ToJsonFile(newTimetable, FilePath.SavedTimetable(newTimetable.Entity.Type, newTimetable.Entity.ID));
 }