private static BindingInfo[] GetTemplateBindings(IisSiteConfiguration config) { if (config.BindingInformation != null && config.BindingProtocol != null && config.Bindings == null) { // use legacy operation property values only if "Binding" script alias is present and "Bindings" is not var legacyBindingInfo = BindingInfo.FromBindingInformation(config.BindingInformation, config.BindingProtocol); return(new[] { legacyBindingInfo }); } else { if (config.Bindings == null) { return(null); } var templateBindings = (from b in config.Bindings let info = BindingInfo.FromMap(b) where info != null select info) .ToArray(); return(templateBindings); } }
public static IisSiteConfiguration FromMwaSite(ILogSink logger, Site site, IisSiteConfiguration template = null) { if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (site == null) { throw new ArgumentNullException(nameof(site)); } var config = new IisSiteConfiguration(); config.Name = site.Name; var app = site.Applications.FirstOrDefault(); if (app == null) { logger.LogWarning("Site does not have an application configured."); } else { var vdir = app.VirtualDirectories.FirstOrDefault(); if (vdir == null) { logger.LogWarning("Site does not have an VirtualDirectory configured."); } else { if (template == null || template.ApplicationPoolName != null) { config.ApplicationPoolName = app.ApplicationPoolName; } if (template == null || template.VirtualDirectoryPhysicalPath != null) { config.VirtualDirectoryPhysicalPath = vdir.PhysicalPath; } } } if (template?.BindingInformation != null && template?.Bindings != null) { logger.LogWarning("Template configuration has both Binding and Bindings specified; the Binding and Protocol properties " + "will be ignored and should be removed from the operation via Text Mode of the Plan Editor."); } var siteBindings = site.Bindings .Select(b => BindingInfo.FromBindingInformation(b.BindingInformation, b.Protocol, b.CertificateStoreName, b.CertificateHash, b)) .ToArray(); if (siteBindings.Length == 0) { logger.LogWarning("Site does not have a Binding configured."); } else { if (template == null || (template.Bindings != null || template.BindingInformation != null)) { config.Bindings = siteBindings.Select(b => b.ToDictionary()).ToArray(); } } return(config); }
public static void SetMwaSite(ILogSink logger, IisSiteConfiguration config, Site site) { if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } if (site == null) { throw new ArgumentNullException(nameof(site)); } if (site.Applications.Count > 1) { logger.LogWarning("Site has more than one Application defined; this will only configure the first one."); } var app = site.Applications.FirstOrDefault(); if (app == null) { logger.LogDebug("Site does not have an Application; creating Application..."); app = site.Applications.Add("/", config.VirtualDirectoryPhysicalPath); } var vdir = app.VirtualDirectories.FirstOrDefault(); if (vdir == null) { logger.LogDebug("Application does not have a Virtual Directory; creating Virtual Directory..."); vdir = app.VirtualDirectories.Add("/", config.VirtualDirectoryPhysicalPath); } if (config.ApplicationPoolName != null) { app.ApplicationPoolName = config.ApplicationPoolName; } if (config.VirtualDirectoryPhysicalPath != null) { vdir.PhysicalPath = config.VirtualDirectoryPhysicalPath; } var templateBindings = GetTemplateBindings(config); if (templateBindings != null) { logger.LogDebug("Clearing bindings..."); site.Bindings.Clear(); logger.LogDebug("Setting bindings..."); foreach (var binding in templateBindings) { Binding iisBinding; if (binding.CertificateHash.Length > 0) { iisBinding = site.Bindings.Add(binding.BindingInformation, binding.CertificateHash, binding.CertificateStoreName); } else { iisBinding = site.Bindings.Add(binding.BindingInformation, binding.Protocol); } iisBinding.SetAttributeValue("sslFlags", (int)binding.SslFlags); } } }