Skip to content

Commit

Permalink
Change paths for services and configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaulomatic committed Jul 19, 2018
1 parent 6da5145 commit 525a315
Show file tree
Hide file tree
Showing 47 changed files with 394 additions and 259 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

*.DS_Store
.idea
Installation

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
https://www.flaticon.com/free-icon/vpn_188120
## SoftEther VPN Client



https://www.flaticon.com/free-icon/vpn_188120
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
<AssemblyCopyRight>Copyright © 2017 - CURRENT_YEAR Tobias Punke.</AssemblyCopyRight>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.1" />
</ItemGroup>
<ItemGroup>
<!--<PackageReference Include="NETStandard.Library" Version="2.0.3" />-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ namespace Logixware.SoftEther.Client
{
public static class LoggerExtensions
{
public static void Debug(this ILogger target, String message)
{
target.Log(LogLevel.Debug, 1, message, null, (s, e) => DateTime.Now + " " + s.ToString());
}

public static void Inform(this ILogger target, String message)
{
target.Log(LogLevel.Information, 1, message, null, (s, e) => DateTime.Now + " " + s.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Logixware.SoftEther.Client.Shell.Platform
{

public class BashShell : IShell
{
public ExecutionResult ExecuteCommand(String command)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;

using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -102,12 +103,12 @@ public void StartClient()
if (__StartExecution.Succeeded)
{
var __Message = $"Successfully started the VPN client: {__StartExecution.Result}";
this._Logger.Inform(__Message);
this._Logger?.Inform(__Message);
}
else
{
var __Message = $"Error starting the VPN client: {__StartExecution.Result}";
this._Logger.Error(__Message);
this._Logger?.Error(__Message);
}
}

Expand All @@ -119,12 +120,12 @@ public void StopClient()
if (__StopExecution.Succeeded)
{
var __Message = $"Successfully stopped the VPN client: {__StopExecution.Result}";
this._Logger.Inform(__Message);
this._Logger?.Inform(__Message);
}
else
{
var __Message = $"Error stopping the VPN client: {__StopExecution.Result}";
this._Logger.Error(__Message);
this._Logger?.Error(__Message);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace Logixware.SoftEther.Client.VpnService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

[assembly: System.Reflection.AssemblyCopyright("Copyright © 2017 - 2018 Tobias Punke.")]
[assembly: System.Reflection.AssemblyVersion("1.0.0.0")]
[assembly: System.Reflection.AssemblyFileVersion("1.0.0.5")]
[assembly: System.Reflection.AssemblyInformationalVersion("1.0.0.5")]
[assembly: System.Reflection.AssemblyFileVersion("1.0.0.11")]
[assembly: System.Reflection.AssemblyInformationalVersion("1.0.0.11")]


Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0.5
1.0.0.11
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;

namespace Logixware.SoftEther.Client.Daemon
using Logixware.SoftEther.Client.Daemon.Entities;

namespace Logixware.SoftEther.Client.Daemon.Configuration
{
public class ClientConfigurationSection
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Logixware.SoftEther.Client.Daemon.Platform
namespace Logixware.SoftEther.Client.Daemon.Configuration
{
public class MacPlatformConfigurationSection
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace Logixware.SoftEther.Client.Daemon
namespace Logixware.SoftEther.Client.Daemon.Entities
{
// ReSharper disable once InconsistentNaming
public class IPv4Information
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Logixware.SoftEther.Client.Daemon
namespace Logixware.SoftEther.Client.Daemon.Entities
{
// ReSharper disable once InconsistentNaming
public class IPv4Route
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace Logixware.SoftEther.Client.Daemon
namespace Logixware.SoftEther.Client.Daemon.Entities
{
// ReSharper disable once InconsistentNaming
public class IPv6Information
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Logixware.SoftEther.Client.Daemon
namespace Logixware.SoftEther.Client.Daemon.Entities
{
// ReSharper disable once InconsistentNaming
public class IPv6Route
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Logixware.SoftEther.Client.Daemon
namespace Logixware.SoftEther.Client.Daemon.Entities
{
public class VirtualNetwork
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
using System;
using System.IO;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

using Logixware.SoftEther.Client.VpnService;
using Logixware.SoftEther.Client.Daemon.Platform;

using Logixware.SoftEther.Client.Shell;
using Logixware.SoftEther.Client.Shell.Platform;

namespace Logixware.SoftEther.Client.Daemon
namespace Logixware.SoftEther.Client.Daemon.Hosting
{
public class Program
{
Expand All @@ -30,6 +22,7 @@ public static async Task Main(String[] args)
configHost.SetBasePath(Directory.GetCurrentDirectory());
configHost.AddJsonFile("hostsettings.json", optional: true);
configHost.AddEnvironmentVariables(prefix: "PREFIX_");
configHost.ConfigureHostConfiguration();
configHost.AddCommandLine(args);
})

Expand All @@ -38,36 +31,15 @@ public static async Task Main(String[] args)
configApp.AddJsonFile("appsettings.json", optional: true);
configApp.AddJsonFile($"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json", optional: true);
configApp.AddEnvironmentVariables(prefix: "PREFIX_");
configApp.ConfigureAppConfiguration(hostContext);
configApp.AddCommandLine(args);

__ConfigurationRoot = configApp.Build();
})

.ConfigureServices((hostContext, services) =>
{
services.AddLogging();
services.AddHostedService<ProgramService>();
services.AddSingleton(services);
services.AddSingleton<IClientConfiguration, ClientConfiguration>();
services.AddSingleton<ICommandLineInterface, CommandLineInterface>();
services.AddSingleton<IConnectionVerifier, PingConnectionVerifier>();

services.AddSingleton(__ConfigurationRoot);

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
services.AddSingleton<IShell, BashShell>();
services.AddSingleton<IPlatform, MacPlatform>();
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
services.AddSingleton<IShell, BashShell>();
services.AddSingleton<IPlatform, LinuxPlatform>();
}
else
{
throw new NotSupportedException("Platform not supported.");
}
services.ConfigureServices(__ConfigurationRoot);
})

.ConfigureLogging((hostContext, configLogging) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Runtime.InteropServices;

using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

using Logixware.SoftEther.Client.Shell;
using Logixware.SoftEther.Client.Shell.Platform;
using Logixware.SoftEther.Client.VpnService;

using Logixware.SoftEther.Client.Daemon.Services;

namespace Logixware.SoftEther.Client.Daemon.Hosting
{
internal static class ProgramCollectionExtensions
{
internal static void ConfigureHostConfiguration(this IConfigurationBuilder configHost)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
configHost.AddJsonFile("/Library/Preferences/Logixware/Logixware.SoftEther.Client.Daemon/hostsettings.json", optional: true);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
configHost.AddJsonFile("/etc/logixware/Logixware.SoftEther.Client.Daemon/hostsettings.json", optional: true);
}
else
{
throw new NotSupportedException("Platform not supported.");
}
}

internal static void ConfigureAppConfiguration(this IConfigurationBuilder configApp, HostBuilderContext hostContext)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
configApp.AddJsonFile("/Library/Preferences/Logixware/Logixware.SoftEther.Client.Daemon/appsettings.json", optional: true);
configApp.AddJsonFile($"/Library/Preferences/Logixware/Logixware.SoftEther.Client.Daemon/appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json", optional: false);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
configApp.AddJsonFile("/etc/logixware/Logixware.SoftEther.Client.Daemon/appsettings.json", optional: true);
configApp.AddJsonFile($"/etc/logixware/Logixware.SoftEther.Client.Daemon/appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json", optional: true);
}
else
{
throw new NotSupportedException("Platform not supported.");
}
}

internal static void ConfigureServices(this IServiceCollection services, IConfigurationRoot configurationRoot)
{
services.AddSingleton(services);
services.AddSingleton(configurationRoot);

services.AddHostedService<ProgramService>();

services.AddSingleton<IClientService, ClientService>();
services.AddSingleton<IInternetConnectionVerifier, InternetConnectionVerifier>();
services.AddSingleton<IClientConfiguration, ClientConfiguration>();
services.AddSingleton<ICommandLineInterface, CommandLineInterface>();
services.AddSingleton<IVpnConnectionVerifier, PingVpnConnectionVerifier>();

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
services.AddSingleton<IShell, BashShell>();
services.AddSingleton<IPlatform, MacPlatform>();
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
services.AddSingleton<IShell, BashShell>();
services.AddSingleton<IPlatform, LinuxPlatform>();
}
else
{
throw new NotSupportedException("Platform not supported.");
}
}
}
}
Loading

0 comments on commit 525a315

Please sign in to comment.