public static Timetable CreateTimetable() { var timetable = new Timetable("Test", Layout()); timetable.AddTrain(CreateTrain1()); timetable.AddTrain(CreateTrain2()); return(timetable); }
private (Maybe <Timetable> item, IEnumerable <Message> messages) GetTestTimetable(string name) { var(item, messages) = GetLayout(name); if (item.IsNone) { return(Maybe <Timetable> .None("Layout does not exist."), messages); } var result = new Timetable(name, item.Value); result.AddTrain(TestDataFactory.CreateTrain1()); result.AddTrain(TestDataFactory.CreateTrain2()); return(Maybe <Timetable> .Item(result), messages); }
protected void NewTrain(GridView view, TrainDirection direction) { using (var tef = new TrainEditForm(tt, direction)) { if (tef.ShowModal(this) == DialogResult.Ok) { tt.AddTrain(tef.Train, true); UpdateListView(view, direction); } } }
private void closeButton_Click(object sender, EventArgs e) { var copy = modeSelect.SelectedState == 0; if (!offsetValidator.Valid || (copy && (!countValidator.Valid || !changeValidator.Valid))) { var msg = offsetValidator.Valid ? "" : offsetValidator.ErrorMessage + Environment.NewLine; if (copy) { msg += countValidator.Valid ? "" : countValidator.ErrorMessage + Environment.NewLine; msg += changeValidator.Valid ? "" : changeValidator.ErrorMessage + Environment.NewLine; } MessageBox.Show("Bitte erst alle Felder korrekt ausfüllen:" + Environment.NewLine + msg); Result = DialogResult.None; return; } var th = new TrainEditHelper(); var offset = int.Parse(offsetTextBox.Text); if (copy) { var count = int.Parse(countTextBox.Text); var add = int.Parse(changeTextBox.Text); var trains = th.CopyTrainMultiple(train, offset, nameTextBox.Text, copyAllCheckBox.Checked.Value, count, add); foreach (var newTrain in trains) { if (tt.Trains.Any(t => t.TName == newTrain.TName)) { if (MessageBox.Show($"Es ist bereits ein Zug mit der Zugnummer {newTrain.TName} in diesem Fahrplan vorhanden, soll diese Kopie trotzdem angelegt werden?", "Züge kopieren", MessageBoxButtons.YesNo) == DialogResult.No) { continue; } } tt.AddTrain(newTrain, true); } } else { th.MoveTrain(train, offset); } Close(DialogResult.Ok); }
protected void NewTrain(GridView view, TrainDirection direction) { using (var tef = new TrainEditForm(tt, direction)) { if (tef.ShowModal(this) == DialogResult.Ok) { tt.AddTrain(tef.Train); if (tef.NextTrains.Any()) { tt.SetTransitions(tef.Train, tef.NextTrains); } UpdateListView(view, direction); } } }
private void NewTrain(GridView view) { using (var trf = TrainRouteForm.NewTrain(info)) { if (trf.ShowModal(this) != DialogResult.Ok) { return; } using (var tef = new TrainEditForm(info.Timetable, TrainDirection.tr, trf.Path)) { if (tef.ShowModal(this) == DialogResult.Ok) { tt.AddTrain(tef.Train, true); UpdateListView(view, TrainDirection.tr); } } } }
private static IEnumerable <Message> GetTrains(Timetable timetable, Excel.Workbook book) { var messages = new List <Message>(); Excel.Worksheet sheet = book.Worksheets["Trains"] as Excel.Worksheet; var r = 2; Train currentTrain = null; while (true) { var row = (Array)sheet.get_Range(Cell("A", r), Cell("K", r)).Cells.Value; if (row.GetValue(1, 1) == null) { break; } else { var type = row.Value(9).ToUpperInvariant(); switch (type) { case "TRAINDEF": if (currentTrain != null) { timetable.AddTrain(currentTrain); } var trainId = row.Value(TrainIdColumn); currentTrain = new Train(trainId.ParseTrainNumber(), trainId) { Category = trainId.ParsesTrainCategory() }; break; case "TIMETABLE": try { var station = timetable.Layout.Station(row.Value(3)); var arrivalTime = Time.Parse(row.Value(5)); var departureTime = Time.Parse(row.Value(6)); var note = row.Value(11); if (station.IsNone) { messages.Add(Message.Error(string.Format(CultureInfo.CurrentCulture, Resources.Strings.ThereIsNoStationWithSignatureOrName, station.Value))); } else { var trackNumber = row.Value(4); var track = station.Value.Track(trackNumber); if (track.IsNone) { messages.Add(Message.Error(string.Format(CultureInfo.CurrentCulture, Resources.Strings.TrainAtStationAtTimeRefersToANonexistingTrack, currentTrain, station.Value, arrivalTime, departureTime, trackNumber))); } if (messages.CanContinue()) { var call = new StationCall(track.Value, Time.Parse(row.Value(5)), Time.Parse(row.Value(6))); if (!string.IsNullOrWhiteSpace(note)) { call.Notes.Add(new StationCallNote(note)); } currentTrain.Add(call); } } } catch (Exception ex) { messages.Add(Message.System(ex.Message)); } break; default: break; } } r++; } if (currentTrain != null) { timetable.AddTrain(currentTrain); } return(messages); }
public void LinkedTrainsPerformanceTest() { var tt = new Timetable(TimetableType.Linear); var stations = new Station[100]; for (int i = 0; i < 100; i++) { var sta = new Station(tt); sta.SName = "Station " + i; sta.Positions.SetPosition(Timetable.LINEAR_ROUTE_ID, i); tt.AddStation(sta, Timetable.LINEAR_ROUTE_ID); stations[i] = sta; } var normalTrain = new Train(TrainDirection.ti, tt) { TName = "P 01" }; tt.AddTrain(normalTrain); normalTrain.AddLinearArrDeps(); for (int i = 0; i < 100; i++) { var ardp = normalTrain.GetArrDep(stations[i]); ardp.Arrival = new TimeEntry(0, i * 30); ardp.Departure = new TimeEntry(0, i * 30 + 10); } var link = new TrainLink(normalTrain, 10) { TimeDifference = new TimeEntry(0, 30), TimeOffset = new TimeEntry(0, 0), TrainNamingScheme = new AutoTrainNameGen(normalTrain.TName, 2) }; normalTrain.AddLink(link); LinkedTrain linkedTrain = null; for (int i = 0; i < link.TrainCount; i++) { linkedTrain = new LinkedTrain(link, i); tt.AddTrain(linkedTrain); } var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 100; i++) { var ardps = linkedTrain.GetArrDepsUnsorted(); } sw.Stop(); Console.WriteLine("Linked read: " + ((float)sw.ElapsedMilliseconds) / 100); var sw2 = new Stopwatch(); sw2.Start(); for (int i = 0; i < 100; i++) { var ardps = normalTrain.GetArrDepsUnsorted(); } sw2.Stop(); Console.WriteLine("Normal read: " + ((float)sw2.ElapsedMilliseconds) / 100); var sw3 = new Stopwatch(); var sta3 = stations[0]; var ardp3 = normalTrain.GetArrDep(sta3); sw3.Start(); for (int i = 0; i < 100; i++) { ardp3.Arrival = new TimeEntry(0, i); } sw3.Stop(); Console.WriteLine("Write: " + ((float)sw3.ElapsedMilliseconds) / 100); }