/// <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())); }
/// <summary> /// 执行方法前先执行这 /// </summary> /// <param name="context"></param> public override void OnActionExecuting(ActionExecutingContext context) { base.OnActionExecuting(context); try { string Moudle = String.Format("接收[{0}-{1}]请求 {2}", MoudleName, MethodName, context.ActionDescriptor.DisplayName); string RequestAddress = String.Format("RequestAddress: {0}:{1}", context.HttpContext.Connection.RemoteIpAddress.ToString(), context.HttpContext.Connection.RemotePort.ToString()); string URL = String.Format("uri: {0}", context.HttpContext.Request.Path.Value.ToString()); string method = String.Format("method: {0}", context.HttpContext.Request.Method.ToString()); string contentType = String.Format("contentType: {0}", context.HttpContext.Request.ContentType == null ? "null" : context.HttpContext.Request.ContentType.ToString()); string parameter = String.Format("parameter: {0}", JsonConvert.SerializeObject(context.ActionArguments)); StringBuilder message = new StringBuilder(); message.AppendLine(Moudle); message.AppendLine(RequestAddress); message.AppendLine(URL); message.AppendLine(method); message.AppendLine(contentType); message.AppendLine(parameter); LogAgent.Info(message.ToString()); CounterToken counterToken = LogAgent.StartCounter(); context.ActionDescriptor.Properties.TryAdd("Action-" + context.HttpContext.TraceIdentifier, counterToken); } catch (Exception ex) { LogAgent.Error(ex.ToString()); } }
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); }
/// <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()); } }
private void Release(CounterToken token) { ((ManualResetEvent)this.inUseEvents[token.Index]).Reset(); ((ManualResetEvent)this.freeEvents[token.Index]).Set(); }
public static TimeSpan Stop(this CounterToken counterToken) { return(LogAgent.StopCounter(counterToken)); }
public static void StopAndLog(this CounterToken counterToken, string msg, LogLevel level = LogLevel.Info) { LogAgent.StopCounterAndLog(counterToken, msg, level); }