-
Notifications
You must be signed in to change notification settings - Fork 4
/
RouteClient.cs
237 lines (213 loc) · 6.75 KB
/
RouteClient.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.InteropServices;
namespace nmsRouteClient
{
public static class RouteClient
{
public static Route XMLToObject(string xml)
{
if (String.IsNullOrEmpty(xml)) return null;
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(Route));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
byte[] bb = System.Text.Encoding.UTF8.GetBytes(xml);
ms.Write(bb, 0, bb.Length);
ms.Flush();
ms.Position = 0;
System.IO.StreamReader reader = new System.IO.StreamReader(ms);
Route c = (Route)xs.Deserialize(reader);
reader.Close();
return c;
}
}
public class nmsRouteClientStopList
{
private List<string> nam = new List<string>();
private List<double> lat = new List<double>();
private List<double> lon = new List<double>();
public nmsRouteClientStopList() { }
public int Count { get { return nam.Count; } }
public void AddStop(string nam, double lat, double lon)
{
if (nam.Length > 200) throw new Exception("Stop name must be less 200 symbols length");
this.nam.Add(nam);
this.lat.Add(lat);
this.lon.Add(lon);
}
public string[] GetStopNames() { return nam.ToArray(); }
public double[] GetLatt() { return lat.ToArray(); }
public double[] GetLonn() { return lon.ToArray(); }
}
public class Stop
{
/// <summary>
/// Èìÿ
/// </summary>
[XmlText]
public string name = "";
/// <summary>
/// Øèðîòà
/// </summary>
[XmlAttribute()]
public double lat = 0;
/// <summary>
/// Äîëãîòà
/// </summary>
[XmlAttribute()]
public double lon = 0;
public Stop() { }
public Stop(string name, double lat, double lon)
{
this.name = name;
this.lat = lat;
this.lon = lon;
}
}
public class XYPoint
{
/// <summary>
/// Äîëãîòà
/// </summary>
[XmlAttribute()]
public double x = 0;
/// <summary>
/// Øèðîòà
/// </summary>
[XmlAttribute()]
public double y = 0;
public XYPoint(double x, double y)
{
this.x = x;
this.y = y;
}
public XYPoint() { }
}
public class RoutePoint
{
public RoutePoint() { }
public RoutePoint(int no, double x, double y, double segmentLength, double segmentTime, double totalLength, DateTime totalTime)
{
this.no = no;
this.x = x;
this.y = y;
this.sLen = segmentLength;
this.sTime = segmentTime;
this.tLen = totalLength;
this.tTime = totalTime;
}
/// <summary>
/// Íóìðàöèÿ ñ 1
/// </summary>
[XmlAttribute()]
public int no = 0;
/// <summary>
/// Èíñòðóêöèÿ1
/// </summary>
public string iToDo = "";
/// <summary>
/// Èíñòðóêöèÿ2
/// </summary>
public string iToGo = "";
/// <summary>
/// Èíñòðóêöèÿ1
/// </summary>
public string iStreet = "";
/// <summary>
/// Äîëãîòà
/// </summary>
[XmlAttribute()]
public double x = 0;
/// <summary>
/// Øèðîòà
/// </summary>
[XmlAttribute()]
public double y = 0;
/// <summary>
/// Âðåìÿ òåêóùåãî ñåãìåíòà â ìèí
/// </summary>
[XmlAttribute()]
public double sTime = 0;
/// <summary>
/// Äëèíà òåêóùåãî ñåãìåíòà â êì
/// </summary>
[XmlAttribute()]
public double sLen = 0;
/// <summary>
/// Âðåìÿ ïðèáûòèÿ â íà÷àëî ñåãìåíòà
/// </summary>
[XmlAttribute()]
public DateTime tTime = DateTime.Now;
/// <summary>
/// Äëèíà îò íà÷àëà ìàðøðóòà äî ñåãìåíòà
/// </summary>
[XmlAttribute()]
public double tLen = 0;
}
public class Route
{
public Route() { }
/// <summary>
/// Äëèíà ìàðøðóòà â êì
/// </summary>
public double driveLength = 0;
/// <summary>
/// ðàññòîÿíèå ìåæäó ïðîìåæóòî÷íûìè òî÷êàìè ìàðøðóòà
/// </summary>
[XmlArrayItem("dls")]
public double[] driveLengthSegments = new double[0];
/// <summary>
/// Âðåìÿ â ïóòè â ìèí
/// </summary>
public double driveTime = 0;
/// <summary>
/// âðåìÿ ìåæäó ïðîìåæóòî÷íûìè òî÷êàìè ìàðøðóòà
/// </summary>
[XmlArrayItem("dts")]
public double[] driveTimeSegments = new double[0];
/// <summary>
/// Âðåìÿ âûåçäà
/// </summary>
public DateTime startTime = DateTime.Now;
/// <summary>
/// Âðåìÿ ïðèáûòèÿ
/// </summary>
public DateTime finishTime = DateTime.Now;
/// <summary>
/// Ìàðøðóòíûå òî÷êè
/// </summary>
[XmlArrayItem("stop")]
public Stop[] stops = new Stop[0];
/// <summary>
/// ïîëèëèíèÿ ìàðøðóòà
/// </summary>
[XmlArrayItem("p")]
public XYPoint[] polyline = new XYPoint[0];
/// <summary>
/// èíäåêñ, óêàçûâàþùèé íà ýëåìåíò ìàññèâà polyline äëÿ êàæäîãî
/// ó÷àñòêà ìåæäó ïðîìåæóòî÷íûìè òî÷êàìè ìàðøðóòà
/// </summary>
[XmlArrayItem("ps")]
public int[] polylineSegments = new int[0];
/// <summary>
/// èíñòðóêöèè
/// </summary>
[XmlArrayItem("i")]
public RoutePoint[] instructions = new RoutePoint[0];
/// <summary>
/// èíäåêñ, óêàçûâàþùèé íà ýëåìåíò ìàññèâà instructions äëÿ êàæäîãî
/// ó÷àñòêà ìåæäó ïðîìåæóòî÷íûìè òî÷êàìè ìàðøðóòà
/// </summary>
[XmlArrayItem("is")]
public int[] instructionsSegments = new int[0];
/// <summary>
/// Îøèáêà, åñëè åñòü
/// </summary>
public string LastError = String.Empty;
}
}