XElement SaveToDisk(IResource resource, StringBuilder contents, string directoryName, TxFileManager fileManager) { if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } if (_dev2FileWrapper.Exists(resource.FilePath)) { // Remove readonly attribute if it is set var attributes = _dev2FileWrapper.GetAttributes(resource.FilePath); if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { _dev2FileWrapper.SetAttributes(resource.FilePath, attributes ^ FileAttributes.ReadOnly); } } var xml = contents.ToXElement(); xml = resource.UpgradeXml(xml, resource); var result = xml.ToStringBuilder(); var signedXml = HostSecurityProvider.Instance.SignXml(result); lock (Common.GetFileLock(resource.FilePath)) { signedXml.WriteToFile(resource.FilePath, Encoding.UTF8, fileManager); } return(xml); }