forked from tmoonlight/NSmartProxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNSmartProxyClient.cs
More file actions
105 lines (93 loc) · 3.15 KB
/
NSmartProxyClient.cs
File metadata and controls
105 lines (93 loc) · 3.15 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using log4net;
using Microsoft.Extensions.Configuration;
using NSmartProxy.Client;
using NSmartProxy.Data;
using NSmartProxy.Interfaces;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Exception = System.Exception;
namespace NSmartProxy
{
class NSmartProxyClient
{
public class Log4netLogger : INSmartLogger
{
public void Debug(string message)
{
Console.WriteLine(message);
Logger.Debug(message);
}
public void Error(string message, Exception ex)
{
Console.WriteLine(message);
Logger.Error(message,ex);
}
}
public static ILog Logger;
public static IConfigurationRoot Configuration { get; set; }
static void Main(string[] args)
{
//log
NSmartProxyClient.Logger = LogManager.GetLogger(Assembly.GetEntryAssembly(), "NSmartServer");
//Thread.Sleep(3000);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("*** NSmart ClientRouter v0.1 ***");
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
Configuration = builder.Build();
//start clientrouter.
try
{
StartClient().Wait();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("Client terminated,press any key to continue.");
Console.Read();
}
private static async Task StartClient()
{
Router clientRouter = new Router(new Log4netLogger());
//read config from config file.
SetConfig(clientRouter);// clientRouter.SetConifiguration();
Task tsk = clientRouter.ConnectToProvider();
try
{
await tsk;
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
private static void SetConfig(Router clientRouter)
{
Config config = new Config();
config.ProviderAddress = Configuration.GetSection("ProviderAddress").Value;
config.ProviderPort = int.Parse(Configuration.GetSection("ProviderPort").Value);
config.ProviderConfigPort = int.Parse(Configuration.GetSection("ProviderConfigPort").Value);
var configClients = Configuration.GetSection("Clients").GetChildren();
foreach (var cli in configClients)
{
config.Clients.Add(new ClientApp
{
IP = cli["IP"],
TargetServicePort = int.Parse(cli["TargetServicePort"])
});
}
// Configuration.GetSection("1").
clientRouter.SetConifiguration(config);
}
}
}