//--------------------------------------------------------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)); }
//--------------------------------------------------------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)); }
//--------------------------------------------------------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)); }