/// <summary> /// Clear all existing data and create blank XMLTV workspace /// </summary> public void Clear() { try { localErrors = new List <XMLTVError>(); // New document for new data var newDoc = new XmlTVDocument(_rootGeneratorName, _rootGeneratorUrl, _rootDataSourceName); xmlData = new XmlTVData(newDoc); } catch (Exception ex) { addError(ex); } }
/// <summary> /// Load an XML TV file, and merge contents into existing data (if any) /// </summary> /// <param name="filename"></param> /// <param name="mergeOnly"></param> /// <returns></returns> public bool LoadXmlTV(string filename, bool mergeOnly = false) { try { var xmlTVLoad = new XmlTVDocument(); xmlTVLoad.Load(filename); var localData = new XmlTVData(xmlTVLoad); var localRootTvNode = localData.rootNode; // Check for root TV node if (localRootTvNode == null) { addError(1002, "root TV node was not found", XMLTVError.ErrorSeverity.Error, "", "LoadXmlTV"); return(false); } // Check for dupe channel ids if (validateChannel(xmlData, localData)) { return(false); } if (validateProgramme(xmlData, localData)) { return(false); } if (mergeOnly) { CopyXmlData(ref localData, xmlData, false); } else { CopyXmlData(ref localData, xmlData, true); } return(true); } catch (System.Exception ex) { addError(ex); } return(false); }
public XmlTVData(XmlTVDocument doc) { rootDocument = doc; channelData = new Dictionary <string, Channel>(); rootNode = doc.TvElement; // Build internal dictionary for channels foreach (XmlElement channelNode in rootNode.SelectNodes("channel")) { rootNode.RemoveChild(channelNode); if (channelNode.Attributes["id"] == null) { continue; } var thisChannel = new Channel(); thisChannel.ChanelNode = channelNode; channelData.Add(channelNode.Attributes["id"].Value, thisChannel); } // Build internal dictionary for programmes foreach (XmlElement programmeNode in rootNode.SelectNodes("programme")) { rootNode.RemoveChild(programmeNode); if (programmeNode.Attributes["start"] == null || programmeNode.Attributes["channel"] == null) { continue; } // Find channelnode var channelId = programmeNode.Attributes["channel"].Value; if (channelData.ContainsKey(channelId)) { // Add programme var start = XMLTV.XmlTV.StringToDate(programmeNode.Attributes["start"].Value).UtcDateTime; if (!channelData[channelId].programmeNodes.ContainsKey(start)) { channelData[channelId].programmeNodes.Add(start, programmeNode); } } } }
public XmlTV(Config configuration = null, string generatorname = "", string generatorurl = "", string datasourcename = "") { try { localErrors = new List <XMLTVError>(); _rootGeneratorName = generatorname == string.Empty ? "XMLTVSharp 1.0" : generatorname; _rootGeneratorUrl = generatorurl == string.Empty ? "https://github.com/M0OPK/SDJSharp" : generatorurl; _rootDataSourceName = datasourcename != string.Empty ? datasourcename : string.Empty; // New document for new data var newDoc = new XmlTVDocument(_rootGeneratorName, _rootGeneratorUrl, _rootDataSourceName); xmlData = new XmlTVData(newDoc); config = configuration ?? new Config(); } catch (Exception ex) { addError(ex); } }