//---------------------------------------------------------------------------------------------------------------------
        public BookingManager.PriceItineraryRequest GetPriceIntineraryRequest(int numadt, int numchd, String faretype, String currency, String sourceorg, String agentcode, GetAvailabilityResponse availresponse)
        {
            PriceItineraryRequest priceitinrequest = new PriceItineraryRequest();
            priceitinrequest.Signature = signature;
            priceitinrequest.ItineraryPriceRequest = new ItineraryPriceRequest();// this is from service contract class
            priceitinrequest.ItineraryPriceRequest.TypeOfSale = new TypeOfSale();
            priceitinrequest.ItineraryPriceRequest.TypeOfSale.FareTypes = new string[1];
            priceitinrequest.ItineraryPriceRequest.TypeOfSale.FareTypes[0] = faretype;
            priceitinrequest.ItineraryPriceRequest.SSRRequest = new SSRRequest();

            priceitinrequest.ItineraryPriceRequest.PriceItineraryBy = PriceItineraryBy.JourneyWithLegs;

            SellJourneyByKeyRequestData sellkeyrequest = new SellJourneyByKeyRequestData();
            priceitinrequest.ItineraryPriceRequest.SellByKeyRequest = sellkeyrequest;

            PriceJourneyRequestData pricerequest = new PriceJourneyRequestData();
            pricerequest.CurrencyCode = currency;
            pricerequest.PaxCount = (short)(numadt + numchd);// to check if this is required

            //setting up the paxdetails to get the pricing correctly, must follow my get avaialbility function call
            pricerequest.Passengers = new Passenger[numadt + numchd];

            for (int i = 0; i < (numadt + numchd); i++)
            {
                pricerequest.Passengers[i] = new Passenger();// instantiate to avoid Null Pointer Exception error
                pricerequest.Passengers[i].State = MessageState.New;

               pricerequest.Passengers[i].PassengerTypeInfos = new PassengerTypeInfo[1];//change back to 1 if it does not work
               pricerequest.Passengers[i].PassengerTypeInfos[0] = new PassengerTypeInfo();//change back PassengerTypeInfos to 0 if it doesnt work

                if (i < numadt)
                {
                    pricerequest.Passengers[i].PassengerTypeInfos[0].PaxType = "ADT";
                }
                else
                {
                    pricerequest.Passengers[i].PassengerTypeInfos[0].PaxType = "CHD";
                }

                pricerequest.Passengers[i].PassengerTypeInfos[0].DOB = DateTime.Parse("0001-01-01");

            }
            //new set input on 20nd March
            SellRequest sellrequest = new SellRequest();
            sellrequest.Signature = signature;
            sellrequest.SellRequestData = new SellRequestData();
            sellrequest.SellRequestData.SellBy = SellBy.Journey;
            sellrequest.SellRequestData.SellJourneyRequest = new SellJourneyRequest();
            SellResponse sellresponse = clientapi.Sell(sellrequest);
            //end of input

            pricerequest.PriceJourneys = new PriceJourney[1];// set this to 1 for a 1 way trip

            for (int i = 0; i < pricerequest.PriceJourneys.Length; i++)
            {
                pricerequest.PriceJourneys[i] = new PriceJourney();

                // now i need to get all the available segments for price itinerary

                Segment[] segment = availresponse.GetTripAvailabilityResponse.Schedules[i][0].Journeys[0].Segments;

                //i want to use the flight designator object for the segment as it contains the carriercode, flight number used to identify a flight
                Console.WriteLine("Flight Number is :" + segment[i].FlightDesignator.CarrierCode + " " + segment[i].FlightDesignator.FlightNumber);
                Console.WriteLine("FlightTiming is : " + segment[i].STD + " " + segment[i].STA);

                PriceSegment[] pricesegment = new PriceSegment[segment.Length];//find the pricing of that particular segment : for a 1 way journey with 2 points, it will be 1 segment

                SegmentSSRRequest[] ssrRequest = new SegmentSSRRequest[segment.Length];

                for (int j = 0; j < segment.Length; j++)
                {

                    //to setup the segment details and equate the values of price to segment

                    pricesegment[j] = new PriceSegment();
                    pricesegment[j].ActionStatusCode = "NN";
                    pricesegment[j].FlightDesignator = segment[j].FlightDesignator;
                    pricesegment[j].DepartureStation = segment[j].DepartureStation;
                    pricesegment[j].ArrivalStation = segment[j].ArrivalStation;
                    pricesegment[j].STA = pricesegment[j].STA;

                    //SSR setup

                    ssrRequest[j] = new SegmentSSRRequest();
                    ssrRequest[j].DepartureStation = segment[j].DepartureStation;
                    ssrRequest[j].ArrivalStation = segment[j].ArrivalStation;
                    ssrRequest[j].FlightDesignator = segment[j].FlightDesignator;
                    ssrRequest[j].STD = segment[j].STD;

                    //now assume that 1 SSR is tied to 1 passenger to 1 direct flight

                    ssrRequest[j].PaxSSRs = new PaxSSR[1];
                    ssrRequest[j].PaxSSRs[0] = new PaxSSR();
                    ssrRequest[j].PaxSSRs[0].ActionStatusCode = "SS";
                    ssrRequest[j].PaxSSRs[0].DepartureStation = segment[j].DepartureStation;
                    ssrRequest[j].PaxSSRs[0].ArrivalStation = segment[j].ArrivalStation;
                    ssrRequest[j].PaxSSRs[0].SSRCode = "BG20";// type of SSR
                    ssrRequest[j].PaxSSRs[0].SSRNumber = 0;//this is the index of the passenger array, tag the SSR to the first passenger

                    //now set up the Fare according to the GetAvailability Response, no need to choose the option- same as Booking2

                    Fare fare = segment[j].Fares[0];
                    pricesegment[j].Fare = new SellFare();
                    pricesegment[j].Fare.CarrierCode = fare.CarrierCode;
                    pricesegment[j].Fare.ClassOfService = fare.ClassOfService;
                    pricesegment[j].Fare.FareApplicationType = fare.FareApplicationType;
                    pricesegment[j].Fare.FareBasisCode = fare.FareBasisCode;
                    pricesegment[j].Fare.ProductClass = fare.ProductClass;
                    pricesegment[j].Fare.RuleNumber = fare.RuleNumber;
                }
                priceitinrequest.ItineraryPriceRequest.SSRRequest.SegmentSSRRequests = ssrRequest;

                priceitinrequest.ItineraryPriceRequest.PriceItineraryBy = PriceItineraryBy.JourneyWithLegs;
                priceitinrequest.ItineraryPriceRequest.PriceJourneyWithLegsRequest = pricerequest;

            }

            if (sourceorg.Length > 0)
            {
                pricerequest.SourcePOS = new PointOfSale();
                pricerequest.SourcePOS.AgentCode = agentcode;
                pricerequest.SourcePOS.OrganizationCode = sourceorg;
                pricerequest.SourcePOS.DomainCode = "EXT";
                pricerequest.SourcePOS.LocationCode = "API";
            }
            else
            {
                pricerequest.SourcePOS = null;
            }
            //sell my SSR on 22nd March -new input
            if (priceitinrequest.ItineraryPriceRequest.SSRRequest.SegmentSSRRequests != null)
            {
                sellrequest.SellRequestData = new SellRequestData();
                sellrequest.SellRequestData.SellSSR = new SellSSR();
                sellrequest.SellRequestData.SellSSR.SSRRequest = priceitinrequest.ItineraryPriceRequest.SSRRequest;
                sellrequest.SellRequestData.SellBy = SellBy.SSR;
                sellresponse = clientapi.Sell(sellrequest);
                System.Console.WriteLine("Total Flight + SSR cost {0:C}", sellresponse.BookingUpdateResponseData.Success.PNRAmount.TotalCost);
            }
            //end of SSR code

            return priceitinrequest;
        }
