Exemplo n.º 1
0
        void service_getRacksCompleted(object sender, ClearChannelService.getRacksCompletedEventArgs e)
        {
            var xmlDoc = XDocument.Parse("<racks>" + e.Result + "</racks>");

            var racks = from item in xmlDoc.Descendants("station")
                        select new Rack
                        {
                            Id = Convert.ToInt32(item.Value)
                        };

            var service = new ClearChannelService.ClearChannelSoapClient();
            service.getRackCompleted += service_getRackCompleted;

            foreach (var rack in racks)
            {
                service.getRackAsync(rack.Id, rack);
            }
        }
Exemplo n.º 2
0
        void service_getRackCompleted(object sender, ClearChannelService.getRackCompletedEventArgs e)
        {
            try
            {
                var rack = (Rack)e.UserState;

                var xmlDoc = XDocument.Parse(e.Result.Replace("&", "&amp;"));

                var node = xmlDoc.Element("station");
                rack.Description = node.Element("description").Value;
                rack.Longitude = Convert.ToDouble(node.Element("longitute").Value);
                rack.Latitude = Convert.ToDouble(node.Element("latitude").Value);
                rack.Bikes = Convert.ToInt32(node.Element("ready_bikes").Value);
                rack.EmptyLocks = Convert.ToInt32(node.Element("empty_locks").Value);
                rack.Online = node.Element("online").Value == "1" ? true : false;

                Rack oldRack = Model.Racks.SingleOrDefault(r => r.Id == rack.Id);

                if (oldRack != null)
                    Model.Racks.Remove(oldRack);

                Model.Racks.Add(rack);
            }
            catch { }
        }