Пример #1
0
        public void Update()
        {
            if (IsConntected)
            {
                string msg = messageService.PopRawMessage();

                if (msg != string.Empty)
                {
                    ADSBMessageBase parsedMessage = messageBuilder.BuildMessage(msg);
                    if (parsedMessage == null)
                    {
                        return;
                    }

                    if (!Planes.ContainsKey(parsedMessage.ICAO))
                    {
                        Planes.Add(parsedMessage.ICAO, new Plane(parsedMessage.ICAO));
                    }

                    //Console.WriteLine(parsedMessage.ToString());


                    Planes[parsedMessage.ICAO].addMessageToPlane(parsedMessage);
                }
            }
        }
 private void GetAllPlanes()
 {
     foreach (var plane in BL.BL.GetAllPlanes())
     {
         Planes.Add(new PlaneViewModel(plane));
     }
 }
Пример #3
0
        private async void LoadData()
        {
            var planes = await context.GetPlanes();

            var ports = await context.GetPorts();

            foreach (var item in ports)
            {
                Ports.Add(item);
            }
            Destinations.Refresh();
            Origins.Refresh();

            foreach (var item in planes)
            {
                Planes.Add(item);
            }

            PlanesView.Refresh();
            this.PortFrom = SettingConfiguration.GetIntValue("PortId");

            var portTo = ports.Where(O => O.Id != SettingConfiguration.GetIntValue("PortId")).FirstOrDefault();

            if (portTo != null)
            {
                this.PortTo = portTo.Id;
            }
        }
Пример #4
0
        void LoadFromXML(DataTemplate planeTemplate)
        {
            XDocument document = DataLoader.LoadXmlFromResources("/Data/FlightMap.xml");

            if (document != null)
            {
                foreach (XElement element in document.Element("Planes").Elements())
                {
                    List <GeoPoint> points = new List <GeoPoint>();
                    foreach (XElement infoElement in element.Element("Path").Elements())
                    {
                        GeoPoint geoPoint = new GeoPoint(Convert.ToDouble(infoElement.Element("Latitude").Value, CultureInfo.InvariantCulture), Convert.ToDouble(infoElement.Element("Longitude").Value, CultureInfo.InvariantCulture));
                        points.Add(geoPoint);
                    }
                    PlaneInfo info = new PlaneInfo(element.Element("PlaneName").Value, element.Element("PlaneID").Value, element.Element("EndPointName").Value, element.Element("StartPointName").Value, Convert.ToInt32(element.Element("Speed").Value), Convert.ToInt32(element.Element("Altitude").Value), points);
                    info.CurrentFlightTime = Convert.ToDouble(element.Element("CurrentFlightTime").Value, CultureInfo.InvariantCulture);
                    planesInfo.Add(info);
                }
            }
            foreach (PlaneInfo info in planesInfo)
            {
                MapCustomElement mapCustomElement = new MapCustomElement()
                {
                    Content = info, ContentTemplate = planeTemplate
                };
                BindingOperations.SetBinding(mapCustomElement, MapCustomElement.LocationProperty, new Binding("Position")
                {
                    Source = info
                });
                Planes.Add(mapCustomElement);
                AddPaths(info);
            }
        }
Пример #5
0
        private void AddPlane()
        {
            DesignerCanvas desgnCanv = new DesignerCanvas
            {
                DesignerControl  = DesignerControl,
                IsHitTestVisible = false,
                PlaneName        = "Name"
            };

            if (Planes.Count < 1)
            {
                desgnCanv.Background = Brushes.White;
            }
            else
            {
                desgnCanv.Background = Brushes.Transparent;
            }

            if (ActivPlane == null)
            {
                Planes.Add(desgnCanv);
            }
            else
            {
                Planes.Insert(Planes.IndexOf(ActivPlane) + 1, desgnCanv);
            }

            ActivPlane = desgnCanv;

            RefreshPlaneStates();
        }
Пример #6
0
 private void GetCollectionsDataFromDB()
 {
     FlightsViewModel.GetAllCompanies().ForEach(c => Companies.Add(c.name));
     FlightsViewModel.GetAllCities().ForEach(c => Cities.Add(c));
     FlightsViewModel.GetExistingPlanes().ForEach(p => Planes.Add(p));
     FlightsViewModel.GetTrips().ForEach(f => Trips.Add(f));
 }
Пример #7
0
 public void AddPlain(Plane plane)
 {
     if (Planes.Contains(plane))
     {
         throw new ApplicationException("Plane already exist");
     }
     Planes.Add(plane);
 }
