예제 #1
0
        public override IEnumerable <DataObject> ProcessInternal(ClientBase client, ResponseContainer container)
        {
            HtmlDocument       doc        = container.ResponseHtml.Value;
            HtmlNodeCollection worldNodes = doc.DocumentNode.SelectNodes("//div[@id='myWorlds']/div[@id='planetList']/div[starts-with(@id, 'planet-')]");

            if (worldNodes == null)
            {
                yield break;
            }

            foreach (HtmlNode node in worldNodes)
            {
                int    id         = int.Parse(PlanetIdRegex.Match(node.GetAttributeValue("id", null)).Groups[1].Value, client.ServerCulture);
                string name       = node.SelectSingleNode(".//span[contains(@class, 'planet-name')]").InnerText;
                string coordinate = node.SelectSingleNode(".//span[contains(@class, 'planet-koords')]").InnerText;

                PlanetListItem item = new PlanetListItem
                {
                    Id         = id,
                    Name       = name,
                    Coordinate = Coordinate.Parse(coordinate, CoordinateType.Planet)
                };

                yield return(item);
            }
        }
예제 #2
0
        public List <PlanetListItem> PlanetList()
        {
            using (var ctx = new ApplicationDbContext())
            {
                var planetEntity = ctx.Planets;
                var planetList   = new List <PlanetListItem>();
                foreach (var item in planetEntity)
                {
                    var planetListItem = new PlanetListItem()
                    {
                        PlanetId       = item.PlanetId,
                        Name           = item.Name,
                        BadGuys        = item.BadGuys,
                        PrimaryColor   = item.PrimaryColor,
                        SecondaryColor = item.SecondaryColor
                    };
                    planetList.Add(planetListItem);
                }

                return(planetList);
            }
        }