예제 #1
0
 /// <summary>
 /// 添加或者合并Tables
 /// </summary>
 /// <param name="sqlConfig"></param>
 /// <param name="sqlTables"></param>
 public static void AddOrCombine(this ISqlConfig sqlConfig, IEnumerable <IConfigTableInfo> sqlTables)
 {
     foreach (var l in sqlTables)
     {
         sqlConfig.AddOrCombine(l);
     }
 }
예제 #2
0
 /// <summary>
 /// Sql数据库访问
 /// </summary>
 /// <param name="sqlConfig">数据库配置</param>
 /// <param name="userContext">用户上下文</param>
 public MsSqlQuery(ISqlConfig sqlConfig, IUserContext userContext)
 {
     AppendWhere  = " where 1=1 ";
     _sqlConfig   = sqlConfig;
     _userContext = userContext;
     _log         = Log.Log.GetLog("SqlTraceLog");
 }
예제 #3
0
 /// <summary>
 /// ef工作单元
 /// </summary>
 /// <param name="sqlConfig">sql配置</param>
 public ReadEfUnitOfWork(ISqlConfig sqlConfig)
 {
     _log    = Log.Log.GetLog("EfTraceLog");
     TraceId = DateTimeExtensions.GetUnixTimestamp().ToString() + "___" + base.GetHashCode();
     //_log.Warn("R工作单元创建" + this.TraceId);
     //NLog.LogManager.GetLogger("Debug").Error("R工作单元创建" + this.TraceId);
     _sqlConfig = sqlConfig;
 }
예제 #4
0
 /// <summary>
 /// 添加sql
 /// </summary>
 /// <param name="sqlConfig"></param>
 /// <param name="tableName"></param>
 /// <param name="sqlInfos"></param>
 public static void AddSqls(this ISqlConfig sqlConfig, string tableName,
                            IEnumerable <KeyValuePair <string, IConfigSqlInfo> > sqlInfos)
 {
     foreach (var pair in sqlInfos)
     {
         sqlConfig.Add(tableName, pair.Key, pair.Value);
     }
 }
예제 #5
0
 /// <summary>
 /// Установить новые настройки подключения
 /// </summary>
 /// <param name="value"></param>
 public void SetConfig(ISqlConfig value)
 {
     config = value;
     if (IsConnected())
     {
         Connect();
     }
 }
예제 #6
0
 /// <summary>
 /// ef工作单元
 /// </summary>
 /// <param name="sqlConfig">sql配置</param>
 public WriteEfUnitOfWork(ISqlConfig sqlConfig)
 {
     _log = Log.Log.GetLog("EfTraceLog");
     //TraceId = DateTimeExtensions.GetUnixTimestamp().ToString();
     //_log.Warn("W工作单元创建" + this.TraceId);
     TraceId = Uuid.Next();
     //NLog.LogManager.GetLogger("Debug").Error("W工作单元创建" + this.TraceId);
     _sqlConfig = sqlConfig;
 }
예제 #7
0
 /// <summary>
 /// Sql数据库访问
 /// </summary>
 /// <param name="sqlConfig">数据库配置</param>
 /// <param name="userContext">用户上下文</param>
 public SqlQuery(ISqlConfig sqlConfig, IUserContext userContext)
 {
     AppendWhere  = " where 1=1 ";
     _sqlConfig   = sqlConfig;
     _userContext = userContext;
     _log         = Log.Log.GetLog("SqlTraceLog");
     //this.CreateDbConnection();
     //this.Open();
 }
예제 #8
0
        public SQLRepository(ISqlConfig config)
        {
            _config = config;

            _client = new CosmosClient(config.EndPointUri, config.PrimaryKey);

            _database = _client.CreateDatabaseIfNotExistsAsync(_config.DataBase).Result.Database;

            _container = _database.CreateContainerIfNotExistsAsync(_config.Container, _config.PartitionKey).Result.Container;
        }
예제 #9
0
        /// <summary>
        /// 加载sql的配置文件
        /// </summary>
        /// <param name="sqlConfig"></param>
        /// <param name="configFilePath"></param>
        /// <param name="encoding"></param>
        public static void LoadFile(this ISqlConfig sqlConfig, string configFilePath, Encoding encoding)
        {
            var config = CommonExtensions.JsonToObjectNeedDefaultValue <JsonConfigTableInfo>(File.ReadAllText(configFilePath, encoding));

            if (string.IsNullOrEmpty(config.Name))
            {
                config.Name = Path.GetFileNameWithoutExtension(configFilePath);
            }
            sqlConfig.AddOrCombine(config);
        }
예제 #10
0
        public DBConfigTable(ISqlConfig config, string tableName, DbContext db)
        {
            config.CheckNull(nameof(config));
            tableName.CheckStringIsNullOrEmpty(nameof(tableName));
            db.CheckNull(nameof(db));

            _config   = config;
            DB        = db;
            TableName = tableName;
        }
