コード例 #1
0
 public string GetValue(string key)
 {
     try
     {
         var entityModelFactory = new EntityModelFactory();
         entityModelFactory.ConnectionString = ConnectionString;
         var entityModels = entityModelFactory.GetEntityModels <EntityModel>(tmpUserCacheTableName, $"select * from {tmpUserCacheTableName} where `key`='{key}'", "id");
         if (entityModels != null && entityModels.Any())
         {
             foreach (var item in entityModels)
             {
                 return(item["value"].ToString());
             }
             return(null);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
コード例 #2
0
 public static bool StaticSetValue(string value, string key)
 {
     try
     {
         var entityModelFactory = new EntityModelFactory();
         entityModelFactory.ConnectionString = ConnectionString;
         var entityModels = entityModelFactory.GetEntityModels <EntityModel>(tmpUserCacheTableName, $"select * from {tmpUserCacheTableName} where `key`='{key}';", "id");
         if (entityModels != null && entityModels.Any() && entityModels.Count > 0)
         {
             foreach (var item in entityModels)
             {
                 if (item["key"].ToString() == key)
                 {
                     item["value"] = value;
                     item.SaveChange("value");
                 }
             }
             return(true);
         }
         else
         {
             var entityModel = new EntityModel();
             entityModel.ConnectionString = ConnectionString;
             entityModel.EntityName       = tmpUserCacheTableName;
             entityModel.PrimaryKey       = new KeyValuePair <string, object>("id", Guid.NewGuid());
             entityModel.Add("key", key);
             entityModel.Add("value", value);
             return(entityModelFactory.AddEntityModel(entityModel));
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
コード例 #3
0
 public Dictionary <string, object> GetAll()
 {
     try
     {
         var entityModelFactory = new EntityModelFactory();
         entityModelFactory.ConnectionString = ConnectionString;
         var entityModels = entityModelFactory.GetEntityModels <EntityModel>(tmpUserCacheTableName, $"select * from {tmpUserCacheTableName}", "id");
         if (entityModels != null && entityModels.Any())
         {
             var dictionary = new Dictionary <string, object>();
             foreach (var item in entityModels)
             {
                 dictionary.Add(item["key"].ToString(), Json2KeyValue.JsonConvert.DeserializeObject <UserInfo>(item["value"].ToString()));
             }
             return(dictionary);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
コード例 #4
0
 public bool Contains(string key)
 {
     try
     {
         var entityModelFactory = new EntityModelFactory();
         entityModelFactory.ConnectionString = ConnectionString;
         var entityModels = entityModelFactory.GetEntityModels <EntityModel>(tmpUserCacheTableName, $"select * from {tmpUserCacheTableName} where `key`='{key}'", "id");
         if (entityModels != null && entityModels.Any())
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }