Esempio n. 1
0
        public CifSchedule Convert(CifParser.Schedule source, CifSchedule destination, ResolutionContext context)
        {
            var schedule = CreateSchedule(source, context);

            MapLocations(source.Records, schedule, context);

            return(schedule);
        }
Esempio n. 2
0
        public static CifSchedule CreateSchedule(string timetableId             = "X12345",
                                                 StpIndicator indicator         = StpIndicator.Permanent,
                                                 ICalendar calendar             = null,
                                                 ScheduleLocation[] stops       = null,
                                                 CifService service             = null,
                                                 string retailServiceId         = null,
                                                 AccomodationClass sleeperClass = AccomodationClass.None)
        {
            retailServiceId = retailServiceId ?? $"VT{timetableId.Substring(1, 4)}00";

            var schedule = new CifSchedule()
            {
                TimetableUid         = timetableId,
                StpIndicator         = indicator,
                RetailServiceId      = retailServiceId,
                TrainIdentity        = $"9Z{timetableId.Substring(1, 2)}",
                Operator             = new Toc(retailServiceId.Substring(0, 2)),
                Status               = ServiceStatus.PermanentPassenger,
                Category             = ServiceCategory.ExpressPassenger,
                ReservationIndicator = ReservationIndicator.Supported,
                SeatClass            = AccomodationClass.Both,
                SleeperClass         = sleeperClass,
                Calendar             = calendar ?? EverydayAugust2019,
            };

            if (service != null)
            {
                schedule.AddToService(service);
            }

            if (indicator != StpIndicator.Cancelled)
            {
                stops = stops ?? DefaultLocations;
                foreach (var location in stops)
                {
                    location.SetParent(schedule);
                }
            }

            return(schedule);
        }
Esempio n. 3
0
        private void MapLocations(IEnumerable <IRecord> records, CifSchedule schedule, ResolutionContext context)
        {
            var locations = new List <ScheduleLocation>(16);
            var start     = Time.NotValid;
            var sequence  = new Sequence();

            foreach (var record in records)
            {
                ScheduleLocation working = null;

                switch (record)
                {
                case IntermediateLocation il:
                    working = MapLocation(il);
                    break;

                case OriginLocation ol:
                    working = MapOrigin(ol);
                    break;

                case TerminalLocation tl:
                    working = MapDestination(tl);
                    break;

                case ScheduleChange sc:
                    // _logger.Debug("Unhandled ScheduleChange : {record}", sc);
                    break;

                default:
                    _logger.Warning("Unhandled record {recordType} : {record}", record.GetType(), record);
                    break;
                }

                // Only add stops that we care about i.e. in the MSL
                if (working?.Location != null)
                {
                    EnsureTimesGoToTheFuture(working);
                    working.SetParent(schedule);
                    working.Id = sequence.GetNext();
                }
            }

            ScheduleLocation MapLocation(IntermediateLocation il)
            {
                return(il.WorkingPass == null
                    ? (ScheduleLocation)context.Mapper.Map <IntermediateLocation, ScheduleStop>(il, null)
                    : context.Mapper.Map <IntermediateLocation, SchedulePass>(il, null));
            }

            ScheduleLocation MapOrigin(OriginLocation ol)
            {
                var origin = context.Mapper.Map <OriginLocation, ScheduleStop>(ol, null);

                start = origin.Departure.IsBefore(origin.WorkingDeparture) ? origin.Departure : origin.WorkingDeparture;
                return(origin);
            }

            ScheduleLocation MapDestination(TerminalLocation tl)
            {
                return(context.Mapper.Map <TerminalLocation, ScheduleStop>(tl, null));
            }

            void EnsureTimesGoToTheFuture(ScheduleLocation scheduleLocation)
            {
                if (start.Equals(Time.NotValid))
                {
                    _logger.Warning($"ID: {scheduleLocation.Id} Have not set start: {schedule.TimetableUid}");
                }
                scheduleLocation.AddDay(start);
            }
        }
Esempio n. 4
0
 public void IsPublicService(CifSchedule schedule, bool expected)
 {
     Assert.Equal(expected, schedule.IsPublicSchedule());
 }