Skip to content

Commit 3ec68ea

Browse files
committed
Add exceptional time for suspending request to AMI Proxy Server
1 parent af622b7 commit 3ec68ea

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

AMI_Monitor/AMIMonitor.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,21 @@ private void readConf() {
4949
String value = ConfigurationManager.AppSettings[key];
5050
if (key != "token")
5151
{
52+
// <!--key= servicename, value=<<ip|host>:<port>,<durationTime>,<<excep-start>-<excep-end>>-->
53+
// <key="Service1" value="127.0.0.1:9090,10,01:30:00-20:00:00" />
5254
String[] values = value.Split(',');
5355
String[] host_port = values[(int)AMIServer.config_en.address].Split(':');
54-
String str = "key=" + key + ", value=" + value + " ==> host=" + host_port[(int)AMIServer.config_en.hostname] + ", port=" + host_port[(int)AMIServer.config_en.port] + ", duration time=" + values[(int)AMIServer.config_en.durationTime];
56+
String[] except_time = values[(int)AMIServer.config_en.exception].Split('-');
57+
TimeSpan start = TimeSpan.Parse(except_time[(int)AMIServer.config_en.excpetional_start_time]);
58+
TimeSpan end = TimeSpan.Parse(except_time[(int)AMIServer.config_en.excpetional_end_time]);
59+
String str = "key=" + key + ", value=" + value + " ==> host=" + host_port[(int)AMIServer.config_en.hostname] + ", port=" + host_port[(int)AMIServer.config_en.port] + ", duration time=" + values[(int)AMIServer.config_en.durationTime] + ", exception: ["+except_time[(int)AMIServer.config_en.excpetional_start_time]+"-"+except_time[(int)AMIServer.config_en.excpetional_end_time]+"]";
5560
Console.WriteLine(str);
56-
this.list_AMIServer.Add(new AMIServer(key, host_port[(int)AMIServer.config_en.hostname], int.Parse(host_port[(int)AMIServer.config_en.port]), int.Parse(values[(int)AMIServer.config_en.durationTime])));
61+
this.list_AMIServer.Add(new AMIServer(key,
62+
host_port[(int)AMIServer.config_en.hostname],
63+
int.Parse(host_port[(int)AMIServer.config_en.port]),
64+
int.Parse(values[(int)AMIServer.config_en.durationTime]),
65+
start,
66+
end));
5767
}
5868
else {
5969
Console.WriteLine("Key={0} value={1}", key, value);
@@ -74,8 +84,11 @@ private void checkAMIServer(object obj)
7484
Thread.Sleep(500);
7585
DateTime dateTime = DateTime.Now;
7686
double diff = dateTime.Subtract(amiServer.TimeStmap).TotalSeconds;
77-
78-
if (diff >= amiServer.DurationTime ) {
87+
TimeSpan timeSpand = dateTime.TimeOfDay;
88+
if (diff >= amiServer.DurationTime
89+
&& !(amiServer.Exceptional_start_time < timeSpand && timeSpand < amiServer.Exceptional_end_time)
90+
) {
91+
Console.WriteLine("{0} < {1} < {2}", amiServer.Exceptional_start_time, timeSpand, amiServer.Exceptional_end_time);
7992
amiServer.TimeStmap = DateTime.Now;
8093
Console.WriteLine("Servcie {0} sending request", amiServer.Name);
8194
try

AMI_Monitor/AMIServer.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ class AMIServer
1010
{
1111
static int Second = 1000;
1212
public enum state_enum { stop=0, running=1, pause=2 };
13-
public enum config_en { address = 0, durationTime = 1, hostname = 0, port = 1 }
13+
public enum config_en { address = 0, durationTime = 1, hostname = 0, port = 1, exception = 2, excpetional_start_time=0, excpetional_end_time=1}
1414
private state_enum state = state_enum.pause;
1515
private String host = "127.0.0.1";
1616
private String name = "Undefined";
17+
private TimeSpan exceptional_start_time;
18+
private TimeSpan exceptional_end_time;
19+
1720
private int port = 59000;
1821
private int durationTime = 30; //second
1922
private long time_stamp = 0;
@@ -26,10 +29,13 @@ public enum config_en { address = 0, durationTime = 1, hostname = 0, port = 1 }
2629
internal state_enum State { get => state; set => state = value; }
2730
public int DurationTime { get => durationTime; set => durationTime = value; }
2831
public DateTime TimeStmap { get => timeStmap; set => timeStmap = value; }
32+
public TimeSpan Exceptional_start_time { get => exceptional_start_time; set => exceptional_start_time = value; }
33+
public TimeSpan Exceptional_end_time { get => exceptional_end_time; set => exceptional_end_time = value; }
2934

3035
public AMIServer() { this.TimeStmap = DateTime.Now; }
3136
public AMIServer(String name, String host, int port) { this.Name = name; this.Host = host; this.Port = port; this.TimeStmap = DateTime.Now; }
3237
public AMIServer(String name, String host, int port, int durationTime) { this.Name = name; this.Host = host; this.Port = port; this.DurationTime = durationTime; this.TimeStmap = DateTime.Now; }
38+
public AMIServer(String name, String host, int port, int durationTime, TimeSpan exceptional_start_time, TimeSpan exceptional_end_time) { this.Name = name; this.Host = host; this.Port = port; this.DurationTime = durationTime; this.TimeStmap = DateTime.Now; this.exceptional_start_time = exceptional_start_time; this.exceptional_end_time = exceptional_end_time; }
3339

3440
}
3541
}

AMI_Monitor/app.config

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<!-- for Test : 5MIkfmCenOQ57YoCCq5F2pg0DycCfLjP5B3IdrUbxKs-->
88
<add key="token" value="5MIkfmCenOQ57YoCCq5F2pg0DycCfLjP5B3IdrUbxKs"></add>
99

10-
<!--key= servicename, value=<<ip|host>:<port>,<durationTime>>-->
11-
<add key="service1" value="192.168.243.137:59000,30" />
12-
<add key="service2" value="192.168.243.137:59001,60" />
13-
<add key="service3" value="192.168.243.137:59002,120" />
10+
<!--key= servicename, value=<<ip|host>:<port>,<durationTime>,<<excep-start>-<excep-end>>>-->
11+
<add key="service1" value="192.168.243.137:59000,3,17:30:00-17:40:00" />
12+
<add key="service2" value="192.168.243.137:59001,60,01:00:00-02:00:00" />
13+
<add key="service3" value="192.168.243.137:59002,120,01:00:00-02:00:00" />
1414
</appSettings>
1515
</configuration>

0 commit comments

Comments
 (0)