public static void UpdateIisApplications( ExistingInstalledInstallationLogic newLogic, ExistingInstalledInstallationLogic oldLogic ) { var appGetter = new Func<ExistingInstalledInstallationLogic, IEnumerable<WebApplication>>( logic => logic?.existingInstallationLogic.RuntimeConfiguration.WebApplications.Where( i => i.IisApplication != null ).ToImmutableArray() ?? Enumerable.Empty<WebApplication>() ); var newApps = appGetter( newLogic ); var oldApps = appGetter( oldLogic ); if( newApps.Any() ) IsuStatics.UpdateIisAppPool( newLogic.existingInstallationLogic.IisAppPoolName ); var newSiteNames = new HashSet<string>(); var newVirtualDirectoryNames = new HashSet<string>(); foreach( var app in newApps ) { var site = app.IisApplication as Site; if( site != null ) { IsuStatics.UpdateIisSite( getIisSiteName( newLogic, app ), newLogic.existingInstallationLogic.IisAppPoolName, app.Path, site.HostNames ); newSiteNames.Add( getIisSiteName( newLogic, app ) ); continue; } var virtualDirectory = app.IisApplication as VirtualDirectory; if( virtualDirectory != null ) { IsuStatics.UpdateIisVirtualDirectory( virtualDirectory.Site, virtualDirectory.Name, newLogic.existingInstallationLogic.IisAppPoolName, app.Path ); newVirtualDirectoryNames.Add( virtualDirectory.Name ); continue; } throw new ApplicationException( "unrecognized IIS application type" ); } foreach( var app in oldApps ) { var site = app.IisApplication as Site; if( site != null ) { if( !newSiteNames.Contains( getIisSiteName( oldLogic, app ) ) ) IsuStatics.DeleteIisSite( getIisSiteName( oldLogic, app ) ); continue; } var virtualDirectory = app.IisApplication as VirtualDirectory; if( virtualDirectory != null ) { if( !newVirtualDirectoryNames.Contains( virtualDirectory.Name ) ) IsuStatics.DeleteIisVirtualDirectory( virtualDirectory.Site, virtualDirectory.Name ); continue; } throw new ApplicationException( "unrecognized IIS application type" ); } if( oldApps.Any() && ( !newApps.Any() || newLogic.existingInstallationLogic.IisAppPoolName != oldLogic.existingInstallationLogic.IisAppPoolName ) ) IsuStatics.DeleteIisAppPool( oldLogic.existingInstallationLogic.IisAppPoolName ); }
private static string getIisSiteName( ExistingInstalledInstallationLogic logic, WebApplication app ) { return "{0} - {1}".FormatWith( logic.existingInstallationLogic.RuntimeConfiguration.FullShortName, app.Name ); }