예제 #1
0
        private static int GetTowings(TowingsOptions opts)
        {
            if (!AMSTools.FileOK(opts.FileName))
            {
                return(-1);
            }

            var t = GetFromToTime(opts.Today, opts.Yesterday, opts.Tomorrow, opts.From, opts.To);

            if (t == null)
            {
                return(-1);
            }

            string start = t.Item1.ToString("yyyy-MM-ddTHH:mm:ss");
            string end   = t.Item2.ToString("yyyy-MM-ddTHH:mm:ss");

            string uri = Parameters.AMS_REST_SERVICE_URI + "/" + Parameters.APT_CODE + "/Towings/" + start + "/" + end;

            if (opts.CSV)
            {
                AMSTools.Out(GetCSV(AMSTools.GetRestURI(uri).Result, "Towing", BaseType.Towing, null), opts.FileName);
            }
            else
            {
                AMSTools.Out(AMSTools.PrintXML(AMSTools.GetRestURI(uri).Result), opts.FileName);
            }
            return(1);
        }
예제 #2
0
        private static void GetDowngrades(DownGradeOptions opts)
        {
            if (!AMSTools.FileOK(opts.FileName))
            {
                return;
            }

            var t = GetFromToTime(opts.Today, opts.Yesterday, opts.Tomorrow, opts.From, opts.To);

            if (t == null)
            {
                return;
            }

            using (AMSIntegrationServiceClient client = new AMSIntegrationServiceClient(AMSTools.GetWSBinding(), AMSTools.GetWSEndPoint())) {
                try {
                    XmlElement res = client.GetStandDowngrades(Parameters.TOKEN, t.Item1, t.Item2, Parameters.APT_CODE, AirportIdentifierType.IATACode);

                    //Output in XML format
                    AMSTools.Out(AMSTools.PrintXML(res.OuterXml), opts.FileName);
                } catch (Exception e) {
                    Console.WriteLine(e.Message);
                }
            }
        }
예제 #3
0
 private static int GetAircrafts(AircraftsOptions opts)
 {
     if (!AMSTools.FileOK(opts.FileName))
     {
         return(-1);
     }
     AMSTools.Out(AMSTools.PrintXML(AMSTools.GetAircrafts()), opts.FileName);
     return(1);
 }
예제 #4
0
        private static int GetCarousels(CarouselOptions opts)
        {
            if (!AMSTools.FileOK(opts.FileName))
            {
                return(-1);
            }
            try {
                string uri    = Parameters.AMS_REST_SERVICE_URI + $"{Parameters.APT_CODE}/Carousels";
                string result = AMSTools.GetRestURI(uri).Result;
                AMSTools.Out(AMSTools.PrintXML(result), opts.FileName);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }

            return(1);
        }
예제 #5
0
        private static int GetAirlines(AirlinesOptions opts)
        {
            if (!AMSTools.FileOK(opts.FileName))
            {
                return(-1);
            }

            if (opts.CSV)
            {
                AMSTools.Out(GetCSV(AMSTools.GetAirlines(), "Airline", BaseType.Airline, ".//ams:AirlineState"), opts.FileName);
            }
            else
            {
                AMSTools.Out(AMSTools.PrintXML(AMSTools.GetAirlines()), opts.FileName);
            }

            return(1);
        }
