using System; using System.Collections.Generic; using System.Linq; using System.Text; using IvyBus; using System.Timers; namespace Data { public class AircraftsList { private Dictionary> listOfAircrafts; private IvyBus.IvyControl TheIvyBus; private List aircraftViews; private Timer t_endWaitingForUpdate; #region Constructeur public AircraftsList(IvyBus.IvyControl TheIvyBus) { this.TheIvyBus = TheIvyBus; listOfAircrafts = new Dictionary>(); aircraftViews = new List(); 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(); } //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> 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 } }