Пример #8
0
        public void AddNewPlane(String producerName, String type, String internationalID, double minimalTrackLength)
        {
            Plane plane = new Plane(producerName, type, internationalID, minimalTrackLength, SystemTime, 0);

            Planes.Add(plane);
            ArrivedPlanes.Add(plane);
            PlaneArrivals.Add("plane " + plane.GetInternationalID() + " arrived " + plane.GetArrivalTime());
        }
Пример #9
0
 private void OnNewPlane(Plane plane)
 {
     guiDispatcher.Invoke(() =>
     {
         Planes.Add(plane);
         RaisePropertyChanged(nameof(Planes));
     });
 }
Пример #10
0
        private async void Create()
        {
            var created = await airportConnector.PlaneEndpoint.Create(newPlane);

            Planes.Add(created);
            newPlane = new Plane();
            RaisePropertyChanged(() => Planes);
            RaisePropertyChanged(() => NewPlane);
        }
Пример #11
0
        private async void FillPlanesCollection()
        {
            var temp = await service.GetEntities();

            foreach (var item in temp)
            {
                Planes.Add(item);
            }
        }
Пример #12
0
        public void Expand()
        {
            foreach (var plane in Planes)
            {
                plane.Value.Expand();
            }

            Planes.Add(GetMinIndex() - 1, new Plane(Planes.First().Value.Width, Planes.First().Value.Height));
            Planes.Add(GetMaxIndex() + 1, new Plane(Planes.First().Value.Width, Planes.First().Value.Height));
        }
Пример #13
0
        private void AddPlaneAction(object obj)
        {
            var form = new Views.AddNewPlanes();

            form.ShowDialog();
            var vm = (AddNewPlaneViewModel)form.DataContext;

            if (vm.SaveSuccess && vm.SaveResult != null)
            {
                Planes.Add(vm.SaveResult);
            }
            PlanesView.Refresh();
        }
Пример #14
0
        public void GenerateActiveState(int opsCount)
        {
            List <String> arrived    = new List <String>();
            List <String> allocated  = new List <String>();
            List <String> departured = new List <String>();

            for (int i = 0; i < opsCount; i++)
            {
                if (i % 7 == 0)
                {   // Count -1 to test upper type sub
                    Planes.Add(new Plane("Producer " + i, "Type " + i, "" + i, TrackTypesLengthList[i % TrackTypesLengthList.Count],
                                         SystemTime, 0));
                    if (NotifyArrival("" + i))
                    {
                        arrived.Add("" + i);
                    }
                }
                else
                if (i % 7 == 1 && departured.Count > 0)
                {
                    String randomID = departured[i % departured.Count];
                    if (NotifyArrival(randomID))
                    {
                        departured.Remove(randomID);
                        arrived.Add(randomID);
                    }
                }
                else
                if ((i % 7 == 2 || i % 7 == 3 || i % 7 == 6) && allocated.Count > 0)
                {
                    String randomID = allocated[i % allocated.Count];
                    if (NotifyDeparture(randomID))
                    {
                        allocated.Remove(randomID);
                        departured.Add(randomID);
                    }
                }
                else
                if ((i % 7 == 4 || i % 7 == 5) && arrived.Count > 0)
                {
                    String randomID = arrived[i % arrived.Count];
                    if (NotifyTrackRequirement(randomID, i % 11))
                    {
                        arrived.Remove(randomID);
                        allocated.Add(randomID);
                    }
                }
                SystemTime = SystemTime.AddMinutes(10);
            }
        }
Пример #15
0
        /// <summary>
        /// Plane is moving
        /// </summary>
        /// <param name="plane"></param>
        private async void Moved(Common.Plane plane)
        {
            await DispatcherHelper.ExecuteOnUIThreadAsync(() =>
            {
                //If it's not his last station
                if (plane.StationNumber != 0)
                {
                    var pl = Planes.Where(p => p.Name == plane.Name).FirstOrDefault();
                    if (pl == null)
                    {
                        Planes.Add(new Models.Plane(plane.Name, plane.ActionDate, plane.waitingTime, plane.flightState)
                        {
                            StationNumber = plane.StationNumber
                        });
                    }
                    else
                    {
                        pl.StationNumber = plane.StationNumber;
                    }
                }
                else
                {
                    Planes.Remove(Planes.Where(p => p.Name == plane.Name).First());
                }


                var previous = Stations.Where(s => s.Number == plane.PreviousStationNumber).FirstOrDefault();
                if (previous != null && previous.Plane != null)
                {
                    previous.Plane = null;
                }

                var nextstation = Stations.Where(s => s.Number == plane.StationNumber).FirstOrDefault();
                if (nextstation != null)
                {
                    nextstation.Plane = plane.Name;
                }

                //if it's his first station
                if (plane.PreviousStationNumber == 0)
                {
                    var flight = FutureFlights.Where(f => f.Name == plane.Name).FirstOrDefault();
                    if (flight != null)
                    {
                        FutureFlights.Remove(flight);
                    }
                }
            });
        }
