public void Get_Resolver_DoesNot_Throw_Exception_If_ProcessResource_Was_Called() { // arrange string path = EmbeddedResourceUtil.ExportToPath("Castle.Windsor.Extensions.Test.data", "castle.config", Path.GetTempPath()); PropertiesInterpreter interpreter = new PropertiesInterpreter(path); WindsorContainer container = new WindsorContainer(); interpreter.ProcessResource(interpreter.Source, container.Kernel.ConfigurationStore, container.Kernel); ConfigurationProcessingException actual = null; IPropertyResolver resolver = null; // act try { resolver = interpreter.Resolver; } catch (ConfigurationProcessingException e) { actual = e; } // assert Assert.IsNull(actual); Assert.IsNotNull(resolver); }
public override Expression ToExpression <T>(IPropertyResolver propertyResolver) { return(Expression.Call( instance: null, likeMethod ?? throw new Exception(), functions, this.Left.ToExpression <T>(propertyResolver), this.Right.ToExpression <T>(propertyResolver))); }
public void Get_Resolver_DoesNot_Throws_Exception_Once_SubSystem_Is_Initialised() { // arrange string path = EmbeddedResourceUtil.ExportToPath("Castle.Windsor.Extensions.Test.data", "castle.config", Path.GetTempPath()); PropertiesSubSystem subSystem = new PropertiesSubSystem(path); WindsorContainer container = new WindsorContainer(); container.Kernel.AddSubSystem(PropertiesSubSystem.SubSystemKey, subSystem); KernelException actual = null; IPropertyResolver resolver = null; // act try { resolver = subSystem.Resolver; } catch (KernelException e) { actual = e; } // assert Assert.IsNull(actual); Assert.IsNotNull(resolver); }
public void Get_Resolver_Throws_Exception_If_SubSystem_Not_Initialised() { // arrange string path = EmbeddedResourceUtil.ExportToPath("Castle.Windsor.Extensions.Test.data", "invalid-castle.config", Path.GetTempPath()); PropertiesSubSystem subSystem = new PropertiesSubSystem(path); const string expectedMessagePrefix = "Error processing node castle"; string actualMessage = string.Empty; IPropertyResolver resolver = null; // act try { resolver = subSystem.Resolver; WindsorContainer container = new WindsorContainer(); container.Kernel.AddSubSystem(PropertiesSubSystem.SubSystemKey, subSystem); } catch (ConfigurationProcessingException e) { actualMessage = e.Message; } // assert Assert.IsNull(resolver); Assert.IsTrue(actualMessage.StartsWith(expectedMessagePrefix)); }
public void Get_Resolver_Throws_Exception_If_ProcessResource_Was_Not_Called() { // arrange string path = EmbeddedResourceUtil.ExportToPath("Castle.Windsor.Extensions.Test.data", "castle.config", Path.GetTempPath()); PropertiesInterpreter interpreter = new PropertiesInterpreter(path); ConfigurationProcessingException expected = new ConfigurationProcessingException("Properties file has not been processed yet. Have you missed calling PropertiesInterpreter.ProcessResource(IResource,IConfigurationStore,IKernel)"); ConfigurationProcessingException actual = null; // act try { IPropertyResolver resolver = interpreter.Resolver; } catch (ConfigurationProcessingException e) { actual = e; } // assert Assert.IsNotNull(actual); Assert.AreEqual(expected.Message, actual.Message); }
public PropertyManager( IValueTypePropertyHandler valueTypePropertyHandler, IPropertyNameStrategy propertyNameStrategy, IPropertyResolver propertyResolver, IStringPropertyHandler stringPropertyHandler, IContentAreaPropertyHandler contentAreaPropertyHandler, IUrlPropertyHandler urlPropertyHandler, IStringArrayPropertyHandler stringArrayPropertyHandler, IContentReferencePropertyHandler contentReferencePropertyHandler, IPageTypePropertyHandler pageTypePropertyHandler, IContentReferenceListPropertyHandler contentReferenceListPropertyHandler, IXhtmlStringPropertyHandler xhtmlStringPropertyHandler, ILinkItemCollectionPropertyHandler linkItemCollectionPropertyHandler, ICustomPropertiesHandler customPropertiesHandler ) { _valueTypePropertyHandler = valueTypePropertyHandler ?? throw new ArgumentNullException(nameof(valueTypePropertyHandler)); _propertyNameStrategy = propertyNameStrategy ?? throw new ArgumentNullException(nameof(propertyNameStrategy)); _propertyResolver = propertyResolver ?? throw new ArgumentNullException(nameof(propertyResolver)); _stringPropertyHandler = stringPropertyHandler ?? throw new ArgumentNullException(nameof(stringPropertyHandler)); _contentAreaPropertyHandler = contentAreaPropertyHandler ?? throw new ArgumentNullException(nameof(contentAreaPropertyHandler)); _urlPropertyHandler = urlPropertyHandler ?? throw new ArgumentNullException(nameof(urlPropertyHandler)); _stringArrayPropertyHandler = stringArrayPropertyHandler ?? throw new ArgumentNullException(nameof(stringArrayPropertyHandler)); _contentReferencePropertyHandler = contentReferencePropertyHandler ?? throw new ArgumentNullException(nameof(contentReferencePropertyHandler)); _pageTypePropertyHandler = pageTypePropertyHandler ?? throw new ArgumentNullException(nameof(pageTypePropertyHandler)); _contentReferenceListPropertyHandler = contentReferenceListPropertyHandler ?? throw new ArgumentNullException(nameof(contentReferenceListPropertyHandler)); _xhtmlStringPropertyHandler = xhtmlStringPropertyHandler ?? throw new ArgumentNullException(nameof(xhtmlStringPropertyHandler)); _linkItemCollectionPropertyHandler = linkItemCollectionPropertyHandler ?? throw new ArgumentNullException(nameof(linkItemCollectionPropertyHandler)); _customPropertiesHandler = customPropertiesHandler ?? throw new ArgumentNullException(nameof(customPropertiesHandler)); }
public IConfigurationProvider Build(IConfigurationBuilder builder) { Resolver = !_secretId.IsEmpty() ? new PropertyResolver(PropertySecret.ReadFromSecret(_secretId).Properties) : new PropertyResolver(_values !); return(new PropertyResolverProvider(this)); }
public ResolverConfigurationProvider(IConfiguration configuration, IPropertyResolver propertyResolver) { configuration.VerifyNotNull(nameof(configuration)); propertyResolver.VerifyNotNull(nameof(propertyResolver)); _configuration = configuration; _propertyResolver = propertyResolver; }
/// <summary> /// The add property resolver. /// </summary> /// <param name="mappings"> /// The mappings. /// </param> /// <param name="propertyResolver"> /// The property resolver. /// </param> public static void AddPropertyResolver( this IEnumerable <TypeMapping> mappings, IPropertyResolver propertyResolver) { foreach (var map in mappings) { map.PropertyResolvers.Add(propertyResolver); } }
public NHibernatePingData(ISessionFactory factory) { if (factory == null) { throw new ArgumentNullException(); } this.sessionFactory = factory; PropertyResolver = ReflectionPropertyResolver.SharedInstance; }
/// <summary> /// Contribute to component model before standard <see cref="IContributeComponentModelConstruction" /> run. /// </summary> /// <param name="kernel"></param> /// <param name="model"></param> public override void BuildComponentModel(IKernel kernel, ComponentModel model) { PropertyInfo[] props = model.Implementation.GetProperties(); m_implPropertyTypes = props.ToDictionary(k => k.Name, v => v); PropertiesSubSystem subsystem = kernel.GetSubSystem <PropertiesSubSystem>(PropertiesSubSystem.SubSystemKey); m_resolver = subsystem.Resolver; }
public PropertyManager( IPropertyNameStrategy propertyNameStrategy, IPropertyResolver propertyResolver, IPropertyHandlerService propertyHandlerService ) { _propertyNameStrategy = propertyNameStrategy ?? throw new ArgumentNullException(nameof(propertyNameStrategy)); _propertyResolver = propertyResolver ?? throw new ArgumentNullException(nameof(propertyResolver)); _propertyHandlerService = propertyHandlerService; }
/// <summary> /// Resolve property /// </summary> /// <param name="self">string to resolve</param> /// <param name="resolver">resolver</param> /// <returns>resolved string</returns> public static string Resolve(this string self, IPropertyResolver resolver) { if (self.IsEmpty()) { return(self ?? string.Empty); } resolver.Verify(nameof(resolver)).IsNotNull(); return(resolver.Resolve(self)); }
public void AddPropertyResolver(Type type, IPropertyResolver propertyResolver) { if (!_propertyResolvers.ContainsKey(type)) { _propertyResolvers.Add(type, propertyResolver); } else { _propertyResolvers[type] = propertyResolver; } }
public PropertyManager( IPropertyNameStrategy propertyNameStrategy, IPropertyResolver propertyResolver, IPropertyHandlerService propertyHandlerService, IContentSerializerSettings contentSerializerSettings ) { _propertyNameStrategy = propertyNameStrategy ?? throw new ArgumentNullException(nameof(propertyNameStrategy)); _propertyResolver = propertyResolver ?? throw new ArgumentNullException(nameof(propertyResolver)); _contentSerializerSettings = contentSerializerSettings ?? throw new ArgumentNullException(nameof(contentSerializerSettings)); _propertyHandlerService = propertyHandlerService; }
public XmlEditor(string path, IEntityParser <EntityBase> parser, IPropertyResolver <EntityBase> propertyResolver) { _parser = parser; _propertyResolver = propertyResolver; _path = path; _baseTags = new List <string> { TagName.Book, TagName.Newspaper, TagName.Patent }; _collectionTag = new List <string> { TagName.Authors }; }
public void GetValue_Simple_Works_As_Expected() { // arrange string path = EmbeddedResourceUtil.ExportToPath("Castle.Windsor.Extensions.Test.data", "castle.config", Path.GetTempPath()); PropertiesSubSystem subSystem = new PropertiesSubSystem(path); WindsorContainer container = new WindsorContainer(); container.Kernel.AddSubSystem(PropertiesSubSystem.SubSystemKey, subSystem); IConversionManager manager = (IConversionManager)container.Kernel.GetSubSystem(SubSystemConstants.ConversionManagerKey); manager.Add(new PersonTypeConverter()); IPropertyResolver resolver = subSystem.Resolver; // act string strParam = resolver.GetValue("strParam"); double dblParam = resolver.GetValue <double>("dblParam"); string[] arrParam = resolver.GetValue <string[]>("arrParam"); IDictionary <string, string> dictParam = resolver.GetValue <IDictionary <string, string> >("dictParam"); List <double> listParam = resolver.GetValue <List <double> >("listParam"); Person[] personArr = resolver.GetValue <Person[]>("personArr"); // assert Assert.AreEqual("this is string", strParam); Assert.AreEqual(20.12, dblParam); Assert.AreEqual("arr item 1", arrParam[0]); Assert.AreEqual(strParam, arrParam[1]); Assert.AreEqual(@"..\etc\config.ini", arrParam[2]); Assert.IsTrue(dictParam.ContainsKey("key1")); Assert.IsTrue(dictParam.ContainsKey("key2")); Assert.AreEqual("value 1", dictParam["key1"]); Assert.AreEqual("value 2", dictParam["key2"]); Assert.AreEqual(21.2, listParam[0]); Assert.AreEqual(3, listParam[1]); Assert.AreEqual(dblParam, listParam[2]); Assert.AreEqual("Mihir", personArr[0].Name); Assert.AreEqual(30, personArr[0].PersonAge); Assert.AreEqual("Sneha", personArr[1].Name); Assert.AreEqual(33, personArr[1].PersonAge); // act Dependency[] dependencies = resolver.TryGetDependencies <TestClass>("strParam", "arrParam", "refParam", "dictParam", "listParam", "personArr"); container.Register(Component.For <TestClass>().DependsOn(dependencies)); // assert Assert.IsNotNull(container.Resolve <TestClass>()); }
/// <summary> /// Should obtain the contents from the resource, /// interpret it and populate the <see cref="IConfigurationStore" /> /// accordingly. /// </summary> /// <param name="resource">Resource to process</param> /// <param name="store">Windsor configuration store</param> /// <param name="kernel">Windsor kernel</param> public override void ProcessResource(IResource resource, IConfigurationStore store, IKernel kernel) { var resourceSubSystem = kernel.GetSubSystem(SubSystemConstants.ResourceKey) as IResourceSubSystem; PropertiesXmlProcessor processor = new PropertiesXmlProcessor(EnvironmentName, resourceSubSystem); IConversionManager converter = kernel.GetConversionManager(); processor.Process(resource); // setup the properties resolver m_resolver = new PropertyResolver(processor, converter); m_processResourceCalled = true; }
/// <summary> /// Initializes a new instance of the <see cref="PropertyGridView"/> class. /// </summary> /// <param name="propertyResolver">The class responsible for finding the object properties /// for a given data object.</param> /// <exception cref="ArgumentNullException">Thrown when any input argument is <c>null</c>.</exception> public PropertyGridView(IPropertyResolver propertyResolver) { if (propertyResolver == null) { throw new ArgumentNullException(nameof(propertyResolver)); } HideTabsButton(); DisableDescriptionAreaAutoSizing(); TranslateToolTips(); PropertySort = PropertySort.Categorized; this.propertyResolver = propertyResolver; Name = "PropertiesPanelGridView"; }
public XmlEditor(string path) { _path = path; _baseTags = new List <string> { TagName.Book, TagName.Newspaper, TagName.Patent }; _propertyResolver = new PropertyResolver(); _parser = new LibraryParser(); _collectionTag = new List <string> { TagName.Authors }; if (!File.Exists(path)) { CreateDocumentTemplate(); } }
public static IConfigurationBuilder AddJsonFile(this IConfigurationBuilder configurationBuilder, string file, JsonFileOption jsonFileOption, bool optional = false) { configurationBuilder.VerifyNotNull(nameof(configurationBuilder)); file.VerifyNotEmpty(nameof(file)); if (jsonFileOption != JsonFileOption.Enhance) { configurationBuilder.AddJsonFile(file, optional); return(configurationBuilder); } IPropertyResolver resolver = configurationBuilder .Build() .BuildResolver(); ConfigurationTools.GetJsonFiles(file, resolver) .ForEach(x => configurationBuilder.AddJsonFile(x, optional)); return(configurationBuilder); }
public static IReadOnlyList <string> GetJsonFiles(string file, IPropertyResolver resolver) { file.VerifyNotEmpty(nameof(file)); resolver.VerifyNotNull(nameof(resolver)); file = resolver.Resolve(file); if (!File.Exists(file)) { return new[] { file } } ; string folder = Path.GetDirectoryName(file) !; var stack = new Stack <string>(new[] { file }); var list = new List <string>(); while (stack.TryPop(out string?inlcudeFile)) { list.Add(inlcudeFile); File.Exists(inlcudeFile).VerifyAssert(x => x == true, $"File {inlcudeFile} does not exist"); try { new ConfigurationBuilder() .AddJsonFile(inlcudeFile) .Build() .AsEnumerable() .Where(x => x.Key.StartsWith("$include")) .Select(x => resolver.Resolve(x.Value)) .Select(x => Path.Combine(folder, x)) .Reverse() .ForEach(x => stack.Push(x)); } catch (InvalidDataException) { } } return(list); } }
public void GivenPropertyName_WhenSet_ReturnCorrectName() { var option = new TestOptionName { Name = "Name1", Value = 3, OptionalValue = 10 }; IPropertyResolver resolver = option.BuildResolver(); List <KeyValuePair <string, string> > testValues = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>(nameof(TestOptionName.Name), "Name1"), new KeyValuePair <string, string>(nameof(TestOptionName.Value), "3"), new KeyValuePair <string, string>("optional.value", "10"), }; resolver.SourceProperties.Count.Should().Be(testValues.Count); resolver.SourceProperties .Zip(testValues, (o, i) => new { o, i }) .All(x => x.o.Key == x.i.Key && x.o.Value == x.i.Value) .Should().BeTrue(); }
public override Expression ToExpression <T>(IPropertyResolver propertyResolver) { (Expression left, Expression right) = this.TryAlignTypes <T>(propertyResolver); return(Expression.LessThan(left, right)); }
public abstract Expression ToExpression <T>(IPropertyResolver propertyResolver);
/// <summary> /// Should obtain the contents from the resource, /// interpret it and populate the <see cref="IConfigurationStore" /> /// accordingly. /// </summary> /// <param name="resource">Resource to process</param> /// <param name="store">Windsor configuration store</param> /// <param name="kernel">Windsor kernel</param> public override void ProcessResource(IResource resource, IConfigurationStore store, IKernel kernel) { var resourceSubSystem = kernel.GetSubSystem(SubSystemConstants.ResourceKey) as IResourceSubSystem; PropertiesXmlProcessor processor = new PropertiesXmlProcessor(EnvironmentName, resourceSubSystem); IConversionManager converter = kernel.GetConversionManager(); processor.Process(resource); // setup the properties resolver m_resolver = new PropertyResolver(processor, converter); m_processResourceCalled = true; }
/// <summary> /// Should obtain the contents from the resource, /// interpret it and populate the <see cref="T:Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore" /> /// accordingly. /// </summary> /// <param name="resource"></param> /// <param name="store"></param> /// <param name="kernel"></param> public override void ProcessResource(IResource resource, IConfigurationStore store, IKernel kernel) { PropertiesJsonProcessor processor = new PropertiesJsonProcessor(); processor.Process(resource); IConversionManager converter = kernel.GetConversionManager(); // setup the properties resolver Resolver = new PropertyResolver(processor, converter); m_processResourceCalled = true; }
/// <summary> /// Sets the <see cref="IPropertyResolver"/> implementation for resolving key of entities. /// </summary> /// <param name="resolver">An instance of <see cref="IPropertyResolver"/>.</param> public static void SetPropertyResolver(IPropertyResolver resolver) => _propertyResolver = resolver;
public EseentPingData(PersistentDictionary <int, T> persistentDictionary) { m_dict = persistentDictionary; PropertyResolver = ReflectionPropertyResolver.SharedInstance; }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationFeatureCommandHandler"/> class. /// </summary> /// <param name="propertyResolver">The object responsible for finding the object properties /// for a given data object.</param> /// <param name="mainWindow">The main user interface of the application.</param> public ApplicationFeatureCommandHandler(IPropertyResolver propertyResolver, IMainWindow mainWindow) { this.propertyResolver = propertyResolver; this.mainWindow = mainWindow; }
public override Expression ToExpression <T>(IPropertyResolver propertyResolver) { return(Expression.Multiply(this.Left.ToExpression <T>(propertyResolver), this.Right.ToExpression <T>(propertyResolver))); }
public CustomTypeGenerator WithPropertyResolver(IPropertyResolver propertyResolver) { propertyResolvers.Add(propertyResolver); return(this); }
/// <summary> /// Initialise this sub system /// </summary> /// <param name="kernel">Windsor kernel</param> public void Init(IKernelInternal kernel) { m_interpreter.ProcessResource(m_interpreter.Source, kernel.ConfigurationStore, kernel); Resolver = m_interpreter.Resolver; }