Skip to content

Commit

Permalink
Merge branch 'UshakovMV_GUI_Adjustment'
Browse files Browse the repository at this point in the history
  • Loading branch information
EvilLord666 committed Nov 5, 2017
2 parents d763bda + 4f8c7e6 commit 71595ff
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 119 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using log4net;
using MossbauerLab.TinyTcpServer.Core.Server;

namespace MossbauerLab.TinyTcpServer.MnGUI.Factories
{
public static class ServerFactory
{
public static ITcpServer Create(String ipAddress, UInt16 port, String serverScriptFile, ILog logger = null, TcpServerConfig config = null)
{
return new FlexibleTcpServer(serverScriptFile, ipAddress, port, logger, false, config);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MossbauerLab.TinyTcpServer.Core.Server;

namespace MossbauerLab.TinyTcpServer.MnGUI.Helpers
{
public static class TcpServerConfigBuilder
{
public static TcpServerConfig Build(String serverConfig)
{
if(String.IsNullOrEmpty(serverConfig))
throw new ArgumentNullException("serverConfig");
if(!File.Exists(serverConfig))
throw new ApplicationException("Config file does not exists");
IList<String> content = File.ReadAllLines(serverConfig).Select(line=>line.Trim().ToLower())
.Where(line => !String.IsNullOrEmpty(line))
.Where(line => !line.StartsWith(CommentarySymbol))
.ToList();
TcpServerConfig config = new TcpServerConfig();
Int32 value = GetConfigurationValue(content, ParallelTaskKey);
if (value != -1) // otherwise we using default value
config.ParallelTask = value;
value = GetConfigurationValue(content, ClientBufferSizeKey);
if (value != -1) // otherwise we using default value
config.ClientBufferSize = value;
value = GetConfigurationValue(content, ChunkSizeKey);
if (value != -1) // otherwise we using default value
config.ChunkSize = value;
value = GetConfigurationValue(content, ClientConnectAttemptsKey);
if (value != -1) // otherwise we using default value
config.ClientConnectAttempts = value;
value = GetConfigurationValue(content, ClientConnectTimeoutKey);
if (value != -1) // otherwise we using default value
config.ClientConnectTimeout = value;
value = GetConfigurationValue(content, ClientInactivityTimeKey);
if (value != -1) // otherwise we using default value
config.ClientInactivityTime = value;
value = GetConfigurationValue(content, ReadTimeoutKey);
if (value != -1) // otherwise we using default value
config.ReadTimeout = value;
value = GetConfigurationValue(content, WriteTimeoutKey);
if (value != -1) // otherwise we using default value
config.WriteTimeout = value;
value = GetConfigurationValue(content, ClientReadAttemptsKey);
if (value != -1) // otherwise we using default value
config.ClientReadAttempts= value;
value = GetConfigurationValue(content, ServerCloseTimeoutKey);
if (value != -1) // otherwise we using default value
config.ServerCloseTimeout = value;
return config;
}

private static Int32 GetConfigurationValue(IList<String> fileContent, String key)
{
try
{
String configLine = fileContent.FirstOrDefault(line => line.ToLower().StartsWith(key.ToLower()));
if (configLine == null)
return -1;
Int32 index = configLine.IndexOf(KeyValueSeparator, StringComparison.InvariantCulture);
if (index <= 0)
return -1;
String value = configLine.Substring(index + 1);
return Int32.Parse(value);
}
catch (Exception)
{
return -1;
}
}

private const String KeyValueSeparator = "=";
private const String CommentarySymbol = "#";

private const String ParallelTaskKey = "ParallelTask";
private const String ClientBufferSizeKey = "ClientBufferSize";
private const String ChunkSizeKey = "ChunkSize";
private const String ClientConnectAttemptsKey = "ClientConnectAttempts";
private const String ClientInactivityTimeKey = "ClientInactivityTime";
private const String ClientConnectTimeoutKey = "ClientConnectTimeout";
private const String ClientReadAttemptsKey = "ClientReadAttempts";
private const String ReadTimeoutKey = "ReadTimeout";
private const String ServerCloseTimeoutKey = "ServerCloseTimeout";
private const String WriteTimeoutKey = "WriteTimeout";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\lib\log4net.dll</HintPath>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MossbauerLab.SimpleExtensions">
<HintPath>..\lib\MossbauerLab.SimpleExtensions.dll</HintPath>
</Reference>
<Reference Include="MossbauerLab.TinyTcpServer.Core">
<HintPath>..\lib\MossbauerLab.TinyTcpServer.Core.dll</HintPath>
<Reference Include="MossbauerLab.TinyTcpServer.Core, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MossbauerLab.TinyTcpServer.Core.1.2.0\lib\net40\MossbauerLab.TinyTcpServer.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -53,9 +52,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Data\ServerType.cs" />
<Compile Include="Helpers\TcpServerConfigBuilder.cs" />
<Compile Include="LogUtils\RichTextBoxAppender.cs" />
<Compile Include="View\Forms\Factories\ServerFactory.cs" />
<Compile Include="Factories\ServerFactory.cs" />
<Compile Include="View\Helpers\ServerConfigInfoHelper.cs" />
<Compile Include="View\Forms\MainForm.cs">
<SubType>Form</SubType>
Expand All @@ -65,6 +64,7 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="View\Utils\OpenDialogRunner.cs" />
<EmbeddedResource Include="View\Forms\MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
Expand All @@ -78,6 +78,7 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="App.config" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 71595ff

Please sign in to comment.