Ejemplo n.º 1
0
        public void Load(System.Xml.XmlTextReader tr, string localName)
        {
            tr.ReadStartElement(localName);

            tr.ReadElementContentAsBoolean("IsEnabled", string.Empty);

            tr.ReadEndElement();
        }
Ejemplo n.º 2
0
        private static PackageMatch ParseMatch(System.Xml.XmlTextReader reader)
        {
            // Make sure we're in right position
            reader.ReadStartElement("match");

            PackageMatch match = new PackageMatch();

            if (reader.LocalName == "channel")
            {
                match.ChannelId = reader.ReadElementString();
            }

            if (reader.LocalName == "dep")
            {
                PackageDep dep = new PackageDep(reader);
                match.Dep = dep;
                //dep.Unref ();

                // Move reader to start of next element
                while (reader.Read())
                {
                    if (reader.NodeType == System.Xml.XmlNodeType.Element)
                    {
                        break;
                    }
                }
            }

            if (reader.LocalName == "glob")
            {
                match.Glob = reader.ReadElementString();
            }

            if (reader.LocalName == "importance")
            {
                int    gteq     = 0;
                string gteq_str = reader["gteq"];
                if (gteq_str != null)
                {
                    gteq = System.Xml.XmlConvert.ToInt32(gteq_str);
                }

                PackageImportance imp = RC.Global.PackageImportanceFromString(reader.ReadElementString());
                match.SetImportance(imp, Convert.ToBoolean(gteq));
            }

            return(match);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads the element content as collection.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        public static System.Collections.Generic.List <T> ReadElementContentAsCollection <T>(this System.Xml.XmlReader reader) where T : class
        {
            System.Collections.Generic.List <T>    result     = new System.Collections.Generic.List <T>();
            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
            string xml = reader.ReadOuterXml();

            using (System.IO.StringReader sr = new System.IO.StringReader(xml))
            {
                using (System.Xml.XmlTextReader xmlTextReader = new System.Xml.XmlTextReader(sr))
                {
                    xmlTextReader.ReadStartElement();
                    while (!xmlTextReader.EOF)
                    {
                        if (xmlTextReader.NodeType == System.Xml.XmlNodeType.EndElement)
                        {
                            xmlTextReader.ReadEndElement();
                            continue;
                        }

                        T obj;

                        if (xmlTextReader.IsEmptyElement && xmlTextReader.HasAttributes)
                        {
                            obj = serializer.Deserialize(xmlTextReader) as T;
                        }
                        else
                        {
                            System.Xml.XmlReader subTree = xmlTextReader.ReadSubtree();
                            obj = serializer.Deserialize(subTree) as T;
                        }
                        if (obj != null)
                        {
                            result.Add(obj);
                        }

                        if (!xmlTextReader.IsEmptyElement)
                        {
                            xmlTextReader.Read();
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
Archivo: Trigger.cs Proyecto: hpie/hpie
 /// <summary>
 /// Gets basic event information.
 /// </summary>
 /// <param name="log">The event's log.</param>
 /// <param name="source">The event's source. Can be <c>null</c>.</param>
 /// <param name="eventId">The event's id. Can be <c>null</c>.</param>
 /// <returns><c>true</c> if subscription represents a basic event, <c>false</c> if not.</returns>
 public bool GetBasic(out string log, out string source, out int? eventId)
 {
     log = source = null;
     eventId = null;
     if (!string.IsNullOrEmpty(this.Subscription))
     {
         using (System.IO.MemoryStream str = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(this.Subscription)))
         {
             using (System.Xml.XmlTextReader rdr = new System.Xml.XmlTextReader(str))
             {
                 rdr.MoveToContent();
                 rdr.ReadStartElement("QueryList");
                 if (rdr.Name == "Query" && rdr.MoveToAttribute("Path"))
                 {
                     string path = rdr.Value;
                     if (rdr.MoveToElement() && rdr.ReadToDescendant("Select") && path.Equals(rdr["Path"], StringComparison.InvariantCultureIgnoreCase))
                     {
                         string content = rdr.ReadString();
                         System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(content,
                             @"\*(?:\[System\[(?:Provider\[\@Name='(?<s>[^']+)'\])?(?:\s+and\s+)?(?:EventID=(?<e>\d+))?\]\])",
                             System.Text.RegularExpressions.RegexOptions.IgnoreCase |
                             System.Text.RegularExpressions.RegexOptions.Compiled |
                             System.Text.RegularExpressions.RegexOptions.Singleline |
                             System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace);
                         if (m.Success)
                         {
                             log = path;
                             if (m.Groups["s"].Success)
                                 source = m.Groups["s"].Value;
                             if (m.Groups["e"].Success)
                                 eventId = Convert.ToInt32(m.Groups["e"].Value);
                             return true;
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
Ejemplo n.º 5
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);
        }