예제 #1
0
        public bool PTMEquals(PTMRow node)
        {
            try
            {
                foreach (string key in valueMap.Keys)
                {
                    if (valueMap[key] != node.valueMap[key])
                    {
                        return(false);
                    }
                }

                // Just in case a new element has been added to the record
                foreach (string key in node.valueMap.Keys)
                {
                    if (node.valueMap[key] != valueMap[key])
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Trace(ex.Message);
                return(false);
            }

            return(true);
        }
예제 #2
0
        public FlightNode(PTMRow flight, string kind, string airport)
        {
            flightKind = kind;
            airlineDesignatorIATA = flight.airline;
            scheduledDate = flight.sto;
            flightNumber = flight.flight;
            airportCodeIATA = airport;

            flightKey = airlineDesignatorIATA + flightNumber + scheduledDate.Substring(0, 10);
        }
예제 #3
0
        private string ConstructSOAPMessage(List <XmlNode> retainedPTMs, FlightNode depFlight, PTMRow ptm)
        {
            // The top part of the message which includes the departing flight info
            string soapUpdateMessage = updateFlightExtendedTop
                                       .Replace("@token", Parameters.TOKEN)
                                       .Replace("@iataAirline", depFlight.airlineDesignatorIATA)
                                       .Replace("@icaoAirline", depFlight.airlineDesignatorICAO)
                                       //                .Replace("@iataAirport", depFlight.airportCodeIATA)
                                       .Replace("@iataAirport", Parameters.HOME_AIRPORT_IATA)
                                       .Replace("@icaoAirport", depFlight.airportCodeICAO)
                                       .Replace("@fltNum", depFlight.flightNumber)
                                       .Replace("@sto", depFlight.scheduledDate);


            // The TableValue Construction for each of the PTMs
            string tableRowEntries = "";

            foreach (XmlNode node in retainedPTMs)
            {
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(node.OwnerDocument.NameTable);
                nsmgr.AddNamespace("ams", "http://www.sita.aero/ams6-xml-api-datatypes");
                nsmgr.AddNamespace("amsmess", "http://www.sita.aero/ams6-xml-api-messages");
                XmlNodeList values = node.SelectNodes(".//ams:Value", nsmgr);

                string rowEntry = tableRowTemplateTop;
                foreach (XmlNode value in values)
                {
                    string key = value.Attributes["propertyName"].InnerText;
                    string v   = value.InnerText;

                    rowEntry += tableRowPropertyTemplate.Replace("@field", key).Replace("@value", v);
                }

                rowEntry        += tableRowTemplateBottom;
                tableRowEntries += rowEntry;
            }

            //So we now have to add the updated or additional PTM
            if (ptm != null)
            {
                string rowEntry = tableRowTemplateTop;
                foreach (string key in ptm.valueMap.Keys)
                {
                    rowEntry += tableRowPropertyTemplate.Replace("@field", key).Replace("@value", ptm.valueMap[key]);
                }

                rowEntry        += tableRowTemplateBottom;
                tableRowEntries += rowEntry;
            }


            // Complete constructing the message by adding the bottom part of the message
            soapUpdateMessage += tableRowEntries + updateFlightExtendedBottomFixed;

            if (Parameters.DEEPTRACE)
            {
                logger.Trace(soapUpdateMessage);
            }

            logger.Trace(soapUpdateMessage);

            return(soapUpdateMessage);
        }
예제 #4
0
        private async Task UpdateDeprtaureFlightPTMEntriesAsync(List <XmlNode> retainedPTMs, FlightNode depFlight, PTMRow ptm)
        {
            string soapUpdateMessage = this.ConstructSOAPMessage(retainedPTMs, depFlight, ptm);


            // Send the message via the AMS WebServices endpoint
            try
            {
                logger.Info($"Updating Departure Flight {depFlight.flightKey}");
                using (var client = new HttpClient())
                {
                    HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, Parameters.BASE_URI)
                    {
                        Content = new StringContent(soapUpdateMessage, Encoding.UTF8, "text/xml")
                    };
                    requestMessage.Headers.Add("SOAPAction", "http://www.sita.aero/ams6-xml-api-webservice/IAMSIntegrationService/UpdateFlightExtended");

                    using (HttpResponseMessage response = await client.SendAsync(requestMessage))
                    {
                        if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted || response.StatusCode == HttpStatusCode.Created || response.StatusCode == HttpStatusCode.NoContent)
                        {
                            logger.Trace($"Update of departure Flight Succeeded OK. Departure Flight {depFlight.flightKey} ");
                            _ = ProcessResponse(response);

                            return;
                        }
                        else
                        {
                            logger.Error("Error Updating Departure Flight");
                            logger.Error(response.StatusCode);
                            if (logger.IsTraceEnabled)
                            {
                                _ = ProcessErrorResponse(response);
                            }
                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.StackTrace);
                return;
            }
        }
예제 #5
0
        public async Task <bool> DispatchUpdateToDepartureFlight(FlightNode arrFlight, FlightNode depFlight, PTMRow updateOrAddPTM = null)
        {
            // arrFlight - the flight node for the arriving flight
            // ptm - the PTM record that has to be removed from a departure flight

            XmlNode depFlightNode = await this.GetFlight(depFlight);

            if (depFlightNode == null || depFlightNode.OuterXml.Contains("FLIGHT_NOT_FOUND"))
            {
                logger.Trace($"Departure Flight Not Found: {depFlight.flightKey }");
                return(false);
            }
            else
            {
                logger.Trace($"Departure Flight Found: {depFlight.flightKey }");
            }

            XmlNode departurePTMSNodes = GetTransfersFromFlight(depFlightNode);

            if (departurePTMSNodes == null)
            {
                logger.Trace($"No PTM Entries were found in departure flight: {depFlight.flightKey }");

                //If this was only a delete, then we can return now
                if (updateOrAddPTM == null)
                {
                    return(true);
                }
            }

            // A list for holding the PTMs we want to retain
            List <XmlNode> retainedPTMs = new List <XmlNode>();

            if (departurePTMSNodes != null)
            {
                foreach (XmlNode node in departurePTMSNodes)
                {
                    PTMRow departurePTMEntry = new PTMRow(node);

                    // If the flight keys are the same, then don't add it to the list. For Updates and Addtions
                    // the updatePTM will be passed along the chain so it is added

                    if (arrFlight.flightKey != departurePTMEntry.flightKey)
                    {
                        retainedPTMs.Add(node);
                    }
                }
            }

            // The updatePTM has the departure flight information in it, so We need to modify it so it has the arrival flight information in it
            if (updateOrAddPTM != null)
            {
                updateOrAddPTM.valueMap["Sl--_AirlineIATA"]  = arrFlight.airlineDesignatorIATA;
                updateOrAddPTM.valueMap["Sl--_FlightNumber"] = arrFlight.flightNumber;
                if (Parameters.STO_DATETIME)
                {
                    updateOrAddPTM.valueMap["dl--_STO"] = arrFlight.scheduledDate + "T00:00:00";
                }
                else
                {
                    updateOrAddPTM.valueMap["dl--_STO"] = arrFlight.scheduledDate;
                }
            }

            _ = UpdateDeprtaureFlightPTMEntriesAsync(retainedPTMs, depFlight, updateOrAddPTM);

            return(true);
        }
예제 #6
0
        public bool UpdateOrAddOrRemovePTMFromDepartureFlight(FlightNode arrFlight, FlightNode depFlight, PTMRow updateOrAddPTM = null)
        {
            _dispatcherList.Add(new Tuple <FlightNode, FlightNode, PTMRow>(arrFlight, depFlight, updateOrAddPTM));



            return(true);
        }
예제 #7
0
        public Tuple <List <PTMRow>, List <PTMRow>, List <PTMRow> > ClassifyTransferChanges(XmlNode transferChanges)
        {
            /*
             * Determine the entries which are additions, updates and deletions
             */

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(transferChanges.OwnerDocument.NameTable);

            nsmgr.AddNamespace("ams", "http://www.sita.aero/ams6-xml-api-datatypes");
            nsmgr.AddNamespace("amsmess", "http://www.sita.aero/ams6-xml-api-messages");

            // Tne XML node containing the old entries
            XmlNode oldNode;

            try
            {
                oldNode = transferChanges.SelectSingleNode(".//ams:OldValue[@propertyName='Tl--_TransferLoads']", nsmgr);
            }
            catch (Exception)
            {
                logger.Trace("Old Transfer Values Not Found");
                return(null);
            }

            // The XML node containing the new entries
            XmlNode newNode;

            try
            {
                newNode = transferChanges.SelectSingleNode(".//ams:NewValue[@propertyName='Tl--_TransferLoads']", nsmgr);
            }
            catch (Exception)
            {
                logger.Trace("New Transfer Values Not Found");
                return(null);
            }

            //Create a list of the Old entries
            List <PTMRow> oldList = new List <PTMRow>();

            try
            {
                foreach (XmlNode row in oldNode.SelectNodes(".//ams:Row", nsmgr))
                {
                    PTMRow ptmRow = new PTMRow(row);
                    if (Parameters.DEEPTRACE)
                    {
                        logger.Trace($"Old Values Entry {ptmRow.ToString()}");
                    }
                    oldList.Add(ptmRow);
                }
            }
            catch (Exception e)
            {
                logger.Trace(e.Message);
                return(null);
            }

            // Create a list of the new entries
            List <PTMRow> newList = new List <PTMRow>();

            try
            {
                foreach (XmlNode row in newNode.SelectNodes(".//ams:Row", nsmgr))
                {
                    PTMRow ptmRow = new PTMRow(row);
                    if (Parameters.DEEPTRACE)
                    {
                        logger.Trace($"New Values Entry {ptmRow.ToString()}");
                    }
                    newList.Add(ptmRow);
                }
            }
            catch (Exception e)
            {
                logger.Trace(e.Message);
                return(null);
            }

            // Examine the list to create a new list of the adds, updates and deletes
            List <PTMRow> additionsList = GetAdditions(oldList, newList);
            List <PTMRow> updateList    = GeUpdates(oldList, newList);
            List <PTMRow> deleteList    = GetDeletions(oldList, newList);

            //Print out the individual lists of logging is enabled.
            if (logger.IsTraceEnabled)
            {
                logger.Trace("Addition List:");
                foreach (PTMRow row in additionsList)
                {
                    logger.Trace(row.ToString);
                }

                logger.Trace("Updates List:");
                foreach (PTMRow row in updateList)
                {
                    logger.Trace(row.ToString);
                }

                logger.Trace("Delete List:");
                foreach (PTMRow row in deleteList)
                {
                    logger.Trace(row.ToString);
                }
            }

            return(new Tuple <List <PTMRow>, List <PTMRow>, List <PTMRow> >(additionsList, updateList, deleteList));
        }
예제 #8
0
 // Is the supplied node referring to the same flight as this node?
 public bool FlightEquals(PTMRow node)
 {
     return(node.flightKey == this.flightKey);
 }