Beispiel #1
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Delete(int id)
        {
            var          type         = typeof(TInterface);
            CounterToken counterToken = LogAgent.StartCounter();
            var          tablename    = PropertiesHelper.Instance().GetTableName(type);

            if (string.IsNullOrEmpty(tablename))
            {
                return(-1);
            }
            var sbColumnList  = new List <string>();
            var WhereList     = new List <string>();
            var ParaList      = new List <DbParameter>();
            var KeyProperties = PropertiesHelper.Instance().GetKeyProperties(type);

            foreach (var item in KeyProperties)
            {
                WhereList.Add(string.Format("{0}=@{0}", item.Name));
                ParaList.Add(DbFactory.Instance().CreateDataParameter(string.Format("@{0}", item.Name), id));
            }
            var sSQL = string.Format("Delete from {0} WHERE {1};", tablename, string.Join("AND", WhereList.ToArray()));

            LogAgent.StopCounterAndLog(counterToken, "[CreateSQL]-Delete:");
            return(RepositoryHelper.ExecuteNonQuery(CommandType.Text, sSQL, ParaList.ToArray()));
        }
Beispiel #2
0
 public static string Value()
 {
     if (string.IsNullOrEmpty(fingerPrint))
     {
         CounterToken counterToken = LogAgent.StartCounter();
         string       newValue     = RegistryUtil.GetRegeditkeyValue(LicenseConstData.KeyRegistyPath, LicenseConstData.MacCodeKey);
         if (string.IsNullOrEmpty(newValue))
         {
             string cpuId  = CpuId();
             string biosId = BiosId();
             string baseId = BaseId();
             fingerPrint = GetHash(
                 "\nCPU >> " + cpuId +
                 "\nBIOS >> " + biosId
                 + "\nBASE >> " + baseId
                 );
             RegistryUtil.SetSecurityLey(fingerPrint, LicenseConstData.KeyRegistyPath, LicenseConstData.MacCodeKey);
             LogAgent.Info("CPU:" + cpuId + ";BIOS:" + biosId + ";BASE:" + baseId);
         }
         else
         {
             fingerPrint = newValue;
         }
         LogAgent.StopCounterAndLog(counterToken, "SystemUtil.Value:" + fingerPrint + " " + newValue);
     }
     return(fingerPrint);
 }
Beispiel #3
0
        /// <summary>
        /// 更新方法
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Update(TInterface entity)
        {
            if (!(entity is TRealType))
            {
                return(0);
            }
            CounterToken counterToken = LogAgent.StartCounter();
            var          type         = typeof(TInterface);
            var          tablename    = PropertiesHelper.Instance().GetTableName(type);

            if (string.IsNullOrEmpty(tablename))
            {
                return(-1);
            }
            var sbColumnList     = new List <string>();
            var sbWhereList      = new List <string>();
            var ParaList         = new List <DbParameter>();
            var AllProperties    = PropertiesHelper.Instance().GetAllProperties(type);
            var KeyProperties    = PropertiesHelper.Instance().GetKeyProperties(type);
            var ignoreProperties = PropertiesHelper.Instance().GetIgnoreProperties(type);
            var AllPropertiesExceptKeyAndIgnore = AllProperties.Except(KeyProperties).Except(ignoreProperties);

            //动态生成sql语句
            foreach (var item in AllPropertiesExceptKeyAndIgnore)
            {
                object value = item.GetValue(entity, null);
                sbColumnList.Add(string.Format("{0}=@{0}", item.Name));
                ParaList.Add(DbFactory.Instance().CreateDataParameter(string.Format("@{0}", item.Name), item.GetValue(entity, null)));
                //if (value != null)
                //{
                // }
            }
            //where条件
            foreach (var item in KeyProperties)
            {
                sbWhereList.Add(string.Format("{0}=@{0}", item.Name));
                ParaList.Add(DbFactory.Instance().CreateDataParameter(string.Format("@{0}", item.Name), item.GetValue(entity)));
            }
            var sSQL = string.Format("Update {0} Set {1} WHERE {2};", tablename,
                                     string.Join(",", sbColumnList.ToArray()), string.Join(",", sbWhereList.ToArray()));

            LogAgent.StopCounterAndLog(counterToken, "[CreateSQL]-Update:");
            return(RepositoryHelper.ExecuteNonQuery(CommandType.Text, sSQL, ParaList.ToArray()));
        }
 /// <summary>
 /// 执行方法后执行这
 /// </summary>
 /// <param name="context"></param>
 public override void OnActionExecuted(ActionExecutedContext context)
 {
     base.OnActionExecuted(context);
     try
     {
         object obj    = null;
         bool   result = context.ActionDescriptor.Properties.TryGetValue("Action-" + context.HttpContext.TraceIdentifier, out obj);
         if (result && obj is CounterToken)
         {
             CounterToken counterToken = (CounterToken)obj;
             LogAgent.StopCounterAndLog(counterToken, String.Format("结束[{0}-{1}]请求{2}", MoudleName, MethodName, context.ActionDescriptor.DisplayName));
             return;
         }
     }
     catch (Exception ex)
     {
         LogAgent.Error(ex.ToString());
     }
 }
Beispiel #5
0
 public static void StopAndLog(this CounterToken counterToken, string msg, LogLevel level = LogLevel.Info)
 {
     LogAgent.StopCounterAndLog(counterToken, msg, level);
 }