From 1c693ccfc1aa3b8054a7ded0ead04425ef2967d2 Mon Sep 17 00:00:00 2001 From: Anton Nikolaev Date: Wed, 27 Jun 2018 12:34:23 +0300 Subject: [PATCH] Allow shared access for reading registry files --- .../Plexus.Interop.Apps.Manager/Internal/AppsDto.cs | 10 ++++++---- .../Internal/RegistryDto.cs | 6 ++++-- .../src/Plexus.Interop.Metamodel.Json/JsonRegistry.cs | 2 +- .../Internal/WebSocketTransmissionServer.cs | 5 +++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/desktop/src/Plexus.Interop.Apps.Manager/Internal/AppsDto.cs b/desktop/src/Plexus.Interop.Apps.Manager/Internal/AppsDto.cs index fecfb6391..c93e6dc50 100644 --- a/desktop/src/Plexus.Interop.Apps.Manager/Internal/AppsDto.cs +++ b/desktop/src/Plexus.Interop.Apps.Manager/Internal/AppsDto.cs @@ -14,11 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -namespace Plexus.Interop.Apps.Internal +namespace Plexus.Interop.Apps.Internal { using Newtonsoft.Json; using System.Collections.Generic; using System.IO; + using System.Text; internal sealed class AppsDto { @@ -27,11 +28,12 @@ internal sealed class AppsDto public static AppsDto Load(string filePath) { - using (var file = File.OpenText(filePath)) - using (var reader = new JsonTextReader(file)) + using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + using (var streamReader = new StreamReader(stream, Encoding.UTF8)) + using (var jsonReader = new JsonTextReader(streamReader)) { var serializer = new JsonSerializer(); - return serializer.Deserialize(reader); + return serializer.Deserialize(jsonReader); } } } diff --git a/desktop/src/Plexus.Interop.Metamodel.Json/Internal/RegistryDto.cs b/desktop/src/Plexus.Interop.Metamodel.Json/Internal/RegistryDto.cs index 059515455..e795165d2 100644 --- a/desktop/src/Plexus.Interop.Metamodel.Json/Internal/RegistryDto.cs +++ b/desktop/src/Plexus.Interop.Metamodel.Json/Internal/RegistryDto.cs @@ -19,6 +19,7 @@ namespace Plexus.Interop.Metamodel.Json.Internal using Newtonsoft.Json; using System.Collections.Generic; using System.IO; + using System.Text; internal sealed class RegistryDto { @@ -30,8 +31,9 @@ internal sealed class RegistryDto public static RegistryDto LoadFromFile(string filePath) { - using (var file = File.OpenText(filePath)) - using (var reader = new JsonTextReader(file)) + using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + using (var streamReader = new StreamReader(stream, Encoding.UTF8)) + using (var reader = new JsonTextReader(streamReader)) { var serializer = new JsonSerializer(); return serializer.Deserialize(reader); diff --git a/desktop/src/Plexus.Interop.Metamodel.Json/JsonRegistry.cs b/desktop/src/Plexus.Interop.Metamodel.Json/JsonRegistry.cs index 8de8752b7..b1c83c61c 100644 --- a/desktop/src/Plexus.Interop.Metamodel.Json/JsonRegistry.cs +++ b/desktop/src/Plexus.Interop.Metamodel.Json/JsonRegistry.cs @@ -26,7 +26,7 @@ public static class JsonRegistry { public static IRegistry LoadRegistry(string fileName) { - using (var stream = File.Open(fileName, FileMode.Open)) + using (var stream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { return LoadRegistry(stream); } diff --git a/desktop/src/Plexus.Interop.Transport.Transmission.WebSockets.Server/Internal/WebSocketTransmissionServer.cs b/desktop/src/Plexus.Interop.Transport.Transmission.WebSockets.Server/Internal/WebSocketTransmissionServer.cs index 455f84bfa..be90888fa 100644 --- a/desktop/src/Plexus.Interop.Transport.Transmission.WebSockets.Server/Internal/WebSocketTransmissionServer.cs +++ b/desktop/src/Plexus.Interop.Transport.Transmission.WebSockets.Server/Internal/WebSocketTransmissionServer.cs @@ -151,10 +151,11 @@ private void Configure(IApplicationBuilder app) { using (var webSocket = await context.WebSockets.AcceptWebSocketAsync().ConfigureAwait(false)) { - using (var stream = File.OpenText(physicalPath)) + using (var stream = File.Open(physicalPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + using (var streamReader = new StreamReader(stream)) { var bytes = Encoding.UTF8.GetBytes( - await stream.ReadToEndAsync().ConfigureAwait(false)); + await streamReader.ReadToEndAsync().ConfigureAwait(false)); await webSocket .SendAsync( new ArraySegment(bytes),