diff --git a/OS.Common/Models/Enums/ResultTypes.cs b/OS.Common/ComModels/Enums/ResultTypes.cs
similarity index 88%
rename from OS.Common/Models/Enums/ResultTypes.cs
rename to OS.Common/ComModels/Enums/ResultTypes.cs
index 17f9ff6..7920c93 100644
--- a/OS.Common/Models/Enums/ResultTypes.cs
+++ b/OS.Common/ComModels/Enums/ResultTypes.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace OS.Common.Models.Enums
+namespace OS.Common.ComModels.Enums
{
public enum ResultTypes
{
diff --git a/OS.Common/Models/Enums/SortType.cs b/OS.Common/ComModels/Enums/SortType.cs
similarity index 86%
rename from OS.Common/Models/Enums/SortType.cs
rename to OS.Common/ComModels/Enums/SortType.cs
index 740476c..3411283 100644
--- a/OS.Common/Models/Enums/SortType.cs
+++ b/OS.Common/ComModels/Enums/SortType.cs
@@ -1,5 +1,5 @@
-namespace OS.Common.Models.Enums
+namespace OS.Common.ComModels.Enums
{
public enum SortType
{
diff --git a/OS.Common/Models/PageModel.cs b/OS.Common/ComModels/PageModel.cs
similarity index 98%
rename from OS.Common/Models/PageModel.cs
rename to OS.Common/ComModels/PageModel.cs
index 98bdd7a..fcbfc84 100644
--- a/OS.Common/Models/PageModel.cs
+++ b/OS.Common/ComModels/PageModel.cs
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
-using OS.Common.Models.Enums;
+using OS.Common.ComModels.Enums;
-namespace OS.Common.Models
+namespace OS.Common.ComModels
{
public static class SearchModelExtention
diff --git a/OS.Common/Models/ResultModel.cs b/OS.Common/ComModels/ResultModel.cs
similarity index 73%
rename from OS.Common/Models/ResultModel.cs
rename to OS.Common/ComModels/ResultModel.cs
index aa9d191..7765ebe 100644
--- a/OS.Common/Models/ResultModel.cs
+++ b/OS.Common/ComModels/ResultModel.cs
@@ -1,7 +1,7 @@
-using OS.Common.Models.Enums;
+using OS.Common.ComModels.Enums;
-namespace OS.Common.Models
+namespace OS.Common.ComModels
{
public class ResultModel
{
@@ -10,7 +10,6 @@ namespace OS.Common.Models
///
public ResultModel()
{
-
}
@@ -21,8 +20,8 @@ namespace OS.Common.Models
///
public ResultModel(int ret=200, string message = "")
{
- this._ret = ret;
- this.message = message;
+ Ret = ret;
+ Message = message;
}
@@ -33,13 +32,11 @@ namespace OS.Common.Models
///
public ResultModel(ResultTypes ret = ResultTypes.Success, string message = "")
{
- this._ret = (int) ret;
- this.message = message;
+ this.Ret = (int) ret;
+ this.Message = message;
}
-
- private int _ret = 200;
///
/// 返回结果
/// 2xx 成功相关状态(如: 200)
@@ -48,15 +45,11 @@ namespace OS.Common.Models
/// 5xx 服务器内部相关错误信息
/// 6xx 系统级定制错误信息,如升级维护等
///
- public int ret
- {
- get { return _ret; }
- set { _ret = value; }
- }
+ public int Ret { get; set; }
///
/// 错误或者状态
///
- public string message { get; set; }
+ public string Message { get; set; }
}
}
diff --git a/OS.Common/Utils/ChineseUtil.cs b/OS.Common/ComUtils/ChineseUtil.cs
similarity index 99%
rename from OS.Common/Utils/ChineseUtil.cs
rename to OS.Common/ComUtils/ChineseUtil.cs
index efbf42e..d2a6831 100644
--- a/OS.Common/Utils/ChineseUtil.cs
+++ b/OS.Common/ComUtils/ChineseUtil.cs
@@ -2,7 +2,7 @@
using System.Text;
using System.Text.RegularExpressions;
-namespace OS.Common.Utils
+namespace OS.Common.ComUtils
{
public class ChineseUtil
{
diff --git a/OS.Common/Utils/ConfigUtil.cs b/OS.Common/ComUtils/ConfigUtil.cs
similarity index 97%
rename from OS.Common/Utils/ConfigUtil.cs
rename to OS.Common/ComUtils/ConfigUtil.cs
index 06c2aa9..f15a92f 100644
--- a/OS.Common/Utils/ConfigUtil.cs
+++ b/OS.Common/ComUtils/ConfigUtil.cs
@@ -2,7 +2,7 @@
using System.Collections.Specialized;
using System.Configuration;
-namespace OS.Common.Utils
+namespace OS.Common.ComUtils
{
public static class ConfigUtil
{
diff --git a/OS.Common/Utils/ImageUtil.cs b/OS.Common/ComUtils/ImageUtil.cs
similarity index 99%
rename from OS.Common/Utils/ImageUtil.cs
rename to OS.Common/ComUtils/ImageUtil.cs
index eaa7828..cde8b4d 100644
--- a/OS.Common/Utils/ImageUtil.cs
+++ b/OS.Common/ComUtils/ImageUtil.cs
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
using System.Web;
using System.Collections;
-namespace OS.Common.Utils
+namespace OS.Common.ComUtils
{
//public static class ImageHelper
diff --git a/OS.Common/ComUtils/StringUtil.cs b/OS.Common/ComUtils/StringUtil.cs
new file mode 100644
index 0000000..fd71f61
--- /dev/null
+++ b/OS.Common/ComUtils/StringUtil.cs
@@ -0,0 +1,75 @@
+
+using System;
+using System.Text;
+
+namespace OS.Common.Utilss
+{
+ public static class StringUtil
+ {
+ #region Filter
+
+ ///
+ /// 过滤 Sql 语句字符串中的注入脚本
+ ///
+ /// 传入的字符串
+ /// 过滤后的字符串
+ public static string SqlFilter(string source)
+ {
+ source = source.Replace("\"", "");
+ source = source.Replace("&", "&");
+ source = source.Replace("<", "<");
+ source = source.Replace(">", ">");
+ source = source.Replace("delete", "");
+ source = source.Replace("update", "");
+ source = source.Replace("insert", "");
+ source = source.Replace("'", "''");
+ source = source.Replace(";", ";");
+ source = source.Replace("(", "(");
+ source = source.Replace(")", ")");
+ source = source.Replace("Exec", "");
+ source = source.Replace("Execute", "");
+ source = source.Replace("xp_", "x p_");
+ source = source.Replace("sp_", "s p_");
+ source = source.Replace("0x", "0 x");
+ return source;
+ }
+
+ #endregion
+
+ #region 字符串转码
+
+ ///
+ /// 根据指定编码转化成对应的64位编码
+ ///
+ ///
+ ///
+ ///
+ public static string ToBase64(this string source, Encoding encoding)
+ {
+ if (string.IsNullOrEmpty(source))
+ {
+ throw new ArgumentNullException("source", "转化Base64字符串不能为空");
+ }
+ byte[] bytes = encoding.GetBytes(source);
+ return Convert.ToBase64String(bytes);
+ }
+
+ ///
+ /// 从base64编码解码出正常的值
+ ///
+ ///
+ ///
+ ///
+ public static string FromBase64(this string source, Encoding encoding)
+ {
+ if (string.IsNullOrEmpty(source))
+ {
+ throw new ArgumentNullException("source", "解码Base64字符串不能为空");
+ }
+ byte[] bytes = encoding.GetBytes(source);
+ return encoding.GetString(bytes);
+ }
+
+ #endregion
+ }
+}
diff --git a/OS.Common/Utils/TypeUtil.cs b/OS.Common/ComUtils/TypeUtil.cs
similarity index 92%
rename from OS.Common/Utils/TypeUtil.cs
rename to OS.Common/ComUtils/TypeUtil.cs
index 836c74b..0bcad23 100644
--- a/OS.Common/Utils/TypeUtil.cs
+++ b/OS.Common/ComUtils/TypeUtil.cs
@@ -2,11 +2,13 @@
using System.Collections.Concurrent;
using System.Reflection;
-namespace OS.Common.Utils
+namespace OS.Common.ComUtils
{
+ ///
+ /// 内部使用获取属性相关信息
+ ///
internal static class TypeUtil
{
-
private static ConcurrentDictionary attrDirs = new ConcurrentDictionary();
public static object[] GetPropertiAttributes( string typeName, PropertyInfo fd, Type attributeType )
diff --git a/OS.Common/Extention/DTO/ColumnAliasAttribute.cs b/OS.Common/Extention/DTO/ColumnAliasAttribute.cs
index 1d68f48..3831feb 100644
--- a/OS.Common/Extention/DTO/ColumnAliasAttribute.cs
+++ b/OS.Common/Extention/DTO/ColumnAliasAttribute.cs
@@ -18,7 +18,6 @@ using System.Reflection;
namespace OS.Common.Extention
{
-
#region 类型属性的自定义属性处理
///
@@ -129,8 +128,4 @@ namespace OS.Common.Extention
}
#endregion
-
-
-
-
}
diff --git a/OS.Common/Extention/DTO/DTOExtetion.cs b/OS.Common/Extention/DTO/DTOExtetion.cs
index d8a403e..926f48f 100644
--- a/OS.Common/Extention/DTO/DTOExtetion.cs
+++ b/OS.Common/Extention/DTO/DTOExtetion.cs
@@ -1,13 +1,9 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
-using System.Collections.ObjectModel;
using System.Collections.Specialized;
-using System.Data;
-using System.Data.Common;
using System.Linq;
using System.Reflection;
-using System.Text;
#region Copyright (C) 2014 北京金色世纪商旅网络科技股份有限公司
@@ -54,33 +50,33 @@ namespace OS.Common.Extention
return tModel;
}
- ///
- /// 从DataReader中获取实体信息
- ///
- ///
- ///
- public static TModel SetToModel(this IDataReader dr) where TModel : class ,new()
- {
- TModel tModel=new TModel();
+ /////
+ ///// 从DataReader中获取实体信息
+ /////
+ /////
+ /////
+ //public static TModel SetToModel(this IDataReader dr) where TModel : class ,new()
+ //{
+ // TModel tModel=new TModel();
- var properties = GetColumnAttributes( typeof (TModel) );
+ // var properties = GetColumnAttributes( typeof (TModel) );
- for (int i = 0; i < dr.FieldCount; i++)
- {
- string drFieldName = dr.GetName( i );
+ // for (int i = 0; i < dr.FieldCount; i++)
+ // {
+ // string drFieldName = dr.GetName( i );
- if (properties.ContainsKey( drFieldName ) && !dr.IsDBNull( i ))
- {
- var propertyColumnInfo = properties[drFieldName];
- if (!propertyColumnInfo.IsIgnore)
- {
- var propertyInfo = propertyColumnInfo.PropertyInfo;
- propertyInfo.SetValue(tModel, dr[i].ChangeToType(propertyInfo.PropertyType), null);
- }
- }
- }
- return tModel;
- }
+ // if (properties.ContainsKey( drFieldName ) && !dr.IsDBNull( i ))
+ // {
+ // var propertyColumnInfo = properties[drFieldName];
+ // if (!propertyColumnInfo.IsIgnore)
+ // {
+ // var propertyInfo = propertyColumnInfo.PropertyInfo;
+ // propertyInfo.SetValue(tModel, dr[i].ChangeToType(propertyInfo.PropertyType), null);
+ // }
+ // }
+ // }
+ // return tModel;
+ //}
#region 属性处理
@@ -189,75 +185,75 @@ namespace OS.Common.Extention
#region 创建数据参数部分
- ///
- /// 从实体中获取 所有数据库参数和值
- ///
- ///
- ///
- public static DbParameters GetDbParameteres(this TModel tModel, DataBaseType type=DataBaseType.SqlServer) where TModel : class
- {
- DbParameters parameters=new DbParameters(type);
- var properties = GetColumnAttributes(typeof(TModel));
- foreach (var pro in properties)
- {
- var pcInfo = pro.Value;
- if (!pcInfo.IsIgnore && !pcInfo.IsAuto)
- {
- parameters.AddInParameter(pcInfo.Alias,
- GetPropertityValue(pcInfo.PropertyInfo, tModel));
- }
- else if (pcInfo.IsAuto)
- {
- parameters.AddOutParameter(pcInfo.Alias,DbType.Int64);
- }
- }
- return parameters;
- }
+ /////
+ ///// 从实体中获取 所有数据库参数和值
+ /////
+ /////
+ /////
+ //public static DbParameters GetDbParameteres(this TModel tModel, DataBaseType type=DataBaseType.SqlServer) where TModel : class
+ //{
+ // DbParameters parameters=new DbParameters(type);
+ // var properties = GetColumnAttributes(typeof(TModel));
+ // foreach (var pro in properties)
+ // {
+ // var pcInfo = pro.Value;
+ // if (!pcInfo.IsIgnore && !pcInfo.IsAuto)
+ // {
+ // parameters.AddInParameter(pcInfo.Alias,
+ // GetPropertityValue(pcInfo.PropertyInfo, tModel));
+ // }
+ // else if (pcInfo.IsAuto)
+ // {
+ // parameters.AddOutParameter(pcInfo.Alias,DbType.Int64);
+ // }
+ // }
+ // return parameters;
+ //}
- ///
- /// 设置SqlServer数据库插入参数和语句
- ///
- ///
- ///
- public static void SetSqlServerInsertPara(this DbCommand com, TModel tModel, string tableName)
- {
- DbParameters parameters = new DbParameters(DataBaseType.SqlServer);
- var properties = GetColumnAttributes(typeof (TModel));
+ /////
+ ///// 设置SqlServer数据库插入参数和语句
+ /////
+ /////
+ /////
+ //public static void SetSqlServerInsertPara(this DbCommand com, TModel tModel, string tableName)
+ //{
+ // DbParameters parameters = new DbParameters(DataBaseType.SqlServer);
+ // var properties = GetColumnAttributes(typeof (TModel));
- StringBuilder strColumns = new StringBuilder();
- StringBuilder strValues = new StringBuilder();
- string strAuto = string.Empty;
+ // StringBuilder strColumns = new StringBuilder();
+ // StringBuilder strValues = new StringBuilder();
+ // string strAuto = string.Empty;
- foreach (var pro in properties)
- {
- var pcInfo = pro.Value;
- if (!pcInfo.IsIgnore && !pcInfo.IsAuto)
- {
- var para = parameters.AddInParameter(pcInfo.Alias,
- DbParameters.ConvertToDbType(pcInfo.PropertyInfo.PropertyType),
- GetPropertityValue(pcInfo.PropertyInfo, tModel));
+ // foreach (var pro in properties)
+ // {
+ // var pcInfo = pro.Value;
+ // if (!pcInfo.IsIgnore && !pcInfo.IsAuto)
+ // {
+ // var para = parameters.AddInParameter(pcInfo.Alias,
+ // DbParameters.ConvertToDbType(pcInfo.PropertyInfo.PropertyType),
+ // GetPropertityValue(pcInfo.PropertyInfo, tModel));
- if (strColumns.Length > 0)
- strColumns.Append(",");
- if (strValues.Length > 0)
- strValues.Append(",");
+ // if (strColumns.Length > 0)
+ // strColumns.Append(",");
+ // if (strValues.Length > 0)
+ // strValues.Append(",");
- strColumns.Append("[").Append(pcInfo.Alias).Append("]");
- strValues.Append(para.ParameterName);
- }
- else if (pcInfo.IsAuto)
- {
- var para = parameters.AddOutParameter(pcInfo.Alias, DbType.Int64);
- strAuto = string.Format(" set {0}=@@identity", para.ParameterName);
- }
- }
+ // strColumns.Append("[").Append(pcInfo.Alias).Append("]");
+ // strValues.Append(para.ParameterName);
+ // }
+ // else if (pcInfo.IsAuto)
+ // {
+ // var para = parameters.AddOutParameter(pcInfo.Alias, DbType.Int64);
+ // strAuto = string.Format(" set {0}=@@identity", para.ParameterName);
+ // }
+ // }
- com.CommandType = CommandType.Text;
- com.CommandText = string.Format("insert into {0}({1}) values ({2}) {3}", tableName, strColumns, strValues,
- strAuto);
- com.Parameters.AddRange(parameters.ToArray());
- }
+ // com.CommandType = CommandType.Text;
+ // com.CommandText = string.Format("insert into {0}({1}) values ({2}) {3}", tableName, strColumns, strValues,
+ // strAuto);
+ // com.Parameters.AddRange(parameters.ToArray());
+ //}
private static object GetPropertityValue(PropertyInfo proper, TModel tModel)
{
@@ -274,338 +270,338 @@ namespace OS.Common.Extention
#region 数据库参数定义
- public enum DataBaseType
- {
- SqlServer,
- Oracle
- }
+ //public enum DataBaseType
+ //{
+ // SqlServer,
+ // Oracle
+ //}
- public static class DataBase
- {
- public static DbProviderFactory GetDbProvider(DataBaseType type=DataBaseType.SqlServer)
- {
- DbProviderFactory factory = null;
- switch (type)
- {
- case DataBaseType.SqlServer:
- factory = DbProviderFactories.GetFactory("System.Data.SqlClient");
- break;
- case DataBaseType.Oracle:
- factory = DbProviderFactories.GetFactory("System.Data.OracleClient");
- break;
- }
- if (factory == null)
- {
- throw new ArgumentNullException("type", "DbProviderFactory do not support!");
- }
- return factory;
- }
- }
+ //public static class DataBase
+ //{
+ // public static DbProviderFactory GetDbProvider(DataBaseType type=DataBaseType.SqlServer)
+ // {
+ // DbProviderFactory factory = null;
+ // switch (type)
+ // {
+ // case DataBaseType.SqlServer:
+ // factory = DbProviderFactories.GetFactory("System.Data.SqlClient");
+ // break;
+ // case DataBaseType.Oracle:
+ // factory = DbProviderFactories.GetFactory("System.Data.OracleClient");
+ // break;
+ // }
+ // if (factory == null)
+ // {
+ // throw new ArgumentNullException("type", "DbProviderFactory do not support!");
+ // }
+ // return factory;
+ // }
+ //}
- ///
- /// 数据库参数封装
- ///
- public class DbParameters : Collection
- {
- private readonly DataBaseType _dataBaseType;
- ///
- ///
- ///
- ///
- public DbParameters(DataBaseType type)
- {
- _dataBaseType = type;
- }
+ /////
+ ///// 数据库参数封装
+ /////
+ //public class DbParameters : Collection
+ //{
+ // private readonly DataBaseType _dataBaseType;
+ // ///
+ // ///
+ // ///
+ // ///
+ // public DbParameters(DataBaseType type)
+ // {
+ // _dataBaseType = type;
+ // }
- ///
- /// 添加输入参数
- ///
- ///
- ///
- ///
- public DbParameter AddInParameter(string name, DbType dbType)
- {
- return AddParameter(name, dbType, ParameterDirection.Input, String.Empty, DataRowVersion.Default, null);
- }
+ // ///
+ // /// 添加输入参数
+ // ///
+ // ///
+ // ///
+ // ///
+ // public DbParameter AddInParameter(string name, DbType dbType)
+ // {
+ // return AddParameter(name, dbType, ParameterDirection.Input, String.Empty, DataRowVersion.Default, null);
+ // }
- ///
- /// 添加输入参数
- ///
- ///
- ///
- ///
- public DbParameter AddInParameter(string name, object value)
- {
- return AddParameter(name, ConvertToDbType(value==null?typeof(object):value.GetType()), ParameterDirection.Input, String.Empty, DataRowVersion.Default, value);
- }
+ // ///
+ // /// 添加输入参数
+ // ///
+ // ///
+ // ///
+ // ///
+ // public DbParameter AddInParameter(string name, object value)
+ // {
+ // return AddParameter(name, ConvertToDbType(value==null?typeof(object):value.GetType()), ParameterDirection.Input, String.Empty, DataRowVersion.Default, value);
+ // }
- ///
- /// 添加输入参数
- ///
- ///
- ///
- ///
- ///
- public DbParameter AddInParameter(string name, DbType dbType, object value)
- {
- return AddParameter(name, dbType, ParameterDirection.Input, String.Empty, DataRowVersion.Default, value);
- }
+ // ///
+ // /// 添加输入参数
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // public DbParameter AddInParameter(string name, DbType dbType, object value)
+ // {
+ // return AddParameter(name, dbType, ParameterDirection.Input, String.Empty, DataRowVersion.Default, value);
+ // }
- ///
- /// 添加一个新的参数
- ///
- /// 参数名称,不带前缀的,例如直接 “name”
- /// 参数类型
- /// 参数大小
- /// 参数值
- public DbParameter AddInParameter(string name, DbType dbType, int size, object value)
- {
- return AddParameter(name, dbType, size, ParameterDirection.Input, true, 0, 0, String.Empty, DataRowVersion.Default,
- value);
- }
+ // ///
+ // /// 添加一个新的参数
+ // ///
+ // /// 参数名称,不带前缀的,例如直接 “name”
+ // /// 参数类型
+ // /// 参数大小
+ // /// 参数值
+ // public DbParameter AddInParameter(string name, DbType dbType, int size, object value)
+ // {
+ // return AddParameter(name, dbType, size, ParameterDirection.Input, true, 0, 0, String.Empty, DataRowVersion.Default,
+ // value);
+ // }
- ///
- /// 添加输入参数
- ///
- ///
- ///
- ///
- ///
- ///
- public DbParameter AddInParameter(string name, DbType dbType, string sourceColumn, DataRowVersion sourceVersion)
- {
- return AddParameter(name, dbType, 0, ParameterDirection.Input, true, 0, 0, sourceColumn, sourceVersion, null);
- }
+ // ///
+ // /// 添加输入参数
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // public DbParameter AddInParameter(string name, DbType dbType, string sourceColumn, DataRowVersion sourceVersion)
+ // {
+ // return AddParameter(name, dbType, 0, ParameterDirection.Input, true, 0, 0, sourceColumn, sourceVersion, null);
+ // }
- ///
- /// 添加输出参数
- ///
- ///
- ///
- public DbParameter AddOutParameter(string name, DbType dbType)
- {
- return AddParameter(name, dbType, 0, ParameterDirection.Output, true, 0, 0, String.Empty, DataRowVersion.Default,
- DBNull.Value);
- }
+ // ///
+ // /// 添加输出参数
+ // ///
+ // ///
+ // ///
+ // public DbParameter AddOutParameter(string name, DbType dbType)
+ // {
+ // return AddParameter(name, dbType, 0, ParameterDirection.Output, true, 0, 0, String.Empty, DataRowVersion.Default,
+ // DBNull.Value);
+ // }
- ///
- /// 添加输出参数
- ///
- ///
- ///
- ///
- public DbParameter AddOutParameter(string name, DbType dbType, int size)
- {
- return AddParameter(name, dbType, size, ParameterDirection.Output, true, 0, 0, String.Empty, DataRowVersion.Default,
- DBNull.Value);
- }
+ // ///
+ // /// 添加输出参数
+ // ///
+ // ///
+ // ///
+ // ///
+ // public DbParameter AddOutParameter(string name, DbType dbType, int size)
+ // {
+ // return AddParameter(name, dbType, size, ParameterDirection.Output, true, 0, 0, String.Empty, DataRowVersion.Default,
+ // DBNull.Value);
+ // }
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public DbParameter AddParameter(string name, DbType dbType, ParameterDirection direction, string sourceColumn,
- DataRowVersion sourceVersion, object value)
- {
- return AddParameter(name, dbType, 0, direction, false, 0, 0, sourceColumn, sourceVersion, value);
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // public DbParameter AddParameter(string name, DbType dbType, ParameterDirection direction, string sourceColumn,
+ // DataRowVersion sourceVersion, object value)
+ // {
+ // return AddParameter(name, dbType, 0, direction, false, 0, 0, sourceColumn, sourceVersion, value);
- }
+ // }
- ///
- /// 添加参数
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- protected DbParameter AddParameter(string name, DbType dbType, int size, ParameterDirection direction, bool nullable,
- byte precision,
- byte scale, string sourceColumn, DataRowVersion sourceVersion, object value)
- {
- DbParameter parameter = CreateParameter(name, dbType, size, direction, nullable, precision, scale,
- sourceColumn, sourceVersion, value);
- Add(parameter);
- return parameter;
- }
+ // ///
+ // /// 添加参数
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // protected DbParameter AddParameter(string name, DbType dbType, int size, ParameterDirection direction, bool nullable,
+ // byte precision,
+ // byte scale, string sourceColumn, DataRowVersion sourceVersion, object value)
+ // {
+ // DbParameter parameter = CreateParameter(name, dbType, size, direction, nullable, precision, scale,
+ // sourceColumn, sourceVersion, value);
+ // Add(parameter);
+ // return parameter;
+ // }
- ///
- /// 创建参数
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- protected internal DbParameter CreateParameter(string name, DbType dbType, int size, ParameterDirection direction,
- bool nullable, byte precision,
- byte scale, string sourceColumn, DataRowVersion sourceVersion, object value)
- {
- DbParameter para = DataBase.GetDbProvider(_dataBaseType).CreateParameter();
- para.ParameterName = string.Concat(PreParaToken, name);
- ConfigureParameter(para, dbType, size, direction, nullable, precision, scale, sourceColumn, sourceVersion,
- value);
- return para;
- }
+ // ///
+ // /// 创建参数
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // protected internal DbParameter CreateParameter(string name, DbType dbType, int size, ParameterDirection direction,
+ // bool nullable, byte precision,
+ // byte scale, string sourceColumn, DataRowVersion sourceVersion, object value)
+ // {
+ // DbParameter para = DataBase.GetDbProvider(_dataBaseType).CreateParameter();
+ // para.ParameterName = string.Concat(PreParaToken, name);
+ // ConfigureParameter(para, dbType, size, direction, nullable, precision, scale, sourceColumn, sourceVersion,
+ // value);
+ // return para;
+ // }
- ///
- /// 配置参数信息
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- protected virtual void ConfigureParameter(DbParameter param, DbType dbType, int size,
- ParameterDirection direction, bool nullable, byte precision, byte scale, string sourceColumn,
- DataRowVersion sourceVersion, object value)
- {
- param.DbType = dbType;
- param.Size = size;
- param.Value = value ?? DBNull.Value;
- param.Direction = direction;
- param.IsNullable = nullable;
- param.SourceColumn = sourceColumn;
- param.SourceVersion = sourceVersion;
- }
+ // ///
+ // /// 配置参数信息
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // ///
+ // protected virtual void ConfigureParameter(DbParameter param, DbType dbType, int size,
+ // ParameterDirection direction, bool nullable, byte precision, byte scale, string sourceColumn,
+ // DataRowVersion sourceVersion, object value)
+ // {
+ // param.DbType = dbType;
+ // param.Size = size;
+ // param.Value = value ?? DBNull.Value;
+ // param.Direction = direction;
+ // param.IsNullable = nullable;
+ // param.SourceColumn = sourceColumn;
+ // param.SourceVersion = sourceVersion;
+ // }
- ///
- /// 索引器
- ///
- ///
- ///
- public DbParameter this[string name]
- {
- get
- {
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentNullException("ParameterName","查询的属性名称不能为空!");
- }
- return Items.FirstOrDefault(dbp => dbp.ParameterName ==string.Concat(PreParaToken, name));
- }
- }
+ // ///
+ // /// 索引器
+ // ///
+ // ///
+ // ///
+ // public DbParameter this[string name]
+ // {
+ // get
+ // {
+ // if (string.IsNullOrEmpty(name))
+ // {
+ // throw new ArgumentNullException("ParameterName","查询的属性名称不能为空!");
+ // }
+ // return Items.FirstOrDefault(dbp => dbp.ParameterName ==string.Concat(PreParaToken, name));
+ // }
+ // }
- private string _preParaToken;
+ // private string _preParaToken;
- ///
- /// 当前数据的库操作符号
- ///
- public String PreParaToken
- {
- get
- {
- if (string.IsNullOrEmpty(_preParaToken))
- {
- switch (_dataBaseType)
- {
- case DataBaseType.SqlServer:
- _preParaToken = "@";
- break;
- //case DataBaseType.Oracle:
- // _preParaToken = ":";
- // break;
- default:
- _preParaToken = string.Empty;
- break;
- }
- }
- return _preParaToken;
- }
- }
+ // ///
+ // /// 当前数据的库操作符号
+ // ///
+ // public String PreParaToken
+ // {
+ // get
+ // {
+ // if (string.IsNullOrEmpty(_preParaToken))
+ // {
+ // switch (_dataBaseType)
+ // {
+ // case DataBaseType.SqlServer:
+ // _preParaToken = "@";
+ // break;
+ // //case DataBaseType.Oracle:
+ // // _preParaToken = ":";
+ // // break;
+ // default:
+ // _preParaToken = string.Empty;
+ // break;
+ // }
+ // }
+ // return _preParaToken;
+ // }
+ // }
- #region 数据库类型和.net类型映射
- ///
- /// 数据库类型和.net类型映射
- ///
- private static Dictionary typeMap=new Dictionary();
- ///
- ///
- ///
- static DbParameters()
- {
- typeMap[typeof(byte)] = DbType.Byte;
- typeMap[typeof(sbyte)] = DbType.SByte;
- typeMap[typeof(short)] = DbType.Int16;
- typeMap[typeof(ushort)] = DbType.UInt16;
- typeMap[typeof(int)] = DbType.Int32;
- typeMap[typeof(uint)] = DbType.UInt32;
- typeMap[typeof(long)] = DbType.Int64;
- typeMap[typeof(ulong)] = DbType.UInt64;
- typeMap[typeof(float)] = DbType.Single;
- typeMap[typeof(double)] = DbType.Double;
- typeMap[typeof(decimal)] = DbType.Decimal;
- typeMap[typeof(bool)] = DbType.Boolean;
- typeMap[typeof(string)] = DbType.String;
- typeMap[typeof(char)] = DbType.StringFixedLength;
- typeMap[typeof(Guid)] = DbType.Guid;
- typeMap[typeof(DateTime)] = DbType.DateTime;
- typeMap[typeof(DateTimeOffset)] = DbType.DateTimeOffset;
- typeMap[typeof(TimeSpan)] = DbType.Time;
- typeMap[typeof(byte[])] = DbType.Binary;
- typeMap[typeof(byte?)] = DbType.Byte;
- typeMap[typeof(sbyte?)] = DbType.SByte;
- typeMap[typeof(short?)] = DbType.Int16;
- typeMap[typeof(ushort?)] = DbType.UInt16;
- typeMap[typeof(int?)] = DbType.Int32;
- typeMap[typeof(uint?)] = DbType.UInt32;
- typeMap[typeof(long?)] = DbType.Int64;
- typeMap[typeof(ulong?)] = DbType.UInt64;
- typeMap[typeof(float?)] = DbType.Single;
- typeMap[typeof(double?)] = DbType.Double;
- typeMap[typeof(decimal?)] = DbType.Decimal;
- typeMap[typeof(bool?)] = DbType.Boolean;
- typeMap[typeof(char?)] = DbType.StringFixedLength;
- typeMap[typeof(Guid?)] = DbType.Guid;
- typeMap[typeof(DateTime?)] = DbType.DateTime;
- typeMap[typeof(DateTimeOffset?)] = DbType.DateTimeOffset;
- typeMap[typeof(TimeSpan?)] = DbType.Time;
- }
- #endregion
+ // #region 数据库类型和.net类型映射
+ // ///
+ // /// 数据库类型和.net类型映射
+ // ///
+ // private static Dictionary typeMap=new Dictionary();
+ // ///
+ // ///
+ // ///
+ // static DbParameters()
+ // {
+ // typeMap[typeof(byte)] = DbType.Byte;
+ // typeMap[typeof(sbyte)] = DbType.SByte;
+ // typeMap[typeof(short)] = DbType.Int16;
+ // typeMap[typeof(ushort)] = DbType.UInt16;
+ // typeMap[typeof(int)] = DbType.Int32;
+ // typeMap[typeof(uint)] = DbType.UInt32;
+ // typeMap[typeof(long)] = DbType.Int64;
+ // typeMap[typeof(ulong)] = DbType.UInt64;
+ // typeMap[typeof(float)] = DbType.Single;
+ // typeMap[typeof(double)] = DbType.Double;
+ // typeMap[typeof(decimal)] = DbType.Decimal;
+ // typeMap[typeof(bool)] = DbType.Boolean;
+ // typeMap[typeof(string)] = DbType.String;
+ // typeMap[typeof(char)] = DbType.StringFixedLength;
+ // typeMap[typeof(Guid)] = DbType.Guid;
+ // typeMap[typeof(DateTime)] = DbType.DateTime;
+ // typeMap[typeof(DateTimeOffset)] = DbType.DateTimeOffset;
+ // typeMap[typeof(TimeSpan)] = DbType.Time;
+ // typeMap[typeof(byte[])] = DbType.Binary;
+ // typeMap[typeof(byte?)] = DbType.Byte;
+ // typeMap[typeof(sbyte?)] = DbType.SByte;
+ // typeMap[typeof(short?)] = DbType.Int16;
+ // typeMap[typeof(ushort?)] = DbType.UInt16;
+ // typeMap[typeof(int?)] = DbType.Int32;
+ // typeMap[typeof(uint?)] = DbType.UInt32;
+ // typeMap[typeof(long?)] = DbType.Int64;
+ // typeMap[typeof(ulong?)] = DbType.UInt64;
+ // typeMap[typeof(float?)] = DbType.Single;
+ // typeMap[typeof(double?)] = DbType.Double;
+ // typeMap[typeof(decimal?)] = DbType.Decimal;
+ // typeMap[typeof(bool?)] = DbType.Boolean;
+ // typeMap[typeof(char?)] = DbType.StringFixedLength;
+ // typeMap[typeof(Guid?)] = DbType.Guid;
+ // typeMap[typeof(DateTime?)] = DbType.DateTime;
+ // typeMap[typeof(DateTimeOffset?)] = DbType.DateTimeOffset;
+ // typeMap[typeof(TimeSpan?)] = DbType.Time;
+ // }
+ // #endregion
- ///
- /// 将.net类型转成数据库类型
- ///
- ///
- ///
- internal static DbType ConvertToDbType(Type type)
- {
- if (type.IsEnum)
- {
- return DbType.Int32;
- }
- if (typeMap.ContainsKey(type))
- {
- return typeMap[type];
- }
- return DbType.String;
- }
- }
+ // ///
+ // /// 将.net类型转成数据库类型
+ // ///
+ // ///
+ // ///
+ // internal static DbType ConvertToDbType(Type type)
+ // {
+ // if (type.IsEnum)
+ // {
+ // return DbType.Int32;
+ // }
+ // if (typeMap.ContainsKey(type))
+ // {
+ // return typeMap[type];
+ // }
+ // return DbType.String;
+ // }
+ //}
#endregion
diff --git a/OS.Common/Extention/DateTimeExtention.cs b/OS.Common/Extention/DateTimeExtention.cs
index e506498..5a012a0 100644
--- a/OS.Common/Extention/DateTimeExtention.cs
+++ b/OS.Common/Extention/DateTimeExtention.cs
@@ -5,7 +5,7 @@ namespace OS.Common.Extention
public static class DateTimeExtention
{
///
- /// 获取秒数(格林威治时间)
+ /// 获取距离1970-01-01 的秒数(格林威治时间)
///
///
///
diff --git a/OS.Common/Extention/UrlExtension.cs b/OS.Common/Extention/UrlExtension.cs
new file mode 100644
index 0000000..d0da71d
--- /dev/null
+++ b/OS.Common/Extention/UrlExtension.cs
@@ -0,0 +1,27 @@
+using System;
+
+namespace OS.Http.Extention
+{
+ public static class UrlExtension
+ {
+ ///
+ /// Url编码处理
+ ///
+ public static string UrlEncode(this string input)
+ {
+ return Uri.EscapeDataString(input);
+ }
+ ///
+ /// Url编码处理
+ ///
+ public static string UrlEncode(this object input)
+ {
+ if (input != null)
+ {
+ return Uri.EscapeDataString(input.ToString());
+ }
+ return string.Empty;
+ }
+
+ }
+}
diff --git a/OS.Common/Log/LogHelper.cs b/OS.Common/Log/LogHelper.cs
deleted file mode 100644
index fdc9630..0000000
--- a/OS.Common/Log/LogHelper.cs
+++ /dev/null
@@ -1,171 +0,0 @@
-
-
-using System.Collections.Generic;
-using System.Data;
-using System.Threading.Tasks.Dataflow;
-using OS.Common.Models.Enums;
-
-namespace OS.Common.Log
-{
- using System;
-
- public class LogInfo
- {
- ///
- /// 空构造函数
- ///
- public LogInfo()
- {
- }
-
- ///
- /// 日志构造函数
- ///
- ///
- ///
- ///
- ///
- internal LogInfo(LogLevelEnum loglevel,string category,string msg,object key=null)
- {
- Level = loglevel;
- Category = category;
- Message = msg;
- Key = key;
- }
-
- ///
- /// 日志等级
- ///
- public LogLevelEnum Level { get; set; }
-
- ///
- /// 日志类型
- ///
- public string Category { get; set; }
- ///
- /// key值 可以是id等
- ///
- public object Key { get; set; }
-
- ///
- /// 日志信息
- ///
- public string Message { get; set; }
- }
-
- ///
- /// 日志写模块
- ///
- public static class LogHelper
- {
-
- #region 异步模块定义
-
- private static Dictionary logCateActions=
- new Dictionary();
-
- private static ILogWriter defaultWriter = null;
-
- ///
- /// 构造函数
- ///
- static LogHelper()
- {
- defaultWriter = new Log.LogWriter();
- }
-
- ///
- /// 返回操作日志方法
- ///
- ///
- ///
- private static ILogWriter CreateLogWriter(string category)
- {
- if (string.IsNullOrEmpty(category))
- throw new NoNullAllowedException("注册日志 category 不能不空!");
- if(logCateActions.ContainsKey(category))
- throw new ArgumentException(string.Format("日志模块已存在 {0} 模块",category));
-
- if (!string.IsNullOrEmpty(category) && logCateActions.ContainsKey(category))
- {
- return logCateActions[category];
- }
- return defaultWriter;
- }
-
- ///
- /// 异步缓冲池
- ///
- private static ActionBlock logActionList=new ActionBlock(info =>
- {
- var act = CreateLogWriter(info.Category);
- act.WriteLog(new LogInfo(info.Level,info.Category,info.Message,info.Key));
- },new ExecutionDataflowBlockOptions() { MaxDegreeOfParallelism = 3 } );
-
- ///
- /// 注册日志存储模块
- ///
- ///
- ///
- public static void RegisterLogWrite(string category,ILogWriter writer )
- {
- logCateActions.Add(category, writer);
- }
-
- #endregion
-
-
- ///
- /// 记录信息
- ///
- /// 分类
- /// 日志信息
- /// 关键值
- public static void Info(string category,string msg,object key=null)
- {
- Log(new LogInfo(LogLevelEnum.Info, category, msg, key));
- }
-
- ///
- /// 记录警告,用于未处理异常的捕获
- ///
- /// 分类
- /// 日志信息
- /// 关键值
- public static void Warning(string category, string msg, object key = null)
- {
- Log(new LogInfo(LogLevelEnum.Warning, category, msg, key));
- }
-
- ///
- /// 记录错误,用于捕获到的异常信息记录
- ///
- /// 分类
- /// 日志信息
- /// 关键值
- public static void Error(string category, string msg, object key = null)
- {
- Log(new LogInfo(LogLevelEnum.Error, category, msg, key));
- }
-
- ///
- /// 记录错误,用于捕获到的异常信息记录
- ///
- /// 分类
- /// 日志信息
- /// 关键值
- public static void Trace(string category, string msg, object key = null)
- {
- Log(new LogInfo(LogLevelEnum.Trace, category, msg, key));
- }
-
- ///
- /// 记录日志
- ///
- ///
- public static void Log(LogInfo info)
- {
- logActionList.Post(info);
- }
- }
-}
diff --git a/OS.Common/Log/LogWriter.cs b/OS.Common/Log/LogWriter.cs
deleted file mode 100644
index c2f852c..0000000
--- a/OS.Common/Log/LogWriter.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-using System;
-using System.IO;
-using System.Text;
-using OS.Common.Models.Enums;
-
-namespace OS.Common.Log
-{
- class LogWriter : ILogWriter
- {
- private readonly string m_LogDirPath = null;
- private const string LOG_FORMAT = "{0:T} {1} {2}:{3}";
-
- public LogWriter()
- {
- m_LogDirPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"log\");
- if (!Directory.Exists(m_LogDirPath))
- Directory.CreateDirectory(m_LogDirPath);
- }
-
- private string getLogFilePath(string type)
- {
- StringBuilder sb = new StringBuilder(m_LogDirPath);
- sb.Append(DateTime.Now.ToString("yyyyMMdd"));
- sb.Append("_");
- sb.Append(type);
- sb.Append(".txt");
- return sb.ToString();
- }
-
-
- private object obj = new object();
-
- ///
- /// 写日志
- ///
- ///
- ///
- ///
- ///
- public void WriteLog(LogLevelEnum logLevel, string category,string msg,object key=null)
- {
- lock (obj)
- {
- using (StreamWriter sw = new StreamWriter(getLogFilePath(logLevel.ToString()), true, Encoding.Default))
- {
- sw.WriteLine(LOG_FORMAT, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), key, category, msg);
- sw.Close();
- }
- }
- }
-
- }
-}
diff --git a/OS.Common/Models/BaseModel.cs b/OS.Common/Models/BaseModel.cs
deleted file mode 100644
index 3535980..0000000
--- a/OS.Common/Models/BaseModel.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-
-namespace OS.Common.Models
-{
- public class BaseAutoModel
- {
- ///
- /// ID
- ///
- public long Id { get; set; }
-
- ///
- /// 创建时间
- ///
- public long create_time { get; set; }
-
- private int _ret = 200;
- ///
- /// 结果状态
- ///
- public int ret {
- get { return _ret; }
- set { _ret = value; }
- }
-
- ///
- /// 结果状态描述
- ///
- public string message { get; set; }
- }
-}
diff --git a/OS.Common/Models/Enums/LogLevelEnum.cs b/OS.Common/Models/Enums/LogLevelEnum.cs
deleted file mode 100644
index 9365b40..0000000
--- a/OS.Common/Models/Enums/LogLevelEnum.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace OS.Common.Models.Enums
-{
- public enum LogLevelEnum
- {
- ///
- /// 跟踪查看
- ///
- Trace,
- ///
- /// 信息
- ///
- Info,
-
- ///
- /// 错误
- ///
- Error,
-
- ///
- /// 警告
- ///
- Warning,
-
-
- }
-}
diff --git a/OS.Common/Models/ResultEntity.cs b/OS.Common/Models/ResultEntity.cs
deleted file mode 100644
index 852a908..0000000
--- a/OS.Common/Models/ResultEntity.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-namespace OS.Common.Models
-{
- public class ResultEntity
- {
- ///
- /// 200成功
- ///
- public int ret { get; set; }
- ///
- /// 错误或者状态
- ///
- public string message { get; set; }
- }
-}
diff --git a/OS.Common/Modules/AsynModule/AsynBlock.cs b/OS.Common/Modules/AsynModule/AsynBlock.cs
new file mode 100644
index 0000000..d5beb77
--- /dev/null
+++ b/OS.Common/Modules/AsynModule/AsynBlock.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace OS.Common.Modules.AsynModule
+{
+ internal class AsynBlock:IAsynBlock
+ {
+ ///
+ /// post
+ ///
+ ///
+ ///
+ ///
+ ///
+ public bool Asyn(Action asynAction, T t)
+ {
+ return ThreadPool.QueueUserWorkItem(obj =>
+ {
+ var para = (T) obj;
+ asynAction(para);
+ }, t);
+ }
+ }
+}
diff --git a/OS.Common/Modules/AsynModule/AsynUtil.cs b/OS.Common/Modules/AsynModule/AsynUtil.cs
new file mode 100644
index 0000000..cd6292a
--- /dev/null
+++ b/OS.Common/Modules/AsynModule/AsynUtil.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using OS.Common.Modules.CacheModule;
+
+namespace OS.Common.Modules.AsynModule
+{
+ ///
+ /// 异步
+ ///
+ public static class AsynUtil
+ {
+ internal static Dictionary AsynModules=
+ new Dictionary();
+
+
+ ///
+ /// 通过模块名称获取异步处理模块实例
+ ///
+ ///
+ ///
+ public static IAsynBlock GetAsynBlock(string asynModule)
+ {
+ if (!string.IsNullOrEmpty(asynModule)&& AsynModules.ContainsKey(asynModule))
+ {
+ return AsynModules[asynModule];
+ }
+ return AsynModules[ModuleAsynKeys.Default];
+ }
+
+
+ ///
+ /// 调用异步方法
+ ///
+ ///
+ ///
+ ///
+ /// 异步模块名称
+ ///
+ public static bool Asyn(Action asynAction, T t,string moduleName=ModuleAsynKeys.Default)
+ {
+ return GetAsynBlock(moduleName).Asyn(asynAction, t);
+ }
+
+
+ }
+}
diff --git a/OS.Common/Modules/AsynModule/IAsynBlock.cs b/OS.Common/Modules/AsynModule/IAsynBlock.cs
new file mode 100644
index 0000000..03f8e25
--- /dev/null
+++ b/OS.Common/Modules/AsynModule/IAsynBlock.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OS.Common.Modules.AsynModule
+{
+ public interface IAsynBlock
+ {
+ ///
+ /// post
+ ///
+ ///
+ ///
+ ///
+ ///
+ bool Asyn(Action asynAction, T t);
+ }
+}
diff --git a/OS.Common/Modules/CacheModule/Cache.cs b/OS.Common/Modules/CacheModule/Cache.cs
new file mode 100644
index 0000000..56b2702
--- /dev/null
+++ b/OS.Common/Modules/CacheModule/Cache.cs
@@ -0,0 +1,115 @@
+using System;
+using System.Collections.Generic;
+using System.Runtime.Caching;
+
+namespace OS.Common.Modules.CacheModule
+{
+ public class Cache : ICache
+ {
+ ///
+ /// 添加缓存,已存在不更新
+ ///
+ /// 添加缓存对象类型
+ /// 添加对象的key
+ /// 值
+ /// 相对过期的TimeSpan
+ /// 绝对过期时间
+ /// 缓存分区db
+ /// 是否添加成功
+ public bool Add(string key, T obj, TimeSpan slidingExpiration, DateTime? absoluteExpiration = null,
+ int db = 0)
+ {
+ return Add(key, obj, slidingExpiration, absoluteExpiration, db, false);
+ }
+
+ ///
+ /// 添加缓存,如果存在则更新
+ ///
+ /// 添加缓存对象类型
+ /// 添加对象的key
+ /// 值
+ /// 相对过期的TimeSpan
+ /// 绝对过期时间
+ /// 缓存分区db
+ /// 是否添加成功
+ public bool AddOrUpdate(string key, T obj, TimeSpan slidingExpiration, DateTime? absoluteExpiration = null,
+ int db = 0)
+ {
+ return Add(key, obj, slidingExpiration, absoluteExpiration, db, true);
+ }
+
+
+ private static bool Add(string key, T obj, TimeSpan slidingExpiration, DateTime? absoluteExpiration,
+ int db, bool isUpdate)
+ {
+ if (slidingExpiration == TimeSpan.Zero && absoluteExpiration == null)
+ throw new ArgumentNullException("slidingExpiration", "缓存过期时间不正确,需要设置固定过期时间或者相对过期时间");
+
+ var cachePllicy = new CacheItemPolicy();
+
+ if (slidingExpiration == TimeSpan.Zero)
+ {
+ cachePllicy.AbsoluteExpiration = new DateTimeOffset(absoluteExpiration.Value);
+ }
+ else
+ {
+ cachePllicy.SlidingExpiration = slidingExpiration;
+ }
+
+ if (isUpdate)
+ {
+ MemoryCache.Default.Set(key, obj, cachePllicy, db>0? db.ToString():null);
+ return true;
+ }
+ return MemoryCache.Default.Add(key, obj, cachePllicy, db>0? db.ToString():null);
+ }
+
+ ///
+ /// 获取缓存对象
+ ///
+ /// 获取缓存对象类型
+ /// key
+ /// 缓存分区db
+ /// 获取指定key对应的值
+ public T Get(string key, int db=0)
+ {
+ return (T)MemoryCache.Default.Get(key, db>0? db.ToString():null);
+ }
+
+
+ ///
+ /// 获取缓存对象
+ ///
+ /// 获取缓存对象类型
+ /// key列表
+ /// 缓存分区db
+ /// 获取多个不同类型key对应的不同值
+ public IDictionary Get(IEnumerable keys, int db=0)
+ {
+ return MemoryCache.Default.GetValues(keys, db>0? db.ToString():null);
+ }
+
+ ///
+ /// 移除缓存对象
+ ///
+ ///
+ ///
+ /// 是否成功
+ public bool Remove(string key, int db=0)
+ {
+ return MemoryCache.Default.Remove(key, db>0? db.ToString():null)!=null;
+ }
+
+
+ ///
+ /// 判断是否存在缓存对象
+ ///
+ /// key值
+ /// 缓存分区db
+ ///
+ public bool Contains(string key, int db=0)
+ {
+ return MemoryCache.Default.Contains(key, db>0? db.ToString():null);
+ }
+ }
+}
diff --git a/OS.Common/Modules/CacheModule/CacheUtil.cs b/OS.Common/Modules/CacheModule/CacheUtil.cs
new file mode 100644
index 0000000..546ddf5
--- /dev/null
+++ b/OS.Common/Modules/CacheModule/CacheUtil.cs
@@ -0,0 +1,114 @@
+using System;
+using System.Collections.Generic;
+using System.Runtime.Caching;
+
+namespace OS.Common.Modules.CacheModule
+{
+ public static class CacheUtil
+ {
+ internal static Dictionary CacheModules=
+ new Dictionary();
+
+
+ ///
+ /// 通过模块名称获取
+ ///
+ ///
+ ///
+ public static ICache GetCache(string cacheModule)
+ {
+ if (!string.IsNullOrEmpty(cacheModule) && CacheModules.ContainsKey(cacheModule))
+ {
+ return CacheModules[cacheModule];
+ }
+ return CacheModules[ModuleCacheKeys.Default];
+ }
+
+ ///
+ /// 添加缓存,已存在不更新
+ ///
+ /// 添加缓存对象类型
+ /// 添加对象的key
+ /// 值
+ /// 相对过期的TimeSpan
+ /// 绝对过期时间
+ /// 缓存分区名称
+ /// 模块名称
+ /// 是否添加成功
+ public static bool Add(string key, T obj, TimeSpan slidingExpiration, DateTime? absoluteExpiration = null,
+ int db = 0, string moduleName=ModuleCacheKeys.Default)
+ {
+ return GetCache(moduleName).Add(key, obj, slidingExpiration, absoluteExpiration, db);
+ }
+
+ ///
+ /// 添加缓存,如果存在则更新
+ ///
+ /// 添加缓存对象类型
+ /// 添加对象的key
+ /// 值
+ /// 相对过期的TimeSpan
+ /// 绝对过期时间
+ /// 缓存分区db
+ /// 模块名称
+ /// 是否添加成功
+ public static bool AddOrUpdate(string key, T obj, TimeSpan slidingExpiration, DateTime? absoluteExpiration = null,
+ int db = 0, string moduleName=ModuleCacheKeys.Default)
+ {
+ return GetCache(moduleName).AddOrUpdate(key, obj, slidingExpiration, absoluteExpiration, db);
+ }
+
+
+ ///
+ /// 获取缓存对象
+ ///
+ /// 获取缓存对象类型
+ /// key
+ /// 缓存分区db
+ /// 模块名称
+ /// 获取指定key对应的值
+ public static T Get(string key, int db=0, string moduleName=ModuleCacheKeys.Default)
+ {
+ return GetCache(moduleName).Get(key, db);
+ }
+
+
+ ///
+ /// 获取缓存对象
+ ///
+ /// 获取缓存对象类型
+ /// key列表
+ /// 缓存分区db
+ /// 模块名称
+ /// 获取多个不同类型key对应的不同值
+ public static IDictionary Get(IEnumerable keys, int db=0, string moduleName=ModuleCacheKeys.Default)
+ {
+ return GetCache(moduleName).Get(keys, db);
+ }
+
+ ///
+ /// 移除缓存对象
+ ///
+ ///
+ ///
+ /// 模块名称
+ /// 是否成功
+ public static bool Remove(string key, int db=0, string moduleName=ModuleCacheKeys.Default)
+ {
+ return GetCache(moduleName).Remove(key, db);
+ }
+
+
+ ///
+ /// 判断是否存在缓存对象
+ ///
+ /// key值
+ /// 缓存分区db
+ /// 模块名称
+ ///
+ public static bool Contains(string key, int db=0, string moduleName=ModuleCacheKeys.Default)
+ {
+ return GetCache(moduleName).Contains(key, db);
+ }
+ }
+}
diff --git a/OS.Common/Modules/CacheModule/ICache.cs b/OS.Common/Modules/CacheModule/ICache.cs
new file mode 100644
index 0000000..efb0fdf
--- /dev/null
+++ b/OS.Common/Modules/CacheModule/ICache.cs
@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+
+namespace OS.Common.Modules.CacheModule
+{
+ public interface ICache
+ {
+ ///
+ /// Ìí¼ӻº´棬ÒѴæÔڲ»¸üÐÂ
+ ///
+ /// Ìí¼ӻº´æ¶ÔÏóÀàÐÍ
+ /// Ìí¼ӶÔÏóµÄkey
+ /// ֵ
+ /// Ïà¶ԹýÆڵÄTimeSpan
+ /// ¾ø¶ԹýÆÚʱ¼ä
+ /// »º´æ·ÖÇødb
+ /// ÊǷñÌí¼ӳɹ¦
+ bool Add(string key, T obj, TimeSpan slidingExpiration, DateTime? absoluteExpiration = null,
+ int db = 0);
+
+ ///
+ /// Ìí¼ӻº´æ,Èç¹û´æÔÚÔò¸üÐÂ
+ ///
+ /// Ìí¼ӻº´æ¶ÔÏóÀàÐÍ
+ /// Ìí¼ӶÔÏóµÄkey
+ /// ֵ
+ /// Ïà¶ԹýÆڵÄTimeSpan
+ /// ¾ø¶ԹýÆÚʱ¼ä
+ /// »º´æ·ÖÇødb
+ /// ÊǷñÌí¼ӳɹ¦
+ bool AddOrUpdate(string key, T obj, TimeSpan slidingExpiration, DateTime? absoluteExpiration = null,
+ int db = 0);
+
+ ///
+ /// »ñȡ»º´æ¶ÔÏó
+ ///
+ /// »ñȡ»º´æ¶ÔÏóÀàÐÍ
+ /// key
+ /// »º´æ·ÖÇødb
+ /// »ñȡָ¶¨key¶ÔӦµÄֵ
+ T Get(string key, int db=0);
+
+ ///
+ /// »ñȡ»º´æ¶ÔÏó
+ ///
+ /// »ñȡ»º´æ¶ÔÏóÀàÐÍ
+ /// keyÁбí
+ /// »º´æ·ÖÇødb
+ /// »ñȡ¶à¸ö²»ͬÀàÐÍkey¶ÔӦµIJ»ֵͬ
+ IDictionary Get(IEnumerable keys, int db=0);
+
+ ///
+ /// ÒƳý»º´æ¶ÔÏó
+ ///
+ ///
+ ///
+ /// ÊǷñ³ɹ¦
+ bool Remove(string key, int db=0);
+
+ ///
+ /// ÅжÏÊǷñ´æÔڻº´æ¶ÔÏó
+ ///
+ /// keyֵ
+ /// »º´æ·ÖÇødb
+ ///
+ bool Contains(string key, int db=0);
+ }
+}
\ No newline at end of file
diff --git a/OS.Common/Log/ILogWriter.cs b/OS.Common/Modules/LogModule/ILogWriter.cs
similarity index 80%
rename from OS.Common/Log/ILogWriter.cs
rename to OS.Common/Modules/LogModule/ILogWriter.cs
index bc99b0c..8ef0947 100644
--- a/OS.Common/Log/ILogWriter.cs
+++ b/OS.Common/Modules/LogModule/ILogWriter.cs
@@ -1,6 +1,6 @@
-using OS.Common.Models.Enums;
+using OS.Common.ComModels.Enums;
-namespace OS.Common.Log
+namespace OS.Common.LogModule
{
///
/// 日志写实现接口
diff --git a/OS.Common/Modules/LogModule/LogUtil.cs b/OS.Common/Modules/LogModule/LogUtil.cs
new file mode 100644
index 0000000..676760b
--- /dev/null
+++ b/OS.Common/Modules/LogModule/LogUtil.cs
@@ -0,0 +1,174 @@
+
+using System.Collections.Generic;
+using OS.Common.Modules;
+using OS.Common.Modules.AsynModule;
+
+namespace OS.Common.LogModule
+{
+
+ public enum LogLevelEnum
+ {
+ ///
+ /// 跟踪查看
+ ///
+ Trace,
+ ///
+ /// 信息
+ ///
+ Info,
+
+ ///
+ /// 错误
+ ///
+ Error,
+
+ ///
+ /// 警告
+ ///
+ Warning,
+
+
+ }
+
+ public class LogInfo
+ {
+ ///
+ /// 空构造函数
+ ///
+ public LogInfo()
+ {
+ }
+
+ ///
+ /// 日志构造函数
+ ///
+ ///
+ ///
+ ///
+ ///
+ internal LogInfo(LogLevelEnum loglevel,string msg,object key=null,string moduleName=ModuleLogKeys.Default)
+ {
+ Level = loglevel;
+ ModuleName = moduleName;
+ Message = msg;
+ Key = key;
+ }
+
+ ///
+ /// 日志等级
+ ///
+ public LogLevelEnum Level { get; set; }
+
+ ///
+ /// 日志类型
+ ///
+ public string ModuleName { get; set; }
+ ///
+ /// key值 可以是id等
+ ///
+ public object Key { get; set; }
+
+ ///
+ /// 日志信息
+ ///
+ public string Message { get; set; }
+ }
+
+ ///
+ /// 日志写模块
+ ///
+ public static class LogUtil
+ {
+ /////
+ ///// 异步缓冲池
+ /////
+ //private static ActionBlock logActionList=new ActionBlock(info =>
+ //{
+ // var act = CreateLogWriter(info.Category);
+ // act.WriteLog(new LogInfo(info.Level,info.Category,info.Message,info.Key));
+ //},new ExecutionDataflowBlockOptions() { MaxDegreeOfParallelism = 3 } );
+
+ ///
+ /// 记录日志操作的异步模块
+ ///
+ internal static string LogAsynModuleName
+ {
+ get;
+ set;
+ }
+
+
+ internal static Dictionary logModules=
+ new Dictionary();
+
+
+ ///
+ /// 通过模块名称获取日志模块实例
+ ///
+ ///
+ ///
+ public static ILogWriter GetLogWrite(string logModule)
+ {
+ if (!string.IsNullOrEmpty(logModule)&&logModules.ContainsKey(logModule))
+ {
+ return logModules[logModule];
+ }
+ return logModules[ModuleCacheKeys.Default];
+ }
+
+ ///
+ /// 记录信息
+ ///
+ /// 日志信息
+ /// 关键值
+ /// 模块名称
+ public static void Info(string msg,object key=null,string moduleName=ModuleCacheKeys.Default)
+ {
+ Log(new LogInfo(LogLevelEnum.Info, msg, key, moduleName));
+ }
+
+ ///
+ /// 记录警告,用于未处理异常的捕获
+ ///
+ /// 日志信息
+ /// 关键值
+ /// 模块名称
+ public static void Warning( string msg, object key = null, string moduleName=ModuleCacheKeys.Default)
+ {
+ Log(new LogInfo(LogLevelEnum.Warning, msg, key, moduleName));
+ }
+
+ ///
+ /// 记录错误,用于捕获到的异常信息记录
+ ///
+ /// 日志信息
+ /// 关键值
+ /// 模块名称
+ public static void Error( string msg, object key = null, string moduleName=ModuleCacheKeys.Default)
+ {
+ Log(new LogInfo(LogLevelEnum.Error, msg, key, moduleName));
+ }
+
+ ///
+ /// 记录错误,用于捕获到的异常信息记录
+ ///
+ /// 分类
+ /// 日志信息
+ /// 关键值
+ /// 模块名称
+ public static void Trace(string category, string msg, object key = null, string moduleName=ModuleCacheKeys.Default)
+ {
+ Log(new LogInfo(LogLevelEnum.Trace, msg, key, moduleName));
+ }
+
+ ///
+ /// 记录日志
+ ///
+ ///
+ public static void Log(LogInfo info)
+ {
+ var logWrite = GetLogWrite(info.ModuleName);
+ AsynUtil.Asyn(logWrite.WriteLog, info, LogAsynModuleName); // logActionList.Post(info);
+ }
+ }
+}
diff --git a/OS.Common/Modules/LogModule/LogWriter.cs b/OS.Common/Modules/LogModule/LogWriter.cs
new file mode 100644
index 0000000..b7ab4d5
--- /dev/null
+++ b/OS.Common/Modules/LogModule/LogWriter.cs
@@ -0,0 +1,49 @@
+using System;
+using System.IO;
+using System.Text;
+
+namespace OS.Common.LogModule
+{
+ internal class LogWriter : ILogWriter
+ {
+ private readonly string logDirPath = null;
+ private const string logFormat = "{0:T} {1} {2}:{3}";
+
+ public LogWriter()
+ {
+ logDirPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"log\");
+ if (!Directory.Exists(logDirPath))
+ Directory.CreateDirectory(logDirPath);
+ }
+
+ private string getLogFilePath(string type)
+ {
+ StringBuilder sb = new StringBuilder(logDirPath);
+ sb.Append(DateTime.Now.ToString("yyyyMMdd"));
+ sb.Append("_");
+ sb.Append(type);
+ sb.Append(".txt");
+ return sb.ToString();
+ }
+
+
+ private object obj = new object();
+
+ ///
+ /// 写日志
+ ///
+ ///
+ public void WriteLog(LogInfo info)
+ {
+ lock (obj)
+ {
+ using (StreamWriter sw = new StreamWriter(getLogFilePath(info.Level.ToString()), true, Encoding.Default))
+ {
+ sw.WriteLine(logFormat, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), info.Key, info.ModuleName, info.Message);
+ sw.Close();
+ }
+ }
+ }
+
+ }
+}
diff --git a/OS.Common/Modules/ModuleKeys.cs b/OS.Common/Modules/ModuleKeys.cs
new file mode 100644
index 0000000..f4bd6ee
--- /dev/null
+++ b/OS.Common/Modules/ModuleKeys.cs
@@ -0,0 +1,35 @@
+namespace OS.Common.Modules
+{
+ ///
+ /// 缓存Module名称
+ ///
+ public class ModuleCacheKeys
+ {
+ ///
+ /// 默认系统缓存
+ ///
+ public const string Default = "default";
+ }
+
+ ///
+ /// 异步Module名称
+ ///
+ public class ModuleAsynKeys
+ {
+ ///
+ /// 默认系统异步
+ ///
+ public const string Default = "default";
+ }
+
+ ///
+ /// 日志Module名称
+ ///
+ public class ModuleLogKeys
+ {
+ ///
+ /// 默认本地文件日志
+ ///
+ public const string Default = "default";
+ }
+}
diff --git a/OS.Common/OS.Common.csproj b/OS.Common/OS.Common.csproj
index e36490a..e66234c 100644
--- a/OS.Common/OS.Common.csproj
+++ b/OS.Common/OS.Common.csproj
@@ -36,14 +36,16 @@
-
-
- False
- ..\..\OS.Enjoyurt\packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll
-
+
+
+
+
+
+
+
@@ -51,28 +53,28 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+