コード例 #1
0
        /// <inheritdoc />
        /// <summary>
        /// Load a <see cref="Coach" /> from a set of comma-separated values.
        /// </summary>
        /// <param name="data">The comma-separated <see cref="Coach" /> data.</param>
        /// <returns>
        /// A boolean indicating the result of the load.
        /// </returns>
        public override bool Load(string data)
        {
            if (!base.Load(data))
            {
                return(false);
            }

            string[] parts = data.Split(',');
            if (parts.Length < 6)
            {
                Logger.LogFunctionEntry(string.Empty, "Failed to load coach! Missing parameters.");
                return(false);
            }

            switch (parts[5])
            {
            case "Hands-on":
                Type = CoachType.HandsOn;
                break;

            case "Support":
                Type = CoachType.Support;
                break;

            default:
                Logger.LogFunctionEntry(string.Empty, "Failed to load coach! Could not convert coach type.");
                return(false);
            }

            return(true);
        }
コード例 #2
0
 public Task <Train> FetchTrainAsync(DateTime date, Station source, Station destination, string trainNumber)
 {
     return(Task.FromResult(Train.Create(
                                GetTrainNumber(), source, destination,
                                date.Date.AddHours(7).AddMinutes(15),
                                date.Date.AddHours(21).AddMinutes(53),
                                new[] { CoachType.Create("Platzkarte", "П", 5), CoachType.Create("Coupe", "К", 10) }
                                )));
 }
コード例 #3
0
ファイル: UzService.cs プロジェクト: RainmakerUA/uzticket-net
        public Task <Coach[]> ListCoachesAsync(Train train, CoachType coachType)
        {
            var data = new IPersistable[] { train, coachType }.ToRequestDictionary(
                new Dictionary <string, string>
            {
                ["another_ec"] = "0"
            });

            return(GetJsonAsync <Coach[]>("train_wagons/", data: data, jsonKey: "wagons"));
        }
コード例 #4
0
        public async Task <Coach[]> ListCoachesAsync(Train train, CoachType coachType)
        {
            var data = new IPersistable[] { train, coachType }.ToRequestDictionary(
                new Dictionary <string, string>
            {
                ["another_ec"] = "0"
            });
            var result = await GetJson("train_wagons/", data : data);

            return(result["wagons"].Deserialize <Coach[]>());
        }
コード例 #5
0
        public async Task <Dictionary <string, int> > GetAvaliablePlacesCount(CoachType coachType)
        {
            var trainSet = await _dataContext.GetTrains();

            var placesCount = trainSet.Trains.SelectMany(train => train.AvaliableCoaches)
                              .GroupBy(coach => coach.TypeLetter)
                              .ToDictionary(gcoach => gcoach.Key, gcoach => gcoach
                                            .Sum(it => it.PlacesCount));

            return(placesCount);
        }
コード例 #6
0
        /// <summary>
        /// Convert the coach type into a serialized-safe format.
        /// </summary>
        /// <param name="coachType">The coach type.</param>
        /// <returns></returns>
        private static string ConvertCoachType(CoachType coachType)
        {
            switch (coachType)
            {
            case CoachType.HandsOn:
                return("Hands-on");

            case CoachType.Support:
                return("Support");
            }

            // If this happens, there is something terribly wrong.
            return("NULL");
        }
コード例 #7
0
        public async Task <Coach[]> ListCoachesAsync(Train train, CoachType coachType)
        {
            var data = new Dictionary <string, string>
            {
                ["from"]          = train.SourceStation.ID.ToString(),
                ["to"]            = train.DestinationStation.ID.ToString(),
                ["train"]         = train.Number,
                ["date"]          = train.DepartureTime.DateTime.ToRequestString(),
                ["wagon_type_id"] = coachType.Letter,
                ["another_ec"]    = "0"
            };
            var result = await GetJson("train_wagons/", data : data);

            return(ModelBase.FromJsonArray <Coach>(result["wagons"]));
        }
コード例 #8
0
        public async Task <List <UZCoachSet> > GetCoaches(UZTrain train, CoachType coachType)
        {
            var coaches = coachType != CoachType.Any
                ? train.AvaliableCoaches.Where(it => it.TypeLetter.Equals(UZCoachTypeMapper.GetCoachLetter(coachType)))
                : train.AvaliableCoaches;
            var coachSets = new List <UZCoachSet>();

            foreach (var coach in coaches)
            {
                var requestConfig = _translator.GetCoachesRequest(train, coach);
                var coachesSet    = await _gateway.GetCoaches(requestConfig);

                coachSets.Add(coachesSet);
            }
            return(coachSets);
        }
