public async Task <IViewComponentResult> InvokeAsync(ModuleDataComponent data) { _action = data.ModuleAction; _cacheEngine = data.CacheEngine; _module = data.Module; _page = data.Page; _requiredClaims = data.RequiredClaims; // Check module rights if (!HasRequiredClaim() || !ValidViewComponentRights()) { return(Content(string.Empty)); } if (HttpContext.Request.QueryString.HasValue) { LoadQueryString(); } switch (data.ModuleAction) { case ModuleActions.Add: return(await OnViewComponentLoad()); case ModuleActions.Update: return(await OnViewComponentUpdate()); case ModuleActions.Delete: return(await OnViewComponentDelete()); default: return(await OnViewComponentLoad()); } }
public PageController(IViewManager viewManager, CacheEngine cacheEngine, IViewComponentDescriptorCollectionProvider viewcomponents, IParameterManager parameterManager) : base(viewManager, cacheEngine, viewcomponents, parameterManager) { }
public void AddCacheWithOneParameter() { var cache = new CacheEngine(new MemoryCacheProvider()); Assert.Equal("Banana", cache.Get(() => OneParameterMethod("banana"))); Assert.Equal("Banana", MemoryCache.Default[cache.BuildKey(() => OneParameterMethod("banana"))]); Assert.Equal("Banana", cache.Get(() => OneParameterMethod("banana"))); }
public void BuildKeyWithClassParameter() { var cache = new CacheEngine(new MemoryCacheProvider()); Assert.Equal("CacheHelper.Core.Tests.CacheEngineTests.ClassParameterMethod_System.Int32_1_System.String_Fredrik", cache.BuildKey(() => ClassParameterMethod(new Test { Id = 1, Name = "Fredrik" }))); }
public void AddCacheWithEnumParameter() { var cache = new CacheEngine(new MemoryCacheProvider()); Assert.Equal("apa", cache.Get(() => OneEnumParameterMethod(EnumTest.Apa))); Assert.Equal("apa", MemoryCache.Default[cache.BuildKey(() => OneEnumParameterMethod(EnumTest.Apa))]); Assert.Equal("apa", cache.Get(() => OneEnumParameterMethod(EnumTest.Apa))); }
public void AddCacheWithNoParameter() { var cache = new CacheEngine(new MemoryCacheProvider()); Assert.Equal("This is a test!", cache.Get(() => NoParameterMethod())); Assert.Equal("This is a test!", MemoryCache.Default[cache.BuildKey(() => NoParameterMethod())]); Assert.Equal("This is a test!", cache.Get(() => NoParameterMethod())); }
public void KeyNotFoundInt() { var cache = new CacheEngine(new MemoryCacheProvider()); Assert.Equal(10, cache.Get(() => KeyNotFoundIntMethod())); Assert.Equal(10, MemoryCache.Default[cache.BuildKey(() => KeyNotFoundIntMethod())]); Assert.Equal(10, cache.Get(() => KeyNotFoundIntMethod())); }
public void BuildKeyForMethodsWithOverride() { var cache = new CacheEngine(new MemoryCacheProvider()); var f = cache.BuildKey(() => OvverrideTest1(1)); var s = cache.BuildKey(() => OvverrideTest1("1")); Assert.NotEqual(f, s); }
public void AddCacheWithMultipleParameter() { var cache = new CacheEngine(new MemoryCacheProvider()); Assert.Equal("CARROT & POTATO", cache.Get(() => MultipleParameterMethod("carrot", "potato"))); Assert.Equal("CARROT & POTATO", MemoryCache.Default[cache.BuildKey(() => MultipleParameterMethod("carrot", "potato"))]); Assert.Equal("CARROT & POTATO", cache.Get(() => MultipleParameterMethod("carrot", "potato"))); }
public void BuildKeyWithTwoParameter() { var cache = new CacheEngine(new MemoryCacheProvider()); Assert.Equal("CacheHelper.Core.Tests.CacheEngineTests.TwoParameterMethod_System.Int32_1_System.String_Fredrik1_CacheHelper.Core.Tests.CacheEngineTests+EnumTest:Apa", cache.BuildKey(() => TwoParameterMethod(new Test { Id = 1, Name = "Fredrik1" }, EnumTest.Apa))); }
public void AddCacheWithNoParameterAndSetExpires() { var cache = new CacheEngine(new MemoryCacheProvider()); cache.Get(() => NoParameterMethod(), TimeSpan.FromMilliseconds(200)); Assert.NotNull(MemoryCache.Default[cache.BuildKey(() => NoParameterMethod())]); Thread.Sleep(250); Assert.Null(MemoryCache.Default[cache.BuildKey(() => NoParameterMethod())]); }
public SiteConfigurationController(CacheEngine cacheEngine, IParameterManager parametermanager, IWebHostEnvironment hostingEnvironment, IEmailSender emailSender, IEmailManager emailManager) { _cacheEngine = cacheEngine; _parameterManager = parametermanager; _hostingEnvironment = hostingEnvironment; _emailSender = emailSender; _emailManager = emailManager; }
public TemplateController(IViewManager viewManager, CacheEngine cacheEngine, IViewComponentDescriptorCollectionProvider viewcomponents, IParameterManager parameterManager) { _viewManager = viewManager; _cacheEngine = cacheEngine; _viewcomponents = viewcomponents; _parameterManager = parameterManager; }
public MailAutoreplyData UpdateAutoreply(int mailboxId, bool turnOn, bool onlyContacts, bool turnOnToDate, DateTime fromDate, DateTime toDate, string subject, string html) { var result = MailEngineFactory .AutoreplyEngine .SaveAutoreply(mailboxId, turnOn, onlyContacts, turnOnToDate, fromDate, toDate, subject, html); CacheEngine.Clear(Username); return(result); }
protected override void OnAttached(string name, IServerPart part) { switch (name) { case PartNames.Cache: _cacheEngine = (CacheEngine)part; break; default: throw new NotImplementedException($"Unknown part: '{name}'"); } }
public void AddCacheWithExpiry() { var cache = new CacheEngine(new MemoryCacheProvider()); Assert.Equal("This is a test!", cache.Get(() => NoParameterMethod(), TimeSpan.FromMilliseconds(200))); Thread.Sleep(100); Assert.NotEqual(null, MemoryCache.Default[cache.BuildKey(() => NoParameterMethod())]); Assert.Equal("This is a test!", cache.Get(() => NoParameterMethod(), TimeSpan.FromMilliseconds(200))); Thread.Sleep(100); Assert.Equal(null, MemoryCache.Default[cache.BuildKey(() => NoParameterMethod())]); Assert.Equal("This is a test!", cache.Get(() => NoParameterMethod(), TimeSpan.FromMilliseconds(200))); Assert.NotEqual(null, MemoryCache.Default[cache.BuildKey(() => NoParameterMethod())]); }
public ActionResult Index() { const string key = "books"; var books = CacheEngine.Get <List <Book> >(key); if (books == null) { books = BookData.GetBooks(); CacheEngine.Add(key, books); } ViewBag.books = books; return(View()); }
/// <summary> /// Get element(s) from cache /// </summary> /// <typeparam name="T"></typeparam> /// <param name="cacheKey"></param> /// <param name="action"></param> /// <returns></returns> protected T GetFromCache <T>(string cacheKey, Action action) { T output = default(T); if (CacheEngine.Exists(cacheKey)) { output = CacheEngine.Get <T>(cacheKey); } else { action(); } return(output); }
protected override void Do() { try { SetProgress((int?)MailOperationRemoveMailboxProgress.Init, "Setup tenant and user"); var tenant = _mailBox.TenantId; var user = _mailBox.UserId; CoreContext.TenantManager.SetCurrentTenant(tenant); try { SecurityContext.AuthenticateMe(new Guid(user)); } catch { // User was removed SecurityContext.AuthenticateMe(ASC.Core.Configuration.Constants.CoreSystem); } SetProgress((int?)MailOperationRemoveMailboxProgress.RemoveFromDb, "Remove mailbox from Db"); var engine = new EngineFactory(tenant); engine.ServerMailboxEngine.RemoveMailbox(_mailBox); SetProgress((int?)MailOperationRemoveMailboxProgress.RecalculateFolder, "Recalculate folders counters"); engine.OperationEngine.RecalculateFolders(); SetProgress((int?)MailOperationRemoveMailboxProgress.ClearCache, "Clear accounts cache"); CacheEngine.Clear(user); SetProgress((int?)MailOperationRemoveMailboxProgress.RemoveIndex, "Remove Elastic Search index by messages"); engine.IndexEngine.Remove(_mailBox); } catch (Exception e) { Logger.Error("Mail operation error -> Remove mailbox: {0}", e); Error = "InternalServerError"; } }
static void Main(string[] args) { const string key = "books"; var books = CacheEngine.Get <List <Book> >(key); if (books == null) { books = BookData.GetBooks(); CacheEngine.Add(key, books); } var cachedBooks = CacheEngine.Get <List <Book> >(key); foreach (var book in books) { System.Console.WriteLine(book.Name); } System.Console.ReadKey(); }
protected override void Do() { try { SetProgress((int?)MailOperationRemoveMailboxProgress.Init, "Setup tenant and user"); CoreContext.TenantManager.SetCurrentTenant(CurrentTenant); SecurityContext.AuthenticateMe(CurrentUser); var engine = new EngineFactory(_mailBoxData.TenantId, _mailBoxData.UserId); SetProgress((int?)MailOperationRemoveMailboxProgress.RemoveFromDb, "Remove mailbox from Db"); var freedQuotaSize = engine.MailboxEngine.RemoveMailBoxInfo(_mailBoxData); SetProgress((int?)MailOperationRemoveMailboxProgress.FreeQuota, "Decrease newly freed quota space"); engine.QuotaEngine.QuotaUsedDelete(freedQuotaSize); SetProgress((int?)MailOperationRemoveMailboxProgress.RecalculateFolder, "Recalculate folders counters"); engine.FolderEngine.RecalculateFolders(); SetProgress((int?)MailOperationRemoveMailboxProgress.ClearCache, "Clear accounts cache"); CacheEngine.Clear(_mailBoxData.UserId); SetProgress((int?)MailOperationRemoveMailboxProgress.RemoveIndex, "Remove Elastic Search index by messages"); engine.IndexEngine.Remove(_mailBoxData); SetProgress((int?)MailOperationRemoveMailboxProgress.Finished); } catch (Exception e) { Logger.ErrorFormat("Mail operation error -> Remove mailbox: {0}", e.ToString()); Error = "InternalServerError"; } }
protected override void Do() { try { SetProgress((int?)MailOperationRemoveDomainProgress.Init, "Setup tenant and user"); CoreContext.TenantManager.SetCurrentTenant(CurrentTenant); try { SecurityContext.AuthenticateMe(CurrentUser); } catch { // User was removed SecurityContext.AuthenticateMe(ASC.Core.Configuration.Constants.CoreSystem); } SetProgress((int?)MailOperationRemoveDomainProgress.RemoveFromDb, "Remove domain from Db"); var tenant = CurrentTenant.TenantId; var mailboxes = new List <MailBoxData>(); var engine = new EngineFactory(tenant); using (var db = new DbManager(Defines.CONNECTION_STRING_NAME, Defines.RemoveDomainTimeout)) { var daoFactory = new DaoFactory(db); using (var tx = daoFactory.DbManager.BeginTransaction(IsolationLevel.ReadUncommitted)) { var serverGroupDao = daoFactory.CreateServerGroupDao(tenant); var serverAddressDao = daoFactory.CreateServerAddressDao(tenant); var groups = serverGroupDao.GetList(_domain.Id); foreach (var serverGroup in groups) { serverAddressDao.DeleteAddressesFromMailGroup(serverGroup.Id); serverAddressDao.Delete(serverGroup.AddressId); serverGroupDao.Delete(serverGroup.Id); } var serverAddresses = serverAddressDao.GetDomainAddresses(_domain.Id); var serverMailboxAddresses = serverAddresses.Where(a => a.MailboxId > -1 && !a.IsAlias); foreach (var serverMailboxAddress in serverMailboxAddresses) { var mailbox = engine.MailboxEngine.GetMailboxData( new ConcreteTenantServerMailboxExp(serverMailboxAddress.MailboxId, tenant, false)); if (mailbox == null) { continue; } mailboxes.Add(mailbox); engine.MailboxEngine.RemoveMailBox(daoFactory, mailbox, false); } serverAddressDao.Delete(serverAddresses.Select(a => a.Id).ToList()); var serverDomainDao = daoFactory.CreateServerDomainDao(tenant); serverDomainDao.Delete(_domain.Id); var serverDao = daoFactory.CreateServerDao(); var server = serverDao.Get(tenant); var serverEngine = new Server.Core.ServerEngine(server.Id, server.ConnectionString); serverEngine.RemoveDomain(_domain.Name); tx.Commit(); } } SetProgress((int?)MailOperationRemoveDomainProgress.ClearCache, "Clear accounts cache"); CacheEngine.ClearAll(); SetProgress((int?)MailOperationRemoveDomainProgress.RemoveIndex, "Remove Elastic Search index by messages"); foreach (var mailbox in mailboxes) { engine.IndexEngine.Remove(mailbox); } } catch (Exception e) { Logger.Error("Mail operation error -> Remove mailbox: {0}", e); Error = "InternalServerError"; } }
public void BuildKeyWithReferenceToNonMethod() { var cache = new CacheEngine(new MemoryCacheProvider()); Assert.Throws <ExpressionBodyNotSupported>(() => cache.BuildKey(() => "asd")); }
public void BuildRegularKey() { var cache = new CacheEngine(new MemoryCacheProvider()); Assert.Equal("test", cache.BuildKey("test")); }
public void BuildKeyWithNoParameter() { var cache = new CacheEngine(new MemoryCacheProvider()); Assert.Equal("CacheHelper.Core.Tests.CacheEngineTests.NoParameterMethod", cache.BuildKey(() => NoParameterMethod())); }
public void BuildKeyWithOneParameter() { var cache = new CacheEngine(new MemoryCacheProvider()); Assert.Equal("CacheHelper.Core.Tests.CacheEngineTests.OneParameterMethod_System.String:carrot", cache.BuildKey(() => OneParameterMethod("carrot"))); }
public void BuildKeyWithMultipleParameter() { var cache = new CacheEngine(new MemoryCacheProvider()); Assert.Equal("CacheHelper.Core.Tests.CacheEngineTests.MultipleParameterMethod_System.String:test1_System.Int32:1_System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]:2", cache.BuildKey(() => MultipleParameterMethod("test1", 1, 2))); }
public void BuildKeyWithOneEnumParameter() { var cache = new CacheEngine(new MemoryCacheProvider()); Assert.Equal("CacheHelper.Core.Tests.CacheEngineTests.OneEnumParameterMethod_CacheHelper.Core.Tests.CacheEngineTests+EnumTest:Apa", cache.BuildKey(() => OneEnumParameterMethod(EnumTest.Apa))); }
public StatisticsManager(KastraDbContext dbContext, CacheEngine cacheEngine) { _dbContext = dbContext; _cacheEngine = cacheEngine; }
public void BuildRegularKeyWithParameters() { var cache = new CacheEngine(new MemoryCacheProvider()); Assert.Equal("test_carrot_potato", cache.BuildKey("test", "carrot", "potato")); }