public static void UpdateSaved(List <SavedGroup> savedGroups) { // Removing cash from deleted saved groups if needed List <SavedGroup> deletedGroups = GetSaved() .Where(oldGroup => !savedGroups.Exists(group => group.ID == oldGroup.ID)) .ToList(); if (deletedGroups.Count > 0) { deletedGroups.ForEach((dg) => { try { File.Delete(FilePath.SavedTimetable(dg.ID)); } catch {} }); } // Saving saved groups list Serialisation.ToJsonFile(savedGroups, FilePath.SavedGroupsList); Device.BeginInvokeOnMainThread(() => { MessagingCenter.Send(Application.Current, MessageTypes.SavedGroupsChanged, savedGroups); }); // Updating selected group if needed if (GetSelected() == null && savedGroups.Count > 0) { UpdateSelected(savedGroups[0]); } }
public static void UpdateSelected(SavedGroup selectedGroup) { Serialisation.ToJsonFile((Group)selectedGroup, FilePath.SelectedGroup); Device.BeginInvokeOnMainThread(() => { MessagingCenter.Send(Application.Current, MessageTypes.SelectedGroupChanged, (Group)selectedGroup); }); }
public static void UpdateLessonSettings(int groupID, List <LessonSettings> lessonSettings) { Serialisation.ToJsonFile(lessonSettings, FilePath.LessonSettings(groupID)); Device.BeginInvokeOnMainThread(() => { MessagingCenter.Send(Application.Current, MessageTypes.LessonSettingsChanged, groupID); }); }
public static EventList GetEventsLocal(int groupID) { List <Event> localEvents = Serialisation.FromJsonFile <List <Event> >(FilePath.SavedTimetable(groupID)); if (localEvents == null) { return(null); } var events = new EventList(localEvents); return(events); }
public static List <LessonSettings> GetLessonSettings(int groupID) { var lessonSettings = new List <LessonSettings>(); string filePath = FilePath.LessonSettings(groupID); if (!File.Exists(filePath)) { return(lessonSettings); } lessonSettings = Serialisation.FromJsonFile <List <LessonSettings> >(filePath) ?? lessonSettings; return(lessonSettings); }
public static Group GetSelected() { string filePath = FilePath.SelectedGroup; if (!File.Exists(filePath)) { return(null); } Group selectedGroup = Serialisation.FromJsonFile <Group>(filePath); return(selectedGroup); }
private static DateTime?GetLastCistAllEntitiesUpdateTime() { string filePath = FilePath.LastCistAllEntitiesUpdate; if (!File.Exists(filePath)) { return(null); } DateTime lastTimetableUpdate = Serialisation.FromJsonFile <DateTime>(filePath); return(lastTimetableUpdate); }
public static List <SavedGroup> GetSaved() { List <SavedGroup> loadedGroups = new List <SavedGroup>(); string filePath = FilePath.SavedGroupsList; if (!File.Exists(filePath)) { return(loadedGroups); } loadedGroups = Serialisation.FromJsonFile <List <SavedGroup> >(filePath) ?? loadedGroups; return(loadedGroups); }
public static List <Group> GetAllLocal() { List <Group> loadedGroups; string filePath = FilePath.AllGroupsList; if (!File.Exists(filePath)) { return(null); } loadedGroups = Serialisation.FromJsonFile <List <Group> >(filePath); return(loadedGroups); }
public static DateTime?GetLastTimetableUpdate() { #if DEBUG return(null); #endif string filePath = FilePath.LastTimetableUpdate; if (!File.Exists(filePath)) { return(null); } DateTime lastTimetableUpdate = Serialisation.FromJsonFile <DateTime>(filePath); return(lastTimetableUpdate); }
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); }
public static async Task <List <Local::TimetableInfo> > GetTimetableLocal(List <Local::Entity> entities) { List <Local::TimetableInfo> timetables = new(); if (entities == null) { return(timetables); } foreach (var entity in entities) { Local::TimetableInfo timetableInfo = await Serialisation.FromJsonFile <Local::TimetableInfo>(FilePath.SavedTimetable(entity.Type, entity.ID)); if (timetableInfo == null) { continue; } timetables.Add(timetableInfo); } return(timetables); }
public static Dictionary <int, EventList> GetEventsFromCist(DateTime dateStart, DateTime dateEnd, params Group[] groups) { if (groups == null || groups.Length == 0 || CheckUpdateTimetableFromCistRights() == false) { return(null); } using (var client = new WebClient()) { client.Encoding = Encoding.GetEncoding("Windows-1251"); try { var timetables = new Dictionary <int, EventList>(); Uri uri = new Uri(Urls.CistTimetableUrl(dateStart, dateEnd, groups.Select(g => g.ID).ToArray())); string data = client.DownloadString(uri); SettingsDataStore.UpdateLastTimetableUpdate(); if (groups.Length == 1) { List <Event> events = EventList.Parse(data); if (events == null) { return(null); } timetables.Add(groups[0].ID, new EventList(events)); } else { Dictionary <string, List <Event> > timetablesStr = EventList.Parse(data, true); foreach (Group group in groups) { List <Event> groupEvents = new List <Event>(); if (timetablesStr.Keys.Contains(group.Name)) { groupEvents = timetablesStr[group.Name]; } timetables.Add(group.ID, new EventList(groupEvents)); } } foreach (int groupID in timetables.Keys) { Serialisation.ToJsonFile(timetables[groupID].Events, FilePath.SavedTimetable(groupID)); Device.BeginInvokeOnMainThread(() => { MessagingCenter.Send(Application.Current, MessageTypes.TimetableUpdated, groupID); }); } return(timetables); } catch (Exception ex) { Device.BeginInvokeOnMainThread(() => { MessagingCenter.Send(Application.Current, MessageTypes.ExceptionOccurred, ex); }); } } return(null); }
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("&", "&"); 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); }
public static void UpdateLastTimetableUpdate() { Serialisation.ToJsonFile(DateTime.Now, FilePath.LastTimetableUpdate); }
public static void UpdateCistAllEntitiesUpdateTime() { Serialisation.ToJsonFile(DateTime.Now, FilePath.LastCistAllEntitiesUpdate); }
private static void UpdateTimetableLocal(Local.TimetableInfo newTimetable) { Serialisation.ToJsonFile(newTimetable, FilePath.SavedTimetable(newTimetable.Entity.Type, newTimetable.Entity.ID)); }
public static void UpdateSettings(AppSettings settings) { Serialisation.ToJsonFile(settings, FilePath.AppSettings); }
public static AppSettings GetSettings() { return(Serialisation.FromJsonFile <AppSettings>(FilePath.AppSettings) ?? new AppSettings()); }
private static Task UpdateTimetableLocal(Local::TimetableInfo newTimetable) { return(Serialisation.ToJsonFile(newTimetable, FilePath.SavedTimetable(newTimetable.Entity.Type, newTimetable.Entity.ID))); }
public static List <Group> GetAllFromCist() { List <Group> groups = new List <Group>(); using (var client = new WebClient()) { client.Encoding = Encoding.GetEncoding("Windows-1251"); try { List <int> branches = new List <int>(); // Getting branches Uri uri = new Uri(Urls.CistAllGroupsSource(null)); string branchesListPage = client.DownloadString(uri); foreach (string part in branchesListPage.Split(new string[] { "IAS_Change_Groups(" }, StringSplitOptions.RemoveEmptyEntries).Skip(1)) { string branchIdStr = part.Remove(part.IndexOf(')')); if (!int.TryParse(branchIdStr, out int branchID)) { continue; } branches.Add(branchID); } //Getting groups foreach (int branchID in branches) { uri = new Uri(Urls.CistAllGroupsSource(branchID)); string branchGroupsPage = client.DownloadString(uri); foreach (string part in branchGroupsPage.Split(new string[] { "IAS_ADD_Group_in_List(" }, StringSplitOptions.RemoveEmptyEntries).Skip(1)) { string[] groupInfo = part .Remove(part.IndexOf(")\">")) .Split(new char[] { ',', '\'' }, StringSplitOptions.RemoveEmptyEntries); if (groupInfo.Length < 2 || !int.TryParse(groupInfo.Last(), out int groupID)) { continue; } for (int i = 0; i < groupInfo.Length - 1; i++) { Group group = new Group { ID = groupID, Name = groupInfo[i] }; groups.Add(group); } } } Serialisation.ToJsonFile(groups, FilePath.AllGroupsList); } catch (Exception ex) { Device.BeginInvokeOnMainThread(() => { MessagingCenter.Send(Application.Current, MessageTypes.ExceptionOccurred, ex); }); groups = null; } } return(groups); }