public bool hasLinkAny(RattlerStation first, RattlerStation second) { return(links.Find( i => i.getA().Equals(first) && i.getB().Equals(second) || i.getA().Equals(second) && i.getB().Equals(first) ) != null); }
public ExpressTrain(RattlerStation A, RattlerStation B, double averageSpeed, int capacity) { this.capacity = capacity; this.averageSpeed = averageSpeed; this.A = A; this.B = B; }
public override LinkStation ReadJson( JsonReader reader, Type objectType, LinkStation existingValue, bool hasExistingValue, JsonSerializer serializer ) { if (reader.TokenType.Equals(JsonToken.StartObject)) { JObject obj = JObject.Load(reader); string rawType = obj["type"].Value <string>(); RattlerTransportType type = RattlerTransportType.ofValue(rawType); int id1 = obj["station1"] != null ? obj["station1"].Value <int>() : 0; int id2 = obj["station2"] != null ? obj["station2"].Value <int>() : 0; double distance = obj["station2"] != null ? obj["distance"].Value <double>() : 0; RattlerStation station1 = core.stationService.getById(id1); RattlerStation station2 = core.stationService.getById(id2); LinkStation linkStation = new LinkStation(station1, station2, distance); return(linkStation); } throw new JsonException("Неудалось прочесть"); }
public ExpressTrain(string name, RattlerStation A, RattlerStation B) { this.name = name; this.capacity = 56; this.averageSpeed = 47.5; this.A = A; this.B = B; }
private void addStations(long[] stationsId, RattlerTransport transport) { foreach (long id in stationsId) { RattlerStation station = core.stationService.getById(id); transport.addStation(station); } }
public bool hasLink(RattlerTransportType type, RattlerStation first, RattlerStation second) { return(links.Find( i => i.getType().Equals(type) && ( i.getA().Equals(first) && i.getB().Equals(second) || i.getA().Equals(second) && i.getB().Equals(first) ) ) != null); }
public void removeStation(RattlerStation station) { if (station.Equals(B)) { this.B = null; } else if (station.Equals(A)) { this.A = null; } }
private void done(object sender, RoutedEventArgs e) { string name; if (BoxName.Text.Trim().Length > 0) { name = BoxName.Text; } else { new ErrorWindow("Ошибка в имени").Show(); return; } if (Type == WindowType.CREATE) { if (RattlerTransportType.TRAM.Equals(stationType)) { Station = new SimpleRattlerStation <Tram>(name, stationType); } else if (RattlerTransportType.METRO.Equals(stationType)) { Station = new SimpleRattlerStation <Metro>(name, stationType); } else if (RattlerTransportType.TRAIN.Equals(stationType)) { Station = new SimpleRattlerStation <Train>(name, stationType); } else if (RattlerTransportType.EXPRESS_TRAIN.Equals(stationType)) { Station = new SimpleRattlerStation <ExpressTrain>(name, stationType); } else if (RattlerTransportType.COMPLEX.Equals(stationType)) { Station = new ComplexRattlerStation(name); } else { new ErrorWindow("Не выбран тип транспорта!").Show(); return; } MainWindow.core.stationService.addStation(Station); } else { Station.name = name; } MainWindow.main.updateGrids(); Close(); }
public override RattlerStore ReadJson( JsonReader reader, Type objectType, RattlerStore existingValue, bool hasExistingValue, JsonSerializer serializer ) { if (reader.TokenType.Equals(JsonToken.StartObject)) { JObject obj = JObject.Load(reader); core.store.maxTransportId = obj["max-transport-id"] != null ? obj["max-transport-id"].Value <long>() : 1; core.store.maxTransportId = obj["max-station-id"] != null ? obj["max-station-id"].Value <long>() : 1; // Load stations List <RattlerStation> stations = new List <RattlerStation>(); if (obj["stations"] != null) { foreach (JToken jToken in obj["stations"]) { RattlerStation station = JsonConvert.DeserializeObject <RattlerStation>(jToken.ToString()); core.stationService.addStation(station); } } // Load links List <LinkStation> links = new List <LinkStation>(); if (obj["links"] != null) { foreach (JToken jToken in obj["links"]) { LinkStation link = JsonConvert.DeserializeObject <LinkStation>(jToken.ToString()); core.stationService.addLink(link); } } // Load transport List <RattlerTransport> transports = new List <RattlerTransport>(); if (obj["transports"] != null) { foreach (JToken jToken in obj["transports"]) { RattlerTransport transport = JsonConvert.DeserializeObject <RattlerTransport>(jToken.ToString()); core.transportService.addTransport(transport); } } return(core.store); } throw new JsonException("Неудалось прочесть"); }
public void addStation(RattlerStation station) { if (!station.getType().Equals(getType())) throw new ArgumentException("Тип станции не подходит для данного транспорта!"); if (stations.Count > 0) { RattlerStation last = stations[stations.Count - 1]; if (last.hasLink(getType(), last, station)) { stations.Add(station); } else { throw new ApplicationException("Путь между станциями не найден!"); } } else { stations.Add(station); } }
public void addStation(RattlerStation station) { if (station.id == 0) { station.id = core.store.maxStationId++; } else { if (station.id > core.store.maxStationId) { core.store.maxStationId = station.id + 1; } } core.store.stations.Add(station); }
public void addStation(RattlerStation station) { if (A == null) { this.A = station; } else if (B == null) { this.B = station; } else { throw new ApplicationException("Данный тип может иметь лишь две остановки"); } }
public LinkStation addLink(LinkStation linkStation) { RattlerStation A = linkStation.getA(); RattlerStation B = linkStation.getB(); A.addLink(linkStation); try { B.addLink(linkStation); } catch (Exception ex) { A.removeLink(linkStation); throw; } core.store.links.Add(linkStation); return(linkStation); }
public EditStation(RattlerStation station, WindowType type) { InitializeComponent(); Type = type; Station = station; if (type == WindowType.EDIT) { BoxName.Text = station.name; BoxTram.IsEnabled = false; BoxMetro.IsEnabled = false; BoxTrain.IsEnabled = false; BoxExpressTrain.IsEnabled = false; BoxComplex.IsEnabled = false; convertFromType(station.getType()).IsChecked = true; } }
public void removeStation(RattlerStation station) { if (core.store.transports.Count(i => i.getStations().Contains(station)) != 0) { throw new ApplicationException("Нельзя удалить станцию, так как ее используют некоторые маршруты!"); } core.store.stations.Remove(station); List <LinkStation> forDelete = new List <LinkStation>(); foreach (var link in core.store.links) { if (link.getA().Equals(station) || link.getB().Equals(station)) { forDelete.Add(link); } } forDelete.ForEach(i => core.stationService.removeLink(i)); }
public LinkStation(RattlerStation A, RattlerStation B, double distance) { if (A.Equals(B)) { throw new ArgumentException("Станция A и станция B одинаковы!"); } if (!A.getType().Equals(B.getType())) { throw new ArgumentException("Соедиенение станций возможно лишь когда они одного типа!"); } if (distance <= 0) { throw new ArgumentException("Дистанция должна быть положительной"); } this.type = A.getType(); this.A = A; this.B = B; this.distance = distance; }
public bool containsStation(RattlerStation station) { return stations.Contains(station); }
public void removeStation(RattlerStation station) { stations.Remove(station); }
public bool containsStation(RattlerStation station) { return(station != null && (station.Equals(A) || station.Equals(B))); }