Пример #16
0
        public Planes GetAll()
        {
            SqlConnection oCnn = this.CreateConnection();
            using (oCnn)
            {
                oCnn.Open();

                SqlCommand oCmd = new SqlCommand();
                using (oCmd)
                {
                    oCmd.Connection = oCnn;

                    oCmd.CommandType = CommandType.StoredProcedure;
                    oCmd.CommandText = "planesGetAll";

                    Planes oPlanes = new Planes();

                    try
                    {
                        SqlDataReader oReader = oCmd.ExecuteReader();
                        using (oCnn)
                        {
                            while (oReader.Read())
                            {
                                Plan oPlan = new Plan();

                                oPlan.ID = Convert.ToInt32(oReader["id_plan"]);
                                oPlan.Descripcion = Convert.ToString(oReader["desc_plan"]);
                                oPlan.IDEspecialidad = Convert.ToInt32(oReader["id_especialidad"]);

                                oPlanes.Add(oPlan);
                                oPlan = null;
                            }
                            return oPlanes;
                        }
                    }
                    catch (Exception Ex)
                    {
                        Exception ExcepcionManejada = new Exception("Error al recuperar lista de planes", Ex);
                        throw ExcepcionManejada;
                    }
                    finally
                    {
                        oPlanes = null;
                    }
                }
            }
        }
Пример #17
0
 private void ReadPlanes(BinaryReader reader, int planeSize)
 {
     for (var i = 0; i < BitLength; i++)
     {
         var marker = reader.ReadByte();
         if (marker == 0x6d)
         {
             Mask = reader.ReadBytes(planeSize);
         }
         else
         {
             var plane = new VniAnimationPlane(reader, planeSize, marker);
             Planes.Add(plane);
         }
     }
 }
Пример #18
0
    static void CreatePlane(int ind)
    {
        var dirParent = new GameObject(ind.ToString());

        dirParent.transform.position    = Dirs[ind] * (World.Size / 2);
        dirParent.transform.eulerAngles = PlaneRotArray[ind];

        var newPlane = Instantiate(PlanePref, dirParent.transform);

        newPlane.layer = 9 + ind;
        newPlane.transform.localScale       = Vector3.one * (World.Size / 10f);
        newPlane.transform.localPosition    = Vector3.zero;
        newPlane.transform.localEulerAngles = Vector3.zero;


        newPlane.GetComponent <Plane>().EarlyStart();

        Planes.Add(Dirs[ind], newPlane.GetComponent <Plane>());
    }
Пример #19
0
        private void AddItemToList(Equipment item, string newType, DPSData dpsData)
        {
            switch (newType)
            {
            case "AA Gun":
                AAGuns.Add(new AAGun(item, dpsData));
                break;

            case "Auxiliary":
                AuxiliaryItems.Add(new AuxiliaryItem(item));
                break;

            case "Submarine Torpedo":
                SubmarineTorpedoes.Add(new SubmarineTorpedo(item, dpsData));
                break;

            case "Torpedo":
                Torpedoes.Add(new Torpedo(item, dpsData));
                break;

            case "Torpedo Bomber":
                TorpedoBomberPlanes.Add(new TorpedoBomberPlane(item, dpsData));
                break;

            case string s when s.Contains("Gun"):
                MainGuns.Add(new MainGun(item, dpsData));

                break;

            case string s when s == "Fighter" || s == "Dive Bomber" || s == "Seaplane":
                Planes.Add(new Plane(item, dpsData));
                break;

            default:
                AswItems.Add(new ASWItem(item));
                break;
            }
        }
