public SiteDesiredState(Site iisSiteObject , IEnumerable<WebConfigPropertyDesiredState> authDesiredStateList , IISCodeGenerator.IisPoolAndSitesOptions iisOptions) { var rootApp = iisSiteObject.Applications[0]; this.Key = GetSiteKey(iisSiteObject.Name); this.AddAttribute("Name", iisSiteObject.Name); this.AddAttribute("Ensure", "Present"); this.AddAttribute("State", iisSiteObject.State.ToString()); this.ApplicationPool = rootApp.ApplicationPoolName; this.AddAttribute("ApplicationPool", this.ApplicationPool); this.AddAttributeWithComment("PhysicalPath", rootApp.VirtualDirectories[0].PhysicalPath, "This folder must already exist"); if (iisOptions.StandardizeLogFileLocation) { this.AddAttributeWithOverrideValue("LogFileDirectory", @"D:\IISLogs", iisSiteObject.LogFile.Directory); } else { this.AddAttribute("LogFileDirectory", iisSiteObject.LogFile.Directory); } this.AddAttribute("DependsOn", "[cAppPool]" + PoolDesiredState.GetPoolVariableName(this.ApplicationPool)); this.Bindings = GetBindings(iisSiteObject.Bindings); this.Applications = GetApplications(iisSiteObject.Applications, this.Key, this.Name); this.AuthDesiredStateList.AddRange(authDesiredStateList); }
public string GenerateConfig(Options options) { IISCodeGenerator iis = new IISCodeGenerator(); StringBuilder sb = new StringBuilder(); string versionStr = GetApplicationVersion(); string code; sb.AppendFormat("configuration IIS_DSC # Generated by DSC Generator v{0}\n", versionStr); sb.AppendLine("{"); if (options.IisOptions.IisPoolAndSitesGenerationMode != IISCodeGenerator.IisPoolAndSitesGenerationMode.NoGeneration) { code = iis.GenerateIisSiteImports(); sb.AppendLine(code); } sb.AppendLine( Indent + "node localhost"); sb.AppendLine( Indent + "{"); if (options.GenerateIisWindowsFeatures) { var windowsGenerator = new WindowsFeatureCodeGenerator(); code = windowsGenerator.GenerateWindowsFeatures(); sb.Append(code); } if (options.IisOptions.IisPoolAndSitesGenerationMode != IISCodeGenerator.IisPoolAndSitesGenerationMode.NoGeneration) { code = iis.GenerateCode(options.IisOptions); sb.Append(code); } sb.AppendLine( Indent + "}"); sb.AppendLine( "}\n"); sb.AppendLine( "cls\n"); sb.AppendLine( "# Compile this DSC down to an .MOF: An .mof file will be placed in the specified directory:"); sb.AppendLine( "IIS_DSC -OutputPath \"c:\\my_iis_dsc_dir\"\n"); sb.AppendLine( "# Apply the DSC. ALL .mof's in a folder will be executed!:"); sb.AppendLine( "Start-DscConfiguration -Path \"c:\\my_iis_dsc_dir\" -Wait -Debug -ErrorAction Stop -Force -Verbose # this will apply the DSC"); return sb.ToString(); }
public List<PoolDesiredState> BuildPools(IISCodeGenerator.IisPoolAndSitesOptions iisOptions) { ServerManager serverManager = new ServerManager(); List<PoolDesiredState> poolCodeList = new List<PoolDesiredState>(); var pools = serverManager.ApplicationPools; foreach (var pool in pools) { var poolCode = new PoolDesiredState(pool, iisOptions); poolCodeList.Add(poolCode); } return poolCodeList; }
public List<SiteDesiredState> BuildSites(IISCodeGenerator.IisPoolAndSitesOptions iisOptions) { ServerManager serverManager = new ServerManager(); List<SiteDesiredState> siteCodeList = new List<SiteDesiredState>(); WebConfigPropertyDesiredStateAssembler gen = new WebConfigPropertyDesiredStateAssembler(); List<WebConfigPropertyDesiredState> authDesiredStateList = gen.GetAuthenticationDesiredStates(); foreach (var site in serverManager.Sites) { var siteName = site.Name; var siteAuthDesiredStateList = authDesiredStateList.Where(a => CodeGenHelpers.AreEqualCI(a.SiteName, siteName)); var siteCode = new SiteDesiredState(site, siteAuthDesiredStateList, iisOptions); siteCodeList.Add(siteCode); } return siteCodeList; }
private void Initialize(ApplicationPool iisPoolObject, IISCodeGenerator.IisPoolAndSitesOptions iisOptions) { this.Key = GetPoolVariableName(iisPoolObject.Name); this.AddAttribute("Name", iisPoolObject.Name); if (iisOptions.KeepAppPoolsRunning) { this.AddAttributeWithOverrideValue("AutoStart", "True", iisPoolObject.AutoStart.ToString()); } this.AddAttribute("ManagedPipelineMode", iisPoolObject.ManagedPipelineMode.ToString()); this.AddAttribute("ManagedRuntimeVersion", iisPoolObject.ManagedRuntimeVersion); this.AddAttribute("IdentityType", iisPoolObject.ProcessModel.IdentityType.ToString()); this.AddAttribute("Enable32BitAppOnWin64", iisPoolObject.Enable32BitAppOnWin64.ToString()); if (iisOptions.StandardizeAppPoolRecycles) { this.AddAttributeWithOverrideValue("RestartSchedule", "@(\"02:00:00\")", GetScheduleString(iisPoolObject)); } else { this.AddAttribute("RestartSchedule", GetScheduleString(iisPoolObject)); } if (iisOptions.KeepAppPoolsRunning) { this.AddAttributeWithOverrideValue("IdleTimeout", "00:00:00", iisPoolObject.ProcessModel.IdleTimeout.ToString()); this.AddAttributeWithOverrideValue("RestartTimeLimit", "00:00:00", iisPoolObject.Recycling.PeriodicRestart.Time.ToString()); } else { this.AddAttribute("IdleTimeout", iisPoolObject.ProcessModel.IdleTimeout.ToString()); this.AddAttribute("RestartTimeLimit", iisPoolObject.Recycling.PeriodicRestart.Time.ToString()); } }
public PoolDesiredState(ApplicationPool iisPoolObject, IISCodeGenerator.IisPoolAndSitesOptions iisOptions) { Initialize(iisPoolObject, iisOptions); }