Exemple #1
0
        public IImportedItem Create(string line)
        {
            /*  char recordType = line[2];
             * switch(recordType)
             * {
             *    case 'N':*/
            ScheduledRoute route = new ScheduledRoute();

            route.PopulateFromLine(line);
            return(route);

            /*    default:
             *      return null;//TODO: handle Updates and deletes
             * }*/
        }
Exemple #2
0
        public IEnumerable <IImportedItem> ConvertItems(System.IO.StreamReader inStream, out List <Exception> Errors)
        {
            Errors = new List <Exception>();
            List <IImportedItem>     schedules = new List <IImportedItem>();
            BasicScheduleItemFactory bsFactory = new BasicScheduleItemFactory();
            string scheduleStart = bsFactory.GetFieldCode();
            int    lineN         = 1; //header will have been parsed at the very least by this point
            //now parse all the LI lines
            ScheduledStopFactory      interimFact = new ScheduledStopFactory();
            ChangesEnRouteFactory     changesFact = new ChangesEnRouteFactory();
            ScheduleOriginFactory     orginFact   = new ScheduleOriginFactory();
            ScheduleTerminatesFactory termFact    = new ScheduleTerminatesFactory();
            char interimStopFirstChar             = interimFact.GetFieldCode()[0];

            while (!inStream.EndOfStream)
            {
                try
                {
                    string line = inStream.ReadLine();
                    if (line.StartsWith(scheduleStart))
                    {
                        int callNumber = 0;
                        while (line.EndsWith("C"))
                        {
                            //TODO: Cancelations
                            line = inStream.ReadLine();
                        }
                        ScheduledRoute route = (ScheduledRoute)bsFactory.Create(line);
                        line = inStream.ReadLine();
                        while (line.StartsWith("BX"))
                        {
                            line = inStream.ReadLine();
                        }
                        string loLine = line;

                        if (!loLine.StartsWith(orginFact.GetFieldCode()))
                        {
                            throw new ImportFileFormatException("", "Schedule start not found", 0, lineN);
                        }
                        ScheduleOrigin orgin = (ScheduleOrigin)orginFact.Create(loLine);
                        orgin.CallNumber = callNumber++;
                        route.ServiceNodes.Add(orgin);
                        line = inStream.ReadLine();
                        while (line.StartsWith(interimFact.GetFieldCode()) ||
                               line.StartsWith(changesFact.GetFieldCode()))
                        {
                            if (line[0] == interimStopFirstChar)//not for changes en route
                            {
                                ScheduledStop interimStop = (ScheduledStop)interimFact.Create(line);
                                interimStop.CallNumber = callNumber++;
                                route.ServiceNodes.Add(interimStop);
                            }
                            line = inStream.ReadLine();
                            lineN++;
                        }
                        //LT line
                        string ltLine = line;
                        if (!ltLine.StartsWith(termFact.GetFieldCode()))
                        {
                            throw new ImportFileFormatException("", "Schedule end not found", 0, lineN);
                        }
                        ScheduleTerminates terminates = (ScheduleTerminates)termFact.Create(ltLine);
                        terminates.CallNumber = callNumber;
                        route.ServiceNodes.Add(terminates);
                        schedules.Add(route);
                    }
                }
                catch (Exception ex)
                {
                    Errors.Add(ex);
                }
            }
            return(schedules);
        }