Пример #20
0
        private async void FillAdditionalCollections()
        {
            var flights = await FService.GetEntities();

            foreach (var item in flights)
            {
                Flights.Add(item);
            }

            var crews = await CService.GetEntities();

            foreach (var item in crews)
            {
                Crews.Add(item);
            }

            var planes = await PService.GetEntities();

            foreach (var item in planes)
            {
                Planes.Add(item);
            }
        }
        protected override void ParseLine(string line)
        {
            if (line == "processed")
            {
                return;
            }

            var toks = new string[0];

            switch (Version)
            {
            case GtaVersion.III:
            case GtaVersion.ViceCity:
                toks = line.Split(new char[] { ' ', ',', '\t' }, StringSplitOptions.RemoveEmptyEntries);

                if (toks.Length != 5)
                {
                    Log.Error("Invalid number of tokens, expected 5, found {0}", toks.Length);
                    return;
                }

                var level = float.Parse(toks[0]);
                var xMin  = float.Parse(toks[1]);
                var yMin  = float.Parse(toks[2]);
                var xMax  = float.Parse(toks[3]);
                var yMax  = float.Parse(toks[4]);

                Planes.Add(new WaterPlane(new Vector3(xMin, level, yMax), new Vector3(xMax, level, yMax), new Vector3(xMax, level, yMin), new Vector3(xMin, level, yMin)));

                break;

            //http://gtaforums.com/topic/211733-sadoc-waterdat/
            case GtaVersion.SanAndreas:
                toks = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                if (toks.Length == 29)
                {
                    Planes.Add(new WaterPlane(
                                   new Vector3(float.Parse(toks[7 * 1 + 0]), float.Parse(toks[7 * 1 + 2]), float.Parse(toks[7 * 1 + 1])),
                                   new Vector3(float.Parse(toks[7 * 0 + 0]), float.Parse(toks[7 * 0 + 2]), float.Parse(toks[7 * 0 + 1])),
                                   new Vector3(float.Parse(toks[7 * 2 + 0]), float.Parse(toks[7 * 2 + 2]), float.Parse(toks[7 * 2 + 1])),
                                   new Vector3(float.Parse(toks[7 * 3 + 0]), float.Parse(toks[7 * 3 + 2]), float.Parse(toks[7 * 3 + 1])),
                                   int.Parse(toks[28])
                                   ));
                }
                else if (toks.Length == 22)
                {
                    Planes.Add(new WaterPlane(
                                   new Vector3(float.Parse(toks[7 * 2 + 0]), float.Parse(toks[7 * 2 + 2]), float.Parse(toks[7 * 2 + 1])),
                                   new Vector3(float.Parse(toks[7 * 0 + 0]), float.Parse(toks[7 * 0 + 2]), float.Parse(toks[7 * 0 + 1])),
                                   new Vector3(float.Parse(toks[7 * 1 + 0]), float.Parse(toks[7 * 1 + 2]), float.Parse(toks[7 * 1 + 1])),
                                   int.Parse(toks[21])
                                   ));
                }
                else
                {
                    Log.Error("Invalid number of tokens, expected 22 or 29, found {0}", toks.Length);
                }
                break;
            }
        }
