Example #1
0
 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);
 }
Example #2
0
 public ExpressTrain(RattlerStation A, RattlerStation B, double averageSpeed, int capacity)
 {
     this.capacity     = capacity;
     this.averageSpeed = averageSpeed;
     this.A            = A;
     this.B            = B;
 }
Example #3
0
        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("Неудалось прочесть");
        }
Example #4
0
 public ExpressTrain(string name, RattlerStation A, RattlerStation B)
 {
     this.name         = name;
     this.capacity     = 56;
     this.averageSpeed = 47.5;
     this.A            = A;
     this.B            = B;
 }
Example #5
0
 private void addStations(long[] stationsId, RattlerTransport transport)
 {
     foreach (long id in stationsId)
     {
         RattlerStation station = core.stationService.getById(id);
         transport.addStation(station);
     }
 }
Example #6
0
 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);
 }
Example #7
0
 public void removeStation(RattlerStation station)
 {
     if (station.Equals(B))
     {
         this.B = null;
     }
     else if (station.Equals(A))
     {
         this.A = null;
     }
 }
Example #8
0
        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();
        }
Example #9
0
        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("Неудалось прочесть");
        }
Example #10
0
        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);
            }
        }
Example #11
0
 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);
 }
Example #12
0
 public void addStation(RattlerStation station)
 {
     if (A == null)
     {
         this.A = station;
     }
     else if (B == null)
     {
         this.B = station;
     }
     else
     {
         throw new ApplicationException("Данный тип может иметь лишь две остановки");
     }
 }
Example #13
0
        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);
        }
Example #14
0
        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;
            }
        }
Example #15
0
        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));
        }
Example #16
0
        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;
        }
Example #17
0
 public bool containsStation(RattlerStation station) {
     return stations.Contains(station);
 }
Example #18
0
 public void removeStation(RattlerStation station) {
     stations.Remove(station);
 }
Example #19
0
 public bool containsStation(RattlerStation station)
 {
     return(station != null && (station.Equals(A) || station.Equals(B)));
 }