Skip to content

Commit 71595ff

Browse files
committed
Merge branch 'UshakovMV_GUI_Adjustment'
2 parents d763bda + 4f8c7e6 commit 71595ff

File tree

11 files changed

+290
-119
lines changed

11 files changed

+290
-119
lines changed

GUI/MossbauerLab.TinyTcpServer.MnGUI/MossbauerLab.TinyTcpServer.MnGUI/Data/ServerType.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using log4net;
3+
using MossbauerLab.TinyTcpServer.Core.Server;
4+
5+
namespace MossbauerLab.TinyTcpServer.MnGUI.Factories
6+
{
7+
public static class ServerFactory
8+
{
9+
public static ITcpServer Create(String ipAddress, UInt16 port, String serverScriptFile, ILog logger = null, TcpServerConfig config = null)
10+
{
11+
return new FlexibleTcpServer(serverScriptFile, ipAddress, port, logger, false, config);
12+
}
13+
}
14+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using MossbauerLab.TinyTcpServer.Core.Server;
6+
7+
namespace MossbauerLab.TinyTcpServer.MnGUI.Helpers
8+
{
9+
public static class TcpServerConfigBuilder
10+
{
11+
public static TcpServerConfig Build(String serverConfig)
12+
{
13+
if(String.IsNullOrEmpty(serverConfig))
14+
throw new ArgumentNullException("serverConfig");
15+
if(!File.Exists(serverConfig))
16+
throw new ApplicationException("Config file does not exists");
17+
IList<String> content = File.ReadAllLines(serverConfig).Select(line=>line.Trim().ToLower())
18+
.Where(line => !String.IsNullOrEmpty(line))
19+
.Where(line => !line.StartsWith(CommentarySymbol))
20+
.ToList();
21+
TcpServerConfig config = new TcpServerConfig();
22+
Int32 value = GetConfigurationValue(content, ParallelTaskKey);
23+
if (value != -1) // otherwise we using default value
24+
config.ParallelTask = value;
25+
value = GetConfigurationValue(content, ClientBufferSizeKey);
26+
if (value != -1) // otherwise we using default value
27+
config.ClientBufferSize = value;
28+
value = GetConfigurationValue(content, ChunkSizeKey);
29+
if (value != -1) // otherwise we using default value
30+
config.ChunkSize = value;
31+
value = GetConfigurationValue(content, ClientConnectAttemptsKey);
32+
if (value != -1) // otherwise we using default value
33+
config.ClientConnectAttempts = value;
34+
value = GetConfigurationValue(content, ClientConnectTimeoutKey);
35+
if (value != -1) // otherwise we using default value
36+
config.ClientConnectTimeout = value;
37+
value = GetConfigurationValue(content, ClientInactivityTimeKey);
38+
if (value != -1) // otherwise we using default value
39+
config.ClientInactivityTime = value;
40+
value = GetConfigurationValue(content, ReadTimeoutKey);
41+
if (value != -1) // otherwise we using default value
42+
config.ReadTimeout = value;
43+
value = GetConfigurationValue(content, WriteTimeoutKey);
44+
if (value != -1) // otherwise we using default value
45+
config.WriteTimeout = value;
46+
value = GetConfigurationValue(content, ClientReadAttemptsKey);
47+
if (value != -1) // otherwise we using default value
48+
config.ClientReadAttempts= value;
49+
value = GetConfigurationValue(content, ServerCloseTimeoutKey);
50+
if (value != -1) // otherwise we using default value
51+
config.ServerCloseTimeout = value;
52+
return config;
53+
}
54+
55+
private static Int32 GetConfigurationValue(IList<String> fileContent, String key)
56+
{
57+
try
58+
{
59+
String configLine = fileContent.FirstOrDefault(line => line.ToLower().StartsWith(key.ToLower()));
60+
if (configLine == null)
61+
return -1;
62+
Int32 index = configLine.IndexOf(KeyValueSeparator, StringComparison.InvariantCulture);
63+
if (index <= 0)
64+
return -1;
65+
String value = configLine.Substring(index + 1);
66+
return Int32.Parse(value);
67+
}
68+
catch (Exception)
69+
{
70+
return -1;
71+
}
72+
}
73+
74+
private const String KeyValueSeparator = "=";
75+
private const String CommentarySymbol = "#";
76+
77+
private const String ParallelTaskKey = "ParallelTask";
78+
private const String ClientBufferSizeKey = "ClientBufferSize";
79+
private const String ChunkSizeKey = "ChunkSize";
80+
private const String ClientConnectAttemptsKey = "ClientConnectAttempts";
81+
private const String ClientInactivityTimeKey = "ClientInactivityTime";
82+
private const String ClientConnectTimeoutKey = "ClientConnectTimeout";
83+
private const String ClientReadAttemptsKey = "ClientReadAttempts";
84+
private const String ReadTimeoutKey = "ReadTimeout";
85+
private const String ServerCloseTimeoutKey = "ServerCloseTimeout";
86+
private const String WriteTimeoutKey = "WriteTimeout";
87+
}
88+
}

GUI/MossbauerLab.TinyTcpServer.MnGUI/MossbauerLab.TinyTcpServer.MnGUI/MossbauerLab.TinyTcpServer.MnGUI.csproj

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@
3232
<WarningLevel>4</WarningLevel>
3333
</PropertyGroup>
3434
<ItemGroup>
35-
<Reference Include="log4net">
36-
<HintPath>..\lib\log4net.dll</HintPath>
35+
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
36+
<HintPath>..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
37+
<Private>True</Private>
3738
</Reference>
38-
<Reference Include="MossbauerLab.SimpleExtensions">
39-
<HintPath>..\lib\MossbauerLab.SimpleExtensions.dll</HintPath>
40-
</Reference>
41-
<Reference Include="MossbauerLab.TinyTcpServer.Core">
42-
<HintPath>..\lib\MossbauerLab.TinyTcpServer.Core.dll</HintPath>
39+
<Reference Include="MossbauerLab.TinyTcpServer.Core, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
40+
<HintPath>..\packages\MossbauerLab.TinyTcpServer.Core.1.2.0\lib\net40\MossbauerLab.TinyTcpServer.Core.dll</HintPath>
41+
<Private>True</Private>
4342
</Reference>
4443
<Reference Include="System" />
4544
<Reference Include="System.Core" />
@@ -53,9 +52,9 @@
5352
<Reference Include="System.Xml" />
5453
</ItemGroup>
5554
<ItemGroup>
56-
<Compile Include="Data\ServerType.cs" />
55+
<Compile Include="Helpers\TcpServerConfigBuilder.cs" />
5756
<Compile Include="LogUtils\RichTextBoxAppender.cs" />
58-
<Compile Include="View\Forms\Factories\ServerFactory.cs" />
57+
<Compile Include="Factories\ServerFactory.cs" />
5958
<Compile Include="View\Helpers\ServerConfigInfoHelper.cs" />
6059
<Compile Include="View\Forms\MainForm.cs">
6160
<SubType>Form</SubType>
@@ -65,6 +64,7 @@
6564
</Compile>
6665
<Compile Include="Program.cs" />
6766
<Compile Include="Properties\AssemblyInfo.cs" />
67+
<Compile Include="View\Utils\OpenDialogRunner.cs" />
6868
<EmbeddedResource Include="View\Forms\MainForm.resx">
6969
<DependentUpon>MainForm.cs</DependentUpon>
7070
</EmbeddedResource>
@@ -78,6 +78,7 @@
7878
<DependentUpon>Resources.resx</DependentUpon>
7979
</Compile>
8080
<None Include="App.config" />
81+
<None Include="packages.config" />
8182
<None Include="Properties\Settings.settings">
8283
<Generator>SettingsSingleFileGenerator</Generator>
8384
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

GUI/MossbauerLab.TinyTcpServer.MnGUI/MossbauerLab.TinyTcpServer.MnGUI/View/Forms/Factories/ServerFactory.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

GUI/MossbauerLab.TinyTcpServer.MnGUI/MossbauerLab.TinyTcpServer.MnGUI/View/Forms/MainForm.Designer.cs

Lines changed: 66 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)