Example #1
0
        private static int FromXml(System.Xml.XmlTextReader reader, ChannelDelegate callback)
        {
            reader.MoveToContent();
            reader.ReadStartElement("channellist");

            int counter = 0;

            while (reader.Read())
            {
                if (reader.LocalName != "channel")
                {
                    continue;
                }

                if (!reader.HasAttributes)
                {
                    Console.WriteLine("channel doesn't have attributes, skipping");
                    continue;
                }

                Channel c = new Channel(reader["bid"],
                                        reader["name"],
                                        reader["alias"],
                                        reader["description"]);
                c.LegacyId = reader["id"];

                string distros = reader["distro_target"];
                if (distros != null)
                {
                    foreach (string d in distros.Split(new Char[] { ':' }))
                    {
                        c.AddDistroTarget(d);
                    }
                }

                ChannelType type     = ChannelType.Unknown;
                string      type_str = reader["type"];
                if (type_str != null)
                {
                    switch (type_str)
                    {
                    case "helix":
                        type = ChannelType.Helix;
                        break;

                    case "debian":
                        type = ChannelType.Debian;
                        break;

                    case "aptrpm":
                        type = ChannelType.Aptrpm;
                        break;

                    case "yum":
                        type = ChannelType.Yum;
                        break;

                    default:
                        break;
                    }
                }

                c.SetType(type);

                int    subd_priority   = 0;
                int    unsubd_priority = 0;
                string priority        = reader["priority"];
                if (priority != null)
                {
                    subd_priority = Channel.PriorityParse(priority);
                }

                priority = reader["priority_when_unsubscribed"];
                if (priority != null)
                {
                    unsubd_priority = Channel.PriorityParse(priority);
                }

                c.SetPriorities(subd_priority, unsubd_priority);

                c.Path        = reader["path"];
                c.FilePath    = reader["file_path"];
                c.IconFile    = reader["icon"];
                c.PkginfoFile = reader["pkginfo_file"];

                string compressed = reader["pkginfo_compressed"];
                if (compressed != null && compressed == "1")
                {
                    c.PkginfoFileCompressed = true;
                }

                counter++;

                if (!callback(c))
                {
                    break;
                }
            }

            return(counter);
        }