public ConfigReader(string migrationId, double iisVersion, RemoteSystemInfo remoteSystemInfo) : base(migrationId, iisVersion, remoteSystemInfo != null ? remoteSystemInfo.OSVersion : Environment.OSVersion.Version.ToString(), remoteSystemInfo != null ? remoteSystemInfo.ComputerName : Environment.MachineName) { _appHostConfigPath = remoteSystemInfo != null ? remoteSystemInfo.RemoteAppHostConfigPath : string.Empty; _isLocal = remoteSystemInfo == null; Initialize(remoteSystemInfo); }
public static void AddOrUpdate(string computerName, string username, string password, string driveLetter) { var remoteSystemInfo = new RemoteSystemInfo(computerName, username, password, driveLetter); if (smServers.ContainsKey(computerName)) { smServers[computerName] = remoteSystemInfo; } else { smServers.Add(computerName, remoteSystemInfo); } }
public static void Initialize(string computerName, string username, string password, string driveLetter) { var remoteSystemInfo = new RemoteSystemInfo(); remoteSystemInfo.ComputerName = computerName; remoteSystemInfo.Username = username; remoteSystemInfo.Password = password; remoteSystemInfo.SystemDriveLetter = driveLetter; var remoteMetabasePath = string.Format(InetsrvRemotePathFormat, computerName, driveLetter, MetabasePath); var remoteConfigPath = string.Format(InetsrvRemotePathFormat, computerName, driveLetter, ApphostConfigPath); if (File.Exists(remoteConfigPath)) { remoteSystemInfo.RemoteAppHostConfigPath = Path.Combine(Path.GetTempPath(), "applicationHost.Config"); try { File.Copy(remoteConfigPath, remoteSystemInfo.RemoteAppHostConfigPath, true); } catch (Exception ex) { TraceHelper.Tracer.WriteTrace("Unable to copy applicationhost.config"); TraceHelper.Tracer.WriteTrace(ex.ToString()); throw new Exception("Unable to copy applicationhost.config", ex); } remoteSystemInfo.IISVersion = 7; remoteSystemInfo.OSVersion = "6.1"; } else if (File.Exists(remoteMetabasePath)) { remoteSystemInfo.RemoteMetabasePath = Path.Combine(Path.GetTempPath(), "metabase.xml"); try { File.Copy(remoteMetabasePath, remoteSystemInfo.RemoteMetabasePath, true); } catch (Exception ex) { TraceHelper.Tracer.WriteTrace("Unable to copy metabase.xml"); TraceHelper.Tracer.WriteTrace(ex.ToString()); throw new Exception("Unable to copy metabase.xml", ex); } remoteSystemInfo.IISVersion = 6; remoteSystemInfo.OSVersion = "5.2"; } else { throw new Exception("IIS is not installed on the remote system"); } }
public static IISInfoReader GetIISInfoReader(string migrationID, RemoteSystemInfo remoteSystemInfo = null) { //#if DEBUG // return new MetabaseReader(migrationID, IisVersion); //#else var iisVersion = remoteSystemInfo != null ? remoteSystemInfo.IISVersion : IisVersion; if (iisVersion >= 7) { return(new ConfigReader(migrationID, iisVersion, remoteSystemInfo)); } if (iisVersion >= 6) { return(new MetabaseReader(migrationID, iisVersion, remoteSystemInfo)); } return(null); //#endif }
public static IDisposable ImpersonateUser(RemoteSystemInfo systemInfo) { Impersonator impersonator = new Impersonator(); try { if (systemInfo != null) { var loggedInUser = LoggedOnUser.LogonUser(systemInfo.Username, systemInfo.Password); if (loggedInUser != null) { impersonator._impersonationContext = WindowsIdentity.Impersonate(loggedInUser.DangerousGetHandle()); impersonator._impersonatedUser = loggedInUser.Username; } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return impersonator; }
public static IDisposable ImpersonateUser(RemoteSystemInfo systemInfo) { Impersonator impersonator = new Impersonator(); try { if (systemInfo != null) { var loggedInUser = LoggedOnUser.LogonUser(systemInfo.Username, systemInfo.Password); if (loggedInUser != null) { impersonator._impersonationContext = WindowsIdentity.Impersonate(loggedInUser.DangerousGetHandle()); impersonator._impersonatedUser = loggedInUser.Username; } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return(impersonator); }
private void CheckConfig(IISServer server, RemoteSystemInfo remoteSystemInfo) { string configSectionName = "configSections"; string ftpServerSection = "system.ftpServer"; string NameAttribute = "name"; string xpathFormat = "configuration/"; var antaresSchema = new XmlDocument(); antaresSchema.Load(Assembly.GetExecutingAssembly() .GetManifestResourceStream("CompatCheckAndMigrate.Resources.IIS_MergedSchema.xml")); var customerAppHost = new XmlDocument(); var userApphostConfig = Path.Combine(Environment.SystemDirectory, @"inetsrv\config\applicationhost.config"); if (remoteSystemInfo != null) { userApphostConfig = remoteSystemInfo.RemoteAppHostConfigPath; } customerAppHost.Load(userApphostConfig); var antaresConfigSections = new HashSet <string>(StringComparer.Ordinal); XmlNodeList nodes = antaresSchema.SelectNodes("configSchema/sectionSchema"); foreach (XmlNode node in nodes) { antaresConfigSections.Add(node.Attributes[NameAttribute].Value); } var customerConfigSections = new List <string>(); nodes = customerAppHost.SelectNodes("//section"); foreach (XmlNode node in nodes) { XmlNode tempNode = node; string sectionPath = tempNode.Attributes[NameAttribute].Value; while (!string.Equals(tempNode.ParentNode.Name, configSectionName, StringComparison.OrdinalIgnoreCase)) { tempNode = tempNode.ParentNode; sectionPath = tempNode.Attributes[NameAttribute].Value + "/" + sectionPath; } if (!sectionPath.StartsWith(ftpServerSection, StringComparison.OrdinalIgnoreCase)) { customerConfigSections.Add(sectionPath); } } foreach (string customerSection in customerConfigSections) { if (!antaresConfigSections.Contains(customerSection)) { string message = string.Format("Section definition not supported for {0}", customerSection); server.SchemaCheckErrors.Add(message); } var nodeList = customerAppHost.SelectNodes(string.Concat(xpathFormat, customerSection)); foreach (XmlNode node in nodeList) { CheckAttributes(customerSection, antaresSchema, node, server); CheckElements(customerSection, antaresSchema, node, server); } } }
private void Initialize(RemoteSystemInfo remoteSystemInfo) { CheckConfig(Server, remoteSystemInfo); var userApphostConfig = Path.Combine(Environment.SystemDirectory, @"inetsrv\config\applicationhost.config"); var rootDefaultDocList = GetDefaultDocuments(userApphostConfig); CheckSessionState(userApphostConfig, Server); using (ServerManager manager = GetServerManager()) { var config = manager.GetApplicationHostConfiguration(); foreach (var appPool in manager.ApplicationPools) { var isClassicMode = appPool.ManagedPipelineMode == ManagedPipelineMode.Classic ? true : false; double netFxRuntimeVersion = 0; if (!Double.TryParse(appPool.ManagedRuntimeVersion.TrimStart(new char[] { 'v', 'V' }), out netFxRuntimeVersion)) { netFxRuntimeVersion = 2.0; } Server.AppPools.Add( new ApplicationPool( isClassicMode, netFxRuntimeVersion, appPool.Enable32BitAppOnWin64, appPool.Name)); } foreach (var smSite in manager.Sites) { string physicalPath = smSite.Applications["/"].VirtualDirectories["/"].PhysicalPath; if (remoteSystemInfo != null) { physicalPath = remoteSystemInfo.GetRemotePath(physicalPath); } else { physicalPath = Environment.ExpandEnvironmentVariables(physicalPath); } var site = new Site(smSite.Name, smSite.Id); site.PhysicalPath = physicalPath; SetAuthPropertiesForSite(config, ref site); if (Directory.Exists(physicalPath)) { var webconfig = Path.Combine(physicalPath, "web.config"); if (File.Exists(webconfig)) { CheckSessionState(webconfig, Server); var localDefaultDocument = GetDefaultDocuments(webconfig); if (localDefaultDocument.Count > 0) { site.DefaultDocuments = localDefaultDocument.Union(rootDefaultDocList, StringComparer.OrdinalIgnoreCase).ToList(); } else { site.DefaultDocuments = rootDefaultDocList; } } } foreach (var application in smSite.Applications) { if (application.Path == "/") { site.AppPoolName = application.ApplicationPoolName; var gacAssembly = new GacAssemblyDetector(physicalPath); site.Add(gacAssembly.GetGacedAssemblies()); foreach (var vdir in smSite.Applications["/"].VirtualDirectories) { if (vdir.Path != "/") { string vdirPhysicalPath = vdir.PhysicalPath; if (remoteSystemInfo != null) { vdirPhysicalPath = remoteSystemInfo.GetRemotePath(vdirPhysicalPath); } site.Add(new VirtualDirectory(vdir.Path, vdirPhysicalPath)); } } continue; } if (application.VirtualDirectories.Count > 0) { string appPhysicalPath = application.VirtualDirectories[0].PhysicalPath; if (remoteSystemInfo != null && appPhysicalPath != "/") { appPhysicalPath = remoteSystemInfo.GetRemotePath(appPhysicalPath); } List <VirtualDirectory> listVdirs = new List <VirtualDirectory>(); foreach (var vdir in application.VirtualDirectories) { if (vdir.Path != "/") { string vdirPhysicalPath = vdir.PhysicalPath; if (remoteSystemInfo != null) { vdirPhysicalPath = remoteSystemInfo.GetRemotePath(vdirPhysicalPath); } listVdirs.Add(new VirtualDirectory(vdir.Path, vdirPhysicalPath)); } } site.Add(new Application(application.Path, appPhysicalPath) { AppPoolName = application.ApplicationPoolName, VDirs = listVdirs }); if (appPhysicalPath == "/") { continue; } var gacAssemblyForApp = new GacAssemblyDetector(appPhysicalPath); site.Add(gacAssemblyForApp.GetGacedAssemblies()); } } foreach (var binding in smSite.Bindings) { site.Add(new Binding(binding.BindingInformation, binding.Protocol)); } site.IisVersion = this.Server.IISVersion; site.OsVersion = this.Server.OSVersion; GetDatabaseInfo(ref site, physicalPath, remoteSystemInfo != null ? remoteSystemInfo.ComputerName : string.Empty); Server.Sites.Add(site); } } }
public MetabaseReader(string migrationId, double iisVersion, RemoteSystemInfo remoteSystemInfo) : base(migrationId, iisVersion, remoteSystemInfo != null ? remoteSystemInfo.OSVersion : Environment.OSVersion.Version.ToString(), remoteSystemInfo != null ? remoteSystemInfo.ComputerName : Environment.MachineName) { _isLocal = remoteSystemInfo == null; var document = new XmlDocument(); //#if DEBUG // document.Load(@"E:\vsprojects\metabase.xml"); //#else string metabasePath = _isLocal ? Path.Combine(Environment.SystemDirectory, @"inetsrv\metabase.xml") : remoteSystemInfo.RemoteMetabasePath; document.Load(metabasePath); //#endif var enable32Biton64 = false; var defaultAppPoolNode = document.SelectSingleNode(string.Format(NameSpaceAgnosticXPathFormat, "IIsApplicationPools")); var enable32bitAttribute = defaultAppPoolNode.Attributes["Enable32BitAppOnWin64"]; if (enable32bitAttribute != null && !string.IsNullOrEmpty(enable32bitAttribute.Value)) { enable32Biton64 = Convert.ToBoolean(enable32bitAttribute.Value); } XmlNode defaultServiceNode = document.SelectSingleNode(string.Format(NameSpaceAgnosticXPathFormat, "IIsWebService")); var netFxVersion = GetNetFxVersion(defaultServiceNode, null); var defaultAuthenticationType = GetAuthenticationType( defaultServiceNode, EnabledAuthenticationType.Anonymous); var defaultDocList = GetDefaultDocList(defaultServiceNode, null); var iis5IsolationMode = false; var isolationModeAttribute = defaultServiceNode.Attributes["IIs5IsolationModeEnabled"]; if (isolationModeAttribute != null && !string.IsNullOrEmpty(isolationModeAttribute.Value)) { iis5IsolationMode = Convert.ToBoolean(isolationModeAttribute.Value); } var appPoolMap = new Dictionary <string, ApplicationPool>(StringComparer.OrdinalIgnoreCase); var appPoolNodes = document.SelectNodes(string.Format(NameSpaceAgnosticXPathFormat, "IIsApplicationPool")); foreach (XmlNode appPoolNode in appPoolNodes) { string name = string.Empty; var attribute = appPoolNode.Attributes["Location"]; if (attribute != null && !string.IsNullOrEmpty(attribute.Value)) { name = attribute.Value.Replace("/LM/W3SVC/AppPools/", string.Empty); appPoolMap[name] = new ApplicationPool(true, netFxVersion, enable32Biton64, name); } } var siteNodes = document.SelectNodes(string.Format(NameSpaceAgnosticXPathFormat, "IIsWebServer")); foreach (XmlNode siteNode in siteNodes) { var attribute = siteNode.Attributes["Location"]; if (attribute != null) { var m = SiteLocationRegex.Match(attribute.Value); if (m.Success) { long siteId = Convert.ToInt64(m.Groups[1].Value); string siteName = siteNode.Attributes["ServerComment"].Value; var site = new Site(siteName, siteId); string siteRootPath = attribute.Value + "/ROOT"; string lowerCaseSiteRootPath = attribute.Value + "/root"; var localAttribute = siteNode.Attributes["ServerBindings"]; if (localAttribute != null && !string.IsNullOrEmpty(localAttribute.Value)) { AddBinding(localAttribute.Value, "http", ref site); } localAttribute = siteNode.Attributes["SecureBindings"]; if (localAttribute != null && !string.IsNullOrEmpty(localAttribute.Value)) { AddBinding(localAttribute.Value, "https", ref site); } XmlNode currentSiteNode = document.SelectSingleNode(string.Format(ExactAttributeXPath, "Location", siteRootPath)); if (currentSiteNode == null) { currentSiteNode = document.SelectSingleNode(string.Format(ExactAttributeXPath, "Location", lowerCaseSiteRootPath)); } if (currentSiteNode != null) { string physicalPath = currentSiteNode.Attributes["Path"].Value; if (!_isLocal) { physicalPath = remoteSystemInfo.GetRemotePath(physicalPath); } var d = new GacAssemblyDetector(physicalPath); site.Add(d.GetGacedAssemblies()); var tempAttribute = currentSiteNode.Attributes["AppPoolId"]; site.PhysicalPath = physicalPath; if (tempAttribute == null || string.IsNullOrEmpty(tempAttribute.Value)) { site.AppPoolName = "DefaultAppPool"; } else { site.AppPoolName = tempAttribute.Value; } site.DefaultDocuments = GetDefaultDocList(currentSiteNode, defaultDocList); site.EnabledAuthType = GetAuthenticationType(currentSiteNode, defaultAuthenticationType); ApplicationPool appPool; if (appPoolMap.TryGetValue(site.AppPoolName, out appPool)) { appPool.NetFxVersion = GetNetFxVersion(currentSiteNode, netFxVersion); } GetDatabaseInfo(ref site, physicalPath, remoteSystemInfo != null ? remoteSystemInfo.ComputerName : string.Empty); } var appNodes = document.SelectNodes(string.Format(ContainsAttributeXPath, "Location", siteRootPath)); foreach (XmlNode appNode in appNodes) { var tempAttribute = appNode.Attributes["Path"]; if (tempAttribute == null) { // its just a directory continue; } var physicalPath = tempAttribute.Value; tempAttribute = appNode.Attributes["AppFriendlyName"]; if (tempAttribute == null) { // its just a vdir and not an app. No AppPool Settings continue; } if (!_isLocal) { physicalPath = remoteSystemInfo.GetRemotePath(physicalPath); } var g = new GacAssemblyDetector(physicalPath); site.Add(g.GetGacedAssemblies()); GetDatabaseInfo(ref site, physicalPath, remoteSystemInfo != null ? remoteSystemInfo.ComputerName : string.Empty); string appName = tempAttribute.Value; string appAppPoolName = string.Empty; if (string.IsNullOrEmpty(appName)) { appName = Path.GetFileName(physicalPath); } tempAttribute = appNode.Attributes["AppPoolId"]; if (tempAttribute != null) { appAppPoolName = tempAttribute.Value; } if (string.IsNullOrEmpty(appAppPoolName)) { appAppPoolName = "DefaultAppPool"; } ApplicationPool appPool; if (appPoolMap.TryGetValue(appAppPoolName, out appPool)) { appPool.NetFxVersion = GetNetFxVersion(appNode, netFxVersion); } var app = new Application(appName, physicalPath) { AppPoolName = appAppPoolName, }; site.Add(app); } site.IIS5CompatMode = iis5IsolationMode; Server.Sites.Add(site); } } } foreach (var keyValue in appPoolMap) { Server.AppPools.Add(keyValue.Value); } }
public bool PublishDatabase(DeploymentBaseOptions sourceBaseOptions, DeploymentBaseOptions destBaseOptions, string provider, bool logException) { bool publishSucceeded = true; this.LogTrace("Starting db publish for {0}", _localSite.SiteName); try { var providerOption = new DeploymentProviderOptions(provider); foreach (var providerSetting in providerOption.ProviderSettings) { var setting = ConfigurationManager.AppSettings[providerSetting.Name]; if (!string.IsNullOrEmpty(setting)) { try { providerSetting.Value = setting; } catch (Exception ex) { this.LogTrace("Error trying to set value: {0} for setting: {1}, {2}", setting, providerSetting.Name, ex.ToString()); } } } string path = _localSite.Databases[0].DBConnectionString; if (path.Contains("|DataDirectory|")) { // TODO: is there a better way to do this? Can we lookup |DataDirectory| path = path.Replace("|DataDirectory|", this._localSite.PhysicalPath + @"\App_Data\"); } providerOption.Path = path; RemoteSystemInfo remoteSystemInfo = null; if (RemoteSystemInfos.Servers.Any() && UseTrustedConnection(_localSite.Databases[0].DBConnectionString)) { remoteSystemInfo = RemoteSystemInfos.Servers[_localSite.ServerName]; } using (Impersonator.ImpersonateUser(remoteSystemInfo)) { using (var sourceObject = DeploymentManager.CreateObject(providerOption, sourceBaseOptions)) { LogTrace("Starting DB Sync for: {0} using {1}", (string)_localSite.Databases[0].DbConnectionStringBuilder["Initial Catalog"], provider); this.LogTrace("Publishing database as: {0}", destBaseOptions.UserName); try { sourceObject.SyncTo(provider, _publishSettings.SqlDBConnectionString.ConnectionString, destBaseOptions, new DeploymentSyncOptions()); this.LogTrace("DB Synced successfully"); Helper.UpdateStatus(_localSite.SiteName, _localSite.ServerName, true); } catch (Exception ex) { if (logException) { LogTrace("Error starting publish for db: {0}", (string)_localSite.Databases[0].DbConnectionStringBuilder["Initial Catalog"]); this.LogTrace(ex.ToString()); } publishSucceeded = false; } } } } catch (Exception ex) { if (logException) { LogTrace("Error syncing db: {0}", (string)_localSite.Databases[0].DbConnectionStringBuilder["Initial Catalog"]); LogTrace(ex.ToString()); } publishSucceeded = false; } return(publishSucceeded); }
private void Initialize(RemoteSystemInfo remoteSystemInfo) { CheckConfig(Server, remoteSystemInfo); var userApphostConfig = Path.Combine(Environment.SystemDirectory, @"inetsrv\config\applicationhost.config"); var rootDefaultDocList = GetDefaultDocuments(userApphostConfig); CheckSessionState(userApphostConfig, Server); using (ServerManager manager = GetServerManager()) { var config = manager.GetApplicationHostConfiguration(); foreach (var appPool in manager.ApplicationPools) { var isClassicMode = appPool.ManagedPipelineMode == ManagedPipelineMode.Classic ? true : false; double netFxRuntimeVersion = 0; if (!Double.TryParse(appPool.ManagedRuntimeVersion.TrimStart(new char[] { 'v', 'V' }), out netFxRuntimeVersion)) { netFxRuntimeVersion = 2.0; } Server.AppPools.Add( new ApplicationPool( isClassicMode, netFxRuntimeVersion, appPool.Enable32BitAppOnWin64, appPool.Name)); } foreach (var smSite in manager.Sites) { string physicalPath = smSite.Applications["/"].VirtualDirectories["/"].PhysicalPath; if (remoteSystemInfo != null) { physicalPath = remoteSystemInfo.GetRemotePath(physicalPath); } else { physicalPath = Environment.ExpandEnvironmentVariables(physicalPath); } var site = new Site(smSite.Name, smSite.Id); site.PhysicalPath = physicalPath; SetAuthPropertiesForSite(config, ref site); if (Directory.Exists(physicalPath)) { var webconfig = Path.Combine(physicalPath, "web.config"); if (File.Exists(webconfig)) { CheckSessionState(webconfig, Server); var localDefaultDocument = GetDefaultDocuments(webconfig); if (localDefaultDocument.Count > 0) { site.DefaultDocuments = localDefaultDocument.Union(rootDefaultDocList, StringComparer.OrdinalIgnoreCase).ToList(); } else { site.DefaultDocuments = rootDefaultDocList; } } } foreach (var application in smSite.Applications) { if (application.Path == "/") { site.AppPoolName = application.ApplicationPoolName; var gacAssembly = new GacAssemblyDetector(physicalPath); site.Add(gacAssembly.GetGacedAssemblies()); foreach (var vdir in smSite.Applications["/"].VirtualDirectories) { if (vdir.Path != "/") { string vdirPhysicalPath = vdir.PhysicalPath; if (remoteSystemInfo != null) { vdirPhysicalPath = remoteSystemInfo.GetRemotePath(vdirPhysicalPath); } site.Add(new VirtualDirectory(vdir.Path, vdirPhysicalPath)); } } continue; } if (application.VirtualDirectories.Count > 0) { string appPhysicalPath = application.VirtualDirectories[0].PhysicalPath; if (remoteSystemInfo != null && appPhysicalPath != "/") { appPhysicalPath = remoteSystemInfo.GetRemotePath(appPhysicalPath); } List<VirtualDirectory> listVdirs = new List<VirtualDirectory>(); foreach (var vdir in application.VirtualDirectories) { if (vdir.Path != "/") { string vdirPhysicalPath = vdir.PhysicalPath; if (remoteSystemInfo != null) { vdirPhysicalPath = remoteSystemInfo.GetRemotePath(vdirPhysicalPath); } listVdirs.Add(new VirtualDirectory(vdir.Path, vdirPhysicalPath)); } } site.Add(new Application(application.Path, appPhysicalPath) { AppPoolName = application.ApplicationPoolName, VDirs = listVdirs }); if (appPhysicalPath == "/") { continue; } var gacAssemblyForApp = new GacAssemblyDetector(appPhysicalPath); site.Add(gacAssemblyForApp.GetGacedAssemblies()); } } foreach (var binding in smSite.Bindings) { site.Add(new Binding(binding.BindingInformation, binding.Protocol)); } site.IisVersion = this.Server.IISVersion; site.OsVersion = this.Server.OSVersion; GetDatabaseInfo(ref site, physicalPath, remoteSystemInfo != null ? remoteSystemInfo.ComputerName : string.Empty); Server.Sites.Add(site); } } }
private void CheckConfig(IISServer server, RemoteSystemInfo remoteSystemInfo) { string configSectionName = "configSections"; string ftpServerSection = "system.ftpServer"; string NameAttribute = "name"; string xpathFormat = "configuration/"; var antaresSchema = new XmlDocument(); antaresSchema.Load(Assembly.GetExecutingAssembly() .GetManifestResourceStream("CompatCheckAndMigrate.Resources.IIS_MergedSchema.xml")); var customerAppHost = new XmlDocument(); var userApphostConfig = Path.Combine(Environment.SystemDirectory, @"inetsrv\config\applicationhost.config"); if (remoteSystemInfo != null) { userApphostConfig = remoteSystemInfo.RemoteAppHostConfigPath; } customerAppHost.Load(userApphostConfig); var antaresConfigSections = new HashSet<string>(StringComparer.Ordinal); XmlNodeList nodes = antaresSchema.SelectNodes("configSchema/sectionSchema"); foreach (XmlNode node in nodes) { antaresConfigSections.Add(node.Attributes[NameAttribute].Value); } var customerConfigSections = new List<string>(); nodes = customerAppHost.SelectNodes("//section"); foreach (XmlNode node in nodes) { XmlNode tempNode = node; string sectionPath = tempNode.Attributes[NameAttribute].Value; while (!string.Equals(tempNode.ParentNode.Name, configSectionName, StringComparison.OrdinalIgnoreCase)) { tempNode = tempNode.ParentNode; sectionPath = tempNode.Attributes[NameAttribute].Value + "/" + sectionPath; } if (!sectionPath.StartsWith(ftpServerSection, StringComparison.OrdinalIgnoreCase)) { customerConfigSections.Add(sectionPath); } } foreach (string customerSection in customerConfigSections) { if (!antaresConfigSections.Contains(customerSection)) { string message = string.Format("Section definition not supported for {0}", customerSection); server.SchemaCheckErrors.Add(message); } var nodeList = customerAppHost.SelectNodes(string.Concat(xpathFormat, customerSection)); foreach (XmlNode node in nodeList) { CheckAttributes(customerSection, antaresSchema, node, server); CheckElements(customerSection, antaresSchema, node, server); } } }
public MetabaseReader(string migrationId, double iisVersion, RemoteSystemInfo remoteSystemInfo) : base(migrationId, iisVersion, remoteSystemInfo != null ? remoteSystemInfo.OSVersion : Environment.OSVersion.Version.ToString(), remoteSystemInfo != null ? remoteSystemInfo.ComputerName : Environment.MachineName) { _isLocal = remoteSystemInfo == null; var document = new XmlDocument(); //#if DEBUG // document.Load(@"E:\vsprojects\metabase.xml"); //#else string metabasePath = _isLocal ? Path.Combine(Environment.SystemDirectory, @"inetsrv\metabase.xml") : remoteSystemInfo.RemoteMetabasePath; document.Load(metabasePath); //#endif var enable32Biton64 = false; var defaultAppPoolNode = document.SelectSingleNode(string.Format(NameSpaceAgnosticXPathFormat, "IIsApplicationPools")); var enable32bitAttribute = defaultAppPoolNode.Attributes["Enable32BitAppOnWin64"]; if (enable32bitAttribute != null && !string.IsNullOrEmpty(enable32bitAttribute.Value)) { enable32Biton64 = Convert.ToBoolean(enable32bitAttribute.Value); } XmlNode defaultServiceNode = document.SelectSingleNode(string.Format(NameSpaceAgnosticXPathFormat, "IIsWebService")); var netFxVersion = GetNetFxVersion(defaultServiceNode, null); var defaultAuthenticationType = GetAuthenticationType( defaultServiceNode, EnabledAuthenticationType.Anonymous); var defaultDocList = GetDefaultDocList(defaultServiceNode, null); var iis5IsolationMode = false; var isolationModeAttribute = defaultServiceNode.Attributes["IIs5IsolationModeEnabled"]; if (isolationModeAttribute != null && !string.IsNullOrEmpty(isolationModeAttribute.Value)) { iis5IsolationMode = Convert.ToBoolean(isolationModeAttribute.Value); } var appPoolMap = new Dictionary<string, ApplicationPool>(StringComparer.OrdinalIgnoreCase); var appPoolNodes = document.SelectNodes(string.Format(NameSpaceAgnosticXPathFormat, "IIsApplicationPool")); foreach (XmlNode appPoolNode in appPoolNodes) { string name = string.Empty; var attribute = appPoolNode.Attributes["Location"]; if (attribute != null && !string.IsNullOrEmpty(attribute.Value)) { name = attribute.Value.Replace("/LM/W3SVC/AppPools/", string.Empty); appPoolMap[name] = new ApplicationPool(true, netFxVersion, enable32Biton64, name); } } var siteNodes = document.SelectNodes(string.Format(NameSpaceAgnosticXPathFormat, "IIsWebServer")); foreach (XmlNode siteNode in siteNodes) { var attribute = siteNode.Attributes["Location"]; if (attribute != null) { var m = SiteLocationRegex.Match(attribute.Value); if (m.Success) { long siteId = Convert.ToInt64(m.Groups[1].Value); string siteName = siteNode.Attributes["ServerComment"].Value; var site = new Site(siteName, siteId); string siteRootPath = attribute.Value + "/ROOT"; string lowerCaseSiteRootPath = attribute.Value + "/root"; var localAttribute = siteNode.Attributes["ServerBindings"]; if (localAttribute != null && !string.IsNullOrEmpty(localAttribute.Value)) { AddBinding(localAttribute.Value, "http", ref site); } localAttribute = siteNode.Attributes["SecureBindings"]; if (localAttribute != null && !string.IsNullOrEmpty(localAttribute.Value)) { AddBinding(localAttribute.Value, "https", ref site); } XmlNode currentSiteNode = document.SelectSingleNode(string.Format(ExactAttributeXPath, "Location", siteRootPath)); if (currentSiteNode == null) { currentSiteNode = document.SelectSingleNode(string.Format(ExactAttributeXPath, "Location", lowerCaseSiteRootPath)); } if (currentSiteNode != null) { string physicalPath = currentSiteNode.Attributes["Path"].Value; if (!_isLocal) { physicalPath = remoteSystemInfo.GetRemotePath(physicalPath); } var d = new GacAssemblyDetector(physicalPath); site.Add(d.GetGacedAssemblies()); var tempAttribute = currentSiteNode.Attributes["AppPoolId"]; site.PhysicalPath = physicalPath; if(tempAttribute == null || string.IsNullOrEmpty(tempAttribute.Value)) { site.AppPoolName = "DefaultAppPool"; } else { site.AppPoolName = tempAttribute.Value; } site.DefaultDocuments = GetDefaultDocList(currentSiteNode, defaultDocList); site.EnabledAuthType = GetAuthenticationType(currentSiteNode, defaultAuthenticationType); ApplicationPool appPool; if (appPoolMap.TryGetValue(site.AppPoolName, out appPool)) { appPool.NetFxVersion = GetNetFxVersion(currentSiteNode, netFxVersion); } GetDatabaseInfo(ref site, physicalPath, remoteSystemInfo != null ? remoteSystemInfo.ComputerName : string.Empty); } var appNodes = document.SelectNodes(string.Format(ContainsAttributeXPath, "Location", siteRootPath)); foreach (XmlNode appNode in appNodes) { var tempAttribute = appNode.Attributes["Path"]; if (tempAttribute == null) { // its just a directory continue; } var physicalPath = tempAttribute.Value; tempAttribute = appNode.Attributes["AppFriendlyName"]; if (tempAttribute == null) { // its just a vdir and not an app. No AppPool Settings continue; } if (!_isLocal) { physicalPath = remoteSystemInfo.GetRemotePath(physicalPath); } var g = new GacAssemblyDetector(physicalPath); site.Add(g.GetGacedAssemblies()); GetDatabaseInfo(ref site, physicalPath, remoteSystemInfo != null ? remoteSystemInfo.ComputerName : string.Empty); string appName = tempAttribute.Value; string appAppPoolName = string.Empty; if (string.IsNullOrEmpty(appName)) { appName = Path.GetFileName(physicalPath); } tempAttribute = appNode.Attributes["AppPoolId"]; if (tempAttribute != null) { appAppPoolName = tempAttribute.Value; } if (string.IsNullOrEmpty(appAppPoolName)) { appAppPoolName = "DefaultAppPool"; } ApplicationPool appPool; if (appPoolMap.TryGetValue(appAppPoolName, out appPool)) { appPool.NetFxVersion = GetNetFxVersion(appNode, netFxVersion); } var app = new Application(appName, physicalPath) { AppPoolName = appAppPoolName, }; site.Add(app); } site.IIS5CompatMode = iis5IsolationMode; Server.Sites.Add(site); } } } foreach (var keyValue in appPoolMap) { Server.AppPools.Add(keyValue.Value); } }