fixed the issue with resources not disposed correctly (#439)

* fixed the issue with resources not disposed correctly

* disposing language service at shutdown
This commit is contained in:
Leila Lali
2017-08-21 14:32:48 -07:00
committed by GitHub
parent 39dedd88e0
commit 1511f73672
7 changed files with 108 additions and 71 deletions

View File

@@ -1119,27 +1119,30 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
throw new ArgumentException("sourceXml");
}
MemoryStream memoryStream = new MemoryStream();
StreamWriter streamWriter = new StreamWriter(memoryStream);
using (MemoryStream memoryStream = new MemoryStream())
{
using (StreamWriter streamWriter = new StreamWriter(memoryStream))
{
// Writes the xml to the memory stream
streamWriter.Write(sourceXml);
streamWriter.Flush();
// Writes the xml to the memory stream
streamWriter.Write(sourceXml);
streamWriter.Flush();
// Resets the stream to the beginning
memoryStream.Seek(0, SeekOrigin.Begin);
// Resets the stream to the beginning
memoryStream.Seek(0, SeekOrigin.Begin);
// Creates the XML reader from the stream
// and moves it to the correct node
XmlReader xmlReader = XmlReader.Create(memoryStream);
xmlReader.MoveToContent();
// Creates the XML reader from the stream
// and moves it to the correct node
XmlReader xmlReader = XmlReader.Create(memoryStream);
xmlReader.MoveToContent();
// generate the xml document
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.PreserveWhitespace = true;
xmlDocument.LoadXml(xmlReader.ReadOuterXml());
// generate the xml document
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.PreserveWhitespace = true;
xmlDocument.LoadXml(xmlReader.ReadOuterXml());
return xmlDocument;
return xmlDocument;
}
}
}
#endregion