Skip to content

Commit 895b8be

Browse files
committed
Merge pull request #548 from gmarz/master
Create Cache directory if it doesn't exist before writing to
2 parents df2bfc9 + 70c1053 commit 895b8be

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/CodeGeneration/CodeGeneration.LowLevelClient/ApiGenerator.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public static RestApiSpec GetRestSpec(bool useCache)
4545
html = client.DownloadString(useCache ? LocalUri("root.html") : _listingUrl);
4646

4747
var dom = CQ.Create(html);
48-
if (!useCache)
49-
File.WriteAllText(_cacheFolder + "root.html", html);
48+
if (!useCache)
49+
WriteToCache("root.html", html);
5050

5151
var endpoints = dom[".js-directory-link"]
5252
.Select(s => s.InnerText)
@@ -80,8 +80,8 @@ private static KeyValuePair<string, ApiEndpoint> CreateApiDocumentation(bool use
8080
var fileName = rawFile.Split(new[] {'/'}).Last();
8181
Console.WriteLine("Downloading {0}", rawFile);
8282
var json = client.DownloadString(useCache ? LocalUri(fileName) : rawFile);
83-
if (!useCache)
84-
File.WriteAllText(_cacheFolder + fileName, json);
83+
if (!useCache)
84+
WriteToCache(fileName, json);
8585

8686
var apiDocumentation = JsonConvert.DeserializeObject<Dictionary<string, ApiEndpoint>>(json).First();
8787
apiDocumentation.Value.CsharpMethodName = CreateMethodName(
@@ -214,5 +214,13 @@ public static void GenerateEnums(RestApiSpec model)
214214
var source = _razorMachine.Execute(File.ReadAllText(_viewFolder + @"Enums.Generated.cshtml"), model).ToString();
215215
File.WriteAllText(targetFile, source);
216216
}
217+
218+
private static void WriteToCache(string filename, string contents)
219+
{
220+
if (!Directory.Exists(_cacheFolder))
221+
Directory.CreateDirectory(_cacheFolder);
222+
223+
File.WriteAllText(_cacheFolder + filename, contents);
224+
}
217225
}
218226
}

0 commit comments

Comments
 (0)