Skip to content

Commit 700c76c

Browse files
authored
Fixes issue updating files when proxy is running. Closes #244 (#250)
* Fixes issue updating files when proxy is running. Closes #244 * Reoslve PR comments * Resolve PR comments (again)
1 parent b660270 commit 700c76c

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

msgraph-developer-proxy-plugins/MockResponses/MockResponsesLoader.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Microsoft.Graph.DeveloperProxy.Abstractions;
55
using System.Text.Json;
6+
using System.IO;
67

78
namespace Microsoft.Graph.DeveloperProxy.Plugins.MocksResponses;
89

@@ -26,12 +27,16 @@ public void LoadResponses() {
2627
}
2728

2829
try {
29-
var responsesString = File.ReadAllText(_responsesFilePath);
30-
var responsesConfig = JsonSerializer.Deserialize<MockResponseConfiguration>(responsesString);
31-
IEnumerable<MockResponse>? configResponses = responsesConfig?.Responses;
32-
if (configResponses is not null) {
33-
_configuration.Responses = configResponses;
34-
_logger.LogInfo($"Mock responses for {configResponses.Count()} url patterns loaded from {_configuration.MocksFile}");
30+
using (FileStream stream = new FileStream(_responsesFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
31+
using (StreamReader reader = new StreamReader(stream)) {
32+
var responsesString = reader.ReadToEnd();
33+
var responsesConfig = JsonSerializer.Deserialize<MockResponseConfiguration>(responsesString);
34+
IEnumerable<MockResponse>? configResponses = responsesConfig?.Responses;
35+
if (configResponses is not null) {
36+
_configuration.Responses = configResponses;
37+
_logger.LogInfo($"Mock responses for {configResponses.Count()} url patterns loaded from {_configuration.MocksFile}");
38+
}
39+
}
3540
}
3641
}
3742
catch (Exception ex) {

msgraph-developer-proxy-plugins/RandomErrors/GenericErrorResponsesLoader.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Microsoft.Graph.DeveloperProxy.Abstractions;
55
using System.Text.Json;
6+
using System.IO;
67

78
namespace Microsoft.Graph.DeveloperProxy.Plugins.RandomErrors;
89

@@ -26,12 +27,16 @@ public void LoadResponses() {
2627
}
2728

2829
try {
29-
var responsesString = File.ReadAllText(_errorsFile);
30-
var responsesConfig = JsonSerializer.Deserialize<GenericRandomErrorConfiguration>(responsesString);
31-
IEnumerable<GenericErrorResponse>? configResponses = responsesConfig?.Responses;
32-
if (configResponses is not null) {
33-
_configuration.Responses = configResponses;
34-
_logger.LogInfo($"Error responses for {configResponses.Count()} url patterns loaded from from {_configuration.ErrorsFile}");
30+
using (FileStream stream = new FileStream(_errorsFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
31+
using (StreamReader reader = new StreamReader(stream)) {
32+
var responsesString = reader.ReadToEnd();
33+
var responsesConfig = JsonSerializer.Deserialize<GenericRandomErrorConfiguration>(responsesString);
34+
IEnumerable<GenericErrorResponse>? configResponses = responsesConfig?.Responses;
35+
if (configResponses is not null) {
36+
_configuration.Responses = configResponses;
37+
_logger.LogInfo($"Error responses for {configResponses.Count()} url patterns loaded from from {_configuration.ErrorsFile}");
38+
}
39+
}
3540
}
3641
}
3742
catch (Exception ex) {

0 commit comments

Comments
 (0)