private void LoadConfigsIntoCollection(string pattern, ConfigCollection configs) { try { LoadConfigsIntoCollectionFromFiles(pattern, configs); }catch(Exception ex){ throw new ConfiguratorException(string.Format("Error while loading XML configuration for the config with pattern '{0}'", pattern), ex); } }
public void Setup() { eventConfig = null; eventCollection = null; configAddedCount = 0; configRemovedCount = 0; }
public void ConfigCollectionEvents() { IniConfigSource source = new IniConfigSource(); source.Configs.ConfigAdded += new ConfigEventHandler(this.source_configAdded); source.Configs.ConfigRemoved += new ConfigEventHandler(this.source_configRemoved); Assert.AreEqual(configAddedCount, 0); eventCollection = null; IConfig config = source.AddConfig("Test"); Assert.IsTrue(source.Configs == eventCollection); Assert.AreEqual(configAddedCount, 1); Assert.AreEqual("Test", eventConfig.Name); eventCollection = null; config = source.Configs.Add("Test 2"); Assert.IsTrue(source.Configs == eventCollection); Assert.AreEqual(configAddedCount, 2); Assert.AreEqual("Test 2", eventConfig.Name); eventCollection = null; source.Configs.RemoveAt(0); Assert.IsTrue(source.Configs == eventCollection); Assert.AreEqual(configAddedCount, 2); Assert.AreEqual("Test", eventConfig.Name); }
private void VisitMode(ConfigCollection mode) { foreach (var data in mode.Data) { EnterContext(data.Key); VisitValue(data.Value); ExitContext(); } EnterContext("KeyBinds"); foreach (var key in mode.KeyBinds) { EnterContext(key.Key); VisitValue(key.Value); ExitContext(); } ExitContext(); foreach (var cmode in mode.Modes) { EnterContext(cmode.Key); VisitMode(cmode.Value); ExitContext(); } }
public void Renames_BarColorsFocusedWorkspace_Corretly() { // Arrange var expectedBorder = "#001122"; var expectedBackground = "#112233"; var expectedText = "ffeedd"; var data = new ConfigCollection("Default"); var bar = new ConfigCollection("bar", data); var colors = new ConfigCollection("colors", bar); var focus = new ConfigCollection("focused_workspace", bar); data.Modes.Add("bar", bar); bar.Modes.Add("colors", colors); colors.Modes.Add(focus.Name, focus); focus.AddData("border", expectedBorder); focus.AddData("background", expectedBackground); focus.AddData("text", expectedText); var sut = CreateSut(data); // Act var result = sut.ParseStream(null); // Assert result.Should().ContainKey("Bar:Colors:FocusedWorkspace:Border"); result["Bar:Colors:FocusedWorkspace:Border"].Should().Be(expectedBorder); result.Should().ContainKey("Bar:Colors:FocusedWorkspace:Background"); result["Bar:Colors:FocusedWorkspace:Background"].Should().Be(expectedBackground); result.Should().ContainKey("Bar:Colors:FocusedWorkspace:Text"); result["Bar:Colors:FocusedWorkspace:Text"].Should().Be(expectedText); }
public bool Parse(string[] particles, ref ConfigCollection data) { FetchResult = null; // Try parse outer "colors {}" command and return if it was a success if (ParseColors(particles, ref data)) { return(true); } // Try parse colors that has only one color on them (and located inside colors mode) foreach (var color in _validSingleColors) { if (ParseSingleColor(color, particles, ref data)) { return(true); } } // Try parse colors that got three colors on them (and located inside colors mode) foreach (var color in _validColorClass) { if (ParseColorClass(color, particles, ref data)) { return(true); } } return(false); }
private bool ParseSingleColor(string color, string[] particles, ref ConfigCollection data) { if (data.Name != "colors" || particles[0] != color) { return(false); } if (particles.Length != 2) { AddError($"Invalid command \"{string.Join(' ', particles)}\". should be: \"{color} #0055aa\""); return(true); } var regex = new Regex(@"^#([0-9a-fA-F]{6}|[0-9a-fA-F]{8})$", RegexOptions.Compiled); if (regex.IsMatch(particles[1]) == false) { AddError($"bar:colors should be of format #00aaFF or #00aaFFbb (\"{string.Join(' ', particles)}\" is not)"); return(true); } data.AddData(color, particles[1]); FetchResult = new ParseInstructionResult(FileParserStateResult.None, "", this); return(true); }
/// <summary> /// 加载所有配置实现 /// </summary> /// <param name="services"></param> private static void AddImplementTypes(this IServiceCollection services) { var configs = new ConfigCollection(); var assemblies = AssemblyHelper.Load(); foreach (var assembly in assemblies) { var types = assembly.GetTypes().Where(m => typeof(IConfig).IsImplementType(m) && typeof(IConfig) != m); foreach (var implType in types) { if (implType.FullName.NotNull()) { var descriptor = new ConfigDescriptor { Type = implType.FullName.Contains(".Lib.") ? ConfigType.Library : ConfigType.Module, Code = implType.Name.Replace("Config", ""), ImplementType = implType }; configs.Add(descriptor); } } } services.AddChangedEvent(assemblies, configs); services.AddSingleton <IConfigCollection>(configs); }
private bool ParseColorClass(string color, string[] particles, ref ConfigCollection data) { if (data.Name != "colors" || particles[0] != color) { return(false); } if (particles.Length != 4) { AddError($"Invalid command \"{string.Join(' ', particles)}\". should be: \"{color} #0055aa #ffaa00 #bbccdd\""); return(true); } var regex = new Regex(@"^#([0-9a-fA-F]{6}|[0-9a-fA-F]{8})$", RegexOptions.Compiled); for (int i = 1; i < particles.Length; i++) { if (regex.IsMatch(particles[i]) == false) { AddError($"bar:colors should be of format #00aaFF or #00aaFFbb (\"{particles[i]}\" is not)"); return(true); } } // Add this type of colors as modes var newData = new ConfigCollection(color, data); data.Modes.Add(color, newData); newData.AddData("border", particles[1]); newData.AddData("background", particles[2]); newData.AddData("text", particles[3]); FetchResult = new ParseInstructionResult(FileParserStateResult.None, "", this); return(true); }
public bool Parse(string[] particles, ref ConfigCollection data) { if (particles[0] != Instruction) { FetchResult = null; return(false); } variableFinder.PushContext(data); var keybind = variableFinder.ParseAll(particles[1]); var command = string.Join(' ', particles.Skip(2)); if (commandExecutor.Execute(command, data, commandHandler) == null) { AddError($"Unknown bindsym command \"{command}\""); variableFinder.PopContext(); FetchResult = null; return(true); } data.KeyBinds.Add(keybind, command); variableFinder.PopContext(); FetchResult = new ParseInstructionResult(FileParserStateResult.None, "", this); return(true); }
/// <summary> /// 获取配置 /// </summary> /// <param name="appIDs"></param> /// <param name="service"></param> /// <param name="cluster"></param> public void GetConfig(string[] appIDs, ServiceConfig service, string cluster = "default") { RemoteConfigs remoteConfigs = new RemoteConfigs(); foreach (var appID in appIDs) { var data = GetConfigFromServer(service.HomePageUrl, appID, _apolloConfig.Env); if (data != null) { if (data.Configurations != null && data.Configurations.Any()) { ConfigCollection.Set(_apolloConfig.Env, data); } else { ConfigCollection.Remove(_apolloConfig.Env, data.Cluster, data.AppId); } //cluster = data.Cluster; 移除本行代码,避免灰度异常 if (PathHelper.Create(_cachePath)) { var fileName = FileHelper.GetCacheName(_cachePath, _apolloConfig.Env, data.Cluster, data.AppId); FileHelper.Write(fileName, data); } } else { data = GetConfigFromLocal(appID, cluster); } } }
public void ConfigStore() { var configDir = @"config"; var config = new ConfigCollection(configDir); config.CommentConfiguration.Styles.Add(new CustomStyle { Name = "Style-1" }); config.CommentConfiguration.Classifications.Add( new Classification { Name = "Csl-1", Token = "c", Style = config.CommentConfiguration.Styles[0] }); if (Directory.Exists(configDir)) { foreach (var file in Directory.GetFiles(configDir)) { File.Delete(file); } } config.SaveAllChanges(); config.LoadAll(); Assert.Same( config.CommentConfiguration.Styles[0], config.CommentConfiguration.Classifications[0].Style); }
public void CreateWatchedConfig_AddConfigToCollection_ConfigRemovedFromCollectionWhenFileChanged() { var configs = new ConfigCollection(); File.WriteAllText(filePath, @"<configuration><test value=""Hello World"" /></configuration>"); IConfig config1 = FileConfigFactory.CreateWithWatcher("myCustomKey", filePath); configs.Add(config1); Assert.AreEqual("Hello World", configs["myCustomKey"].GetValue("test")); File.WriteAllText(filePath, @"<configuration><test value=""Hello Universe"" /></configuration>"); for (int retries = 100; retries >= 0; retries--) { if (config1.IsDiscarded) { break; } Thread.Sleep(10); } Assert.IsTrue(config1.IsDiscarded, "config not discarded after 1 second"); Assert.IsFalse(configs.Contains("myCustomKey")); IConfig config2 = FileConfigFactory.Create("myCustomKey", filePath); Assert.AreEqual("Hello Universe", config2.GetValue("test")); }
public IConfig Load(string configKey) { var configs = new ConfigCollection(); LoadConfigsIntoCollection(configKey, configs); if(configs.Contains(configKey)) { return configs[configKey]; } return null; }
public static IConfig GetOrAdd(this ConfigCollection cfg, string name) { if (cfg [name] != null) { return(cfg [name]); } return(cfg.Add(name)); }
public void Add_InsertConfigThatIsDiscarded_ThrowsConfigDiscardedException() { var configs = new ConfigCollection(); var config = new Config("testConfig", GetConfigXmlDocument(@"<test />")); config.Discard(); Assert.Throws <ConfigDiscardedException>(() => configs.Add(config)); }
public void AlreadyExistsException() { ConfigBase config = new ConfigBase("Test", null); ConfigCollection collection = new ConfigCollection(null); collection.Add(config); collection.Add(config); // exception }
public void Add_InsertConfig_CollectionContainsConfig() { var configs = new ConfigCollection(); var config = new Config("testConfig", GetConfigXmlDocument(@"<test />")); configs.Add(config); Assert.IsTrue(configs.Contains(config)); }
public void Add_InsertCofigWithSameKeyTwice_ThrowsArgumentException() { var configs = new ConfigCollection(); var config = new Config("testConfig", GetConfigXmlDocument(@"<test />")); configs.Add(config); Assert.Throws <ArgumentException>(() => configs.Add(config)); }
public void Import(LiteDatabase originalDb) { ConfigCollection.InsertBulk(originalDb.GetCollection <ConfigSetting>("config").FindAll()); AliasCollection.InsertBulk(originalDb.GetCollection <Alias>("alias").FindAll()); TimeCollection.InsertBulk(originalDb.GetCollection <TimeEntry>("time").FindAll()); _db.GetCollection <DataFormatVersion>("data_version").Insert(new DataFormatVersion { Version = CurrentDataVersion }); }
public void Add_InsertConfigAndDiscardConfig_CollectionDoesNotContainConfig() { var configs = new ConfigCollection(); var config = new Config("testConfig", GetConfigXmlDocument(@"<test />")); configs.Add(config); Assert.IsFalse(config.IsDiscarded); config.Discard(); Assert.IsTrue(config.IsDiscarded); Assert.IsFalse(configs.Contains(config)); }
public void NameAlreadyExists() { ConfigBase config1 = new ConfigBase("Test", null); ConfigBase config2 = new ConfigBase("Test", null); ConfigCollection collection = new ConfigCollection(null); collection.Add(config1); collection.Add(config2); // merges, no exception }
private TWConfigurationFileParser CreateSut(ConfigCollection data) { var parser = new Mock <IFileParser>(); parser.SetupGet(m => m.Data).Returns(data); var sut = new TWConfigurationFileParser(parser.Object); return(sut); }
public ConfigViewModel() : base("設定") { ConfigCollection.Add(General = new ConfigGeneralViewModel(this)); ConfigCollection.Add(new ConfigRankingViewModel()); ConfigCollection.Add(Video = new ConfigVideoViewModel()); ConfigCollection.Add(Comment = new ConfigCommentViewModel()); ConfigCollection.Add(NGComment = new ConfigNGCommentViewModel()); ConfigCollection.Add(NGFilter = new ConfigNGFilterViewModel()); ConfigCollection.Add(Live = new ConfigLiveViewModel()); }
public void Add_WhenAddingMultipleConfigs_ThenSizeShouldBeEqualToThat() { var config = new ConfigCollection(); const int expectedSize = 2; config.Add(new Mock<IConfig>().Object); config.Add(new Mock<IConfig>().Object); Assert.That(config.Size(), Is.EqualTo(expectedSize)); }
public void AlreadyExistsException() { var config = new ConfigBase("Test", null); var collection = new ConfigCollection(null) { config }; Assert.Throws <ArgumentException>(() => collection.Add(config)); }
public bool?Execute(string cmd, ConfigCollection context, ICommandHandler handler) { var commands = builder.Build(); builder.VariableFinder.PushContext(context); var command = commands.FirstOrDefault(c => c.Validate(cmd)); var result = command?.Execute(handler, cmd); builder.VariableFinder.PopContext(); return(result); }
/// <summary> /// 构造 /// </summary> /// <param name="collection"></param> /// <param name="group"></param> /// <param name="updateAction"></param> /// <param name="classify"></param> public ClassifyGroupConfig(ObservableCollection <TConfig> collection, Expression <Func <TConfig, string> > group, Action <string, TConfig> updateAction, ConfigCollection <ClassifyItem <TConfig> > classify = null) { _collection = collection; _collection.CollectionChanged += CollectionChanged; _groupFunc = group.Compile(); _propertyName = ((MemberExpression)group.Body).Member.Name; _updateAction = updateAction; Classifies = classify ?? new ConfigCollection <ClassifyItem <TConfig> >(); ReGroup(); }
public void Test() { var c1 = new ConfigCollection(); var cc = c1.CommentConfiguration; var c2 = new ConfigCollection(); var c3 = new ConfigCollection(); Assert.Same(cc, c2.CommentConfiguration); Assert.Same(cc, c3.CommentConfiguration); }
public static ConfigCollection SelectAll() { ConfigCollection List = new ConfigCollection(); using (IDataReader rd = SqlHelper.ExecuteReader(DAL.con(), CommandType.StoredProcedure, "tblRss_sp_tblRssConfig_Select_SelectAll_linhnx")) { while (rd.Read()) { List.Add(getFromReader(rd)); } } return(List); }
public void FillConfigValues() { string[] valueNames = _baseKey.GetValueNames(); ConfigCollection configCollection = new ConfigCollection(); foreach (string name in valueNames) { configCollection.Add(new KeyValuePair <string, string>(name, _baseKey.GetValue(name, string.Empty).ToString())); } ConfigValues.Instance.FillConfigValues(configCollection); }
private Resources(string mongoDbConnectionString, string databaseName, int logLevel = 5, Dictionary <string, Func <IDispatchVendor> > additionalDispatchCreatorStrategies = default, string bulkVendorName = "sparkpost", int bulkReadSize = 10000, string surveyBaseDomain = "nps.bz", string unsubscribeUrl = "https://cx.getcloudcherry.com/l/unsub/?token=") { #region MongoDB Management MongoClientSettings settings = MongoClientSettings.FromUrl(new MongoUrl(mongoDbConnectionString)); settings.MaxConnectionIdleTime = TimeSpan.FromMinutes(3); settings.ConnectTimeout = TimeSpan.FromSeconds(20); settings.MaxConnectionPoolSize = 1000; settings.ReadPreference = ReadPreference.Primary; MongoClient = new MongoClient(settings); ConfigCollection = MongoClient.GetDatabase(databaseName).GetCollection <AccountConfiguration>("AccountConfiguration"); LogEventCollection = MongoClient.GetDatabase(databaseName).GetCollection <LogEvent>("EventLog"); BulkMessagePayloadCollection = MongoClient.GetDatabase(databaseName).GetCollection <DB_MessagePayload>("BulkMessage"); AccountConfiguration = ConfigCollection.Find(_ => true).FirstOrDefault(); if (AccountConfiguration == default) { throw new MissingMemberException("Account-Configuration wasn't found"); } #endregion #region Miscellaneous Management HttpClient = new HttpClient(); SmtpLock = new object(); LogLevel = logLevel < 1 ? 1 : logLevel; DispatchReadyVendor_CreationStrategies = new Dictionary <string, Func <IDispatchVendor> >() { { "customsmtp", () => new CustomSMTP() }, { "messagebird", () => new MessageBird() }, { "sparkpost", () => new SparkPost() } }; if (default != additionalDispatchCreatorStrategies) { foreach (var kvp in additionalDispatchCreatorStrategies) { DispatchReadyVendor_CreationStrategies.Add(kvp.Key, kvp.Value); } } BulkVendorName = bulkVendorName; BulkReadSize = bulkReadSize < 0 ? 0 : bulkReadSize; SurveyBaseDomain = surveyBaseDomain; UnsubscribeBaseUrl = unsubscribeUrl; #endregion }
public OperationResult Parse(string inputString) { _json = inputString; var working = new WorkingTransform(); working.Parse(new JsonTextReader(new StringReader(_json))); var entities = working.Yield(); var collection = new ConfigCollection(); collection.WrappedConfigEntities = entities; return(OperationResult.Success(collection)); }
public void Checks_WhenUsingMultipleConfigs_ThenChecksShouldReturnTheCombinationOfTheConfigs() { var configCollection = new ConfigCollection(); var configOne = new Mock<IConfig>(); const int expectedChecks = 4; configOne.Setup(m => m.Checks).Returns( new List<Check> { new Check { Url = "http://www.google.com/" }, new Check { Url = "http://www.bbc.co.uk/" } } ); var configTwo = new Mock<IConfig>(); configTwo.Setup(m => m.Checks).Returns( new List<Check> { new Check { Url = "http://www.bing.com/" }, new Check { Url = "http://www.yahoo.com/" } } ); configCollection.Add(configOne.Object); configCollection.Add(configTwo.Object); var checks = configCollection.Checks; Assert.That(checks.Count, Is.EqualTo(expectedChecks)); Assert.That(checks[0].Url, Is.EqualTo("http://www.google.com/")); Assert.That(checks[1].Url, Is.EqualTo("http://www.bbc.co.uk/")); Assert.That(checks[2].Url, Is.EqualTo("http://www.bing.com/")); Assert.That(checks[3].Url, Is.EqualTo("http://www.yahoo.com/")); }
public void CreateWatchedConfig_AddConfigToCollection_ConfigRemovedFromCollectionWhenFileChanged() { var configs = new ConfigCollection(); File.WriteAllText(filePath, @"<configuration><test value=""Hello World"" /></configuration>"); IConfig config1 = FileConfigFactory.CreateWithWatcher("myCustomKey", filePath); configs.Add(config1); Assert.AreEqual("Hello World", configs["myCustomKey"].GetValue("test")); File.WriteAllText(filePath, @"<configuration><test value=""Hello Universe"" /></configuration>"); for(int retries = 100; retries >= 0; retries--) { if(config1.IsDiscarded) { break; } Thread.Sleep(10); } Assert.IsTrue(config1.IsDiscarded, "config not discarded after 1 second"); Assert.IsFalse(configs.Contains("myCustomKey")); IConfig config2 = FileConfigFactory.Create("myCustomKey", filePath); Assert.AreEqual("Hello Universe", config2.GetValue("test")); }
public static IConfig Create(Options options) { IConfig config; if (HasMultipleFiles(options)) { var configCollection = new ConfigCollection(); foreach (var file in options.Inputfiles) { configCollection.Add(GetConfig(file)); } config = configCollection; } else { config = GetConfig(options.Inputfiles.First()); } return config; }
public void Add_InsertConfigThatIsDiscarded_ThrowsConfigDiscardedException() { var configs = new ConfigCollection(); var config = new Config("testConfig", GetConfigXmlDocument(@"<test />")); config.Discard(); Assert.Throws<ConfigDiscardedException>(() => configs.Add(config)); }
public void Add_InsertCofigWithSameKeyTwice_ThrowsArgumentException() { var configs = new ConfigCollection(); var config = new Config("testConfig", GetConfigXmlDocument(@"<test />")); configs.Add(config); Assert.Throws<ArgumentException>(() => configs.Add(config)); }
public void InitializeCollection(ConfigCollection configs) { if(LoadAllFilesOnInit) { LoadConfigsIntoCollection("*", configs); } }
public ConfigRepository(IConfigLoader configLoader, string systemConfigKey, string appConfigKey) { this.configLoader = configLoader; configurations = configLoader.LoadOnInit(); this.systemConfigKey = systemConfigKey; this.appConfigKey = appConfigKey; }
public void InitializeCollection(ConfigCollection configs) { }
public void ConfigCollection_ImplementsIConfig() { var config = new ConfigCollection(); Assert.That(config, Is.InstanceOf<IConfig>()); }
public void Size_WhenConfigIsEmpty_ThenReturnZero() { var config = new ConfigCollection(); Assert.That(config.Size(), Is.EqualTo(0)); }
public ConfigCollection LoadOnInit() { var configs = new ConfigCollection(); InitializeCollection(configs); return configs; }
private void LoadConfigsIntoCollectionFromFiles(string pattern, ConfigCollection configs) { if(pattern.IndexOfAny(IllegalPathCharacters) < 0) { var files = GetFiles(pattern); foreach(var file in files) { var configFromFile = FileConfigFactory.Create(file, AddFileWatchers); if(!configs.Contains(configFromFile.ConfigKey)) { configs.Add(configFromFile); } } } }