/// <summary>
        /// Retrieves the config values from component's config wrapper.
        /// </summary>
        /// <param name="currentNode">The current node.</param>
        private void RetrieveConfigValuesFromComponent(string nodeIdentifier, IConfigurableAndIOSpecifiable metadata)
        {
            foreach (ConfigPropertyObject configParameter in metadata.ConfigWrapper.ConfigValues.Values)
            {
                string displayParameterName  = String.Format("{0} {1}", metadata.Label, configParameter.DisplayName);
                string extendedParameterName = String.Format("{0}:{1}", nodeIdentifier, configParameter.Name);

                //create property object based on the component's property object
                ConfigPropertyObject propertyObject = new ConfigPropertyObject(configParameter);

                //but change the name - it will be resolved in Nodes factory based on extended parameter name which retNode config parameter is supposed to be overridden
                propertyObject.DisplayName = displayParameterName;
                propertyObject.Name        = extendedParameterName;

                //add it to the compound configWrapperDefinition
                displayParameterName = GetUniqueDisplayName(displayParameterName);
                ConfigSettings.Add(displayParameterName, new ConfigItemSetting(displayParameterName, configParameter.Type, propertyObject));
            }
        }
Пример #2
0
        private void ApplyConfiguration()
        {
            var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            DebugLog(config.FilePath);
            var type1 = typeof(ContainerHelperSection);

            try
            {
                var sections = config.Sections;
                foreach (ConfigurationSection configSection in sections)
                {
                    try
                    {
                        var type = configSection.SectionInformation.Type;
                        // DoLogMethod ( $"Type is {type}" ) ;
                        var sectionType = Type.GetType(type);
                        if (sectionType != null && sectionType.Assembly == type1.Assembly)
                        {
                            DebugLog("Found section " + sectionType.Name);
                            var at           = sectionType.GetCustomAttribute <ConfigTargetAttribute>();
                            var configTarget = Activator.CreateInstance(at.TargetType);
                            var infos        = sectionType
                                               .GetMembers()
                                               .Select(
                                info => Tuple.Create(
                                    info
                                    , info
                                    .GetCustomAttribute <
                                        ConfigurationPropertyAttribute
                                        >()
                                    )
                                )
                                               .Where(tuple => tuple.Item2 != null)
                                               .ToArray();
                            foreach (var(item1, _) in infos)
                            {
                                if (item1.MemberType == MemberTypes.Property)
                                {
                                    foreach (var memberInfo in infos)
                                    {
                                        var attr = at.TargetType.GetProperty(item1.Name);
                                        try
                                        {
                                            var configVal =
                                                ((PropertyInfo)memberInfo.Item1).GetValue(
                                                    configSection
                                                    );
                                            if (attr != null)
                                            {
                                                attr.SetValue(configTarget, configVal);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            DebugLog?.Invoke(
                                                $"Unable to set property {attr.Name}: {ex.Message}"
                                                );
                                        }
                                    }
                                }
                            }

                            ConfigSettings.Add(configTarget);
                        }
                    }
                    catch (Exception ex1)
                    {
                        Logger.Error(ex1, ex1.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                DebugLog(ex.Message);
            }
        }