//public Dictionary<string, bool> cacheByID<T, Dto>(oCachePostResult result, ICacheSynchronized<T, Dto> self) public Dictionary <string, bool> cacheByID(oCachePostResult result) { Dictionary <string, bool> dic = new Dictionary <string, bool>() { }; if (result.Ok) { if (!string.IsNullOrEmpty(result.ServiceArray) && !string.IsNullOrEmpty(result.KeyArray)) { try { string[] aService = result.ServiceArray.Split(','); long[] aKey = result.KeyArray.Split(',').Select(x => long.Parse(x)).ToArray(); string[] paths = _storeCache.Keys.ToArray(); oCacheReload[] ar = new oCacheReload[aKey.Length]; for (int i = 0; i < aKey.Length; i++) { ar[i] = new oCacheReload() { ModelName = aService[i], Id = aKey[i], CacheKey = paths.Where(x => x.StartsWith(aService[i] + "/")).SingleOrDefault() } } ; // Must be check store update output wrong ServiceName ar = ar.Where(x => !string.IsNullOrEmpty(x.CacheKey)).ToArray(); DynamicParameters param = null; string storeName; ICacheService cache = null; string ProjectCode = result.ProjectCode; if (string.IsNullOrEmpty(ProjectCode)) { ProjectCode = "f88m"; } using (IDbConnection cnn = new SqlConnection(_DB_CONST.get_connectString_Mobility())) { cnn.Open(); for (int i = 0; i < ar.Length; i++) { if (_storeClient.ContainsKey(ar[i].CacheKey)) { try { cache = _storeClient[ar[i].CacheKey]; param = new DynamicParameters(); param.Add("@id", ar[i].Id); storeName = string.Format("{0}_{1}_{2}", ProjectCode, ar[i].ModelName, "cacheByID"); dynamic obj = cnn.Query <dynamic>(storeName, param, commandType: CommandType.StoredProcedure); if (obj != null) { string jsonItem = JsonConvert.SerializeObject(obj); DB_ACTION_TYPE type = DB_ACTION_TYPE.DB_INSERT; switch (result.ActionType) { case "DB_INSERT": type = DB_ACTION_TYPE.DB_INSERT; break; case "DB_UPDATE": type = DB_ACTION_TYPE.DB_UPDATE; break; case "DB_REMOVE": type = DB_ACTION_TYPE.DB_REMOVE; break; } if (!string.IsNullOrEmpty(jsonItem)) { bool ok = cache.cacheUpdate(type, ar[i].Id, jsonItem); dic.Add(ar[i].ModelName, ok); } } } catch (Exception exx) { dic.Add(ar[i].ModelName, false); } } } } } catch (Exception ex) { } } } return(dic); }
public bool cacheUpdate(DB_ACTION_TYPE db_type, long id, string jsonItemArray) => _store.cacheUpdate(db_type, id, jsonItemArray);