protected override bool SkipTemplateProperty(IisConfigurationBase template, PropertyInfo templateProperty)
        {
            if (templateProperty.Name == nameof(SiteName))
            {
                return(true);
            }

            if (templateProperty.Name == nameof(ApplicationPath))
            {
                return(true);
            }

            if (templateProperty.Name == nameof(ApplicationPoolName))
            {
                return(true);
            }

            if (!string.IsNullOrEmpty((template as IisApplicationConfiguration)?.CredentialName) &&
                Attribute.IsDefined(templateProperty, typeof(MappedCredentialAttribute)))
            {
                return(false);
            }

            return(base.SkipTemplateProperty(template, templateProperty));
        }
Exemplo n.º 2
0
        protected virtual bool SkipTemplateProperty(IisConfigurationBase template, PropertyInfo templateProperty)
        {
            if (templateProperty.Name == nameof(IExistential.Exists))
            {
                return(true);
            }

            if (templateProperty.Name == nameof(IHasCredentials.CredentialName))
            {
                return(true);
            }

            if (template == null)
            {
                return(false);
            }

            var value = templateProperty.GetValue(template);

            if (value != null)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        protected void SetPropertiesFromMwa(ILogSink logger, ConfigurationElement mwaConfig, IisConfigurationBase template = null)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (mwaConfig == null)
            {
                throw new ArgumentNullException(nameof(mwaConfig));
            }
            var config = this;

            var keyprops = from prop in Persistence.GetPersistentProperties(this.GetType(), false)
                           where Attribute.IsDefined(prop, typeof(ScriptAliasAttribute)) &&
                           Attribute.IsDefined(prop, typeof(ConfigurationKeyAttribute))
                           select prop;

            foreach (var keyProp in keyprops)
            {
                if (SkipTemplateProperty(null, keyProp))
                {
                    continue;
                }
                var mappedProperty = FindMatchingProperty(keyProp.Name.Split('_'), mwaConfig);
                if (mappedProperty != null)
                {
                    keyProp.SetValue(config, mappedProperty.GetValue());
                }
                else
                {
                    logger.LogWarning($"Matching MWA property \"{keyProp.Name}\" was not found.");
                }
            }
            if (template == null)
            {
                return;
            }

            var templateProperties = from prop in Persistence.GetPersistentProperties(this.GetType(), false)
                                     where Attribute.IsDefined(prop, typeof(ScriptAliasAttribute)) &&
                                     !Attribute.IsDefined(prop, typeof(ConfigurationKeyAttribute))
                                     select prop;

            foreach (var templateProperty in templateProperties)
            {
                if (SkipTemplateProperty(template, templateProperty))
                {
                    continue;
                }

                var mappedProperty = FindMatchingProperty(templateProperty.Name.Split('_'), mwaConfig);
                if (mappedProperty != null)
                {
                    templateProperty.SetValue(config, mappedProperty.GetValue());
                }
                else
                {
                    logger.LogWarning($"Matching MWA property \"{templateProperty.Name}\" was not found.");
                }
            }
        }