implement auto port support for socket bridge communication

This commit is contained in:
Gregor Biswanger
2017-10-06 05:04:56 +02:00
parent d3fc1c8657
commit 47996a76d9
14 changed files with 108 additions and 1463 deletions

View File

@@ -19,7 +19,7 @@ namespace ElectronNET.API
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
_socket = IO.Socket("http://localhost:3000");
_socket = IO.Socket("http://localhost:" + BridgeSettings.SocketPort);
_socket.On(Socket.EVENT_CONNECT, () =>
{
Console.WriteLine("Verbunden!");

View File

@@ -0,0 +1,7 @@
namespace ElectronNET.API
{
public static class BridgeSettings
{
public static string SocketPort { get; set; }
}
}

View File

@@ -11,5 +11,11 @@
<PackageReference Include="SocketIoClientDotNet" Version="1.0.3" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Hosting.Abstractions">
<HintPath>..\..\..\..\..\..\..\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.hosting.abstractions\2.0.0\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.Abstractions.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Hosting;
using System;
namespace ElectronNET.API
{
public static class WebHostBuilderExtensions
{
public static IWebHostBuilder UseElectron(this IWebHostBuilder builder, string[] args)
{
foreach (string argument in args)
{
if (argument.ToUpper().Contains("ELECTRONPORT"))
{
BridgeSettings.SocketPort = argument.ToUpper().Replace("/ELECTRONPORT=", "");
Console.WriteLine("Use Electron Port: " + BridgeSettings.SocketPort);
}
}
if(IsElectronActive())
{
builder.UseContentRoot(AppDomain.CurrentDomain.BaseDirectory);
}
return builder;
}
private static bool IsElectronActive()
{
return !string.IsNullOrEmpty(BridgeSettings.SocketPort);
}
}
}