예제 #6
0
        private static int GetStand(StandOptions opts)
        {
            if (!AMSTools.FileOK(opts.FileName))
            {
                return(-1);
            }
            try {
                string uri    = Parameters.AMS_REST_SERVICE_URI + $"{Parameters.APT_CODE}/Stands";
                string result = AMSTools.GetRestURI(uri).Result;

                XElement xmlRoot = XDocument.Parse(result).Root;
                XElement db      = (from n in xmlRoot.Descendants() where (n.Name == "FixedResource" && n.Elements("Name").FirstOrDefault().Value == opts.Stand) select n).FirstOrDefault <XElement>();

                if (db == null)
                {
                    Console.WriteLine($"Stand {opts.Stand} not found");
                    return(-1);
                }
                AMSTools.Out(AMSTools.PrintXML(db.ToString()), opts.FileName);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
            return(1);
        }
예제 #7
0
        public bool Prepare()
        {
            // Calculate the time of the zero time
            DateTime now = DateTime.Now;

            zeroTime = now.AddHours(-3);
            zeroTime = new DateTime(zeroTime.Year, zeroTime.Month, zeroTime.Day, zeroTime.Hour, 0, 0);


            head.AppendChild(style);
            root.AppendChild(head);
            root.AppendChild(body);

            try {
                string result = AMSTools.GetRestURI(Parameters.AMS_REST_SERVICE_URI + $"{Parameters.APT_CODE}/Stands").Result;
                standsDoc = new XmlDocument();
                standsDoc.LoadXml(result);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }


            Console.WriteLine("Retrieving Stands");

            // Create the StandRecords and put them into lists according to Stand Area
            foreach (XmlNode stand in standsDoc.SelectNodes(".//FixedResource"))
            {
                StandRecord standRecord = new StandRecord(stand);
                standMap.Add(standRecord.id, standRecord);

                if (!areaMap.ContainsKey(standRecord.area))
                {
                    areaMap.Add(standRecord.area, new List <StandRecord>());
                }
                areaMap[standRecord.area].Add(standRecord);
            }

            Console.WriteLine("Retrieving Downgrades");
            using (AMSIntegrationServiceClient client = new AMSIntegrationServiceClient(AMSTools.GetWSBinding(), AMSTools.GetWSEndPoint())) {
                // Get the Downgrade records and add them to the appropriat stand
                try {
                    XmlElement          xdowngrades = client.GetStandDowngrades(Parameters.TOKEN, DateTime.Now.AddHours(-24), DateTime.Now.AddHours(24), Parameters.APT_CODE, AirportIdentifierType.IATACode);
                    XmlNamespaceManager nsmgr       = new XmlNamespaceManager(xdowngrades.OwnerDocument.NameTable);
                    nsmgr.AddNamespace("ams", "http://www.sita.aero/ams6-xml-api-datatypes");
                    foreach (XmlElement el in xdowngrades.SelectNodes("//ams:StandDowngradeState", nsmgr))
                    {
                        DownGradeRecord drec = new DownGradeRecord(el, nsmgr);
                        foreach (string standID in drec.standList)
                        {
                            standMap[standID].downgradeList.Add(drec);
                        }
                    }
                } catch (Exception e) {
                    Debug.WriteLine(e.Message);
                }
            }

            Console.WriteLine("Retrieving Flights");
            using (AMSIntegrationServiceClient client = new AMSIntegrationServiceClient(AMSTools.GetWSBinding(), AMSTools.GetWSEndPoint())) {
                XmlElement          res   = client.GetFlights(Parameters.TOKEN, DateTime.Now.AddHours(-24), DateTime.Now.AddHours(24), Parameters.APT_CODE, AirportIdentifierType.IATACode);
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(res.OwnerDocument.NameTable);
                nsmgr.AddNamespace("ams", "http://www.sita.aero/ams6-xml-api-datatypes");


                // Create the flight records and add them to the stands. Position them horizontally.
                foreach (XmlElement el in res.SelectNodes("//ams:Flights/ams:Flight", nsmgr))
                {
                    {
                        FlightRecord flight = new FlightRecord(el, nsmgr);

                        fltMap.Add(flight.flightUniqueID, flight);

                        XmlNode slots = el.SelectSingleNode("./ams:FlightState/ams:StandSlots", nsmgr);

                        if (slots != null)
                        {
                            // Iterate through each of the Stand Slots for the flight

                            foreach (XmlNode slot in slots.SelectNodes("./ams:StandSlot", nsmgr))
                            {
                                SlotRecord slotRecord = new SlotRecord(slot, nsmgr, flight);

                                if (slotRecord.slotStand == null)
                                {
                                    slotRecord.slotStand = "Unallocated";
                                }

                                if (!slotRecord.flight.ShowFlight())
                                {
                                    continue;
                                }

                                if (slotRecord.slotEndDateTime < this.zeroTime || slotRecord.slotStartDateTime > this.zeroTime.AddHours(23))
                                {
                                    //Outside range of Gantt
                                    continue;
                                }


                                TimeSpan tss = slotRecord.slotStartDateTime - this.zeroTime;
                                TimeSpan tse = slotRecord.slotEndDateTime - this.zeroTime;

                                // End of slot before start of zeroTime
                                if (tse.TotalMinutes < 0)
                                {
                                    continue;
                                }

                                // Start of slot more than end of chart
                                if (tss.TotalHours > 23)
                                {
                                    continue;
                                }

                                int width = Convert.ToInt32(tse.TotalMinutes - tss.TotalMinutes);
                                int left  = Convert.ToInt32(tss.TotalMinutes);
                                if (left < 0)
                                {
                                    width += left;
                                    left   = 0;
                                }

                                slotRecord.left  = left;
                                slotRecord.width = width;
                                slotRecord.row   = 1;

                                standMap[slotRecord.slotStand].slotList.Add(slotRecord);
                            }
                        }
                        else
                        {
                            // No Stand Slot Defined for the flight
                            SlotRecord slotRecord = new SlotRecord(null, nsmgr, flight);
                            standMap["Unallocated"].slotList.Add(slotRecord);
                        }
                    }
                }
            }


            // Get the towings
            {
                Console.WriteLine("Retrieving Tow Events");
                string start = DateTime.Now.AddHours(-24).ToString("yyyy-MM-ddTHH:mm:ss");
                string end   = DateTime.Now.AddHours(24).ToString("yyyy-MM-ddTHH:mm:ss");

                string uri        = Parameters.AMS_REST_SERVICE_URI + "/" + Parameters.APT_CODE + "/Towings/" + start + "/" + end;
                string towingsXML = AMSTools.GetRestURI(uri).Result;

                var towsDoc = new XmlDocument();
                towsDoc.LoadXml(towingsXML);

                //Add the tow records to the stand
                foreach (XmlElement el in towsDoc.SelectNodes("//Towing"))
                {
                    TowRecord towRec = new TowRecord(el);
                    try {
                        standMap[towRec.fromStand].fromTows.Add(towRec);
                    } catch (Exception e) {
                        Debug.WriteLine(e.Message);
                    }
                    try {
                        standMap[towRec.toStand].toTows.Add(towRec);
                    } catch (Exception e) {
                        Debug.WriteLine(e.Message);
                    }
                }
            }
            // Position the flight vertically withing row to avoid overlays

            Console.WriteLine("Arranging Layout");
            DeconflictSlotOverlay();

            //Add Tow Flag to slot record
            AddTowFlags();

            return(true);
        }
예제 #8
0
        public async Task Execute()
        {
            if (dataFromFile)
            {
                Console.WriteLine("\n======> Reading Data from files <==========");
            }
            else
            {
                Console.WriteLine("\n======> Checking AMS Access <==========");
                bool amsOK = AMSTools.IsAMSWebServiceAvailable().Result;
                if (!amsOK)
                {
                    Console.WriteLine("======> Error: Cannot access AMS <==========");
                    Console.WriteLine("\nHit Any Key to Exit..");
                    Console.ReadKey();
                    return;
                }
                else
                {
                    Console.WriteLine("======> AMS Access Confirmed <==========");
                }
            }

            try {
                if (hasAirport)
                {
                    Console.WriteLine("\n======> Checking Airports <==========");
                    XmlElement airports = await GetXML(GETAIRPORTSTemplate, Parameters.TOKEN, "http://www.sita.aero/ams6-xml-api-webservice/IAMSIntegrationService/GetAirports", Parameters.AMS_WEB_SERVICE_URI, "airports.xml");

                    Check(airports, "//ams:Airport", "./ams:AirportState/ams:Value[@propertyName='Name']", BaseType.Airport);
                }

                if (hasAirline)
                {
                    Console.WriteLine("\n======> Checking Airlines <==========");
                    XmlElement airlines = await GetXML(GETAIRLINESTemplate, Parameters.TOKEN, "http://www.sita.aero/ams6-xml-api-webservice/IAMSIntegrationService/GetAirlines", Parameters.AMS_WEB_SERVICE_URI, "airlines.xml");

                    Check(airlines, "//ams:Airline", "./ams:AirlineState/ams:Value[@propertyName='Name']", BaseType.Airline);
                }

                if (hasAircraft)
                {
                    Console.WriteLine("\n======> Checking Aircraft <==========");
                    XmlElement aircrafts = await GetXML(GETAIRCRAFTSTemplate, Parameters.TOKEN, "http://www.sita.aero/ams6-xml-api-webservice/IAMSIntegrationService/GetAircrafts", Parameters.AMS_WEB_SERVICE_URI, "aircrafts.xml");

                    Check(aircrafts, "//ams:Aircraft", "./ams:AircraftId/ams:Registration", BaseType.Aircraft);
                }

                if (hasAircraftType)
                {
                    Console.WriteLine("\n======> Checking Aircraft Types <==========");
                    XmlElement actypes = await GetXML(GETAIRCRAFTTYPESSTemplate, Parameters.TOKEN, "http://www.sita.aero/ams6-xml-api-webservice/IAMSIntegrationService/GetAircraftTypes", Parameters.AMS_WEB_SERVICE_URI, "actypes.xml");

                    Check(actypes, "//ams:AircraftType", "./ams:AircraftTypeState/ams:Value[@propertyName='Name']", BaseType.AircraftType);
                }

                if (hasCheckins)
                {
                    Console.WriteLine("\n======> Checking Checkins <==========");
                    string uri    = Parameters.AMS_REST_SERVICE_URI + $"{Parameters.APT_CODE}/CheckIns";
                    string result = AMSTools.GetRestURI(uri).Result;
                    Check(result, BaseType.Checkin);
                }
                if (hasGates)
                {
                    Console.WriteLine("\n======> Checking Gates <==========");
                    string uri    = Parameters.AMS_REST_SERVICE_URI + $"{Parameters.APT_CODE}/Gates";
                    string result = AMSTools.GetRestURI(uri).Result;
                    Check(result, BaseType.Gate);
                }
                if (hasStands)
                {
                    Console.WriteLine("\n======> Checking Stands <==========");
                    string uri    = Parameters.AMS_REST_SERVICE_URI + $"{Parameters.APT_CODE}/Stands";
                    string result = AMSTools.GetRestURI(uri).Result;
                    Check(result, BaseType.Stand);
                }
                if (hasCarousels)
                {
                    Console.WriteLine("\n======> Checking Carousels <==========");
                    string uri    = Parameters.AMS_REST_SERVICE_URI + $"{Parameters.APT_CODE}/Carousels";
                    string result = AMSTools.GetRestURI(uri).Result;
                    Check(result, BaseType.Carousel);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                Console.WriteLine("\nHit Any Key to Exit..");
                Console.ReadKey();
            }

            Console.WriteLine("\nHit Any Key to Exit..");
            Console.ReadKey();
        }
예제 #9
0
        private static int GetFlight(FlightOptions opts)
        {
            if (!AMSTools.FileOK(opts.FileName))
            {
                return(-1);
            }

            var t = GetFromToTime(opts.Today, opts.Yesterday, opts.Tomorrow, opts.From, opts.To);

            if (t == null)
            {
                return(-1);
            }


            double fromOffset = (t.Item1 - DateTime.Now).TotalDays;
            double toOffset   = (t.Item2 - DateTime.Now).TotalDays;

            int start = Convert.ToInt32(Math.Floor(fromOffset));
            int stop  = Convert.ToInt32(Math.Ceiling(toOffset));


            string result = @"<Flights xmlns=""http://www.sita.aero/ams6-xml-api-datatypes>"">";

            for (int off = start; off <= stop; off++)
            {
                bool     found = false;
                DateTime date  = DateTime.Now.AddDays(off);

                using (AMSIntegrationServiceClient client = new AMSIntegrationServiceClient(AMSTools.GetWSBinding(), AMSTools.GetWSEndPoint())) {
                    FlightId arr = AMSTools.GetFlightID(true, opts.Airline, opts.FlightNum, off);

                    try {
                        XmlElement res = client.GetFlight(Parameters.TOKEN, arr);

                        if (!res.OuterXml.Contains("FLIGHT_NOT_FOUND"))
                        {
                            found   = true;
                            result += res.OuterXml;
                            Console.WriteLine($"Arrival Flight {opts.Airline}{opts.FlightNum} found for {date}");
                        }
                    } catch (Exception e) {
                        Console.WriteLine(e.Message);
                    }


                    FlightId dep = AMSTools.GetFlightID(false, opts.Airline, opts.FlightNum, off);

                    try {
                        XmlElement res = client.GetFlight(Parameters.TOKEN, dep);
                        if (!res.OuterXml.Contains("FLIGHT_NOT_FOUND"))
                        {
                            found   = true;
                            result += res.OuterXml;
                            Console.WriteLine($"Departure Flight {opts.Airline}{opts.FlightNum} found for {date}");
                        }
                    } catch (Exception e) {
                        Console.WriteLine(e.Message);
                    }
                }

                if (!found)
                {
                    Console.WriteLine($"Flight {opts.Airline}{opts.FlightNum} not found for {date}");
                }
            }

            result += "</Flights>";

            if (opts.CSV)
            {
                //Output in CSV format
                AMSTools.Out(GetCSV(result, "Flight", BaseType.Flight, ".//ams:FlightState", opts.FlightNum, opts.Linked), opts.FileName);
            }
            else
            {
                //Output in XML format
                AMSTools.Out(AMSTools.PrintXML(result), opts.FileName);
            }

            return(1);
        }
예제 #10
0
        private static int GetFlights(FlightsOptions opts)
        {
            if (!AMSTools.FileOK(opts.FileName))
            {
                return(-1);
            }

            var t = GetFromToTime(opts.Today, opts.Yesterday, opts.Tomorrow, opts.From, opts.To);

            if (t == null)
            {
                return(-1);
            }

            using (AMSIntegrationServiceClient client = new AMSIntegrationServiceClient(AMSTools.GetWSBinding(), AMSTools.GetWSEndPoint())) {
                try {
                    XmlElement res = client.GetFlights(Parameters.TOKEN, t.Item1, t.Item2, Parameters.APT_CODE, AirportIdentifierType.IATACode);

                    if (!res.OuterXml.Contains("FLIGHT_NOT_FOUND"))
                    {
                        if (opts.Airline == null)
                        {
                            // If there is no specific airline specified

                            if (opts.CSV)
                            {
                                //Output in CSV format
                                AMSTools.Out(GetCSV(res.OuterXml, "Flight", BaseType.Flight, ".//ams:FlightState"), opts.FileName);
                            }
                            else
                            {
                                //Output in XML format
                                AMSTools.Out(AMSTools.PrintXML(res.OuterXml), opts.FileName);
                            }
                        }
                        else
                        {
                            // A specifc airline was requested
                            XmlNamespaceManager nsmgr = new XmlNamespaceManager(res.OwnerDocument.NameTable);
                            nsmgr.AddNamespace("ams", "http://www.sita.aero/ams6-xml-api-datatypes");

                            string result = @"<Flights xmlns=""http://www.sita.aero/ams6-xml-api-datatypes>"">";

                            foreach (XmlElement el in res.SelectNodes("//ams:Flights/ams:Flight", nsmgr))
                            {
                                {
                                    XmlNamespaceManager nsmgr2 = new XmlNamespaceManager(el.OwnerDocument.NameTable);
                                    nsmgr2.AddNamespace("ams", "http://www.sita.aero/ams6-xml-api-datatypes");

                                    XmlNode node = el.SelectSingleNode("//ams:FlightId/ams:AirlineDesignator[@codeContext='IATA']", nsmgr2);
                                    if (node?.InnerText == opts.Airline)
                                    {
                                        result += el.OuterXml;
                                    }
                                    else
                                    {
                                        Console.WriteLine($"Flight rejected. Airline Code = {node.InnerText}");
                                    }
                                }
                            }
                            result += "</Flights>";

                            if (opts.CSV)
                            {
                                //Output in CSV format
                                AMSTools.Out(GetCSV(result, "Flight", BaseType.Flight, ".//ams:FlightState"), opts.FileName);
                            }
                            else
                            {
                                //Output in XML format
                                AMSTools.Out(AMSTools.PrintXML(result), opts.FileName);
                            }
                        }
                    }
                } catch (Exception e) {
                    Console.WriteLine(e.Message);
                }
            }


            return(1);
        }
예제 #11
0
        private static void ShowConfig(Options opts)
        {
            if (opts.CheckAMS)
            {
                Console.WriteLine("\nChecking connection to AMS..");
                if (AMSTools.IsAMSWebServiceAvailable().Result)
                {
                    Console.WriteLine("..AMS Native Web Service Available");
                }
                else
                {
                    Console.WriteLine("..AMS Native Web Service NOT Available");
                }
                if (AMSTools.IsAMSRestServiceAvailable())
                {
                    Console.WriteLine("..AMS RestAPI Service Available");
                }
                else
                {
                    Console.WriteLine("..AMS RestAPI Service NOT Available");
                }
            }

            if (opts.Token != null)
            {
                XElement config = ReadConfigFile();
                XElement node   = config.Descendants("add").FirstOrDefault(el => el.Attribute("key").Value == "Token");
                node.Attribute("value").Value = opts.Token;
                config.Save(@"AMSUtilLib.dll.config");
            }
            if (opts.AptCode != null)
            {
                XElement config = ReadConfigFile();
                XElement node   = config.Descendants("add").FirstOrDefault(el => el.Attribute("key").Value == "IATAAirportCode");
                node.Attribute("value").Value = opts.AptCode;
                config.Save(@"AMSUtilLib.dll.config");
            }
            if (opts.RestURL != null)
            {
                XElement config = ReadConfigFile();
                XElement node   = config.Descendants("add").FirstOrDefault(el => el.Attribute("key").Value == "AMSRestServiceURI");
                node.Attribute("value").Value = opts.RestURL;
                config.Save(@"AMSUtilLib.dll.config");
            }
            if (opts.WSURL != null)
            {
                XElement config = ReadConfigFile();
                XElement node   = config.Descendants("add").FirstOrDefault(el => el.Attribute("key").Value == "AMSWebServiceURI");
                node.Attribute("value").Value = opts.WSURL;
                config.Save(@"AMSUtilLib.dll.config");
            }


            Type type = typeof(Parameters);

            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type.TypeHandle);

            if (opts.Verbose)
            {
                Console.WriteLine($"\nAMS Rest Server URI:         {Parameters.AMS_REST_SERVICE_URI}");
                Console.WriteLine($"AMS Web Services Server URI: {Parameters.AMS_WEB_SERVICE_URI}");
                Console.WriteLine($"AMS Access Token:            {Parameters.TOKEN}");
                Console.WriteLine($"Airport Code:                {Parameters.APT_CODE}");
            }
        }