コード例 #1
0
 //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
 #region --Misc Methods (Public)--
 public static void AddToken(TumOnlineRequest request, TumOnlineCredentials credentials)
 {
     if (!credentials.IsValid())
     {
         throw new InvalidTokenTumOnlineException(request.GetRequestUrl(), "Please login first.");
     }
     request.AddQuery(ATTRIBUTE_TOKEN, credentials.TOKEN);
 }
コード例 #2
0
        //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
        #region --Constructors--


        #endregion
        //--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
        #region --Set-, Get- Methods--


        #endregion
        //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
        #region --Misc Methods (Public)--
        public async Task <User> UpdateUserAsync(TumOnlineCredentials credentials, string obfuscatedId, bool force)
        {
            // Wait for the old update to finish first:
            if (!(updateTask is null) && !updateTask.IsCompleted)
            {
                try
                {
                    return(await updateTask.ConfAwaitFalse());
                }
                catch (Exception e)
                {
                    InvokeOnRequestError(new RequestErrorEventArgs(e));
                    Logger.Error("Awaiting for user task failed with:", e);
                    return(null);
                }
            }

            updateTask = Task.Run(async() =>
            {
                if (!force && CacheDbContext.IsCacheEntryValid(TumOnlineService.PERSON_DETAILS.NAME))
                {
                    Logger.Info("No need to fetch user. Cache is still valid.");
                    using (TumOnlineDbContext ctx = new TumOnlineDbContext())
                    {
                        return(ctx.Users.Include(ctx.GetIncludePaths(typeof(User))).FirstOrDefault());
                    }
                }
                User user = null;
                try
                {
                    user = await DownloadUserAsync(credentials, obfuscatedId, force);
                }
                catch (Exception e)
                {
                    InvokeOnRequestError(new RequestErrorEventArgs(e));
                    Logger.Error("Failed to request user with:", e);
                }
                if (!(user is null))
                {
                    using (TumOnlineDbContext ctx = new TumOnlineDbContext())
                    {
                        foreach (User userOld in ctx.Users.Where(u => u.Id == user.Id).Include(ctx.GetIncludePaths(typeof(User))))
                        {
                            if (userOld.Groups.Count() > 0)
                            {
                                ctx.RemoveRange(userOld.Groups);
                                userOld.Groups.Clear();
                            }
                            ctx.Remove(userOld);
                        }
                        ctx.Add(user);
                    }
                    CacheDbContext.UpdateCacheEntry(TumOnlineService.PERSON_DETAILS.NAME, DateTime.Now.Add(TumOnlineService.PERSON_DETAILS.VALIDITY));
                }
コード例 #3
0
        //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
        #region --Constructors--


        #endregion
        //--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
        #region --Set-, Get- Methods--


        #endregion
        //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
        #region --Misc Methods (Public)--
        public async Task <IEnumerable <CalendarEvent> > UpdateAsync(TumOnlineCredentials credentials, bool force)
        {
            // Wait for the old update to finish first:
            if (!(updateTask is null) && !updateTask.IsCompleted)
            {
                try
                {
                    return(await updateTask.ConfAwaitFalse());
                }
                catch (Exception e)
                {
                    InvokeOnRequestError(new RequestErrorEventArgs(e));
                    Logger.Error("Awaiting for calendar task failed with:", e);
                    return(new List <CalendarEvent>());
                }
            }

            updateTask = Task.Run(async() =>
            {
                if (!force && CacheDbContext.IsCacheEntryValid(TumOnlineService.CALENDAR.NAME))
                {
                    Logger.Info("No need to fetch calendar events. Cache is still valid.");
                    return(LoadCalendarEventsFromDb());
                }
                IEnumerable <CalendarEvent> events = null;
                try
                {
                    events = await DownloadCalendarEventsAsync(credentials, force);
                }
                catch (Exception e)
                {
                    InvokeOnRequestError(new RequestErrorEventArgs(e));
                    Logger.Error("Failed to request calendar events with:", e);
                }
                if (!(events is null))
                {
                    using (TumOnlineDbContext ctx = new TumOnlineDbContext())
                    {
                        ctx.RemoveRange(ctx.CalendarEvents);
                        ctx.AddRange(events);
                    }
                    CacheDbContext.UpdateCacheEntry(TumOnlineService.CALENDAR.NAME, DateTime.Now.Add(TumOnlineService.CALENDAR.VALIDITY));

                    // Update the Windows calendar:
                    if (!Settings.GetSettingBoolean(SettingsConsts.DISABLE_WINDOWS_CALENDAR_INTEGRATION))
                    {
                        await UpdateWindowsCalendarAsync(events);
                    }
                    else
                    {
                        Logger.Debug("Not updating the Windows calendar. Setting disabled.");
                    }
                }
コード例 #4
0
        //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
        #region --Constructors--


        #endregion
        //--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
        #region --Set-, Get- Methods--


        #endregion
        //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
        #region --Misc Methods (Public)--
        public async Task <IEnumerable <TuitionFee> > UpdateAsync(TumOnlineCredentials credentials, bool force)
        {
            // Wait for the old update to finish first:
            if (!(updateTask is null) && !updateTask.IsCompleted)
            {
                try
                {
                    return(await updateTask.ConfAwaitFalse());
                }
                catch (Exception e)
                {
                    InvokeOnRequestError(new RequestErrorEventArgs(e));
                    Logger.Error("Awaiting for tuition fees task failed with:", e);
                    return(new List <TuitionFee>());
                }
            }

            updateTask = Task.Run(async() =>
            {
                if (!force && CacheDbContext.IsCacheEntryValid(TumOnlineService.TUITION_FEE_STATUS.NAME))
                {
                    Logger.Info("No need to fetch tuition fees. Cache is still valid.");
                    using (TumOnlineDbContext ctx = new TumOnlineDbContext())
                    {
                        return(ctx.TuitionFees.Include(ctx.GetIncludePaths(typeof(TuitionFee))).ToList());
                    }
                }
                IEnumerable <TuitionFee> fees = null;
                try
                {
                    fees = await DownloadFeesAsync(credentials, force);
                }
                catch (Exception e)
                {
                    InvokeOnRequestError(new RequestErrorEventArgs(e));
                    Logger.Error("Failed to request tuition fees with:", e);
                }
                if (!(fees is null))
                {
                    using (TumOnlineDbContext ctx = new TumOnlineDbContext())
                    {
                        ctx.RemoveRange(ctx.TuitionFees);
                        ctx.AddRange(fees);
                    }
                    CacheDbContext.UpdateCacheEntry(TumOnlineService.GRADES.NAME, DateTime.Now.Add(TumOnlineService.GRADES.VALIDITY));
                }
コード例 #5
0
        //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
        #region --Constructors--


        #endregion
        //--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
        #region --Set-, Get- Methods--


        #endregion
        //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
        #region --Misc Methods (Public)--
        public async Task <Identity> UpdateAsync(TumOnlineCredentials credentials, bool force)
        {
            // Wait for the old update to finish first:
            if (!(updateTask is null) && !updateTask.IsCompleted)
            {
                try
                {
                    return(await updateTask.ConfAwaitFalse());
                }
                catch (Exception e)
                {
                    InvokeOnRequestError(new RequestErrorEventArgs(e));
                    Logger.Error("Awaiting for identity task failed with:", e);
                    return(null);
                }
            }

            updateTask = Task.Run(async() =>
            {
                if (!force && CacheDbContext.IsCacheEntryValid(TumOnlineService.ID.NAME))
                {
                    Logger.Info("No need to fetch identity. Cache is still valid.");
                    using (TumOnlineDbContext ctx = new TumOnlineDbContext())
                    {
                        return(ctx.Identities.Include(ctx.GetIncludePaths(typeof(Identity))).FirstOrDefault());
                    }
                }
                Identity identity = null;
                try
                {
                    identity = await DownloadIdentityAsync(credentials, force);
                }
                catch (Exception e)
                {
                    InvokeOnRequestError(new RequestErrorEventArgs(e));
                    Logger.Error("Failed to request identity with:", e);
                }
                if (!(identity is null))
                {
                    using (TumOnlineDbContext ctx = new TumOnlineDbContext())
                    {
                        ctx.RemoveRange(ctx.Identities);
                        ctx.Add(identity);
                    }
                    CacheDbContext.UpdateCacheEntry(TumOnlineService.ID.NAME, DateTime.Now.Add(TumOnlineService.ID.VALIDITY));
                }