public async Task <TConfig> LoadConfig <TConfig>() where TConfig : EffectConfig, new() { var config = new TConfig(); var path = GetPath(config); if (File.Exists(path)) { var s = await File.ReadAllTextAsync(path); _logger.LogDebug("Config loaded from {path}: {config}", path, s); return(JsonConvert.DeserializeObject <TConfig>(s)); } return(config); }
static _() { // 获取XmlConfigFileAttribute特性,那里会指定配置文件名称 var att = typeof(TConfig).GetCustomAttribute <XmlConfigFileAttribute>(true); if (att == null || att.FileName.IsNullOrWhiteSpace()) { // 这里不能着急,派生类可能通过静态构造函数指定配置文件路径 //throw new XException("编码错误!请为配置类{0}设置{1}特性,指定配置文件!", typeof(TConfig), typeof(XmlConfigFileAttribute).Name); } else { _.ConfigFile = att.FileName; _.ReloadTime = att.ReloadTime; } // 实例化一次,用于触发派生类中可能的静态构造函数 var config = new TConfig(); }
// Glue to initialize a JobHost with the correct config and invoke the Test method. // Config also has the program on it. private void TestWorker <TConfig>() where TConfig : IExtensionConfigProvider, ITest <TConfig>, new() { var prog = new TConfig(); var jobActivator = new FakeActivator(); jobActivator.Add(prog); var appSettings = new FakeNameResolver(); appSettings.Add("y", "123"); IExtensionConfigProvider ext = prog; var host = TestHelpers.NewJobHost <TConfig>(jobActivator, ext, appSettings); ITest <TConfig> test = prog; test.Test(host); }
static public Dictionary <TEnum, TConfig> GetEnumConfigs <TEnum, TConfig>() where TConfig : Attribute { Dictionary <TEnum, TConfig> dict = new Dictionary <TEnum, TConfig>(); FieldInfo[] fieldList = typeof(TEnum).GetFields(); foreach (FieldInfo field in fieldList) { Type type = typeof(TConfig); TConfig tConfig = field.GetCustomAttribute <TConfig>(); if (tConfig == null) { continue; } TEnum tEnum = (TEnum)Enum.Parse(typeof(TEnum), field.Name); dict[tEnum] = tConfig; } return(dict); }
/// <summary> /// 更新新增用户信息 /// </summary> public void UpdateOrSaveUserInfo(ConfigObject configObject) { var entity = UserService.GetFirstEntity(x => x.NSRSBH == configObject.NSRSBH); if (entity != null) { string pwd = configObject.LoginPwd; string certPwd = configObject.CertPwd; entity.LoginPwd = pwd; entity.CertPwd = certPwd; entity.IsRemember = configObject.IsRemember; UserService.UpdateEntities(entity); } else { TConfig tconfig = CommonMapper.ToEntity <TConfig>(configObject); UserService.AddEntities(tconfig); } }
// Glue to initialize a JobHost with the correct config and invoke the Test method. // Config also has the program on it. private void TestWorker <TConfig>() where TConfig : IExtensionConfigProvider, ITest <TConfig>, new() { var prog = new TConfig(); var jobActivator = new FakeActivator(); jobActivator.Add(prog); IExtensionConfigProvider ext = prog; IHost host = new HostBuilder() .ConfigureDefaultTestHost <TConfig>(b => { b.AddExtension(ext); }, activator: jobActivator) .Build(); ITest <TConfig> test = prog; test.Test(host.GetJobHost <TConfig>()); }
public void SendAfterInit() { this.RegisterType <TopHandlerAdapter>(); var mSettings = this.BuildClientSettingsProps(); var authKey = mSettings.Object.ClientSession.AuthKey; var resultTaskSource = new TaskCompletionSource <object>(); var request = new RequestPing(); var response = new TPong(); var config = new TConfig { DcOptions = new TVector <IDcOption>() }; this.Resolve <Mock <IRequestService> >() .BuildGetAllRequestToReply(request) .BuildRegisterRequest <RequestInvokeWithLayer>(Task.FromResult((object)config)); var handlerAdapter = this.Resolve <TopHandlerAdapter>(); // --- mSettings.Object.ClientSession.AuthKey = null; var channel = new EmbeddedChannel(handlerAdapter); mSettings.Object.ClientSession.AuthKey = authKey; channel.Pipeline.FireUserEventTriggered(ESystemNotification.HandshakeComplete); resultTaskSource.SetResult(response); // --- Assert.NotNull(channel.ReadOutbound <RequestInvokeWithLayer>()); Assert.Equal(request, channel.ReadOutbound <RequestPing>()); }
//-------------------------------------- // PUBLIC METHODS //-------------------------------------- public override void initTags() { TConfig.initTags(); foreach (TagTemplate tag in TConfig.tags) { bool IsUniqueTag = true; foreach (TagTemplate t in _tags) { if (t.patern.Equals(tag.patern) && t.name.Equals(tag.name)) { IsUniqueTag = false; } } if (IsUniqueTag) { _tags.Add(tag); } } }
public static TConfig GetConfig <TConfig>() where TConfig : IBankInterfaceConfig, new() { var config = new TConfig(); var requiredFields = config.RequiredFields; var bankName = config.BankName; var loadedConfig = GetValuesFromConfig(bankName, requiredFields); foreach (var keyValuePair in loadedConfig) { if (requiredFields[keyValuePair.Key] == FieldType.StringToStringMap) { config.GetType().GetProperty(keyValuePair.Key).SetValue(config, ParseSecurityAnswers(keyValuePair.Value)); } else { config.GetType().GetProperty(keyValuePair.Key).SetValue(config, keyValuePair.Value); } } return(config); }
public void InitLize(NetConfig netConfig) { tConfig = (TConfig)netConfig; }