-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
60 lines (49 loc) · 1.87 KB
/
Program.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
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Threading;
namespace Tatweer.Traffic
{
internal class Program
{
public static List<Message> Logs = new List<Message>();
private static void Main(string[] args)
{
Console.WriteLine("Tatweer Smart Traffic System");
Console.WriteLine("By Waleed Kasem");
var countsThread = new Thread(LogCounts);
countsThread.Start();
Console.ReadLine();
}
private static void LogCounts()
{
while (true)
{
var connection = RabbitServer.GetConnection();
var channel = RabbitServer.GetChannel(connection);
ReceiveService.ReceiveMessages(channel, Enums.Exchange.Counts);
var period = int.Parse(ConfigurationManager.AppSettings["period"]);
Thread.Sleep(TimeSpan.FromMinutes(period));
// for test
//Thread.Sleep(TimeSpan.FromSeconds(5));
channel.Close();
connection.Close();
var counts = ReceiveService.GetMessages();
if (counts.Any())
{
var sensorWithAccident = RouteAnalysis.GetAccidentProbability(counts);
if (sensorWithAccident != null)
{
var messageBody = MessageService.SerializeSensor(sensorWithAccident);
EmitService.EmitMessage(Enums.Exchange.Accidents, messageBody);
Console.WriteLine(string.Concat("Accident: ", messageBody));
Console.WriteLine("\n\n");
}
}
Debug.WriteLine("Logs Count is: " + counts.Count);
}
}
}
}