Esempio n. 1
0
        /// <summary>
        /// Add a single program to the current dataset
        /// </summary>
        /// <param name="start"></param>
        /// <param name="stop"></param>
        /// <param name="channel"></param>
        /// <param name="title"></param>
        /// <param name="subtitle"></param>
        /// <param name="description"></param>
        /// <param name="categories"></param>
        /// <param name="extraattributes"></param>
        /// <param name="extranodes"></param>
        /// <returns></returns>
        public XmlElement AddProgramme(string start, string stop, string channel, XmlLangText title = null, XmlLangText
                                       subtitle = null, XmlLangText description = null, XmlLangText[] categories = null,
                                       IEnumerable <XmlAttribute> extraattributes = null, IEnumerable <XmlElement> extranodes = null)
        {
            try
            {
                var programmeNode = buildProgrammeNode(start, stop, channel, title, subtitle, description,
                                                       categories, extraattributes, extranodes);

                var startTime = XMLTV.XmlTV.StringToDate(start).UtcDateTime;
                if (xmlData.channelData.ContainsKey(channel))
                {
                    if (xmlData.channelData[channel].programmeNodes.ContainsKey(startTime))
                    {
                        xmlData.channelData[channel].programmeNodes[startTime] = programmeNode;
                    }
                    else
                    {
                        xmlData.channelData[channel].programmeNodes.Add(startTime, programmeNode);
                    }
                }

                return(programmeNode);
            }
            catch (System.Exception ex)
            {
                addError(ex);
            }
            return(null);
        }
Esempio n. 2
0
        public XmlElement buildProgrammeNode(string start, string stop, string channel, XmlLangText title = null,
                                             XmlLangText subtitle                = null, XmlLangText description = null,
                                             XmlLangText[] categories            = null, IEnumerable <XmlAttribute> extraattributes = null,
                                             IEnumerable <XmlElement> extranodes = null, bool replace = false)
        {
            try
            {
                // We need at the very least a start/stop time and channel number
                if (start == string.Empty || stop == string.Empty || channel == string.Empty)
                {
                    return(null);
                }

                if (!replace)
                {
                    var collide = FindFirstProgramme(start, channel);

                    if (collide != null)
                    {
                        addError(2001, "Duplicate programme found", XMLTVError.ErrorSeverity.Error,
                                 $"Duplicate programme found:\r\n{start} from {stop} to {channel}", "AddProgramme");
                        return(null);
                    }
                }

                var programmelNode = xmlData.rootDocument.CreateProgrammeElement(start, stop, channel, title, subtitle, description, categories, extraattributes, extranodes);
                return(programmelNode);
            }
            catch (System.Exception ex)
            {
                addError(ex);
            }
            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Create new XML "channel" element populated with channel details provided
        /// </summary>
        /// <param name="start"></param>
        /// <param name="stop"></param>
        /// <param name="channel"></param>
        /// <param name="title"></param>
        /// <param name="subtitle"></param>
        /// <param name="description"></param>
        /// <param name="categories"></param>
        /// <param name="extraattributes"></param>
        /// <param name="extranodes"></param>
        /// <returns></returns>
        public XmlElement CreateProgrammeElement(string start, string stop, string channel, XmlLangText title = null,
                                                 XmlLangText subtitle                = null, XmlLangText description = null,
                                                 XmlLangText[] categories            = null, IEnumerable <XmlAttribute> extraattributes = null,
                                                 IEnumerable <XmlElement> extranodes = null)
        {
            var programmelNode = CreateElement("programme");

            programmelNode.SetAttribute("start", start);
            programmelNode.SetAttribute("stop", stop);
            programmelNode.SetAttribute("channel", channel);

            if (title != null)
            {
                var titleNode = CreateElement("title");
                titleNode.SetAttribute("lang", title.lang);
                titleNode.InnerText = title.text;
                programmelNode.AppendChild(titleNode);
            }

            if (subtitle != null)
            {
                var subtitleNode = CreateElement("sub-title");
                subtitleNode.SetAttribute("lang", subtitle.lang);
                subtitleNode.InnerText = subtitle.text;
                programmelNode.AppendChild(subtitleNode);
            }

            if (description != null)
            {
                var descriptionNode = CreateElement("desc");
                descriptionNode.SetAttribute("lang", description.lang);
                descriptionNode.InnerText = description.text;
                programmelNode.AppendChild(descriptionNode);
            }

            if (categories != null)
            {
                foreach (var category in categories)
                {
                    var categoryNode = CreateElement("category");
                    categoryNode.SetAttribute("lang", category.lang);
                    categoryNode.InnerText = category.text;
                    programmelNode.AppendChild(categoryNode);
                }
            }

            // Any extra attributes
            if (extraattributes != null)
            {
                foreach (var extra in extraattributes)
                {
                    programmelNode.Attributes.Append(extra);
                }
            }

            // Any extra nodes
            if (extranodes != null)
            {
                foreach (var extra in extranodes)
                {
                    programmelNode.AppendChild(extra);
                }
            }
            return(programmelNode);
        }