Beispiel #1
0
        public override RattlerStation ReadJson(
            JsonReader reader, Type objectType, RattlerStation 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    id   = obj["id"] != null ? obj["id"].Value <int>() : 0;
                string name = obj["name"] != null ? obj["name"].Value <string>() : "unnamed";

                if (type.Equals(RattlerTransportType.COMPLEX))
                {
                    ComplexRattlerStation station = new ComplexRattlerStation(name);
                    station.id   = id;
                    station.name = name;
                    return(station);
                }
                else if (type.Equals(RattlerTransportType.METRO))
                {
                    SimpleRattlerStation <Metro> station = new SimpleRattlerStation <Metro>(name, type);
                    station.id   = id;
                    station.name = name;
                    return(station);
                }
                else if (type.Equals(RattlerTransportType.TRAIN))
                {
                    SimpleRattlerStation <Train> station = new SimpleRattlerStation <Train>(name, type);
                    station.id   = id;
                    station.name = name;
                    return(station);
                }
                else if (type.Equals(RattlerTransportType.TRAM))
                {
                    SimpleRattlerStation <Tram> station = new SimpleRattlerStation <Tram>(name, type);
                    station.id   = id;
                    station.name = name;
                    return(station);
                }
                else if (type.Equals(RattlerTransportType.EXPRESS_TRAIN))
                {
                    SimpleRattlerStation <ExpressTrain> station = new SimpleRattlerStation <ExpressTrain>(name, type);
                    station.id   = id;
                    station.name = name;
                    return(station);
                }
            }

            throw new JsonException("Неудалось прочесть");
        }
        public void demoData()
        {
            SimpleRattlerStation <Metro> station1 = new SimpleRattlerStation <Metro>("Yaroslavl", RattlerTransportType.METRO);
            SimpleRattlerStation <Metro> station2 = new SimpleRattlerStation <Metro>("Rybinsk", RattlerTransportType.METRO);

            core.stationService.addStation(station1);
            core.stationService.addStation(station2);

            Metro metro = new Metro("red way");

            core.transportService.addTransport(metro);

            Train train = new Train("11c");

            core.transportService.addTransport(train);


            LinkStation link = new LinkStation(station1, station2, 10);

            core.stationService.addLink(link);

            metro.addStation(station1);
            metro.addStation(station2);
        }