-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParamsHelper.cs
53 lines (45 loc) · 1.52 KB
/
ParamsHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Encodings
{
public static class ParamsHelper
{
/// <summary>
/// Get application run parameters from command line arguments
/// </summary>
/// <param name="args">application command line arguments</param>
/// <returns></returns>
public static RunParam GetParams(string[] args)
{
RunParam newParams = new RunParam();
//if input and output are defined
if (args.Length >= 2)
{
newParams.InputFileName = args[0];
newParams.OutputFileName = args[1];
for (int i = 2; i < args.Length-1; i++)
{
if (args[i].ToLower().StartsWith("-t"))
{
int t = 0;
if (Int32.TryParse(args[i + 1], out t))
{
newParams.ThreadsNumber = t;
}
else
throw new ApplicationException("Bad threads number parameter");
}
}
}
else
{
throw new ApplicationException("not enough parameters are defined");
}
if (newParams.ThreadsNumber == 0)
newParams.ThreadsNumber = 3;
return newParams;
}
}
}