public async Task <EmailAccount> CreateAsync(EmailAccount entity, EmbeddedUser embeddedUser, string ip)
        {
            await _emailAccounts.CreateAsync(entity);

            if (entity.IsDefault)
            {
                _memoryCacheService.Remove(DefaultEmailAccount);
            }

            // Activity Log.
            await _activityLogService.CreateAsync(SystemKeyword.CreateEmailAccount, entity, embeddedUser, ip);

            return(entity);
        }
예제 #2
0
        private void AddFriendInCache(Friend newFriend)
        {
            var friends = GetCollectionInCache();

            friends.Add(newFriend);

            InMemoryCacheService.Remove(CacheKey);

            InMemoryCacheService.Insert(CacheKey, friends);
        }
        public void BeforeInvoke(InvocationContext invocationContext)
        {
            _memoryCacheAttribute = invocationContext.GetAttributeFromMethod<MemoryCacheAttribute>();
            var cacheKey = _memoryCacheAttribute.CacheKey;
            var cacheConfig = _cacheConfigFactory.Config[cacheKey];
            if (cacheConfig.Enabled)
            {
                if (!string.IsNullOrWhiteSpace(_memoryCacheAttribute.CacheKeyParameterSubstitutions))
                {
                    List<object> paramValues = new List<object>();
                    string[] paramNames = _memoryCacheAttribute.CacheKeyParameterSubstitutions.Split(",", StringSplitOptions.RemoveEmptyEntries);
                    foreach (string paramName in paramNames)
                    {
                        paramValues.Add(invocationContext.GetParameterValue(paramName.Trim()));

                    }
                    cacheKey = string.Format(cacheConfig.CacheKey.ToString(), paramValues.ToArray());

                }
                CacheKey = cacheKey;

                if (_memoryCacheAttribute.RefreshCache)
                {
                    _memoryCacheService.Remove(CacheKey);
                }

                var cacheReturnObj = RetrieveCacheEntry(invocationContext, CacheKey);
                if (cacheReturnObj != null && cacheReturnObj.CacheEntry != null)
                {
                    var returnType = invocationContext.GetMethodReturnType();
                    var isAsyncMethod = returnType != null && returnType.IsGenericType &&
                        returnType.GetGenericTypeDefinition() == typeof(Task<>);
                    if (isAsyncMethod)
                    {
                        invocationContext.OverrideAsyncMethodReturnValue(cacheReturnObj.CacheEntry);
                    }
                    else
                    {
                        invocationContext.OverrideMethodReturnValue(cacheReturnObj.CacheEntry);
                    }

                    invocationContext.TempData[CacheConstants.LOGGING_CACHE_INVOCATIONCONETXT] = string.Format(
                        "{0}{1}{2}", CacheConstants.LOGGING_CACHE_HIT, CacheConstants.LOGGING_CACHE_DELIMITER, cacheKey);
                    invocationContext.BypassInvocation();
                }
                else
                {
                    invocationContext.TempData[CacheConstants.LOGGING_CACHE_INVOCATIONCONETXT] = string.Format(
                           "{0}{1}{2}", CacheConstants.LOGGING_CACHE_MISS, CacheConstants.LOGGING_CACHE_DELIMITER, cacheKey);
                }

            }
        }
        public async Task <bool> UpdateLogTypeAsync(string id, bool enabled)
        {
            var update = Builders <ActivityLogType> .Update
                         .Set(e => e.Enabled, enabled);

            var result = await _dbContext.ActivityLogTypes.UpdatePartiallyAsync(id, update);

            if (result)
            {
                _memoryCacheService.Remove(EnabledActivityLogTypes);
            }

            return(result);
        }
        /// <summary>
        /// Add entry into the configuration.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <param name="value">value to use.</param>
        /// <returns>boolean of success/failure.</returns>
        public bool Add(IConfigItem configItem)
        {
            if (_memoryCacheService.Contains(configItem.key))
            {
                throw new DuplicateKeyException(string.Format("Configuration key already exists {0}", configItem.key));
            }

            if (Monitor.TryEnter(_lockObject))
            {
                try
                {
                    Thread.Sleep(5000);

                    _memoryCacheService.Add(configItem);
                    _fileManager.AddEntry(configItem);
                }
                catch (Exception e)
                {
                    if (_memoryCacheService.Contains(configItem.key))
                    {
                        _memoryCacheService.Remove(configItem.key);
                    }

                    throw new ConfigAddException(string.Format("Configuration add failed for key {0}", configItem.key));
                }
                finally
                {
                    Monitor.Exit(_lockObject);
                }
            }
            else
            {
                throw new ResourceLockedException(string.Format("Resource locked while adding config item {0}", configItem.key));
            }

            return(true);
        }
        public static void StoreCacheObject(T data, IMemoryCacheService cacheObj,
                                            CacheConfig config, string cacheKey)
        {
            if (!config.Enabled)
            {
                return;
            }

            var dataToCache = new Cacheable <T>
            {
                TTL   = DateTime.Now.AddMinutes(config.TimeToLiveMinutes),
                Model = data
            };

            try
            {
                cacheObj.Remove(cacheKey);
                cacheObj.Put(cacheKey, dataToCache);
            }
            catch (Exception ex)
            {
                // LOG
            }
        }
예제 #7
0
        public override async Task UpdateAsync(ActivityLogType entity)
        {
            await base.UpdateAsync(entity);

            _memoryCacheService.Remove(EnabledActivityLogTypesKey);
        }