-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
212 lines (171 loc) · 7.46 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using Newtonsoft.Json;
using System.Text.RegularExpressions;
using System.Globalization;
using AutoMapper;
namespace ConsoleApp1
{
class Program
{
static async Task Main(string[] args)
{
await Listen();
Console.ReadKey();
}
private static async Task Listen()
{
var listener = new HttpListener();
listener.Prefixes.Add(@"http://10.1.0.69/");
listener.Start();
Console.WriteLine("Ожидание подключений...");
while (true)
{
HttpListenerContext context = await listener.GetContextAsync();
HttpListenerRequest request = context.Request;
HttpListenerResponse responce = context.Response;
Stream body = request.InputStream;
using (var sr = new StreamReader(body, Encoding.UTF8))
try
{
responce.StatusCode = Convert.ToInt32(HttpStatusCode.OK);
string str = await sr.ReadToEndAsync();
myObject obj = JsonConvert.DeserializeObject<myObject>(str);
BasicHttpBinding_IEmergencyCard UPDCase = new BasicHttpBinding_IEmergencyCard();
UPDCase.UpdateCase(Map(obj));
}
catch (Exception ex) { Console.WriteLine(ex.Message); }
finally
{
responce.Close();
body.Close();
sr.Close();
Console.WriteLine("Сигнал обработан");
}
}
}
public static EmergencyCaseInfo Map(myObject pars) {
var res = new EmergencyCaseInfo();
res.externalCardId = pars.card.id; //Id в системе ISS
res.caller.firstName = pars.ier.fullName.lastName; // фамилия
res.caller.lastName = pars.ier.fullName.firstName; // имя
res.caller.midleName = pars.ier.fullName.middleName;//отчество
res.caller.phoneNumber = pars.ier.cgPn;// номер
res.info = pars.card.commonData.typeStr + " " + pars.card.commonData.isDanger + " " + pars.card.commonData.description+" "+ pars.card.commonData.timeIsoStr; //информация о происшествии
res.location.entrance = pars.card.location.address.porch;//подьезд
res.location.highway.km = pars.card.location.address.distanceInKm; //километр трассы
res.location.highway.name = pars.card.location.address.road;//название трассы
res.location.house = pars.card.location.address.houseNumber; // номер дома
string buf = pars.card.location.coordinates;// координаты
string buff = buf.Replace('.', ',');
string[] split = buff.Split(' ');
double x = double.Parse(split[0]);
long xx = Convert.ToInt64(x * 3600000);
res.location.latitude = xx;//широта
x = double.Parse(split[1]);
xx = Convert.ToInt64(x * 3600000);
res.location.longitude = xx;//долгота
res.location.locality = pars.card.location.address.city;//город
res.location.municipality = pars.card.location.address.district;//район
res.location.street = pars.card.location.address.streetShort + " " + pars.card.location.address.street;//улица
return res;
}
}
public class myObject {
private Card Card;
private Ier Ier;
private Video Video;
public Card card { get => Card; set => Card = value; }
public Ier ier { get => Ier; set => Ier = value; }
public Video video { get => Video; set => Video = value; }
public myObject() {
this.Card = new Card();
this.Ier = new Ier();
this.Video = new Video();
}
}
public class Card {
private CommonData CommonData;
private string Id;
private Location Location;
public CommonData commonData { get => CommonData; set => CommonData = value; }
public string id { get => Id; set => Id = value; }
public Location location { get => Location; set => Location = value; }
public Card() {
this.CommonData = new CommonData();
this.Location = new Location();
}
}
public class CommonData {
private string Description;
private string IsDanger;
private string TimeIsoStr;
private string TypeStr;
public string description { get => Description; set => Description = value; }
public string isDanger { get => IsDanger; set => IsDanger = value; }
public string timeIsoStr { get => TimeIsoStr; set => TimeIsoStr = value; }
public string typeStr { get => TypeStr; set => TypeStr = value; }
public CommonData() { }
}
public class Location {
private Address Address;
private string Coordinates;
public Address address { get => Address; set => Address = value; }
public string coordinates { get => Coordinates; set => Coordinates = value; }
public Location() {
this.Address = new Address();
}
}
public class Address {
public string City;
public int DistanceInKm;
public string District;
public string HouseNumber;
public string Porch;
public string Road;
public string Street;
public string StreetShort;
public string city { get => City; set => City = value; }
public int distanceInKm { get => DistanceInKm; set => DistanceInKm = value; }
public string district { get => District; set => District = value; }
public string houseNumber { get => HouseNumber; set => HouseNumber = value; }
public string porch { get => Porch; set => Porch = value; }
public string road { get => Road; set => Road = value; }
public string street { get => Street; set => Street = value; }
public string streetShort { get => StreetShort; set => StreetShort = value; }
public Address() { }
}
public class Ier {
private string CgPn;
private FullName FullName;
public string cgPn { get => CgPn; set => CgPn = value; }
public FullName fullName { get => FullName; set => FullName = value; }
public Ier() {
this.FullName = new FullName();
}
}
public class FullName {
private string FirstName;
private string LastName;
private string MiddleName;
public FullName() { }
public string firstName { get => FirstName; set => FirstName = value; }
public string lastName { get => LastName; set => LastName = value; }
public string middleName { get => MiddleName; set => MiddleName = value; }
}
public class Video {
public string RTSPArchive;
public string RTSPLive;
public Video(){}
public string RTSPArchive1 { get => RTSPArchive; set => RTSPArchive = value; }
public string RTSPLive1 { get => RTSPLive; set => RTSPLive = value; }
}
}