From 9b5f7f24955e8422dfeebf6f184518095d2e1caf Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 3 Apr 2016 19:20:56 -0400 Subject: [PATCH] remove temp file from open subtitles --- .../XML-RPC/XmlRpcGenerator.cs | 64 +++++++++---------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/OpenSubtitlesHandler/XML-RPC/XmlRpcGenerator.cs b/OpenSubtitlesHandler/XML-RPC/XmlRpcGenerator.cs index 5a190ab729..c39917e298 100644 --- a/OpenSubtitlesHandler/XML-RPC/XmlRpcGenerator.cs +++ b/OpenSubtitlesHandler/XML-RPC/XmlRpcGenerator.cs @@ -51,47 +51,45 @@ namespace XmlRpcHandler XmlWriterSettings sett = new XmlWriterSettings(); sett.Indent = true; - var requestXmlPath = Path.Combine(Path.GetTempPath(), "request.xml"); - sett.Encoding = Encoding.UTF8; - FileStream str = new FileStream(requestXmlPath, FileMode.Create, FileAccess.Write); - XmlWriter XMLwrt = XmlWriter.Create(str, sett); - // Let's write the methods - foreach (XmlRpcMethodCall method in methods) + using (var ms = new MemoryStream()) { - XMLwrt.WriteStartElement("methodCall");//methodCall - XMLwrt.WriteStartElement("methodName");//methodName - XMLwrt.WriteString(method.Name); - XMLwrt.WriteEndElement();//methodName - XMLwrt.WriteStartElement("params");//params - // Write values - foreach (IXmlRpcValue p in method.Parameters) + XmlWriter XMLwrt = XmlWriter.Create(ms, sett); + // Let's write the methods + foreach (XmlRpcMethodCall method in methods) { - XMLwrt.WriteStartElement("param");//param - if (p is XmlRpcValueBasic) - { - WriteBasicValue(XMLwrt, (XmlRpcValueBasic)p); - } - else if (p is XmlRpcValueStruct) + XMLwrt.WriteStartElement("methodCall");//methodCall + XMLwrt.WriteStartElement("methodName");//methodName + XMLwrt.WriteString(method.Name); + XMLwrt.WriteEndElement();//methodName + XMLwrt.WriteStartElement("params");//params + // Write values + foreach (IXmlRpcValue p in method.Parameters) { - WriteStructValue(XMLwrt, (XmlRpcValueStruct)p); - } - else if (p is XmlRpcValueArray) - { - WriteArrayValue(XMLwrt, (XmlRpcValueArray)p); + XMLwrt.WriteStartElement("param");//param + if (p is XmlRpcValueBasic) + { + WriteBasicValue(XMLwrt, (XmlRpcValueBasic)p); + } + else if (p is XmlRpcValueStruct) + { + WriteStructValue(XMLwrt, (XmlRpcValueStruct)p); + } + else if (p is XmlRpcValueArray) + { + WriteArrayValue(XMLwrt, (XmlRpcValueArray)p); + } + XMLwrt.WriteEndElement();//param } - XMLwrt.WriteEndElement();//param - } - XMLwrt.WriteEndElement();//params - XMLwrt.WriteEndElement();//methodCall + XMLwrt.WriteEndElement();//params + XMLwrt.WriteEndElement();//methodCall + } + XMLwrt.Flush(); + XMLwrt.Close(); + return ms.ToArray(); } - XMLwrt.Flush(); - XMLwrt.Close(); - str.Close(); - string requestContent = File.ReadAllText(requestXmlPath); - return Encoding.UTF8.GetBytes(requestContent); } /// /// Decode response then return the values