public async Task <Author> InsertAuthor(Author author) { if (author == null) { throw new ArgumentNullException("author"); } await _authorRepository.InsertAsync(author); _memoryCacheManager.RemoveByPattern(AUTHOR_PATTERN_KEY); return(author); }
public async Task <Book> InsertBook(Book book) { if (book == null) { throw new ArgumentNullException("book"); } await _bookRepository.InsertAsync(book); _memoryCacheManager.RemoveByPattern(BOOK_PATTERN_KEY); return(book); }
public async Task <Publisher> InsertPublisher(Publisher publisher) { if (publisher == null) { throw new ArgumentNullException("publisher"); } await _publisherRepository.InsertAsync(publisher); _memoryCacheManager.RemoveByPattern(PUBLISHER_PATTERN_KEY); return(publisher); }
public void RemoveByPatternTest() { /* * In this test I provide: * 1. pattern that consists of "key100\d" which matchs to: key1009, but not to key1010 * 2. ICacheManager object with several keys * 3. List<string> with several keys */ ICacheManager icacheManager = new MemoryCacheManager(); icacheManager.Set("key1001", 33, int.MaxValue); icacheManager.Set("key1202", 1244, int.MaxValue); icacheManager.Set("key1003", 512, int.MaxValue); icacheManager.Set("key1204", 55, int.MaxValue); icacheManager.Set("key1005", 32, int.MaxValue); string pattern = @"key100\d"; //"key100" and one digit List <string> keys = new List <string>(); keys.Add("key1001"); keys.Add("key1202"); keys.Add("key1003"); keys.Add("key1204"); keys.Add("key1005"); icacheManager.RemoveByPattern(pattern, keys); Assert.IsNotNull(icacheManager.Get <int>("key1202")); Assert.IsNotNull(icacheManager.Get <int>("key1204")); }
public override void OnSuccess(MethodExecutionArgs args) { var cacheManager = new MemoryCacheManager(); cacheManager.RemoveByPattern(string.IsNullOrEmpty(_pattern) ? string.Format("{0}.{1}.*", args.Method.ReflectedType.Namespace, args.Method.ReflectedType.Name) : _pattern); }
public ActionResult ClearCache(string key) { if (string.IsNullOrEmpty(key)) { var cacheManager = new MemoryCacheManager(); cacheManager.Clear(); } else { var cacheManager = new MemoryCacheManager(); cacheManager.RemoveByPattern(key); } return(RedirectToAction("Index", "Home")); }
public void RemoveByPatternTest() { MemoryCacheManager memoryCacheManager = new MemoryCacheManager(); memoryCacheManager.Set("exampleKey025", 5, int.MaxValue); memoryCacheManager.Set("exampleKey026", 5, int.MaxValue); memoryCacheManager.Set("exampleKey027", 5, int.MaxValue); memoryCacheManager.Set("exampleKey127", 5, int.MaxValue); string pattern = @"exampleKey0\d\d"; memoryCacheManager.RemoveByPattern(pattern); Assert.IsFalse(memoryCacheManager.IsSet("exampleKey025")); Assert.IsFalse(memoryCacheManager.IsSet("exampleKey026")); Assert.IsFalse(memoryCacheManager.IsSet("exampleKey027")); Assert.IsTrue(memoryCacheManager.IsSet("exampleKey127")); }
public async Task RemoveByPatternTest() { MemoryCacheManager memoryCacheManager = new MemoryCacheManager(new MemoryCache(new MemoryCacheOptions { })); await memoryCacheManager.SetAsync("exampleKey025", 5, int.MaxValue); await memoryCacheManager.SetAsync("exampleKey026", 5, int.MaxValue); await memoryCacheManager.SetAsync("exampleKey027", 5, int.MaxValue); await memoryCacheManager.SetAsync("exampleKey127", 5, int.MaxValue); string pattern = @"exampleKey0\d\d"; await memoryCacheManager.RemoveByPattern(pattern); Assert.IsFalse(memoryCacheManager.IsSet("exampleKey025")); Assert.IsFalse(memoryCacheManager.IsSet("exampleKey026")); Assert.IsFalse(memoryCacheManager.IsSet("exampleKey027")); Assert.IsTrue(memoryCacheManager.IsSet("exampleKey127")); }
public string DeleteMenu(int id) { if(AdminRepository.DeleteMenu(id)==false) { return "Cann't Delete! Child record found!"; } else { // Remove entity menu cache ICacheManager cacheManager=new MemoryCacheManager(); cacheManager.RemoveByPattern(MenuHelper.ENTITYMENUKEY); return string.Empty; } }
public ActionResult UpdateMenu(FormCollection collection) { ICacheManager cacheManager=new MemoryCacheManager(); EditMenuModel model=new EditMenuModel(); ResultModel resultModel=new ResultModel(); this.TryUpdateModel(model); if(ModelState.IsValid) { Menu menu=AdminRepository.FindMenu(model.MenuID); if(menu==null) { menu=new Menu(); } menu.DisplayName=model.DisplayName; menu.ParentMenuID=model.ParentMenuID; menu.URL=model.URL; menu.Title=model.Title; IEnumerable<ErrorInfo> errorInfo=AdminRepository.SaveMenu(menu); if(errorInfo!=null) { resultModel.Result+=ValidationHelper.GetErrorInfo(errorInfo); } else { // Remove entity menu cache cacheManager.RemoveByPattern(MenuHelper.ENTITYMENUKEY); resultModel.Result="True||"+menu.MenuID; } } else { foreach(var values in ModelState.Values.ToList()) { foreach(var err in values.Errors.ToList()) { if(string.IsNullOrEmpty(err.ErrorMessage)==false) { resultModel.Result+=err.ErrorMessage+"\n"; } } } } return View("Result",resultModel); }
public ActionResult UpdateEntityMenuSortOrder(FormCollection collection) { ICacheManager cacheManager=new MemoryCacheManager(); ResultModel resultModel=new ResultModel(); int entityMenuID=0; int alterEntityMenuID=0; int.TryParse(collection["entityMenuID"],out entityMenuID); int.TryParse(collection["alterEntityMenuID"],out alterEntityMenuID); EntityMenu entityMenu=AdminRepository.FindEntityMenu(entityMenuID); EntityMenu alterEntityMenu=AdminRepository.FindEntityMenu(alterEntityMenuID); IEnumerable<ErrorInfo> errorInfo=null; if(entityMenu!=null&&alterEntityMenu!=null) { int entityMenuSortOrder=entityMenu.SortOrder; int alterEntityMenuSortOrder=alterEntityMenu.SortOrder; entityMenu.SortOrder=alterEntityMenuSortOrder; alterEntityMenu.SortOrder=entityMenuSortOrder; AdminRepository.SaveEntityMenu(entityMenu); AdminRepository.SaveEntityMenu(alterEntityMenu); } if(errorInfo!=null) { resultModel.Result+=ValidationHelper.GetErrorInfo(errorInfo); } else { // Remove entity menu cache cacheManager.RemoveByPattern(string.Format(MenuHelper.ENTITYMENUKEY,entityMenu.EntityID)); resultModel.Result="True||"+entityMenu.EntityMenuID; } return View("Result",resultModel); }
public ActionResult UpdateEntityMenu(FormCollection collection) { ICacheManager cacheManager=new MemoryCacheManager(); EditEntityMenuModel model=new EditEntityMenuModel(); ResultModel resultModel=new ResultModel(); this.TryUpdateModel(model); //string ErrorMessage = EntityMenuAvailable(model.DisplayName, model.EntityMenuID); //if (String.IsNullOrEmpty(ErrorMessage) == false) { // ModelState.AddModelError("DisplayName", ErrorMessage); //} if(ModelState.IsValid) { EntityMenu entityMenu=AdminRepository.FindEntityMenu(model.EntityMenuID); if(entityMenu==null) { entityMenu=new EntityMenu(); } entityMenu.DisplayName=model.DisplayName; entityMenu.MenuID=model.MenuID; entityMenu.EntityID=Authentication.CurrentEntity.EntityID; IEnumerable<ErrorInfo> errorInfo=AdminRepository.SaveEntityMenu(entityMenu); if(errorInfo!=null) { resultModel.Result+=ValidationHelper.GetErrorInfo(errorInfo); } else { // Remove entity menu cache cacheManager.RemoveByPattern(string.Format(MenuHelper.ENTITYMENUKEY,entityMenu.EntityID)); resultModel.Result="True||"+entityMenu.EntityMenuID; } } else { foreach(var values in ModelState.Values.ToList()) { foreach(var err in values.Errors.ToList()) { if(string.IsNullOrEmpty(err.ErrorMessage)==false) { resultModel.Result+=err.ErrorMessage+"\n"; } } } } return View("Result",resultModel); }
public ActionResult UpdateEntity(FormCollection collection) { ICacheManager cacheManager=new MemoryCacheManager(); ENTITY model=new ENTITY(); ResultModel resultModel=new ResultModel(); this.TryUpdateModel(model); bool isNewEntity=false; string ErrorMessage=EntityNameAvailable(model.EntityName,model.EntityID); if(String.IsNullOrEmpty(ErrorMessage)==false) { ModelState.AddModelError("EntityName",ErrorMessage); } ErrorMessage=EntityCodeAvailable(model.EntityCode,model.EntityID); if(String.IsNullOrEmpty(ErrorMessage)==false) { ModelState.AddModelError("EntityCode",ErrorMessage); } if(ModelState.IsValid) { ENTITY entity=AdminRepository.FindEntity(model.EntityID); if(entity==null) { entity=new ENTITY(); entity.CreatedDate=DateTime.Now; isNewEntity=true; } entity.EntityName=model.EntityName; entity.EntityCode=model.EntityCode; entity.Enabled=model.Enabled; IEnumerable<ErrorInfo> errorInfo=AdminRepository.SaveEntity(entity); if(errorInfo!=null) { resultModel.Result+=ValidationHelper.GetErrorInfo(errorInfo); } else { resultModel.Result="True||"+entity.EntityID; // Create default user if(isNewEntity) { string username="******"; string password="******"; string firstname="admin"; string lastname="admin"; string email="*****@*****.**"; USER user=new USER(); user.Login=username; user.PasswordSalt=SecurityExtensions.CreateSalt(); user.PasswordHash=password.CreateHash(user.PasswordSalt); user.Email=email; user.FirstName=firstname; user.LastName=lastname; user.EntityID=entity.EntityID; user.CreatedDate=DateTime.Now; user.LastUpdatedDate=DateTime.Now; user.Enabled=true; user.IsAdmin=true; AdminRepository.SaveUser(user); } } // Create entity menu if(AdminRepository.GetEntityMenuCount(entity.EntityID)<=0) { AdminRepository.SaveEntityMenu(entity.EntityID); // Remove entity menu cache cacheManager.RemoveByPattern(string.Format(MenuHelper.ENTITYMENUKEY,entity.EntityID)); } } else { foreach(var values in ModelState.Values.ToList()) { foreach(var err in values.Errors.ToList()) { if(string.IsNullOrEmpty(err.ErrorMessage)==false) { resultModel.Result+=err.ErrorMessage+"\n"; } } } } return View("Result",resultModel); }