/// <summary> /// Gets the paged blog previews. /// </summary> /// <param name="token">The token.</param> /// <param name="shouldAddPage">if set to <c>true</c> [should add page].</param> /// <returns>IEnumerable<TableBlogEntity>.</returns> private async Task <IEnumerable <TableBlogEntity> > GetPagedBlogPreviews( TableContinuationToken token, bool shouldAddPage) { var activeTable = this.blogContext.CustomOperation(); var query = (from record in activeTable.CreateQuery <DynamicTableEntity>() where record.PartitionKey == ApplicationConstants.BlogKey && record.Properties["IsDraft"].BooleanValue == false && record.Properties["IsDeleted"].BooleanValue == false && string.Compare(record.RowKey, this.rowKeyToUse, StringComparison.OrdinalIgnoreCase) > 0 select record).Take(this.pageSize); var result = await Task.Run(() => query.AsTableQuery().ExecuteSegmented(token, this.blogContext.TableRequestOptions)); if (!shouldAddPage || null == result.ContinuationToken) { return(result.Select(element => element.ConvertDynamicEntityToEntity <TableBlogEntity>())); } UserPageDictionary.PageDictionary.AddPage(result.ContinuationToken); //// If this is the first page response. Add it to cache as well. if (null == token) { ApplicationCache.Set(ApplicationConstants.BlogsFirstTokenCacheKey, result.ContinuationToken); } return(result.Select(element => element.ConvertDynamicEntityToEntity <TableBlogEntity>())); }
/// <summary> /// Gets the latest blogs. /// </summary> /// <returns>List<BlogPost>.</returns> public async Task <List <BlogPost> > GetLatestBlogs() { IEnumerable <BlogPost> cacheResult; TableContinuationToken token; //// Check in cache first. Retry operation on first failure. Product Issue :( try { cacheResult = ApplicationCache.Get <IEnumerable <BlogPost> >(ApplicationConstants.BlogsCacheKey); token = ApplicationCache.Get <TableContinuationToken>(ApplicationConstants.BlogsFirstTokenCacheKey); } catch (Exception) { cacheResult = ApplicationCache.Get <IEnumerable <BlogPost> >(ApplicationConstants.BlogsCacheKey); token = ApplicationCache.Get <TableContinuationToken>(ApplicationConstants.BlogsFirstTokenCacheKey); } if (null != cacheResult) { //// We need to add token to user page dictionary as well. if (null != token) { UserPageDictionary.PageDictionary.AddPage(token); } return(cacheResult.ToList()); } var result = await this.GetPagedBlogPreviews(null, true); var firstPageBlogs = result.Select(TableBlogEntity.GetBlogPost).ToList(); ApplicationCache.Set(ApplicationConstants.BlogsCacheKey, firstPageBlogs); return(firstPageBlogs); }
//private static void LoadDefaultTrayIcon() //{ // var bi = new BitmapImage(); // bi.BeginInit(); // bi.UriSource = new Uri(@"pack://application:,,,/Resources/Images/WMSLogo.ico", UriKind.RelativeOrAbsolute); // bi.EndInit(); // App.Current.TrayIcon.Icon = bi; //} public static void LoadCultureInfo() { var language = ConfigurationManager.AppSettings["Language"]; LanguageReader.Load(language); Country.Local = new Country(Application.Current.Dispatcher.Thread.CurrentCulture, new string[0]).ToString(); ApplicationCache.Set(Global.GlobalCalendar, new Dictionary <DateTime, Dictionary <string, bool> >(365)); }
public void Login(Employee employee, string role) { ApplicationCache.Set(Global.LoginEmployee, employee); ApplicationCache.Set(Global.LoggerId, employee.AgentId); if (role.IsNotNullOrEmpty()) { //Set Rules SetFunctionKeys(role); } //Log AuditLoginLog(new AuditLog { Action = LanguageReader.GetValue("Logging_Admin_Login"), CurrentUser = employee.AgentId }); }
public void Login(string agentId, Guid roleId) { var employee = _loginRepository.FirstOrDefault(o => o.AgentId == agentId); ApplicationCache.Set(Global.LoginEmployee, employee); ApplicationCache.Set(Global.LoggerId, employee.AgentId); if (roleId != Guid.Empty) { //Set Rules SetFunctionKeys(roleId); } //Log AuditLoginLog(new AuditLog { Action = LanguageReader.GetValue("Logging_Admin_Login"), CurrentUser = employee.AgentId }); }
/// <summary> /// Testimonials this instance. /// </summary> /// <returns>ViewResult.</returns> public ViewResult Testimonials() { this.profileService = new ProfileService(this.documentDbAccess); var result = new List <Testimonial>(); List <Testimonial> cacheResult; //// Check in cache first. Retry operation on first failure. Product Issue :( try { cacheResult = ApplicationCache.Get <List <Testimonial> >(ApplicationConstants.TestimonialCacheKey); } catch (Exception) { cacheResult = ApplicationCache.Get <List <Testimonial> >(ApplicationConstants.TestimonialCacheKey); } if (null != cacheResult) { return(this.View("Testimonials", cacheResult)); } var testimonialCount = Convert.ToInt32(WebConfigurationManager.AppSettings[ApplicationConstants.TopTestimonialCount]); ////Get top N Testimonials. var documentsFeatured = this.profileService.QueryDocument <Testimonial>(testimonialCount); var featured = documentsFeatured.Where(document => document.IsFeatured && document.IsApproved).OrderByDescending(document => document.TestimonialId).ToList(); result.AddRange(featured); if (testimonialCount - featured.Count() <= 0) { return(this.View("Testimonials", result)); } var documentsApproved = this.profileService.QueryDocument <Testimonial>(testimonialCount - featured.Count()); var approved = documentsApproved.Where(document => document.IsApproved && !document.IsFeatured).OrderByDescending(document => document.TestimonialId).ToList(); result.AddRange(approved); ApplicationCache.Set(ApplicationConstants.TestimonialCacheKey, result); return(this.View("Testimonials", result)); }
private void SetFunctionKeys(string role) { var functionKeys = _loginRepository.GetFunctionKeys(role); ApplicationCache.Set(Global.LoginUserFunctionKeys, functionKeys); }
public void AddAndReplaceEntries_AreThreadSafe() { var cache = new ApplicationCache( new CacheOptions { MemoryCacheOptions = new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.Zero, SizeLimit = 20, CompactionPercentage = 0.5 } }); var cts = new CancellationTokenSource(); var random = new Random(); var task0 = Task.Run(() => { while (!cts.IsCancellationRequested) { var entrySize = random.Next(0, 5); cache.Set <object>(new ApplicationKey(random.Next(0, 10).ToString()), entrySize, new MemoryCacheEntryOptions { Size = entrySize }); } }); var task1 = Task.Run(() => { while (!cts.IsCancellationRequested) { var entrySize = random.Next(0, 5); cache.Set <object>(new ApplicationKey(random.Next(0, 10).ToString()), entrySize, new MemoryCacheEntryOptions { Size = entrySize }); } }); var task2 = Task.Run(() => { while (!cts.IsCancellationRequested) { var entrySize = random.Next(0, 5); cache.Set <object>(new ApplicationKey(random.Next(0, 10).ToString()), entrySize, new MemoryCacheEntryOptions { Size = entrySize }); } }); cts.CancelAfter(TimeSpan.FromSeconds(5)); var task3 = Task.Delay(TimeSpan.FromSeconds(7)); Task.WaitAll(task0, task1, task2, task3); Assert.Equal(TaskStatus.RanToCompletion, task0.Status); Assert.Equal(TaskStatus.RanToCompletion, task1.Status); Assert.Equal(TaskStatus.RanToCompletion, task2.Status); Assert.Equal(TaskStatus.RanToCompletion, task3.Status); Assert.InRange(cache.Count(), 0, 20); }