public List <Event> GetEventsFromStorage(string UserID)
        {
            string userFileName     = GetUserFileName(UserID);
            string textFromUserFile = LocalFile.GetDataFromFile(userFileName).Result;

            return(JsonConvert.DeserializeObject <List <Event> >(textFromUserFile) ?? new List <Event>());
        }
Example #2
0
        public List <Event> GetNewEventsFromStorageForUser(string userID)
        {
            string       eventsText    = LocalFile.GetDataFromFile(eventsFile).Result;
            List <Event> events        = JsonConvert.DeserializeObject <List <Event> >(eventsText);
            DateTime     lastCheckDate = GetUserLastCheckDateAndSaveCurrentDate(userID);
            List <Event> newEvents     = (from e in events
                                          where DateTime.Parse(e.EventAddDate) > lastCheckDate
                                          orderby DateTime.Parse(e.EventAddDate)
                                          select e).ToList();

            return(newEvents);
        }
Example #3
0
        public void SaveNewEventsToStorage(List <Event> CurrEvents)
        {
            string       eventsFromStorageText = LocalFile.GetDataFromFile(eventsFile).Result ?? "";
            List <Event> eventsFromStorage     = JsonConvert.
                                                 DeserializeObject <List <Event> >(eventsFromStorageText) ?? new List <Event>();
            List <Event> NonActualEvent = eventsFromStorage.Except(CurrEvents).ToList();
            List <Event> ActualEvent    = eventsFromStorage.Except(NonActualEvent).ToList();
            List <Event> newEvents      = CurrEvents.Except(ActualEvent).ToList();

            eventsFromStorage.AddRange(newEvents);
            string eventsToStorageText = JsonConvert.SerializeObject(eventsFromStorage);

            LocalFile.SaveTextToFile(eventsFile, eventsToStorageText);
        }
Example #4
0
        private DateTime GetUserLastCheckDateAndSaveCurrentDate(string userId)
        {
            string      allUsersText = LocalFile.GetDataFromFile(usersFile).Result;
            List <User> allUsers     = JsonConvert.DeserializeObject <List <User> >(allUsersText) ?? new List <User>();
            int         indexOfUser  = allUsers.FindIndex(u => u.UserID == userId);
            DateTime    lastCheckDate;

            if (indexOfUser < 0)
            {
                allUsers.Add(new User {
                    UserID = userId, LustUpdate = DateTime.Now
                });
                lastCheckDate = default;
            }
            else
            {
                lastCheckDate = allUsers[indexOfUser].LustUpdate;
                allUsers[indexOfUser].LustUpdate = DateTime.Now;
            }
            allUsersText = JsonConvert.SerializeObject(allUsers);
            LocalFile.SaveTextToFile(usersFile, allUsersText);
            return(lastCheckDate);
        }
Example #5
0
 public string GetLastUpdateTelegramFromStorage()
 {
     return(LocalFile.GetDataFromFile(updatesFile).Result ?? "0");
 }
 public string GetLastUpdateTelegramFromStorage()
 {
     return(LocalFile.GetDataFromFile(fileUpdates).Result);
 }