Exemple #1
0
 public void addLink(LinkStation linkStation)
 {
     if (links.Contains(linkStation) || hasLink(linkStation.getType(), linkStation.getA(), linkStation.getB()))
     {
         throw new ApplicationException("Данная связь уже установлена");
     }
     links.Add(linkStation);
 }
Exemple #2
0
        public void removeLink(LinkStation linkStation)
        {
            RattlerTransportType type = linkStation.getType();

            if (!allLinks.ContainsKey(type))
            {
                return;
            }

            allLinks[type].Remove(linkStation);
        }
        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("Неудалось прочесть");
        }
Exemple #4
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);
        }
Exemple #5
0
        public void addLink(LinkStation linkStation)
        {
            RattlerTransportType type = linkStation.getType();
            List <LinkStation>   links;

            if (allLinks.ContainsKey(type))
            {
                links = allLinks[type];
            }
            else
            {
                links          = new List <LinkStation>();
                allLinks[type] = links;
            }

            if (links.Contains(linkStation) || hasLink(type, linkStation.getA(), linkStation.getB()))
            {
                throw new ApplicationException("Данная связь уже установлена");
            }

            links.Add(linkStation);
        }
        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);
        }
Exemple #7
0
 public void removeLink(LinkStation linkStation)
 {
     links.Remove(linkStation);
 }
Exemple #8
0
 public void removeLink(LinkStation linkStation)
 {
     linkStation.getA().removeLink(linkStation);
     linkStation.getB().removeLink(linkStation);
     core.store.links.Remove(linkStation);
 }