private List<BindingsItem> GetBindings(string websiteSettingsFilePath) { // Dict {host}/{port} List<BindingsItem> result = new List<BindingsItem>(); XmlDocumentEx websiteSettings = new XmlDocumentEx(); websiteSettings.Load(websiteSettingsFilePath); XmlElement bindingsElement = websiteSettings.SelectSingleElement("/appcmd/SITE/site/bindings"); if (bindingsElement != null) { foreach (XmlElement bindingElement in bindingsElement.ChildNodes) { result.Add(new BindingsItem(bindingElement.Attributes["bindingInformation"].Value.Split(':')[2], int.Parse(bindingElement.Attributes["bindingInformation"].Value.Split(':')[1]))); } return result; } return null; }
private void ChangeWebsiteSettingsIfNeeded(string path, ImportArgs args) { XmlDocumentEx websiteSettings = new XmlDocumentEx(); websiteSettings.Load(path); args.siteName = this.CreateNewSiteName(InstanceManager.Instances, args.siteName); websiteSettings.SetElementAttributeValue("/appcmd/SITE", "SITE.NAME", args.siteName); websiteSettings.SetElementAttributeValue("/appcmd/SITE/site", "name", args.siteName); websiteSettings.SetElementAttributeValue("/appcmd/SITE", "bindings", "http/*:80:" + args.siteName); // need to change site ID args.siteID = this.CreateNewID(args.siteID); websiteSettings.SetElementAttributeValue("/appcmd/SITE", "SITE.ID", args.siteID.ToString()); websiteSettings.SetElementAttributeValue("/appcmd/SITE/site", "id", args.siteID.ToString()); // change apppool name websiteSettings.SetElementAttributeValue("/appcmd/SITE/site/application", "applicationPool", args.appPoolName); websiteSettings.SetElementAttributeValue("/appcmd/SITE/site/applicationDefaults", "applicationPool", args.appPoolName); // change root folder websiteSettings.SetElementAttributeValue("/appcmd/SITE/site/application/virtualDirectory", "physicalPath", args.rootPath + "\\Website"); // TODO: need to change bindings in right way(maybe with the UI dialog) // websiteSettings.SetElementAttributeValue("/appcmd/SITE/site/bindings/binding[@bindingInformation='*:80:" + args.oldSiteName + "']", "bindingInformation", "*:80:" + args.siteName); XmlElement bindingsElement = websiteSettings.SelectSingleElement("/appcmd/SITE/site/bindings"); if (bindingsElement != null) { bindingsElement.InnerXml = string.Empty; // it's a f*****g HACK, I can't work with xml nodes foreach (var key in args.bindings.Keys) { bindingsElement.InnerXml += "<binding protocol=\"http\" bindingInformation=\"*:{1}:{0}\" />".FormatWith(key, args.bindings[key].ToString()); } // foreach (XmlElement bindingElement in bindingsElement.ChildNodes) // { // //if (bindingElement.Attributes["bindingInformation"].Value.Split(':').Last() != null && bindingElement.Attributes["bindingInformation"].Value.Split(':').Last() != "") // // args.siteBindingsHostnames.Add(bindingElement.Attributes["bindingInformation"].Value.Split(':').Last()); // //if(bindingElement.Attributes["bindingInformation"].Value.Split(':').Last() != null && bindingElement.Attributes["bindingInformation"].Value.Split(':').Last() != "") // //bindingElement.Attributes["bindingInformation"].Value = bindingElement.Attributes["bindingInformation"].Value.Replace(bindingElement.Attributes["bindingInformation"].Value.Split(':').Last(), args.siteName); // } } websiteSettings.Save(websiteSettings.FilePath + ".fixed.xml"); }