Example #1
0
        public static IisAppPoolConfiguration FromMwaApplicationPool(ILogSink logger, ApplicationPool pool, IisAppPoolConfiguration template = null)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (pool == null)
            {
                throw new ArgumentNullException(nameof(pool));
            }

            var config = new IisAppPoolConfiguration();

            config.Name   = pool.Name;
            config.Status = (IisObjectState)pool.State;
            if (template == null)
            {
                return(config);
            }

            var templateProperties = Persistence.GetPersistentProperties(template.GetType(), false)
                                     .Where(p => Attribute.IsDefined(p, typeof(ScriptAliasAttribute)));

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

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

            return(config);
        }
Example #2
0
        private static bool SkipTemplateProperty(IisAppPoolConfiguration template, PropertyInfo templateProperty)
        {
            if (templateProperty.Name == nameof(Status) || templateProperty.Name == nameof(Exists) || templateProperty.Name == nameof(CredentialName))
            {
                return(true);
            }

            var value = templateProperty.GetValue(template);

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

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

            return(true);
        }
Example #3
0
        public static void SetMwaApplicationPool(ILogSink logger, IisAppPoolConfiguration config, ApplicationPool pool)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            if (pool == null)
            {
                throw new ArgumentNullException(nameof(pool));
            }

            var configProperties = Persistence.GetPersistentProperties(config.GetType(), false)
                                   .Where(p => Attribute.IsDefined(p, typeof(ScriptAliasAttribute)));

            foreach (var configProperty in configProperties)
            {
                if (SkipTemplateProperty(config, configProperty))
                {
                    continue;
                }

                object value = configProperty.GetValue(config);

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