Exemplo n.º 1
0
        private void channelList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int idx = channelList1.SelectedIndex;
            Channel.ChannelType selectedType = GetSelectedChannelGroup();

            int count = 0;
            foreach (var ch in chList)
            {
                if (ch.Type == selectedType)
                {
                    if (count == idx)
                    {
                        this.SelectedChannel = ch;
                        break;
                    }
                    count++;
                }
            }
            this.channelList1.Dispose();
            this.Close();
        }
Exemplo n.º 2
0
        public static List<Channel> CreateFromXml(string xml)
        {
            var channels = new List<Channel>();

            var xmlDoc = new XmlDocument();
            try
            {
                xmlDoc.LoadXml(xml);
            }
            catch (XmlException e)
            {
                Utils.DebugLog(e.ToString());
                return null;
            }

            for (int i = 0; i < xmlDoc.DocumentElement.ChildNodes.Count; i++)
            {
                Channel ch = new Channel();

                var node = xmlDoc.DocumentElement.ChildNodes[i];
                Utils.DebugLog(node.Name + ": " + node.InnerXml);
                switch (node.Name)
                {
                    case "channel":
                        ch.Type = ChannelType.Television;
                        break;
                    case "radio_channel":
                        ch.Type = ChannelType.Radio;
                        break;
                    case "user_channel":
                        ch.Type = ChannelType.User;
                        break;
                    case "event_channel":
                        ch.Type = ChannelType.Event;
                        break;
                    default:
                        continue;
                }

                foreach (XmlNode child in node.ChildNodes)
                {
                    switch (child.Name)
                    {
                        case "id":
                            ch.Id = int.Parse(child.FirstChild.Value);
                            break;
                        case "no":
                            ch.No = int.Parse(child.FirstChild.Value);
                            break;
                        case "name":
                            ch.Name = child.FirstChild.Value;
                            break;
                        case "video":
                            ch.Video = child.FirstChild.Value;
                            break;
                        case "thread":
                            {
                                foreach (XmlNode c in child.ChildNodes)
                                {
                                    switch (c.Name)
                                    {
                                        case "last_res":
                                            if (c.FirstChild != null)
                                            {
                                                ch.LastRes = c.FirstChild.Value;
                                            }
                                            break;
                                        case "force":
                                            ch.Force = (int)double.Parse(c.FirstChild.Value);
                                            break;
                                        default:
                                            break;
                                    }
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }

                channels.Add(ch);
            }

            return channels;
        }