Пример #22
0
        private void Read(BinaryReader br)
        {
            Header = new Header
            {
                Version = (Version)br.ReadInt32(),
                Lumps   = new Lump[Lump.NumLumps]
            };

            if (Header.Version != Version.Goldsource)
            {
                throw new NotSupportedException("Only Goldsource (v30) BSP files are supported.");
            }

            for (var i = 0; i < Header.Lumps.Length; i++)
            {
                Header.Lumps[i] = new Lump
                {
                    Offset = br.ReadInt32(),
                    Length = br.ReadInt32()
                };
            }

            // Entities
            var lump = Header.Lumps[Lump.Entities];

            br.BaseStream.Seek(lump.Offset, SeekOrigin.Begin);
            EntityBlock = Encoding.ASCII.GetString(br.ReadBytes(lump.Length));

            // Planes
            lump = Header.Lumps[Lump.Planes];
            br.BaseStream.Seek(lump.Offset, SeekOrigin.Begin);
            while (br.BaseStream.Position < lump.Offset + lump.Length)
            {
                Planes.Add(new Plane
                {
                    Normal   = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()),
                    Distance = br.ReadSingle(),
                    Type     = br.ReadInt32()
                });
            }

            // Textures
            lump = Header.Lumps[Lump.Textures];
            br.BaseStream.Seek(lump.Offset, SeekOrigin.Begin);

            var numTextures = br.ReadUInt32();
            var offsets     = new int[numTextures];

            for (var i = 0; i < numTextures; i++)
            {
                offsets[i] = br.ReadInt32();
            }
            foreach (var offset in offsets)
            {
                br.BaseStream.Seek(lump.Offset + offset, SeekOrigin.Begin);
                var tex = Wad.WadFile.ReadMipTexture(br);
                Textures.Add(tex);
            }

            // Vertices
            lump = Header.Lumps[Lump.Vertices];
            br.BaseStream.Seek(lump.Offset, SeekOrigin.Begin);
            while (br.BaseStream.Position < lump.Offset + lump.Length)
            {
                Vertices.Add(new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()));
            }

            // Visibility
            lump = Header.Lumps[Lump.Visibility];
            br.BaseStream.Seek(lump.Offset, SeekOrigin.Begin);
            VisData = br.ReadBytes(lump.Length);
            //TODO: decompress vis data

            // Nodes
            lump = Header.Lumps[Lump.Nodes];
            br.BaseStream.Seek(lump.Offset, SeekOrigin.Begin);
            while (br.BaseStream.Position < lump.Offset + lump.Length)
            {
                var node = new Node
                {
                    Plane    = br.ReadUInt32(),
                    Children = new short[2],
                    Mins     = new short[3],
                    Maxs     = new short[3]
                };
                for (var i = 0; i < 2; i++)
                {
                    node.Children[i] = br.ReadInt16();
                }
                for (var i = 0; i < 3; i++)
                {
                    node.Mins[i] = br.ReadInt16();
                }
                for (var i = 0; i < 3; i++)
                {
                    node.Maxs[i] = br.ReadInt16();
                }
                node.FirstFace = br.ReadUInt16();
                node.NumFaces  = br.ReadUInt16();
                Nodes.Add(node);
            }

            // Texinfo
            lump = Header.Lumps[Lump.Texinfo];
            br.BaseStream.Seek(lump.Offset, SeekOrigin.Begin);
            while (br.BaseStream.Position < lump.Offset + lump.Length)
            {
                var info = new TextureInfo
                {
                    S          = new Vector4(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()),
                    T          = new Vector4(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()),
                    MipTexture = br.ReadInt32(),
                    Flags      = br.ReadInt32()
                };
                TextureInfos.Add(info);
            }

            // Faces
            lump = Header.Lumps[Lump.Faces];
            br.BaseStream.Seek(lump.Offset, SeekOrigin.Begin);
            while (br.BaseStream.Position < lump.Offset + lump.Length)
            {
                var face = new Face
                {
                    Plane          = br.ReadInt16(),
                    Side           = br.ReadInt16(),
                    FirstEdge      = br.ReadInt32(),
                    NumEdges       = br.ReadInt16(),
                    TextureInfo    = br.ReadInt16(),
                    Styles         = br.ReadBytes(Face.MaxLightmaps),
                    LightmapOffset = br.ReadInt32()
                };
                Faces.Add(face);
            }

            // Lighting
            lump = Header.Lumps[Lump.Lighting];
            br.BaseStream.Seek(lump.Offset, SeekOrigin.Begin);
            Lightmap = br.ReadBytes(lump.Length);

            // Clipnodes
            lump = Header.Lumps[Lump.Clipnodes];
            br.BaseStream.Seek(lump.Offset, SeekOrigin.Begin);
            while (br.BaseStream.Position < lump.Offset + lump.Length)
            {
                var clip = new Clipnode
                {
                    Plane    = br.ReadInt32(),
                    Children = new[] { br.ReadInt16(), br.ReadInt16() }
                };
                Clipnodes.Add(clip);
            }

            // Leaves
            lump = Header.Lumps[Lump.Leaves];
            br.BaseStream.Seek(lump.Offset, SeekOrigin.Begin);
            while (br.BaseStream.Position < lump.Offset + lump.Length)
            {
                var leaf = new Leaf
                {
                    Contents         = (Contents)br.ReadInt32(),
                    VisOffset        = br.ReadInt32(),
                    Mins             = new [] { br.ReadInt16(), br.ReadInt16(), br.ReadInt16() },
                    Maxs             = new [] { br.ReadInt16(), br.ReadInt16(), br.ReadInt16() },
                    FirstMarkSurface = br.ReadUInt16(),
                    NumMarkSurfaces  = br.ReadUInt16(),
                    AmbientLevels    = br.ReadBytes(Leaf.MaxNumAmbientLevels)
                };
                Leaves.Add(leaf);
            }

            // Marksurfaces
            lump = Header.Lumps[Lump.Marksurfaces];
            br.BaseStream.Seek(lump.Offset, SeekOrigin.Begin);
            MarkSurfaces = new ushort[lump.Length / sizeof(ushort)];
            for (var i = 0; i < MarkSurfaces.Length; i++)
            {
                MarkSurfaces[i] = br.ReadUInt16();
            }

            // Edges
            lump = Header.Lumps[Lump.Edges];
            br.BaseStream.Seek(lump.Offset, SeekOrigin.Begin);
            while (br.BaseStream.Position < lump.Offset + lump.Length)
            {
                var edge = new Edge
                {
                    Start = br.ReadUInt16(),
                    End   = br.ReadUInt16()
                };
                Edges.Add(edge);
            }

            // Surfedges
            lump = Header.Lumps[Lump.Surfedges];
            br.BaseStream.Seek(lump.Offset, SeekOrigin.Begin);
            SurfaceEdges = new int[lump.Length / sizeof(int)];
            for (var i = 0; i < SurfaceEdges.Length; i++)
            {
                SurfaceEdges[i] = br.ReadInt32();
            }

            // Models
            lump = Header.Lumps[Lump.Models];
            br.BaseStream.Seek(lump.Offset, SeekOrigin.Begin);
            while (br.BaseStream.Position < lump.Offset + lump.Length)
            {
                var model = new Model
                {
                    Mins      = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()),
                    Maxs      = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()),
                    Origin    = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()),
                    HeadNodes = new [] { br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32() },
                    VisLeaves = br.ReadInt32(),
                    FirstFace = br.ReadInt32(),
                    NumFaces  = br.ReadInt32()
                };
                Models.Add(model);
            }

            ParseEntities();
        }
