/// <summary> /// Returns list of countries supported. /// </summary> /// <returns></returns> public SDCountries GetCountries() { try { var result = GetDynamic(WebGet("available/countries")); if (result == null) { return(null); } var countries = new SDCountries(); foreach (string key in result.Keys) { var thisContinent = new SDCountries.Continent { continentname = key }; foreach (var country in result[key]) { if (country == null) { continue; } var thisCountry = new SDCountries.Country(); try { thisCountry.fullName = country["fullName"]; } catch { } try { thisCountry.shortName = country["shortName"]; } catch { } try { thisCountry.postalCodeExample = country["postalCodeExample"]; } catch { } try { thisCountry.postalCode = country["postalCode"]; } catch { } try { thisCountry.onePostalCode = country["onePostalCode"]; } catch { } thisContinent.countries.Add(thisCountry); } countries.continents.Add(thisContinent); } return(countries); } catch (Exception ex) { addError(ex); } return(null); }
public bool Load(string filename) { if (!File.Exists(filename)) { return(false); } Clear(); var cacheDoc = new XmlDocument(); cacheDoc.Load(filename); var rootNode = cacheDoc.SelectSingleNode("//SDGrabSharpCache"); if (rootNode == null) { return(false); } var countryDataNode = rootNode.SelectSingleNode("CountryData"); var headendDataNode = rootNode.SelectSingleNode("HeadEndData"); var lineupDataNode = rootNode.SelectSingleNode("LineUpData"); var previewDataNode = rootNode.SelectSingleNode("PreviewLineupData"); // Country data if (countryDataNode != null) { countryData = new SDCountries { cacheDate = GetCacheDate(countryDataNode) }; if (validateCacheDate(countryData.cacheDate)) { var continentNodes = countryDataNode.SelectNodes("continent"); foreach (XmlNode continentNode in continentNodes) { var thisContinent = new SDCountries.Continent { cacheDate = GetCacheDate(continentNode), continentname = continentNode.Attributes["name"].Value }; if (validateCacheDate(thisContinent.cacheDate)) { var countryNodes = continentNode.SelectNodes("country"); foreach (XmlNode countryNode in countryNodes) { var thisCountry = new SDCountries.Country { cacheDate = GetCacheDate(countryNode) }; if (validateCacheDate(thisCountry.cacheDate)) { if (countryNode.Attributes["shortname"] != null) { thisCountry.shortName = countryNode.Attributes["shortname"].Value; } if (countryNode.Attributes["postalCodeExample"] != null) { thisCountry.postalCodeExample = countryNode.Attributes["postalCodeExample"].Value; } if (countryNode.Attributes["postalCode"] != null) { thisCountry.postalCode = countryNode.Attributes["postalCode"].Value; } if (countryNode.Attributes["onePostalCode"] != null) { thisCountry.onePostalCode = countryNode.Attributes["onePostalCode"].Value == "true"; } if (countryNode.InnerText != null) { thisCountry.fullName = countryNode.InnerText; } thisContinent.countries.Add(thisCountry); } } countryData.continents.Add(thisContinent); } } } } // Head end data if (headendDataNode != null) { foreach (XmlNode headEndListNode in headendDataNode.SelectNodes("HeadEndList")) { var headEnds = new List <SDHeadendsResponse>(); var thisKey = $"{headEndListNode.Attributes["country"].Value},{headEndListNode.Attributes["postcode"].Value}"; foreach (XmlNode headEndNode in headEndListNode.SelectNodes("HeadEnd")) { var lineUpList = new List <SDHeadendsResponse.SDLineup>(); var thisHeadEnd = new SDHeadendsResponse { cacheDate = GetCacheDate(headEndNode) }; if (!validateCacheDate(thisHeadEnd.cacheDate)) { continue; } if (headEndNode.Attributes["headend"] != null) { thisHeadEnd.headend = headEndNode.Attributes["headend"].Value; } if (headEndNode.Attributes["location"] != null) { thisHeadEnd.location = headEndNode.Attributes["location"].Value; } if (headEndNode.Attributes["transport"] != null) { thisHeadEnd.transport = headEndNode.Attributes["transport"].Value; } foreach (XmlNode lineUpNode in headEndNode.SelectNodes("LineUp")) { var thisLineup = new SDHeadendsResponse.SDLineup { cacheDate = GetCacheDate(lineUpNode) }; if (!validateCacheDate(thisLineup.cacheDate)) { continue; } if (lineUpNode.Attributes["lineup"] != null) { thisLineup.lineup = lineUpNode.Attributes["lineup"].Value; } if (lineUpNode.Attributes["uri"] != null) { thisLineup.uri = lineUpNode.Attributes["uri"].Value; } if (lineUpNode.InnerText != null) { thisLineup.name = lineUpNode.InnerText; } lineUpList.Add(thisLineup); } thisHeadEnd.lineups = lineUpList.ToArray(); headEnds.Add(thisHeadEnd); } headendData.Add(thisKey, headEnds); } } if (previewDataNode != null) { foreach (XmlNode previewLineupNode in previewDataNode.SelectNodes("PreviewLineup")) { var lineup = previewLineupNode?.Attributes["lineup"]?.Value ?? String.Empty; var previewList = new List <SDPreviewLineupResponse>(); foreach (XmlNode channelNode in previewLineupNode.SelectNodes("Channel")) { var channel = new SDPreviewLineupResponse { cacheDate = GetCacheDate(previewLineupNode) }; if (validateCacheDate(channel.cacheDate)) { channel.channel = channelNode?.Attributes["channel"]?.Value ?? string.Empty; channel.callsign = channelNode?.Attributes["callsign"]?.Value ?? string.Empty; channel.name = channelNode.InnerText ?? string.Empty; previewList.Add(channel); } } previewStationData.Add(lineup, previewList); } } // Map/Station/Metadata if (lineupDataNode != null) { //stationMapData = new Dictionary<string, SDGetLineupResponse>(); foreach (XmlNode lineUpNode in lineupDataNode.SelectNodes("LineUp")) { var thisKey = lineUpNode.Attributes["lineup"].Value; var thisStationMap = new SDGetLineupResponse { cacheDate = GetCacheDate(lineUpNode) }; if (validateCacheDate(thisStationMap.cacheDate)) { // Maps var mapList = new List <SDGetLineupResponse.SDLineupMap>(); foreach (XmlNode mapNode in lineUpNode.SelectNodes("Map")) { var thisMap = new SDGetLineupResponse.SDLineupMap { cacheDate = GetCacheDate(mapNode) }; if (validateCacheDate(thisMap.cacheDate)) { if (mapNode.Attributes["atscMajor"] != null) { thisMap.atscMajor = int.Parse(mapNode.Attributes["atscMajor"].Value); } if (mapNode.Attributes["atscMinor"] != null) { thisMap.atscMinor = int.Parse(mapNode.Attributes["atscMinor"].Value); } if (mapNode.Attributes["channel"] != null) { thisMap.channel = mapNode.Attributes["channel"].Value; } if (mapNode.Attributes["deliverySystem"] != null) { thisMap.deliverySystem = mapNode.Attributes["deliverySystem"].Value; } if (mapNode.Attributes["fec"] != null) { thisMap.fec = mapNode.Attributes["fec"].Value; } if (mapNode.Attributes["frequencyHz"] != null) { thisMap.frequencyHz = UInt64.Parse(mapNode.Attributes["frequencyHz"].Value); } if (mapNode.Attributes["logicalChannelNumber"] != null) { thisMap.logicalChannelNumber = mapNode.Attributes["logicalChannelNumber"].Value; } if (mapNode.Attributes["matchType"] != null) { thisMap.matchType = mapNode.Attributes["matchType"].Value; } if (mapNode.Attributes["modulationSystem"] != null) { thisMap.modulationSystem = mapNode.Attributes["modulationSystem"].Value; } if (mapNode.Attributes["networkID"] != null) { thisMap.networkID = mapNode.Attributes["networkID"].Value; } if (mapNode.Attributes["polarization"] != null) { thisMap.polarization = mapNode.Attributes["polarization"].Value; } if (mapNode.Attributes["providerCallsign"] != null) { thisMap.providerCallsign = mapNode.Attributes["providerCallsign"].Value; } if (mapNode.Attributes["serviceID"] != null) { thisMap.serviceID = mapNode.Attributes["serviceID"].Value; } if (mapNode.Attributes["stationID"] != null) { thisMap.stationID = mapNode.Attributes["stationID"].Value; } if (mapNode.Attributes["symbolrate"] != null) { thisMap.symbolrate = int.Parse(mapNode.Attributes["symbolrate"].Value); } if (mapNode.Attributes["transportID"] != null) { thisMap.transportID = mapNode.Attributes["transportID"].Value; } if (mapNode.Attributes["uhfVhf"] != null) { thisMap.uhfVhf = int.Parse(mapNode.Attributes["uhfVhf"].Value); } mapList.Add(thisMap); } } // Stations var stationList = new List <SDGetLineupResponse.SDLineupStation>(); foreach (XmlNode stationNode in lineUpNode.SelectNodes("Station")) { var thisStation = new SDGetLineupResponse.SDLineupStation { cacheDate = GetCacheDate(stationNode) }; if (validateCacheDate(thisStation.cacheDate)) { if (stationNode.Attributes["affiliate"] != null) { thisStation.affiliate = stationNode.Attributes["affiliate"].Value; } if (stationNode.Attributes["id"] != null) { thisStation.stationID = stationNode.Attributes["id"].Value; } if (stationNode.Attributes["callsign"] != null) { thisStation.callsign = stationNode.Attributes["callsign"].Value; } if (stationNode.Attributes["name"] != null) { thisStation.name = stationNode.Attributes["name"].Value; } var broadcastLanguages = new List <string>(); foreach (XmlNode broadcastLanguageNode in stationNode.SelectNodes("BroadcastLanguage")) { broadcastLanguages.Add(broadcastLanguageNode.InnerText); } thisStation.broadcastLanguage = broadcastLanguages.ToArray(); var descriptionLanguages = new List <string>(); foreach (XmlNode descriptionLanguageNode in stationNode.SelectNodes( "DescriptionLanguage")) { descriptionLanguages.Add(descriptionLanguageNode.InnerText); } thisStation.descriptionLanguage = descriptionLanguages.ToArray(); var broadcasterNode = stationNode.SelectSingleNode("Broadcaster"); if (broadcasterNode != null) { thisStation.broadcaster = new SDGetLineupResponse.SDLineupStation.SDStationBroadcaster { city = broadcasterNode.Attributes["city"].Value, state = broadcasterNode.Attributes["state"].Value, postalcode = broadcasterNode.Attributes["postalcode"].Value, country = broadcasterNode.Attributes["country"].Value }; } var logoNode = stationNode.SelectSingleNode("Logo"); if (logoNode != null) { thisStation.logo = new SDGetLineupResponse.SDLineupStation.SDStationLogo { URL = logoNode.Attributes["url"].Value, height = int.Parse(logoNode.Attributes["height"].Value), width = int.Parse(logoNode.Attributes["width"].Value), md5 = logoNode.Attributes["md5"].Value }; } stationList.Add(thisStation); } } thisStationMap.map = mapList.ToArray(); thisStationMap.stations = stationList.ToArray(); // Metadata var metadataNode = lineUpNode.SelectSingleNode("MetaData"); if (metadataNode != null) { thisStationMap.metadata = new SDGetLineupResponse.SDLineupMetadata { lineup = metadataNode.Attributes["lineup"].Value, modified = DateTime.ParseExact( metadataNode.Attributes["modified"].Value, "yyyyMMddHHmmss", CultureInfo.InvariantCulture), transport = metadataNode.Attributes["transport"].Value, modulation = metadataNode.Attributes["modulation"].Value }; } stationMapData.Add(thisKey, thisStationMap); } } } return(true); }