コード例 #9
0
        private static int countAvailavle(
            Request req, Train train, CoachType type, Coach coach, IList <IList <int> > places)
        {
            //TODO: correct time and date checking
            if (// Check if stations are correct
                req.from.StationID != train.From.ID || req.to.StationID != train.Till.ID ||
                // Check departure date frame
                !req.depDateFrame.checkInside(train.From.Date.Date) ||
                // Check departure time frame
                !req.depTimeFrame.checkInside(train.From.Date.TimeOfDay) ||
                // Check arrival time frame
                !req.arrTimeFrame.checkInside(train.Till.Date.TimeOfDay) ||
                // Check Price
                coach.Prices[0] / 100.0 > req.maxPrice ||
                // Check travel time
                (train.Till.Date - train.From.Date) > req.maxTravelTime ||
                // Check coach type TODO: FIX
                false)
            {
                return(0);
            }
            int result = 0;

            foreach (var i in places)
            {
                foreach (int place in i)
                {
                    if (// Check if lower are acceptable
                        (req.seatProps.mayLower || place % 2 == 0) &&
                        // Check if upper are acceptable
                        (req.seatProps.mayUpper || place % 2 == 1) &&
                        // Check if side are acceptable TODO: fix for different types of cars
                        (req.seatProps.maySide || place <= 36) &&
                        // Check if toilet-close are acceptable TODO: fix for diff types of carsS
                        (req.seatProps.mayToilet || Math.Abs(36 - place) > 4))
                    {
                        ++result;
                    }
                }
            }

            return(result);
        }
コード例 #10
0
        private async void CoachTypes_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                type = e.ClickedItem as CoachType;
                // TODO: fix roundTrip
                IDictionary <string, string> parameters = train.getParameters(type, false);
                string res = await Requests.makeRequestAsync(Requests.COACH_URL, parameters);

                //debugOutput.Text = res;
                CoachResponse resp = Factory.Instance.getCoachResponse(res);
                coaches.DataContext = resp.Wrapper.Coaches;
                places.DataContext  = null;
            }
            catch (Exception ex)
            {
                debugOutput.Text = ex.Message;
            }
        }
コード例 #11
0
 /// <summary>
 /// Initializes an empty <see cref="Coach"/>.
 /// </summary>
 public Coach()
 {
     Type = CoachType.HandsOn;
 }
コード例 #12
0
 /// <summary>
 /// Retrieves the number of <see cref="Coach"/> members on this <see cref="Team"/> that are of the specified <see cref="CoachType"/>.
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public int GetCoachCountOfType(CoachType type) => GetMembersOfType <Coach>().Count(member => ((Coach)member).Type == type);
コード例 #13
0
        public async Task <Dictionary <CoachType, IEnumerable <int> > > GetAvaliablePlaces(CoachType coachType = CoachType.Any)
        {
            var trainSet = await _dataContext.GetTrains();

            var coachSets = new List <UZCoachSet>();

            foreach (var train in trainSet.Trains)
            {
                var coachSetsPart = await _dataContext.GetCoaches(train, coachType);

                coachSets.AddRange(coachSetsPart);
            }
            foreach (var coachSet in coachSets)
            {
                var placesSetPart = await _dataContext.GetPlaces(coachSet);

                _placesSets.AddRange(placesSetPart);
            }
            var placesPerCoach = _placesSets.GroupBy(set => set.OwnerRequest.CoachTypeId)
                                 .ToDictionary(gset => UZCoachTypeMapper.GetCoachType(gset.Key), gset => gset
                                               .SelectMany(set => set.Places.AvaliablePlaceNumbers.Values
                                                           .SelectMany(placeArray => placeArray))
                                               .Distinct());

            return(placesPerCoach);
        }
コード例 #14
0
 public bool TryGetCoach(string query, out CoachType coachType)
 {
     string coachString = CleanInput(query.ToLower());
     return coachMap.TryGetValue(coachString, out coachType);
 }
コード例 #15
0
 public static string GetCoachLetter(CoachType coachType)
 {
     return(_coachTypesPerLetters[coachType]);
 }
コード例 #16
0
 public Task <Coach[]> ListCoachesAsync(Train train, CoachType coachType)
 {
     throw new NotImplementedException();
 }