Пример #23
0
 public void AddPlane(Plane plane)
 {
     Planes.Add(plane);
 }
Пример #24
0
        public void ReadFromFile()
        {
            SystemTime = DateTime.Parse(File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking\\PlaneDepartureTrackingMSTest\\SystemTime.txt"));


            String[] planes = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking" +
                                               "\\PlaneDepartureTrackingMSTest\\Planes.txt").Split('\n');
            int test = 0;

            for (int i = 0; i < planes.Length; i++)
            {
                String [] row = planes[i].Split(',');
                if (row.Length >= 6)
                {
                    test++;
                    Plane plane = new Plane(row[0], row[1], row[2],
                                            Double.Parse(row[3]),
                                            DateTime.Parse(row[4]),
                                            Double.Parse(row[6].Replace('.', ',')));
                    plane.SetTrackRequirementTime(DateTime.Parse(row[5]));
                    Planes.Add(plane);
                }
            }
            System.Windows.Forms.MessageBox.Show("" + test);


            String[] trackAllocations = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking\\PlaneDepartureTrackingMSTest\\TrackAllocations.txt").Split(',');
            for (int i = 0; i < trackAllocations.Length; i++)
            {
                String allocation = trackAllocations[i];
                TrackAllocations.Add(allocation);
            }

            ArrivedPlanes.SplayDisabled = true;
            String[] arrivedPlanes = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking" +
                                                      "\\PlaneDepartureTrackingMSTest\\ArrivedPlanes.txt").Split();
            foreach (String planeID in arrivedPlanes)
            {
                TreeNode <Plane> plane = Planes.Find(new Plane(planeID));
                if (plane != null)
                {
                    ArrivedPlanes.Add(plane.Data);
                }
            }
            ArrivedPlanes.SplayDisabled = false;

            String[] planeArrivals = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking\\PlaneDepartureTrackingMSTest\\PlaneArrivals.txt").Split(',');
            foreach (String arrival in planeArrivals)
            {
                PlaneArrivals.Add(arrival);
            }

            String[] planeDepartures = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking\\PlaneDepartureTrackingMSTest\\PlaneDepartures.txt").Split(',');
            foreach (String departure in planeDepartures)
            {
                PlaneDepartures.Add(departure);
            }

            String[] pairs = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking" +
                                              "\\PlaneDepartureTrackingMSTest\\TrackPlanes.txt").Split(',');
            foreach (String pair in pairs)
            {
                String[] splittedPair = pair.Split(':');
                if (splittedPair.Length == 2)
                {
                    String           trackName = splittedPair[0];
                    String           planeID   = splittedPair[1];
                    TreeNode <Plane> plane     = Planes.Find(new Plane(planeID));
                    TreeNode <Track> track     = Tracks.Find(new Track(trackName));
                    if (plane != null && track != null)
                    {
                        plane.Data.Track = track.Data;
                        track.Data.SetPlane(plane.Data);
                    }
                }
            }


            WaitingPlanes.SplayDisabled = true;
            String[] waitingPlanes = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking" +
                                                      "\\PlaneDepartureTrackingMSTest\\WaitingPlanes.txt").Split();
            foreach (String planeID in waitingPlanes)
            {
                TreeNode <Plane> plane = Planes.Find(new Plane(planeID));
                if (plane != null)
                {
                    WaitingPlanes.Add(plane.Data);
                }
            }
            WaitingPlanes.SplayDisabled = false;

            foreach (double length in TrackTypesLengthList)
            {
                TreeNode <TrackType> type = TrackTypes.Find(new TrackType(length));

                if (type != null)
                {
                    type.Data.WaitingPlanesForSearch.SplayDisabled = true;
                    String[] waitingPlanesForSearchTrack = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking" +
                                                                            "\\PlaneDepartureTrackingMSTest\\" +
                                                                            type.Data.Length
                                                                            + "WaitingPlanesForSearch.txt").Split();
                    foreach (String planeID in waitingPlanesForSearchTrack)
                    {
                        TreeNode <Plane> plane = Planes.Find(new Plane(planeID));
                        if (plane != null)
                        {
                            type.Data.WaitingPlanesForSearch.Add(plane.Data);
                        }
                    }
                    type.Data.WaitingPlanesForSearch.SplayDisabled = false;

                    String[] waitingPlanesTrack = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking" +
                                                                   "\\PlaneDepartureTrackingMSTest\\" +
                                                                   type.Data.Length
                                                                   + "WaitingPlanes.txt").Split();
                    foreach (String planeID in waitingPlanesTrack)
                    {
                        TreeNode <Plane> plane = Planes.Find(new Plane(planeID));
                        if (plane != null)
                        {
                            type.Data.WaitingPlanes.Add(plane.Data);
                        }
                    }
                    foreach (Track track in type.Data.Tracks)
                    {
                        String[] trackHistory = File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking" +
                                                                 "\\PlaneDepartureTrackingMSTest\\" +
                                                                 track.GetName() +
                                                                 "History.txt").Split('\n');

                        foreach (String entry in trackHistory)
                        {
                            String[] splittedEntry = entry.Split(',');
                            if (splittedEntry.Length == 2)
                            {
                                track.DepartureHistory.Add(new PlaneShortInfo(splittedEntry[0],
                                                                              DateTime.Parse(splittedEntry[1])));
                            }
                        }
                    }
                }
            }

            waitingCount = Int32.Parse(File.ReadAllText("D:\\.NET Projects\\PlaneDepartureTracking" +
                                                        "\\PlaneDepartureTrackingMSTest\\WaitingCount.txt"));
        }