예제 #11
0
        /// <summary>
        /// 从目录中获取sql的配置文件
        /// </summary>
        /// <param name="sqlConfig"></param>
        /// <param name="configDirectoryPath"></param>
        /// <param name="encoding"></param>
        /// <param name="isAllDirectories"></param>
        /// <param name="fileType"></param>
        public static void LoadDirectory(this ISqlConfig sqlConfig, string configDirectoryPath, Encoding encoding,
                                         bool isAllDirectories         = true,
                                         SqlConfigFileExtType fileType = SqlConfigFileExtType.json)
        {
            bool bLoad = false;

            string[] files;
            if (isAllDirectories)
            {
                files = Directory.GetFiles(configDirectoryPath, "*", SearchOption.AllDirectories);
            }
            else
            {
                files = Directory.GetFiles(configDirectoryPath);
            }
            if (files != null && files.Length > 0)
            {
                if (fileType == SqlConfigFileExtType.all)
                {
                    foreach (var f in files)
                    {
                        sqlConfig.LoadFile(f, encoding);
                    }
                    bLoad = true;
                }
                else
                {
                    var fileExts = new List <string>();
                    if ((fileType & SqlConfigFileExtType.json) == SqlConfigFileExtType.json)
                    {
                        fileExts.Add(EFHelper.Services.EFCoreExUtility.GetEnumDescription(SqlConfigFileExtType.json));
                    }
                    if ((fileType & SqlConfigFileExtType.txt) == SqlConfigFileExtType.txt)
                    {
                        fileExts.Add(EFHelper.Services.EFCoreExUtility.GetEnumDescription(SqlConfigFileExtType.txt));
                    }

                    var finfos = files.Select(l => new FileInfo(l)).Where(l => fileExts.Contains(l.Extension.ToLower())).ToList();
                    if (finfos != null && finfos.Count > 0)
                    {
                        foreach (var f in finfos)
                        {
                            sqlConfig.LoadFile(f, encoding);
                        }
                        bLoad = true;
                    }
                }
            }

            if (!bLoad)
            {
                throw new ArgumentException($"The directory [{configDirectoryPath}] does not exist SQL configuration file.",
                                            nameof(configDirectoryPath));
            }
        }
