Example #1
0
        private static IEnumerable <Message> GetStretches(TrackLayout layout, Excel.Workbook book)
        {
            var messages = new List <Message>();

            Excel.Worksheet sheet = book.Worksheets["Routes"] as Excel.Worksheet;
            for (var r = 2; ; r++)
            {
                var row = (Array)sheet.get_Range(Cell("A", r), Cell("I", r)).Cells.Value;
                if (row.GetValue(1, 1) == null)
                {
                    break;
                }
                else
                {
                    var timetableStretchNumber = row.Value(1);
                    var tracksCount            = int.Parse(row.Value(8), CultureInfo.InvariantCulture);
                    var fromName = row.Value(3);
                    var toName   = row.Value(5);
                    var distance = double.Parse(row.Value(9).Replace(",", "."), NumberStyles.Float, CultureInfo.InvariantCulture);

                    var fromStation = layout.Station(fromName);
                    if (fromStation.IsNone)
                    {
                        messages.Add(Message.Error(fromStation.Message));
                        continue;
                    }
                    var fromExit = new StationExit(toName);
                    fromStation.Value.Add(fromExit);
                    var toStation = layout.Station(toName);
                    if (toStation.IsNone)
                    {
                        messages.Add(Message.Error(toStation.Message));
                    }
                    else
                    {
                        var toExit = new StationExit(fromName);
                        toStation.Value.Add(toExit);
                        var addedStretch = layout.Add(fromExit, toExit, distance, tracksCount);
                        if (!layout.HasTimetableStretch(timetableStretchNumber))
                        {
                            layout.Add(new TimetableStretch(timetableStretchNumber));
                        }
                        layout.TimetableStretch(timetableStretchNumber).Add(addedStretch);
                    }
                }
            }
            return(messages);
        }