Example #1
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T1"></typeparam>
 /// <typeparam name="T2"></typeparam>
 /// <typeparam name="T3"></typeparam>
 /// <typeparam name="T4"></typeparam>
 /// <param name="db"></param>
 /// <param name="sql"></param>
 /// <param name="map"></param>
 /// <param name="parameters"></param>
 /// <param name="splitOn"></param>
 /// <param name="getFromCache"></param>
 /// <returns></returns>
 public static IEnumerable <T1> Get <T1, T2, T3, T4>(this CRMDb db, string sql, Func <T1, T2, T3, T4, T1> map, object parameters = null, string splitOn = "Id", bool getFromCache = false, TimeSpan cacheInterval = default(TimeSpan),
                                                     CommandType commandType = CommandType.Text, int timeoutSeconds = 30)
 {
     try
     {
         var cache = new MemoryCacheManager();
         var key   = GetHashedKey(sql + parameters);
         if (getFromCache && cache.IsExists(key))
         {
             return(cache.Get <IEnumerable <T1> >(key));
         }
         var cs = getConnectionString(db);
         using (var _con = GetSqlConnection(cs))
         {
             _con.Open();
             var result = _con.Query <T1, T2, T3, T4, T1>(sql, map, parameters, splitOn: splitOn, commandType: commandType, commandTimeout: timeoutSeconds);
             return(AddToCache(key, result, cache, getFromCache, cacheInterval));
         }
     }
     catch (Exception ex)
     {
         parameters = (parameters == null) ? new object() : parameters;
         ex.Data.Clear();
         ex.Data.Add("parameters", new JavaScriptSerializer().Serialize(parameters));
         ex.Data.Add("sql", sql);
         Logger.Current.Error("Error while querying using dapper", ex);
         throw ex;
     }
 }
Example #2
0
        public static IEnumerable <dynamic> Get(this CRMDb db, string sql, object parameters = null, bool getFromCache = false, TimeSpan cacheInterval = default(TimeSpan))
        {
            try
            {
                var cache = new MemoryCacheManager();
                var key   = GetHashedKey(sql + parameters);
                if (getFromCache && cache.IsExists(key))
                {
                    return(cache.Get <IEnumerable <dynamic> >(key));
                }

                var cs = getConnectionString(db);
                using (var _con = GetSqlConnection(cs))
                {
                    _con.Open();
                    var result = _con.Query(sql, parameters);
                    return(AddToCache(key, result, cache, getFromCache, cacheInterval));
                }
            }
            catch (Exception ex)
            {
                parameters = (parameters == null) ? new object() : parameters;
                ex.Data.Clear();
                ex.Data.Add("parameters", new JavaScriptSerializer().Serialize(parameters));
                ex.Data.Add("sql", sql);
                Logger.Current.Error("Error while querying using dapper", ex);
                throw ex;
            }
        }
Example #3
0
        bool ICachingService.IsModulePrivate(AppModules module, int accountId)
        {
            string             cacheKey       = "datasharing" + accountId;
            IEnumerable <byte> privateModules = new List <byte>();

            if (!cacheManager.IsExists(cacheKey))
            {
                privateModules = accountRepository.GetPrivateModules(accountId);
                cacheManager.Add(cacheKey, privateModules, DateTimeOffset.MaxValue);
            }
            else
            {
                privateModules = cacheManager.Get <IEnumerable <byte> >(cacheKey);
            }
            return(privateModules.Contains((byte)module));
        }