Example #1
0
 private string GetJson(MDataColumn mdc)
 {
     JsonHelper js = new JsonHelper();
     foreach (var cell in mdc)
     {
         js.Add("Key", cell.ColumnName);
         js.Add("Value", cell.ColumnName);
         js.AddBr();
     }
     return js.ToString(true);
 }
Example #2
0
 /// <summary>
 /// 返回Json格式的结果信息
 /// </summary>
 public static string OutResult(bool result, string msg, params Dictionary<string, object>[] otherKeyValues)
 {
     JsonHelper js = new JsonHelper(false, false);
     js.Add("success", result.ToString().ToLower(), true);
     js.Add("msg", msg);
     if (otherKeyValues.Length > 0)
     {
         string value = string.Empty;
         foreach (KeyValuePair<string, object> item in otherKeyValues[0])
         {
             if (item.Value != null)
             {
                 value = item.Value.ToString();
                 Type t = item.Value.GetType();
                 bool isValueType = t.IsValueType;
                 if (isValueType)
                 {
                     if (t.Name == "Boolean")
                     {
                         value = value.ToLower();
                     }
                 }
                 js.Add(item.Key, value, isValueType);
             }
         }
     }
     return js.ToString();
     /*
     StringBuilder sb = new StringBuilder();
     sb.Append("{");
     sb.Append("\"success\":" + result.ToString().ToLower() + ",");
     sb.Append("\"msg\":\"" + msg + "\"");
     if (otherKeyValues.Length > 0)
     {
         string value = string.Empty;
         foreach (KeyValuePair<string, object> item in otherKeyValues[0])
         {
             if (item.Value != null)
             {
                 value = item.Value.ToString();
                 Type t = item.Value.GetType();
                 bool isValueType = t.IsValueType;
                 if (isValueType)
                 {
                     if (t.Name == "Boolean")
                     {
                         value = value.ToLower();
                     }
                 }
                 sb.AppendFormat(",\"{0}\":{1}", item.Key, isValueType ? value : "\"" + value + "\"");
             }
         }
     }
     sb.Append("}");
     return sb.ToString();
      * */
 }
Example #3
0
 public string GetExcelMapping()
 {
     MDataRow row = ExcelConfig.GetExcelRow(Query<string>("ID"));
     string objName = row.Get<string>(Config_Excel.ExcelName);
     string[] TableNames = row.Get<string>(Config_Excel.TableNames).Split(',');
     Dictionary<string, string> dic = new Dictionary<string, string>();
     JsonHelper js = new JsonHelper();
     foreach (string name in TableNames)
     {
         MDataColumn mdc = DBTool.GetColumns(name);
         js.Add(name, GetJson(mdc), true);
         dic.Add(name, name);
     }
     JsonHelper jh = new JsonHelper();
     jh.Add("objName", objName);
     jh.Add("arrColumns", js.ToString(false));
     jh.Add("arrTables", MDataTable.CreateFrom(dic).ToJson(false, false));
     return jh.ToString();
 }
Example #4
0
        //End
        internal static void SetCache(AopEnum action, AopInfo aopInfo)
        {
            string baseKey = GetBaseKey(aopInfo);
            switch (action)
            {
                case AopEnum.ExeNonQuery:
                case AopEnum.Insert:
                case AopEnum.Update:
                case AopEnum.Delete:
                    if (aopInfo.IsSuccess || aopInfo.RowCount > 0)
                    {
                        ReadyForRemove(baseKey);
                    }
                    return;
            }

            //if (!IsCanOperateCache(baseKey))
            //{
            //    return;
            //}
            if (_MemCache.CacheType == CacheType.LocalCache && _MemCache.RemainMemoryPercentage < 15)//可用内存低于15%
            {
                return;
            }
            string key = GetKey(action, aopInfo, baseKey);
            int flag;//0 正常;1:未识别;2:不允许缓存
            SetBaseKeys(aopInfo, key, out flag);//存档Key,后续缓存失效 批量删除
            if (flag == 2)
            {
                return;//
            }
            double cacheTime = Math.Abs(12 - DateTime.Now.Hour) * 60 + DateTime.Now.Second;//缓存中午或到夜里1点
            if (flag == 1 || aopInfo.PageIndex > 2) // 后面的页数,缓存时间可以短一些
            {
                cacheTime = 2;//未知道操作何表时,只缓存2分钟(比如存储过程等语句)
            }
            switch (action)
            {
                case AopEnum.ExeMDataTableList:
                    if (IsCanCache(aopInfo.TableList))
                    {
                        JsonHelper js = new JsonHelper(false, false);
                        foreach (MDataTable table in aopInfo.TableList)
                        {
                            js.Add(table.TableName, table.ToJson(true, true, RowOp.IgnoreNull));
                        }
                        js.AddBr();
                        _MemCache.Set(key, js.ToString(), cacheTime);
                    }
                    break;
                case AopEnum.Select:
                case AopEnum.ExeMDataTable:
                    if (IsCanCache(aopInfo.Table))
                    {
                        _MemCache.Set(key, aopInfo.Table.ToJson(true, true, RowOp.IgnoreNull), cacheTime);
                    }
                    break;
                case AopEnum.ExeScalar:
                    _MemCache.Set(key, aopInfo.ExeResult, cacheTime);
                    break;
                case AopEnum.Fill:
                    _MemCache.Set(key, aopInfo.Row, cacheTime);
                    break;
                case AopEnum.GetCount:
                    _MemCache.Set(key, aopInfo.RowCount, cacheTime);
                    break;
            }
        }