Ejemplo n.º 1
0
        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 UpdateLessonSettings(int groupID, List <LessonSettings> lessonSettings)
 {
     Serialisation.ToJsonFile(lessonSettings, FilePath.LessonSettings(groupID));
     Device.BeginInvokeOnMainThread(() =>
     {
         MessagingCenter.Send(Application.Current, MessageTypes.LessonSettingsChanged, groupID);
     });
 }
Ejemplo n.º 3
0
 public static void UpdateSelected(SavedGroup selectedGroup)
 {
     Serialisation.ToJsonFile((Group)selectedGroup, FilePath.SelectedGroup);
     Device.BeginInvokeOnMainThread(() =>
     {
         MessagingCenter.Send(Application.Current, MessageTypes.SelectedGroupChanged, (Group)selectedGroup);
     });
 }
 private static Task UpdateTimetableLocal(Local::TimetableInfo newTimetable)
 {
     return(Serialisation.ToJsonFile(newTimetable, FilePath.SavedTimetable(newTimetable.Entity.Type, newTimetable.Entity.ID)));
 }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 public static void UpdateCistAllEntitiesUpdateTime()
 {
     Serialisation.ToJsonFile(DateTime.Now, FilePath.LastCistAllEntitiesUpdate);
 }
Ejemplo n.º 7
0
 public static void UpdateSettings(AppSettings settings)
 {
     Serialisation.ToJsonFile(settings, FilePath.AppSettings);
 }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
 public static void UpdateLastTimetableUpdate()
 {
     Serialisation.ToJsonFile(DateTime.Now, FilePath.LastTimetableUpdate);
 }
Ejemplo n.º 10
0
 private static void UpdateTimetableLocal(Local.TimetableInfo newTimetable)
 {
     Serialisation.ToJsonFile(newTimetable, FilePath.SavedTimetable(newTimetable.Entity.Type, newTimetable.Entity.ID));
 }