public bool SaveBindings(string configPath, string bindingsXml) { string bindingPath = configPath + ".bindings"; try { var sb = new StringBuilder(); if (File.Exists(bindingPath)) { var lines = File.ReadAllLines(bindingPath); foreach (var line in lines) { if (!line.TrimStart().StartsWith("///<binding", StringComparison.OrdinalIgnoreCase)) { sb.AppendLine(line); } } } if (bindingsXml != "<binding />") { sb.Insert(0, "///" + bindingsXml); } ProjectHelpers.CheckFileOutOfSourceControl(bindingPath); if (sb.Length == 0) { ProjectHelpers.DeleteFileFromProject(bindingPath); } else { File.WriteAllText(bindingPath, sb.ToString(), Encoding.UTF8); ProjectHelpers.AddNestedFile(configPath, bindingPath); } IVsPersistDocData persistDocData; if (!BundlerMinifierPackage.IsDocumentDirty(configPath, out persistDocData) && persistDocData != null) { int cancelled; string newName; persistDocData.SaveDocData(VSSAVEFLAGS.VSSAVE_SilentSave, out newName, out cancelled); } else if (persistDocData == null) { new FileInfo(configPath).LastWriteTime = DateTime.Now; } return(true); } catch (Exception ex) { Logger.Log(ex); return(false); } }
public bool SaveBindings(string configPath, string bindingsXml) { string bindingPath = configPath + ".bindings"; try { ProjectHelpers.CheckFileOutOfSourceControl(bindingPath); if (bindingsXml == "<binding />" && File.Exists(bindingPath)) { ProjectHelpers.DeleteFileFromProject(bindingPath); } else { File.WriteAllText(bindingPath, "///" + bindingsXml, Encoding.UTF8); ProjectHelpers.AddNestedFile(configPath, bindingPath); } IVsPersistDocData persistDocData; if (!BundlerMinifierPackage.IsDocumentDirty(configPath, out persistDocData) && persistDocData != null) { int cancelled; string newName; persistDocData.SaveDocData(VSSAVEFLAGS.VSSAVE_SilentSave, out newName, out cancelled); } else if (persistDocData == null) { new FileInfo(configPath).LastWriteTime = DateTime.Now; } return(true); } catch (Exception ex) { Logger.Log(ex); return(false); } }