Beispiel #1
0
        private void ChildrenFromXml(XmlElement element, string name, IrcChannel ircChannel)
        {
            if (!element.HasChildNodes)
            {
                return;
            }

            var childNodeCollection = element.ChildNodes;

            foreach (XmlNode node in childNodeCollection)
            {
                var xmlElement = node as XmlElement;
                if (xmlElement == null)
                {
                    continue;
                }

                if (xmlElement.Name == "users")
                {
                    ircChannel.Users.Clear();

                    foreach (var childNode in xmlElement.ChildNodes)
                    {
                        var childElement = childNode as XmlElement;
                        if (childElement == null)
                        {
                            continue;
                        }

                        ircChannel.Users.Add(this.NewUserFromXmlElement(childElement));
                    }

                    continue;
                }

                if (xmlElement.Name == "stalks")
                {
                    ircChannel.Stalks.Clear();

                    foreach (var childNode in xmlElement.ChildNodes)
                    {
                        var childElement = childNode as XmlElement;
                        if (childElement == null)
                        {
                            continue;
                        }

                        var stalk = this.stalkFactory.NewFromXmlElement(childElement);
                        stalk.Channel = ircChannel.Identifier;
                        ircChannel.Stalks.Add(stalk.Identifier, stalk);
                    }

                    continue;
                }

                this.Logger.DebugFormat("Unrecognised child {0} of channel {1}", xmlElement.Name, name);
            }
        }
Beispiel #2
0
        public IIrcChannel NewFromXmlElement(XmlElement element)
        {
            var name = element.Attributes["name"].Value;

            var guid          = Guid.NewGuid();
            var guidAttribute = element.GetAttribute("guid");

            if (!string.IsNullOrWhiteSpace(guidAttribute))
            {
                guid = Guid.Parse(guidAttribute);
            }

            var ircChannel = new IrcChannel(name, guid);

            this.ChildrenFromXml(element, name, ircChannel);

            return(ircChannel);
        }