Merge pull request #1774 from umbraco/temp-9586-async-content-xml-save
Removes async from filestream instance
This commit is contained in:
@@ -16,32 +16,6 @@ namespace Umbraco.Core
|
||||
/// </summary>
|
||||
internal static class XmlExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Saves the xml document async
|
||||
/// </summary>
|
||||
/// <param name="xdoc"></param>
|
||||
/// <param name="filename"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task SaveAsync(this XmlDocument xdoc, string filename)
|
||||
{
|
||||
if (xdoc.DocumentElement == null)
|
||||
throw new XmlException("Cannot save xml document, there is no root element");
|
||||
|
||||
using (var fs = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Read, bufferSize: 4096, useAsync: true))
|
||||
using (var xmlWriter = XmlWriter.Create(fs, new XmlWriterSettings
|
||||
{
|
||||
Async = true,
|
||||
Encoding = Encoding.UTF8,
|
||||
Indent = true
|
||||
}))
|
||||
{
|
||||
//NOTE: There are no nice methods to write it async, only flushing it async. We
|
||||
// could implement this ourselves but it'd be a very manual process.
|
||||
xdoc.WriteTo(xmlWriter);
|
||||
await xmlWriter.FlushAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool HasAttribute(this XmlAttributeCollection attributes, string attributeName)
|
||||
{
|
||||
return attributes.Cast<XmlAttribute>().Any(x => x.Name == attributeName);
|
||||
|
||||
@@ -844,7 +844,6 @@ namespace umbraco
|
||||
internal void SaveXmlToFile()
|
||||
{
|
||||
LogHelper.Info<content>("Save Xml to file...");
|
||||
|
||||
try
|
||||
{
|
||||
var xml = _xmlContent; // capture (atomic + volatile), immutable anyway
|
||||
@@ -861,7 +860,7 @@ namespace umbraco
|
||||
Directory.CreateDirectory(directoryName);
|
||||
|
||||
// save
|
||||
using (var fs = new FileStream(_xmlFileName, FileMode.Create, FileAccess.Write, FileShare.Read, bufferSize: 4096, useAsync: true))
|
||||
using (var fs = new FileStream(_xmlFileName, FileMode.Create, FileAccess.Write, FileShare.Read))
|
||||
{
|
||||
SaveXmlToStream(xml, fs);
|
||||
}
|
||||
|
||||
@@ -88,19 +88,20 @@ namespace umbraco
|
||||
string originalPath = IOHelper.MapPath(VirtualPathUtility.ToAbsolute(MasterPageFile));
|
||||
string copyPath = IOHelper.MapPath(VirtualPathUtility.ToAbsolute(path));
|
||||
|
||||
FileStream fs = new FileStream(originalPath, FileMode.Open, FileAccess.ReadWrite);
|
||||
StreamReader f = new StreamReader(fs);
|
||||
String newfile = f.ReadToEnd();
|
||||
f.Close();
|
||||
fs.Close();
|
||||
string newFile;
|
||||
using (var fs = new FileStream(originalPath, FileMode.Open, FileAccess.ReadWrite))
|
||||
using (var f = new StreamReader(fs))
|
||||
{
|
||||
newFile = f.ReadToEnd();
|
||||
}
|
||||
|
||||
newfile = newfile.Replace("MasterPageFile=\"~/masterpages/", "MasterPageFile=\"");
|
||||
newFile = newFile.Replace("MasterPageFile=\"~/masterpages/", "MasterPageFile=\"");
|
||||
|
||||
fs = new FileStream(copyPath, FileMode.Create, FileAccess.Write);
|
||||
|
||||
StreamWriter replacement = new StreamWriter(fs);
|
||||
replacement.Write(newfile);
|
||||
replacement.Close();
|
||||
using (var fs = new FileStream(copyPath, FileMode.Create, FileAccess.Write))
|
||||
using (var replacement = new StreamWriter(fs))
|
||||
{
|
||||
replacement.Write(newFile);
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
|
||||
Reference in New Issue
Block a user