-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'UshakovMV_GUI_Adjustment'
- Loading branch information
Showing
11 changed files
with
290 additions
and
119 deletions.
There are no files selected for viewing
12 changes: 0 additions & 12 deletions
12
GUI/MossbauerLab.TinyTcpServer.MnGUI/MossbauerLab.TinyTcpServer.MnGUI/Data/ServerType.cs
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
...sbauerLab.TinyTcpServer.MnGUI/MossbauerLab.TinyTcpServer.MnGUI/Factories/ServerFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...ab.TinyTcpServer.MnGUI/MossbauerLab.TinyTcpServer.MnGUI/Helpers/TcpServerConfigBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
...inyTcpServer.MnGUI/MossbauerLab.TinyTcpServer.MnGUI/View/Forms/Factories/ServerFactory.cs
This file was deleted.
Oops, something went wrong.
87 changes: 66 additions & 21 deletions
87
...rLab.TinyTcpServer.MnGUI/MossbauerLab.TinyTcpServer.MnGUI/View/Forms/MainForm.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.