/// <summary> /// 导入数据到数据库 /// </summary> /// <param name="table">导入的数据表</param> /// <param name="tableName">数据库表名</param> public ImportState ImportSql(DataTable table, string tableName) { if (!TableExist(tableName)) //表名是否存在 { return(ImportState.TableNameError); } if (table == null) { return(ImportState.ExcelFormatError); } ArrayList tableField = GetTableField(tableName); //表格的列名称 StringBuilder columnName = new StringBuilder(); for (int i = 0; i < table.Columns.Count; i++) { columnName.Append(table.Columns[i].ColumnName + ","); string currentColumn = table.Columns[i].ToString().ToUpper(); //当前列名 for (int j = 0; j < tableField.Count; j++) { if (tableField[j].ToString().ToUpper() == table.Columns[i].ToString().ToUpper()) { break; //跳出本层和上一层循环,continue是跳出本层循环,如果用continue,会继续执行j++ Excel里的字段必须在Sql中都有 } if ((tableField[j].ToString().ToUpper() != table.Columns[i].ToString().ToUpper()) && j == tableField.Count - 1) { return(ImportState.FieldMatchError); } } } columnName.Remove(columnName.Length - 1, 1); //移除最后一个逗号 StringBuilder value = null; string con = ConfigContext.GetInstance().DataBaseSettingProvider.SimpleManagerConnstring; try { string strSql = string.Empty; for (int h = 0; h < table.Rows.Count; h++) { value = new StringBuilder(); for (int k = 0; k < table.Columns.Count; k++) //根据列名得到值 { value.Append("'" + table.Rows[h][k].ToString() + "',"); } value.Remove(value.Length - 1, 1); //移除最后一个逗号 strSql = "insert into " + tableName + "(" + columnName.ToString() + ") values(" + value + ")"; SqlHelper.ExecuteNonQuery(con, CommandType.Text, strSql); } //sqlTran.Commit(); return(ImportState.Success); } catch (Exception ex) { ErrorInfo = ex.Message; //sqlTran.Rollback(); return(ImportState.DataTypeError); } }
public void Publish_LesserRevisionIgnored() { //arrange var cts = new CancellationTokenSource(); var context = new ConfigContext(new Couchbase.Configuration()); context.Start(cts); context.Subscribe(_bucket); //act var config1 = new BucketConfig { Name = "default", Rev = 5 }; var config2 = new BucketConfig { Name = "default", Rev = 3 }; context.Publish(config1); Task.Delay(1, cts.Token).GetAwaiter().GetResult(); context.Publish(config2); Task.Delay(1, cts.Token).GetAwaiter().GetResult(); //assert Assert.Equal(config1.Rev, context.Get("default").Rev); }
private static void Main(string[] args) { try { DownloadConfig _config = new DownloadConfig(); _config.FileNameEncryptorIvHexString = "01 02 03 04 05 06 07 08 09 0a 0a 0c 0d 01 02 08"; _config.FileNameEncryptorKey = "DotnetDownloadConfig"; _config.LimitDownloadSpeedKb = 100; _config.DownLoadMainDirectory = @"D:\Downloads"; ConfigContext _configHelper = new ConfigContext(); _configHelper.Save <DownloadConfig>(_config); WebApiOutputCacheConfig _apiOutputCacheConfig = new WebApiOutputCacheConfig(); _apiOutputCacheConfig.EnableOutputCache = true; _configHelper.Save <WebApiOutputCacheConfig>(_apiOutputCacheConfig); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.ReadLine(); } }
public Cluster(Configuration configuration) { if (configuration == null) { throw new InvalidConfigurationException("Configuration is null."); } if (string.IsNullOrWhiteSpace(configuration.Password) || string.IsNullOrWhiteSpace(configuration.UserName)) { throw new InvalidConfigurationException("Username and password are required."); } _configTokenSource = new CancellationTokenSource(); _configuration = configuration; _couchbaseContext = new ConfigContext(_configuration); _couchbaseContext.Start(_configTokenSource); if (_configuration.EnableConfigPolling) { _couchbaseContext.Poll(_configTokenSource.Token); } _lazyQueryClient = new Lazy <IQueryClient>(() => new QueryClient(_configuration)); _lazyAnalyticsClient = new Lazy <IAnalyticsClient>(() => new AnalyticsClient(_configuration)); _lazySearchClient = new Lazy <ISearchClient>(() => new SearchClient(_configuration)); _lazyQueryManager = new Lazy <IQueryIndexes>(() => new QueryIndexes(_lazyQueryClient.Value)); _lazyBucketManager = new Lazy <IBucketManager>(() => new BucketManager(_configuration)); _lazyUserManager = new Lazy <IUserManager>(() => new UserManager(_configuration)); }
public HealthDataRepository(ConfigContext context, ILogger <HealthDataRepository> logger) : base(context, logger) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } string sErr = ""; try { _logger = logger; _context = context; } catch { goto Get_Out; } Get_Out: if (sErr.Length > 0) { _logger.LogError(sErr); } }
protected override bool InitCache() { try { string con = ConfigContext.GetInstance().DataBaseSettingProvider.SimpleManagerConnstring; string sGetSql = "select [PageID],[PageTitle],[PageUrl],[DisplayLeft],[PageDesc],[FatherPid],[LastModifyTime],[menuID] from GameOA.dbo.oa_purviewpage"; using (SqlDataReader oReader = SqlHelper.ExecuteReader(con, CommandType.Text, sGetSql)) { if (oReader == null) { throw new Exception(); } List<BasePurviewPage> tmpList = new List<BasePurviewPage>(); if (oReader.HasRows) { while (oReader.Read()) { BasePurviewPage oTmp = new BasePurviewPage(); oTmp.InitData(oReader); tmpList.Add(oTmp); } } this.addCache(tmpList); return true; } } catch (Exception ex) { this.SaveLog(ex); return false; } }
public IList <Comment> Get() { using (var connect = new ConfigContext()) { return(connect.Comments.ToList()); } }
public Comment Get(int id) { using (var connect = new ConfigContext()) { return(connect.Comments.Where(x => x.Id == id).SingleOrDefault()); } }
public List <User> users() { using (var db = new ConfigContext()) { return(db.User.Include(x => x.Profesion).ToList()); } }
private static void SendToMail(string content) { if (errorTimes > ContinuousTimes) { try { lock (thisLock) { errorTimes = 0; } Mail139Helper.SendMail("游戏登录监视", content, ConfigContext.GetInstance().SendTo139Mail, true); } catch (Exception ex) { Logger.SaveLog("Log in to check mail error", ex); } } else { lock (thisLock) { errorTimes++; } } }
public Cluster(string connectionStr, string username, string password) { var connectionString = ConnectionString.Parse(connectionStr); _configuration = new Configuration() .WithServers(connectionString.Hosts.ToArray()) .WithCredentials(username, password); if (!_configuration.Servers.Any()) { _configuration = _configuration.WithServers("couchbase://localhost"); } _couchbaseContext = new ConfigContext(_configuration); _couchbaseContext.Start(_configTokenSource); if (_configuration.EnableConfigPolling) { _couchbaseContext.Poll(_configTokenSource.Token); } _lazyQueryClient = new Lazy <IQueryClient>(() => new QueryClient(_configuration)); _lazyAnalyticsClient = new Lazy <IAnalyticsClient>(() => new AnalyticsClient(_configuration)); _lazySearchClient = new Lazy <ISearchClient>(() => new SearchClient(_configuration)); _lazyQueryManager = new Lazy <IQueryIndexes>(() => new QueryIndexes(_lazyQueryClient.Value)); _lazyBucketManager = new Lazy <IBucketManager>(() => new BucketManager(_configuration)); _lazyUserManager = new Lazy <IUserManager>(() => new UserManager(_configuration)); }
public bool GetFormula() { bool bHasFormula = false; string con = ConfigContext.GetInstance().DataBaseSettingProvider.SimpleManagerConnstring; string sGetSql = "select * from ConfigFormula where formulaid=@aformulaid"; SqlParameter[] paramsGet = new SqlParameter[1]; paramsGet[0] = SqlParamHelper.MakeInParam("@aformulaid", SqlDbType.Int, 0, _formulaId); using (SqlDataReader aReader = SqlHelper.ExecuteReader(con, CommandType.Text, sGetSql, paramsGet)) { if (aReader == null) { throw new Exception(); } if (aReader.HasRows) { bHasFormula = true; aReader.Read(); this.InitData(aReader); } } if (bHasFormula) { } return(bHasFormula); }
public AppBiz(ConfigContext configContext, IAppListService appListService, IUploadFileService uploadFileService, IMapper mapper, IAuthService authService) { _configContext = configContext; _appListService = appListService; _uploadFileService = uploadFileService; _mapper = mapper; _authService = authService; }
public void Create(Post post) { using (var connect = new ConfigContext()) { connect.Posts.Add(post); connect.SaveChanges(); } }
/// <summary> /// 获取最大Id /// </summary> /// <returns></returns> public int GetMaxId() { string con = ConfigContext.GetInstance().DataBaseSettingProvider.SimpleManagerConnstring; string sGetSql = "select max(groupid) from GameOA.dbo.oa_UserGroup "; object tobj = SqlHelper.ExecuteScalar(con, CommandType.Text, sGetSql); return(Convert.ToInt32(tobj) + 1); }
public void UpsertingExistingNameAndValue_CausesValueToBeStored() { ConfigContext sut = new ConfigContext("LevelKey", "LevelValue"); sut.UpsertConfigValue("AConfigKey", "AConfigValue"); sut.UpsertConfigValue("AConfigKey", "ANewConfigValue"); Assert.That(sut.GetConfigValue("AConfigKey").Equals("ANewConfigValue", StringComparison.InvariantCulture)); }
public User userFind(int id) { using (var db = new ConfigContext()) { this.User = db.User.Find(id); return(this.User); } }
public CloudService() { tenant = App.Context.GetTenantContext().Tenant; cloudConfig = ConfigContext.GetConfig <CloudConfig>(tenant.Name, (config, key) => { cloudConfig = config; }); }
internal MemcachedBucket(string name, Configuration configuration, ConfigContext couchbaseContext) { Name = name; CouchbaseContext = couchbaseContext; Configuration = configuration; CouchbaseContext.Subscribe(this); _httClusterMap = new HttpClusterMap(new CouchbaseHttpClient(Configuration), CouchbaseContext, Configuration); }
public void SettingValidDescriptorValue_ValueIsStored() { ConfigContext sut = new ConfigContext("", ""); sut.PlaneDescriptor = new KeyValuePair <string, string>("PlaneName", "ConfigContextName"); Assert.That(sut.PlaneDescriptor.Key.Equals("PlaneName", StringComparison.InvariantCulture)); Assert.That(sut.PlaneDescriptor.Value.Equals("ConfigContextName", StringComparison.InvariantCulture)); }
public void Create(Comment comment) { using (var connect = new ConfigContext()) { connect.Comments.Add(comment); connect.SaveChanges(); } }
public void TryGetValue_ReturnsFalseIfNoFound() { string configValue; ConfigContext sut = new ConfigContext("LevelKey", "LevelValue"); sut.UpsertConfigValue("AConfigKey", "AConfigValue"); Assert.IsFalse(sut.TryGetConfigValue("MissingKey", out configValue)); }
public virtual void Dispose() { if (ConfigContext != null) { ConfigContext.Dispose(); ConfigContext = null; } }
/// <summary> /// 获取最大栏目序号 /// </summary> /// <returns></returns> public int GetMaxDisplayIndex() { string con = ConfigContext.GetInstance().DataBaseSettingProvider.SimpleManagerConnstring; string sGetSql = "Select max(DisplayIndex) from GameOA.dbo.oa_leftmenu "; object tobj = SqlHelper.ExecuteScalar(con, CommandType.Text, sGetSql); return(Convert.ToInt32(tobj) + 1); }
public void SetUp() { _kernel = new StandardKernel(new ConfigModule()); Assert.IsNotNull(_kernel); _configProvider = _kernel.Get <IConfigProvider>(); _configContext = _kernel.Get <ConfigContext>(); }
public Startup(IConfiguration configuration) { Configuration = configuration; using (var clinet = new ConfigContext(new DbContextOptions <ConfigContext>())) { clinet.Database.EnsureCreated(); } }
internal MemcachedBucket(string name, ClusterOptions clusterOptions, ConfigContext couchbaseContext, HttpClusterMapBase httpClusterMap) { Name = name; CouchbaseContext = couchbaseContext; ClusterOptions = clusterOptions; CouchbaseContext.Subscribe(this); _httpClusterMap = httpClusterMap; }
public async Task AddRangeAsync(IEnumerable <TAggregateRoot> aggregateRoot) { using (var ctx = new ConfigContext()) { ctx.Set <TAggregateRoot>().AddRange(aggregateRoot); await ctx.SaveChangesAsync(); } }
// private static Lazy<Expression<Func<TAggregateRoot, bool>>> equalExpression = new Lazy<Expression<Func<TAggregateRoot, bool>>>(() => //{ // var arg = Expression.Parameter(typeof(TId), "id"); // var exp = Expression.Equal(arg, Expression.Constant(id, typeof(TId))); // var exp2 = Expression.Lambda<Func<TAggregateRoot, bool>>(exp, arg); // return exp2; //}); public async Task AddAsync(TAggregateRoot aggregateRoot) { using (var ctx = new ConfigContext()) { ctx.Set <TAggregateRoot>().Add(aggregateRoot); await ctx.SaveChangesAsync(); } }
private static void Main(string[] args) { try { ConfigContext _configContext = new ConfigContext(); //CacheConfig _cacheConfig = new CacheConfig(); //_cacheConfig.ClusteredByIndex = true; //_cacheConfig.CacheConfigItems = new CacheConfigItem[1]; //_cacheConfig.CacheConfigItems[0] = new CacheConfigItem(); //_cacheConfig.CacheConfigItems[0].Desc = "ASC"; //_cacheConfig.CacheConfigItems[0].IsAbsoluteExpiration = true; //_cacheConfig.CacheConfigItems[0].Minitus = 5; //_cacheConfig.CacheConfigItems[0].Priority = 1; //_cacheConfig.CacheConfigItems[0].ProviderName = "YanZhiwei.DotNet.Core.Config"; //_cacheConfig.CacheProviderItems = new CacheProviderItem[2]; //_cacheConfig.CacheProviderItems[0] = new CacheProviderItem(); //_cacheConfig.CacheProviderItems[0].Desc = "ASC"; //_cacheConfig.CacheProviderItems[0].Type = "YanZhiwei.DotNet.Core.Config"; //_cacheConfig.CacheProviderItems[1] = new CacheProviderItem(); //_cacheConfig.CacheProviderItems[1].Desc = "DES"; //_cacheConfig.CacheProviderItems[1].Type = "YanZhiwei.DotNet.Core.Config.Examples"; //_cacheConfig.UpdateNodeList<CacheProviderItem>(_cacheConfig.CacheProviderItems); //_configContext.Save<CacheConfig>(_cacheConfig, "A"); //var _cacheConfigA = _configContext.Get<CacheConfig>("A"); //var _cacheConfigB = CachedConfigContext.Current.Get<CacheConfig>("A"); //CabInComeConfig _cabInComeConfig = new CabInComeConfig(); //_cabInComeConfig.ClusteredByIndex = false; //_cabInComeConfig.CacheConfigItems = new CabInComeConfigItem[1]; //string _keyId = "3b0ddbf0-cdd3-4695-845a-d10ed99cab52"; //_cabInComeConfig.CacheConfigItems[0] = new CabInComeConfigItem(); //_cabInComeConfig.CacheConfigItems[0].CabId = Guid.NewGuid().ToString(); //_cabInComeConfig.CacheConfigItems[0].VoltageMaxValue = 240; //_cabInComeConfig.CacheConfigItems[0].VoltageMinValue = 210; //_cabInComeConfig.CacheConfigItems[0].CurrentMaxValue = 10; //_cabInComeConfig.CacheConfigItems[0].CurrentMinValue = 1; //_cabInComeConfig.CacheConfigItems[0].KeyId = _keyId; //_configContext.Save<CabInComeConfig>(_cabInComeConfig); var _cacheConfigC = CachedConfigContext.Current.CabInComeConfig; _cacheConfigC.CacheConfigItems[0].CurrentMaxValue = 30; _configContext.Save(_cacheConfigC); _cacheConfigC = CachedConfigContext.Current.CabInComeConfig; } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.ReadLine(); } }