Addressing code review comments by using Streams instead of ing the contents into a string.

This commit is contained in:
Livar Cunha 2017-05-17 21:46:21 -07:00
parent 439c4e6173
commit 9952f2fd68
2 changed files with 21 additions and 16 deletions

View file

@ -13,12 +13,16 @@ namespace Microsoft.DotNet.Cli.Utils
public RuntimeConfigFramework Framework { get; }
public RuntimeConfig(string runtimeConfigPath)
{
var runtimeConfigJson = OpenRuntimeConfig(runtimeConfigPath);
Framework = ParseFramework(runtimeConfigJson);
IsPortable = Framework != null;
{
JObject runtimeConfigJson;
using (var streamReader = new StreamReader(new FileStream(runtimeConfigPath, FileMode.Open)))
{
runtimeConfigJson = OpenRuntimeConfig(streamReader);
}
Framework = ParseFramework(runtimeConfigJson);
IsPortable = Framework != null;
}
public static bool IsApplicationPortable(string entryAssemblyPath)
@ -32,9 +36,9 @@ namespace Microsoft.DotNet.Cli.Utils
return false;
}
private JObject OpenRuntimeConfig(string runtimeConfigPath)
private JObject OpenRuntimeConfig(StreamReader streamReader)
{
var reader = new JsonTextReader(new StringReader(File.ReadAllText(runtimeConfigPath)));
var reader = new JsonTextReader(streamReader);
return JObject.Load(reader);
}

View file

@ -54,7 +54,7 @@ namespace Microsoft.DotNet.Cli
{
var httpClient = new HttpClient();
string result;
Stream result;
try
{
@ -62,21 +62,22 @@ namespace Microsoft.DotNet.Cli
var response = httpClient.GetAsync($"https://api-v2v3search-0.nuget.org/query?q={match}&skip=0&take=100&prerelease=true", cancellation.Token)
.Result;
result = response.Content.ReadAsStringAsync().Result;
result = response.Content.ReadAsStreamAsync().Result;
}
catch (Exception)
{
yield break;
}
using (var reader = new JsonTextReader(new StringReader(result)))
JObject json;
using (var reader = new JsonTextReader(new StreamReader(result)))
{
var json = JObject.Load(reader);
json = JObject.Load(reader);
}
foreach (var id in json["data"])
{
yield return id["id"].Value<string>();
}
foreach (var id in json["data"])
{
yield return id["id"].Value<string>();
}
}
}