diff options
author | hurter | 2011-08-31 16:25:05 +0000 |
---|---|---|
committer | hurter | 2011-08-31 16:25:05 +0000 |
commit | 42dc1d36235292786322d28340a81c6cb3fd46c0 (patch) | |
tree | 6f4ef0d4ad672c54500d9457af90fc599ac9b299 /Data/AircraftsList.cs | |
parent | 5aa429a3e7e9f610f5b2dd8f8e2a865ecfd25ea3 (diff) | |
download | amilis-42dc1d36235292786322d28340a81c6cb3fd46c0.zip amilis-42dc1d36235292786322d28340a81c6cb3fd46c0.tar.gz amilis-42dc1d36235292786322d28340a81c6cb3fd46c0.tar.bz2 amilis-42dc1d36235292786322d28340a81c6cb3fd46c0.tar.xz |
Diffstat (limited to 'Data/AircraftsList.cs')
-rw-r--r-- | Data/AircraftsList.cs | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/Data/AircraftsList.cs b/Data/AircraftsList.cs new file mode 100644 index 0000000..78ccbc2 --- /dev/null +++ b/Data/AircraftsList.cs @@ -0,0 +1,120 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using IvyBus;
+using System.Timers;
+
+namespace Data
+{
+ public class AircraftsList
+ {
+ private Dictionary<string, List<AircraftPosition>> listOfAircrafts;
+ private IvyBus.IvyControl TheIvyBus;
+ private List<IAircraftView> aircraftViews;
+ private Timer t_endWaitingForUpdate;
+
+ #region Constructeur
+ public AircraftsList(IvyBus.IvyControl TheIvyBus)
+ {
+ this.TheIvyBus = TheIvyBus;
+ listOfAircrafts = new Dictionary<string, List<AircraftPosition>>();
+ aircraftViews = new List<IAircraftView>();
+
+ t_endWaitingForUpdate = new Timer();
+ t_endWaitingForUpdate.Elapsed += new ElapsedEventHandler(HandleEndWaitingEvent);
+ t_endWaitingForUpdate.Interval = 4000;
+ t_endWaitingForUpdate.Start();
+
+ TheIvyBus.BindMsg(@"^TrackMovedEvent Flight=([0-9]+) CallSign=([a-zA-Z0-9_-]+) Ssr=([0-9]*)[ ]+Sector=(.*) Layers=(.*) X=(.+) Y=(.+) Vx=(.+) Vy=(.+) Afl=([0-9]+) Rate=(-?[0-9]+) Heading=([-\.0-9]+) GroundSpeed=([0-9]+) Tendency=(-?[0-9]) Time=([0-9]+:[0-9]+:[0-9]+)",
+ UpdateFlight, null);
+ }
+ #endregion
+
+ #region listGestion
+ private void AddAircraftPosition(AircraftPosition pos)
+ {
+ if (!listOfAircrafts.ContainsKey(pos.CallSign))
+ {
+ //New radar Track
+ listOfAircrafts[pos.CallSign] = new List<AircraftPosition>();
+ }
+ //Test if no more than CometLength Item
+ if (listOfAircrafts[pos.CallSign].Count > Config.aircraftCometLength)
+ listOfAircrafts[pos.CallSign].RemoveAt(0);
+
+ listOfAircrafts[pos.CallSign].Add(pos);
+ }
+
+ public Dictionary<string, List<AircraftPosition>> getAircraftList()
+ {
+ return listOfAircrafts;
+ }
+ #endregion
+
+ #region MVCAircraftViews
+ public void addAircraftView(IAircraftView view)
+ {
+ aircraftViews.Add(view);
+ }
+
+ public void removeAircraftView(IAircraftView view)
+ {
+ aircraftViews.Remove(view);
+ }
+
+ private void notifyAircraftViews()
+ {
+ foreach (IAircraftView view in aircraftViews)
+ {
+ view.updateView(listOfAircrafts);
+ }
+ }
+
+ #endregion
+
+ #region IvyGestion
+ private void UpdateFlight(object sender, IvyMessageEventArgs e)
+ {
+ //Create new aircraft and store it
+ AircraftPosition pos = new AircraftPosition();
+
+ pos.Flight = e[0];
+ pos.CallSign = e[1];
+ pos.Ssr = e[2];
+ pos.Sector = e[3];
+ pos.Layers = e[4];
+ pos.X = double.Parse(e[5], TheIvyBus.Culture);
+ pos.Y = double.Parse(e[6], TheIvyBus.Culture);
+ pos.Vx = double.Parse(e[7], TheIvyBus.Culture);
+ pos.Vy = double.Parse(e[8], TheIvyBus.Culture);
+ pos.AFL = int.Parse(e[9], TheIvyBus.Culture);
+ pos.Rate = int.Parse(e[10], TheIvyBus.Culture);
+ pos.Heading = int.Parse(e[11], TheIvyBus.Culture);
+ pos.GroundSpeed = double.Parse(e[12], TheIvyBus.Culture);
+ pos.Tendency = int.Parse(e[13], TheIvyBus.Culture);
+ //Parse the time
+ string sTime = e[14];
+ string[] time = sTime.Split(':');
+
+ pos.Time_Of_Plot = Convert.ToInt32(time[2]) +
+ Convert.ToInt32(time[1]) * 60 +
+ Convert.ToInt32(time[0]) * 3600;
+
+ AddAircraftPosition(pos);
+ notifyAircraftViews();
+ t_endWaitingForUpdate.Stop();
+ t_endWaitingForUpdate.Start();
+ }
+ #endregion
+
+ #region TimerGestion
+ public void HandleEndWaitingEvent(object source, ElapsedEventArgs e)
+ {
+ Console.WriteLine("Vue forcée");
+ TheIvyBus.SendMsg("GetRadarRefresh");
+ t_endWaitingForUpdate.Start();
+ }
+ #endregion
+ }
+}
|