示例#2
0
        private ParseResult parseChatLine(short authTokenId, string serverCode, string logLine, DateTime timeStamp, TunnelQuestContext context)
        {
            var newLine = new ChatLine();

            newLine.AuthTokenId = authTokenId;
            newLine.ServerCode  = serverCode;
            newLine.SentAt      = timeStamp;

            string[] lineWords = logLine.Split(' ', StringSplitOptions.None);

            try
            {
                if (lineWords.Length < 3 || lineWords[1] != "auctions,")
                {
                    throw new InvalidLogLineException(logLine);
                }
            }
            catch (IndexOutOfRangeException)
            {
                throw new InvalidLogLineException(logLine);
            }

            newLine.PlayerName = lineWords[0];
            string playerTypedText = String.Join(' ', lineWords, 2, lineWords.Length - 2).Trim('\'');

            var segments = parseItemNames(playerTypedText, timeStamp);

            // At this point, the only types of segments in Segments are TextSegments and ItemNameSegments.  We want
            // to loop through and attempt to replace each of the generic TextSegments (which represent unrecognized text)
            // with more specific Segments which represent recognized data elements.

            for (int i = 0; i < segments.Count; i++)
            {
                var segment = segments[i];
                if (segment.GetType() == typeof(TextSegment))
                {
                    if (segment.Text.Contains(ChatLogic.CHAT_TOKEN))
                    {
                        // in case anybody tries to be mischevious and actually type the token string into chat
                        segments[i] = new TextSegment("clever girl", segment.HasPrecedingSpace);
                    }
                    else
                    {
                        TextSegment parsedSegment = PriceSegment.TryParse(segments, i);

                        if (parsedSegment == null)
                        {
                            parsedSegment = SeparatorSegment.TryParse(segment);
                        }

                        if (parsedSegment == null)
                        {
                            parsedSegment = BuySellTradeSegment.TryParse(segment);
                        }

                        if (parsedSegment == null)
                        {
                            parsedSegment = OrBestOfferSegment.TryParse(segments, i);
                        }

                        if (parsedSegment != null)
                        {
                            segments[i] = parsedSegment;
                        }
                    }
                }
            }

            // Now that we've parsed all the segments we can recognize, go back through  and see if we
            // can intuit any non-linked auctions (e.g. "WTS jboots mq 5k")

            for (int i = 0; i < segments.Count; i++)
            {
                if (segments[i].GetType() == typeof(TextSegment))
                {
                    // First, merge this TextSegment with any other TextSegments that come immediately after it
                    var indexesToMerge = new List <int>();
                    indexesToMerge.Add(i);
                    string mergedText = segments[i].Text;
                    bool   mergedTextHasPrecedingSpace = segments[i].HasPrecedingSpace;
                    for (int j = i + 1; j < segments.Count; j++)
                    {
                        if (segments[j].GetType() == typeof(TextSegment))
                        {
                            indexesToMerge.Add(j);

                            if (segments[j].HasPrecedingSpace)
                            {
                                mergedText += ' ';
                            }
                            mergedText += segments[j].Text;
                        }
                        else
                        {
                            break;
                        }
                    }
                    indexesToMerge.Reverse(); // delete indexes from back-to-front so that each deleted index doesn't shift the remaining ones into new positions
                    foreach (int index in indexesToMerge)
                    {
                        segments.RemoveAt(index);
                    }

                    // Now that we've got a string containing the text of all the adjacent TextSegments, decide
                    // whether it's something we should create an auction for
                    bool createAuction;

                    // Assume that any unrecognized text which comes *immediately* before or after after an item link is a
                    // description of the item, and *not* something we should create an auction for.
                    if (i > 0 && segments[i - 1] is ItemNameSegment)
                    {
                        createAuction = false;
                    }
                    else if (i < segments.Count && segments[i] is ItemNameSegment)
                    {
                        createAuction = false;
                    }
                    else if (mergedText.StartsWith("PST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        createAuction = false;
                    }
                    else
                    {
                        createAuction = true;
                    }

                    // STUB TODO - will probably end up adding more fine-tuned logic here after testing more
                    // real world auction logs

                    if (createAuction)
                    {
                        segments.Insert(i, new ItemNameSegment(mergedText, mergedText.Trim(), false, mergedTextHasPrecedingSpace)); // the .Trim() is important
                    }
                    else
                    {
                        segments.Insert(i, new TextSegment(mergedText, mergedTextHasPrecedingSpace));
                    }
                }
            }

            // Now that we've created all of the ItemNameSegments, loop through all the segments one last time and
            // use their values to build the Auction objects.  If the same item name is found more than once, only create
            // one single auction for the item.

            var auctions = new Dictionary <string, Auction>();
            BuySellTradeSegment lastFoundBuySellTrade = null;
            var itemsSinceLastSeparator = new List <ItemNameSegment>();

            for (int i = 0; i < segments.Count; i++)
            {
                var segment = segments[i];

                if (segment is ItemNameSegment)
                {
                    var itemNameSegment = (ItemNameSegment)segment;

                    itemsSinceLastSeparator.Add(itemNameSegment);

                    Auction auction;
                    if (auctions.ContainsKey(itemNameSegment.ItemName))
                    {
                        auction = auctions[itemNameSegment.ItemName];
                    }
                    else
                    {
                        auction = new Auction()
                        {
                            ChatLine    = newLine,
                            ChatLineId  = newLine.ChatLineId,
                            ServerCode  = newLine.ServerCode,
                            PlayerName  = newLine.PlayerName,
                            ItemName    = itemNameSegment.ItemName,
                            AliasText   = itemNameSegment.AliasText,
                            IsKnownItem = itemNameSegment.IsKnownItem,
                            IsPermanent = true,
                            CreatedAt   = newLine.SentAt
                        };
                        newLine.Auctions.Add(auction);

                        auctions.Add(itemNameSegment.ItemName, auction);
                    }

                    itemNameSegment.Auction = auction;

                    if (lastFoundBuySellTrade != null)
                    {
                        if (lastFoundBuySellTrade.IsBuying != null)
                        {
                            auction.IsBuying = lastFoundBuySellTrade.IsBuying.Value;
                        }
                        if (lastFoundBuySellTrade.IsAcceptingTrades != null)
                        {
                            auction.IsAcceptingTrades = lastFoundBuySellTrade.IsAcceptingTrades.Value;
                        }
                    }
                }
                else if (segment is BuySellTradeSegment)
                {
                    lastFoundBuySellTrade = ((BuySellTradeSegment)segment);
                }
                else if (segment is PriceSegment)
                {
                    var priceSegment = (PriceSegment)segment;

                    var itemSegmentIndexesWithThisPrice = new List <int>();
                    foreach (var itemNameSegment in itemsSinceLastSeparator)
                    {
                        var auction = auctions[itemNameSegment.ItemName];

                        if (auction.Price == null)
                        {
                            auction.Price = priceSegment.Price;
                        }
                    }
                }
                else if (segment is OrBestOfferSegment)
                {
                    foreach (var itemNameSegment in itemsSinceLastSeparator)
                    {
                        var auction = auctions[itemNameSegment.ItemName];

                        if (auction.Price != null)
                        {
                            auction.IsOrBestOffer = true;
                        }
                    }
                }
                else if (segment is SeparatorSegment)
                {
                    itemsSinceLastSeparator.Clear();
                }
            }

            // now that all the segments have been evaluated and the Auctions contain their final values,
            // update any previously existing auctions as necessary
            var auctionLogic = new AuctionLogic(context);

            foreach (var auction in newLine.Auctions)
            {
                auctionLogic.UpdateReplacedAuctions(auction);
            }

            return(new ParseResult()
            {
                ChatLine = newLine,
                Segments = segments
            });
        }