/// <summary>Returns 'null' if download is not available and caller should keep polling.</summary> private async Task<XElement> TryDownloadFileAsync(IRemoteControlClient client) { _service.LogInfo("Read file from client"); // "ReturnsNull": Only return a file if we have it locally *and* it's not older than our polling time (1 day). using (var stream = await client.ReadFileAsync(__VsRemoteControlBehaviorOnStale.ReturnsNull).ConfigureAwait(false)) { if (stream == null) { _service.LogInfo("Read file completed. Client returned no data"); return null; } _service.LogInfo("Read file completed. Client returned data"); _service.LogInfo("Converting data to XElement"); // We're reading in our own XML file, but even so, use conservative settings // just to be on the safe side. First, disallow DTDs entirely (we will never // have one ourself). And also, prevent any external resolution of files when // processing the xml. var settings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Prohibit, XmlResolver = null }; using (var reader = XmlReader.Create(stream, settings)) { var result = XElement.Load(reader); _service.LogInfo("Converting data to XElement completed"); return result; } } }
public async Task <Stream> ReadFileAsync() { RequiresNotDisposed(); return(await remoteControlClient.ReadFileAsync((BehaviorOnStale)2).ConfigureAwait(false)); }