예제 #12
0
        /// <summary>
        /// 获取Table的配置信息
        /// </summary>
        /// <param name="sqlConfig"></param>
        /// <param name="tableName"></param>
        /// <param name="sqlName"></param>
        /// <param name="sqlInfo"></param>
        /// <returns></returns>
        public static bool TryGetSqlInfo(this ISqlConfig sqlConfig, string tableName, string sqlName, out IConfigSqlInfo sqlInfo)
        {
            sqlInfo = null;
            IConfigTableInfo table;

            if (sqlConfig.TableSqlInfos.TryGetValue(tableName, out table))
            {
                if (table.Sqls.TryGetValue(sqlName, out sqlInfo))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #13
0
        /// <summary>
        /// 获取sql的配置信息
        /// </summary>
        /// <param name="sqlConfig"></param>
        /// <param name="tableName"></param>
        /// <param name="sqlName"></param>
        /// <returns></returns>
        public static IConfigSqlInfo GetSqlInfo(this ISqlConfig sqlConfig, string tableName, string sqlName)
        {
            IConfigTableInfo table;

            if (sqlConfig.TableSqlInfos.TryGetValue(tableName, out table))
            {
                IConfigSqlInfo sqlInfo = null;
                if (table.Sqls.TryGetValue(sqlName, out sqlInfo))
                {
                    return(sqlInfo);
                }
                else
                {
                    throw new ArgumentException($"The key [{sqlName}] does not exist in the {nameof(IConfigSqlInfo)} collection.",
                                                nameof(sqlName));
                }
            }
            else
            {
                throw new ArgumentException($"The key [{tableName}] does not exist in the {nameof(IConfigTableInfo)} collection.",
                                            nameof(tableName));
            }
        }
예제 #14
0
        public SqlConfigManagerBase(ISqlConfigExecutorCreator sqlConfigExecutorCreator, IEFQueryCache efcache,
                                    ISqlParamConverter sqlParamConverter, ISqlPolicyManager policyExecutorMgr,
                                    IObjectReflector objReflec, IEFCoreExtendUtility util)
        {
            sqlConfigExecutorCreator.CheckNull(nameof(sqlConfigExecutorCreator));
            efcache.CheckNull(nameof(efcache));
            sqlParamConverter.CheckNull(nameof(sqlParamConverter));
            policyExecutorMgr.CheckNull(nameof(policyExecutorMgr));
            objReflec.CheckNull(nameof(objReflec));
            util.CheckNull(nameof(util));

            _sqlParamConverter        = sqlParamConverter;
            _efcache                  = efcache;
            _sqlConfigExecutorCreator = sqlConfigExecutorCreator;
            _policyMgr                = policyExecutorMgr;
            _objReflec                = objReflec;
            _util = util;

            _config = new SqlConfig(OnModified);
            _init   = new InitAction(DoInit);

            //添加默认的策略
            AddDefaultPolicies();
        }
예제 #15
0
 public SqlDatabase(ISqlConfig sqlConfig)
 {
     Configure(sqlConfig);
 }
예제 #16
0
파일: SqlFactory.cs 프로젝트: whislai/Whiz
 public static void Configure(ISqlConfig sqlConfig)
 {
     SqlDatabase = new SqlDatabase(sqlConfig.DatabaseProvider, sqlConfig.ConnectionString);
 }
예제 #17
0
        public static IServiceCollection AddSqlService <T>(this IServiceCollection services, ISqlConfig config, bool moreThanOne = false) where T : IDbConnection, new()
        {
            var scopedConfig = new SqlConfig <T>
            {
                ConnectionString = config.ConnectionString,
                Timeout          = config.Timeout
            };

            if (moreThanOne)
            {
                return(services
                       .AddTransient <ISqlService <T>, SqlService <T> >()
                       .AddSingleton <ISqlConfig <T> >(scopedConfig));
            }

            return(services
                   .AddTransient <ISqlService, SqlService <T> >()
                   .AddSingleton <ISqlConfig <T> >(scopedConfig));
        }
예제 #18
0
 public SqlUserProfileRepository(ISqlConfig config)
 {
     _config = config;
 }
예제 #19
0
 public SqlService(ISqlConfig <T> config)
 {
     _config = config;
 }
예제 #20
0
 /// <summary>
 /// 加载sql的配置文件(Encoding默认为Encoding.UTF8)
 /// </summary>
 /// <param name="sqlConfig"></param>
 /// <param name="configFilePath"></param>
 public static void LoadFile(this ISqlConfig sqlConfig, string configFilePath)
 {
     sqlConfig.LoadFile(configFilePath, Encoding.UTF8);
 }
예제 #21
0
 /// <summary>
 /// 加载sql的配置文件
 /// </summary>
 /// <param name="sqlConfig"></param>
 /// <param name="configFile"></param>
 /// <param name="encoding"></param>
 public static void LoadFile(this ISqlConfig sqlConfig, FileInfo configFile, Encoding encoding)
 {
     sqlConfig.LoadFile(configFile.FullName, encoding);
 }
예제 #22
0
 public void Configure(ISqlConfig sqlConfig)
 {
     Configure(sqlConfig.DatabaseProvider, sqlConfig.ConnectionString);
 }
예제 #23
0
 /// <summary>
 /// 从目录中获取sql的配置文件
 /// </summary>
 /// <param name="sqlConfig"></param>
 /// <param name="configDirectory"></param>
 /// <param name="encoding"></param>
 /// <param name="isAllDirectories"></param>
 /// <param name="fileType"></param>
 public static void LoadDirectory(this ISqlConfig sqlConfig, DirectoryInfo configDirectory,
                                  Encoding encoding, bool isAllDirectories = true,
                                  SqlConfigFileExtType fileType            = SqlConfigFileExtType.json)
 {
     sqlConfig.LoadDirectory(configDirectory.FullName, encoding, isAllDirectories, fileType);
 }
예제 #24
0
 /// <summary>
 /// Sql数据库访问
 /// </summary>
 /// <param name="sqlConfig">数据库配置</param>
 /// <param name="userContext">用户上下文</param>
 public SqlQuery(ISqlConfig sqlConfig, IUserContext userContext)
 {
     AppendWhere  = " where 1=1 ";
     _sqlConfig   = sqlConfig;
     _userContext = userContext;
 }
예제 #25
0
 /// <summary>
 /// 从目录中获取sql的配置文件
 /// </summary>
 /// <param name="sqlConfig"></param>
 /// <param name="configDirectoryPath"></param>
 /// <param name="isAllDirectories"></param>
 /// <param name="fileType"></param>
 public static void LoadDirectory(this ISqlConfig sqlConfig, string configDirectoryPath,
                                  bool isAllDirectories         = true,
                                  SqlConfigFileExtType fileType = SqlConfigFileExtType.json)
 {
     sqlConfig.LoadDirectory(configDirectoryPath, Encoding.UTF8, isAllDirectories, fileType);
 }
예제 #26
0
 public ConnectionArgs(ISqlConfig config, StatusDataBase status)
 {
     Config = config;
     Status = status;
 }
예제 #27
0
 /// <summary>
 /// 添加sql
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <param name="sqlConfig"></param>
 /// <param name="sqlInfos"></param>
 public static void AddSqls <TEntity>(this ISqlConfig sqlConfig,
                                      IEnumerable <KeyValuePair <string, IConfigSqlInfo> > sqlInfos)
 {
     sqlConfig.AddSqls(EFHelper.Services.EFCoreExUtility.GetTableName(typeof(TEntity), true), sqlInfos);
 }
예제 #28
0
 static ISqlRepository <T> NewSqlRepository <T>(ISqlConfig <T> config)
 {
     return(new SqlRepository <T>(config));
 }
예제 #29
0
 /// <summary>
 /// 加载sql的配置文件(Encoding默认为Encoding.UTF8)
 /// </summary>
 /// <param name="sqlConfig"></param>
 /// <param name="configFile"></param>
 public static void LoadFile(this ISqlConfig sqlConfig, FileInfo configFile)
 {
     sqlConfig.LoadFile(configFile, Encoding.UTF8);
 }