Пример #25
0
        public Planes GetAllPorEspecialidad(int id)
        {
            SqlConnection oCnn = this.CreateConnection();
            using (oCnn)
            {
                oCnn.Open();

                SqlCommand oCmd = new SqlCommand();
                using (oCmd)
                {
                    oCmd.Connection = oCnn;

                    oCmd.CommandType = CommandType.StoredProcedure;
                    oCmd.CommandText = "planesGetAllPorEspecialidad";

                    oCmd.Parameters.AddWithValue("@id_especialidad", id);

                    //Aunque debemos buscar solo un elemento, siempre devolvemos
                    //una colección. Es más fácil de manipular y controlar
                    Planes oPlanes = new Planes();

                    //No retornamos DataSets, siempre utilizamos objetos para hacernos
                    //independientes de la estructura de las tablas en el resto
                    //de las capas. Para ellos leemos con el DataReader y creamos
                    //los objetos asociados que se esperan
                    try
                    {
                        //Ejecutamos el comando y retornamos los valores
                        SqlDataReader oReader = oCmd.ExecuteReader();
                        using (oReader)
                        {
                            while (oReader.Read())
                            {
                                //si existe algun valor, creamos el objeto y lo almacenamos en la colección
                                Plan oPlan = new Plan();

                                oPlan.ID = Convert.ToInt32(oReader["id_plan"]);
                                oPlan.Descripcion = Convert.ToString(oReader["desc_plan"]);
                                oPlan.IDEspecialidad = Convert.ToInt32(oReader["id_especialidad"]);

                                //Agregamos el objeto a la coleccion de resultados
                                oPlanes.Add(oPlan);

                                oPlan = null;
                            }
                            //retornamos los valores encontrados
                            return oPlanes;
                        }
                    }
                    catch (Exception Ex)
                    {
                        Exception ExcepcionManejada = new Exception("Error al recuperar datos del plan", Ex);
                        throw ExcepcionManejada;
                    }
                    finally
                    {
                        //liberamos la memoria utilizada por los objetos
                        oPlanes = null;
                    }
                }
            }
        }
