public static void SaveBundleFromViewModel(BundleViewModel bundle, string bundleType) { var doc = XDocument.Load(HttpContext.Current.Server.MapPath(Config.BundlesConfigPath)); var bundleEl = new XElement(bundleType + "Bundle"); if (doc.Descendants(bundleType + "Bundle").Any(x => x.Attribute("virtualPath").Value == bundle.VirtualPath)) bundleEl = doc.Descendants(bundleType + "Bundle") .Single(x => x.Attribute("virtualPath").Value == bundle.VirtualPath); else { bundleEl.SetAttributeValue("virtualPath", bundle.VirtualPath); doc.Descendants("bundles").Single().Add(bundleEl); } bundleEl.SetAttributeValue("disableMinification", bundle.DisableMinification.ToString()); bundleEl.Elements().Remove(); if (bundle.Files != null) { foreach (var file in bundle.Files) { var includeEl = new XElement("include"); includeEl.SetAttributeValue("virtualPath", file); bundleEl.Add(includeEl); } } doc.Save(HttpContext.Current.Server.MapPath(Config.BundlesConfigPath)); HttpRuntime.UnloadAppDomain(); }
public static void SaveBundleFromViewModel(BundleViewModel bundle, string bundleType) { var doc = XDocument.Load(HttpContext.Current.Server.MapPath(Config.BundlesConfigPath)); var bundleEl = new XElement(bundleType + "Bundle"); if (doc.Descendants(bundleType + "Bundle").Any(x => x.Attribute("virtualPath").Value == bundle.VirtualPath)) bundleEl = doc.Descendants(bundleType + "Bundle") .Single(x => x.Attribute("virtualPath").Value == bundle.VirtualPath); else { bundleEl.SetAttributeValue("virtualPath", bundle.VirtualPath); doc.Descendants("bundles").Single().Add(bundleEl); } bundleEl.SetAttributeValue("disableMinification", bundle.DisableMinification.ToString()); bundleEl.Elements().Remove(); if (bundle.Files != null) { foreach (var file in bundle.Files) { var includeEl = new XElement("include"); includeEl.SetAttributeValue("virtualPath", file); bundleEl.Add(includeEl); } } doc.Save(HttpContext.Current.Server.MapPath(Config.BundlesConfigPath)); try { //HttpRuntime.UnloadAppDomain(); var webConfigPath = HttpContext.Current.Request.PhysicalApplicationPath + "\\\\Web.config"; System.IO.File.SetLastWriteTimeUtc(webConfigPath, DateTime.UtcNow); } catch (Exception ex) { LogHelper.Info<Bundles>("Optimus failed to restart the application pool, you may need to check permissions on web.config"); } }
public ActionResult Dialog(string snippet) { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(snippet); List<string> scripts = new List<string>(); if (doc.DocumentNode.SelectNodes("//script") != null) { foreach (var scriptNode in doc.DocumentNode.SelectNodes("//script")) { var scriptsource = scriptNode.Attributes["src"].Value; if (!scriptsource.StartsWith("~")) scriptsource = "~" + scriptsource; scripts.Add(scriptsource); } } List<string> stylesheets = new List<string>(); if (doc.DocumentNode.SelectNodes("//link") != null) { foreach (var linkNode in doc.DocumentNode.SelectNodes("//link")) { var stylesheetlink = linkNode.Attributes["href"].Value; if (!stylesheetlink.StartsWith("~")) stylesheetlink = "~" + stylesheetlink; stylesheets.Add(stylesheetlink); } } BundleViewModel m = new BundleViewModel(); m.VirtualPath = "~/bundles/"; if (scripts.Any()) m.Files = scripts; else m.Files = stylesheets; return View(Config.DialogViewPath,m); }
public void PostBundleUpdate(BundleViewModel bundle, string bundleType) { Bundles.SaveBundleFromViewModel(bundle,bundleType); }