Пример #26
0
        /// <summary>
        /// Initialize the view model
        /// </summary>
        private void Init()
        {
            Log("Initializing ..");

            //First task who gets the stations state
            var t1 = new Task(async() =>
            {
                HttpClient httpClient        = new HttpClient();
                httpClient.Timeout           = TimeSpan.FromSeconds(30);
                Task <HttpResponseMessage> t = null;
                try
                {
                    //IMPORTANT !!
                    //If the link above doesn't work , it's because the free azure account doesn't work anymore , so you need to run it locally
                    t = httpClient.GetAsync("https://finalprojectsela.azurewebsites.net/api/airport/GetCurrentStationsState");
                    t.Wait();
                }

                catch (Exception exc)
                {
                    OnError(exc.Message);
                }
                if (t.Result.StatusCode == System.Net.HttpStatusCode.BadRequest || t.Result.StatusCode == System.Net.HttpStatusCode.InternalServerError)
                {
                    OnError(t.Result.Content.ReadAsStringAsync().Result);
                }
                else
                {
                    var result = JsonConvert.DeserializeObject <List <Common.Station> >(t.Result.Content.ReadAsStringAsync().Result);
                    foreach (var station in result)
                    {
                        await DispatcherHelper.ExecuteOnUIThreadAsync(() =>
                        {
                            if (station.Plane != null)
                            {
                                Planes.Add(new Models.Plane(station.Plane.Name, station.Plane.ActionDate, station.Plane.waitingTime, station.Plane.flightState));
                                Stations.Add(new Models.Station(station.Number)
                                {
                                    Plane = station.Plane.Name
                                });
                            }

                            else
                            {
                                Stations.Add(new Models.Station(station.Number));
                            }
                        });
                    }
                }
            });

            //Second Task who get the future departures and arrivals
            var t2 = new Task(async() =>
            {
                HttpClient httpClient        = new HttpClient();
                httpClient.Timeout           = TimeSpan.FromSeconds(30);
                Task <HttpResponseMessage> t = null;
                try
                {
                    //IMPORTANT !!
                    //If the link above doesn't work , it's because the free azure account doesn't work anymore , so you need to run it locally
                    t = httpClient.GetAsync("https://finalprojectsela.azurewebsites.net/api/airport/GetFutureDeparturesAndArrivals");
                    t.Wait();
                }
                catch (Exception exc)
                {
                    OnError(exc.Message);
                }

                if (t.Result.StatusCode == System.Net.HttpStatusCode.BadRequest || t.Result.StatusCode == System.Net.HttpStatusCode.InternalServerError)
                {
                    OnError(t.Result.Content.ReadAsStringAsync().Result);
                }
                else
                {
                    var result = JsonConvert.DeserializeObject <List <Common.Plane> >(t.Result.Content.ReadAsStringAsync().Result);
                    foreach (var plane in result)
                    {
                        await DispatcherHelper.ExecuteOnUIThreadAsync(() =>
                        {
                            FutureFlights.Add(new Models.Plane(plane.Name, plane.ActionDate, plane.waitingTime, plane.flightState));
                        });
                    }
                }
            });

            //Third task who open the hub connection
            var t3 = new Task(() =>
            {
                try
                {
                    //IMPORTANT !!
                    //If the link above doesn't work , it's because the free azure account doesn't work anymore , so you need to run it locally
                    HubConnection hubConnection = new HubConnection("https://finalprojectsela.azurewebsites.net");
                    var proxy = hubConnection.CreateHubProxy("AirportHub");
                    proxy.On <Common.Plane>("departureOrArrival", DepartureOrArrival);
                    proxy.On <Common.Plane>("moved", Moved);
                    proxy.On <string>("onerror", OnError);
                    hubConnection.Start();
                }
                catch (Exception exc)
                {
                    OnError(exc.Message);
                    throw;
                }
            });

            t1.Start();
            t2.Start();
            t3.Start();

            Task.WhenAll(t1, t2, t3).ContinueWith((t) => { Log("Finished initialization ! "); });
        }