コード例 #1
0
        public void Test_canGetXmltvEntireFileAsync()
        {
            Uri serverIp = new Uri(serverProtAndIp_success, UriKind.Absolute);

            PortableXMLTVInterfaceLibraryAsync alpha = new PortableXMLTVInterfaceLibraryAsync();

            var response = alpha.GetXmltvEntireFileAsync(serverIp);

            string result = response.Result.ToString();

            Assert.AreNotEqual("", result);
        }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: leonardant/vboxSuite
        private async Task loadChannelDataIntoDbAsync()
        {
            int clearDbRowsAffected = 0;

            PortableXMLTVInterfaceLibraryAsync P_XmltvIL = new PortableXMLTVInterfaceLibraryAsync();

            var ChannelAndProgrammeList = await P_XmltvIL.GetXmltvEntireFileAsync(new Uri("http://10.100.107.204/", UriKind.Absolute));

            #region // channels

            int numberOfChannelsAddedToDb = 0;

            var channelsFromXML = (from node in ChannelAndProgrammeList.Descendants("channel")
                                   select new
            {
                channelUniqueId = node.Attribute("id").Value.ToString(),
                channelIcon = node.Element("icon").Attribute("src").Value.ToString(),
                channelName = node.Elements("display-name").ElementAt(0).Value.ToString(),
                channelType = node.Elements("display-name").ElementAt(1).Value.ToString(),
                channelCode = node.Elements("display-name").ElementAt(2).Value.ToString(),
                channelPPV = node.Elements("display-name").ElementAt(3).Value.ToString(),
                channelSource = node.Elements("display-name").ElementAt(4).Value.ToString(),
                channelUrl = node.Element("url").Attribute("src").Value.ToString()
            }).Distinct();



            List <channel> channelList = new List <channel>();

            foreach (var item in channelsFromXML)
            {
                channel c = new channel();

                string regexSearch            = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
                Regex  r                      = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
                string channelNameToLookupFix = r.Replace(item.channelName, "_");

                string        imageFile          = @"Assets\ChannelIcons\" + item.channelType + @"\" + channelNameToLookupFix + @".png";
                StorageFolder InstallationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
                var           file = await InstallationFolder.TryGetItemAsync(imageFile);

                c.channelUniqueId = item.channelUniqueId;
                c.channelIcon     = (file != null ? "ms-appx:///" + imageFile : item.channelIcon);
                c.channelName     = item.channelName;
                c.channelType     = item.channelType;
                c.channelCode     = item.channelCode;
                c.channelPPV      = item.channelPPV;
                c.channelSource   = item.channelSource;
                c.channelUrl      = item.channelUrl;

                channelList.Add(c);
            }

            // clear the old db data
            clearDbRowsAffected = await App.dsfdd.Db.ExecuteAsync("delete from channel where channelId > ?", 0);

            numberOfChannelsAddedToDb = await App.dsfdd.Db.InsertAllAsync(channelList.AsEnumerable <channel>());

            if (numberOfChannelsAddedToDb.Equals(0))
            {
                showUserCancelableMessage("no channels added to the database");
            }
            else if (numberOfChannelsAddedToDb.Equals(1))
            {
                showUserCancelableMessage("1 channel added to the database");
            }
            else
            {
                showUserCancelableMessage(numberOfChannelsAddedToDb.ToString() + " channels added to the database");
            }

            #endregion

            #region // programmes

            int numberOfProgrammesAddedToDb = 0;

            var programmesFromXML = (from node in ChannelAndProgrammeList.Descendants("programme")
                                     select new
            {
                programmeStart = node.Attribute("start").Value.ToString(),
                programmeStop = node.Attribute("stop").Value.ToString(),
                programmeChannel = node.Attribute("channel").Value.ToString(),
                programmeTitle = node.Element("title").Value.ToString(),
                programmeDescription = node.Element("desc").Value.ToString(),
                programmeEpisodeNumberSystem = (node.Element("episode-num") != null ? node.Element("episode-num").Attribute("system").Value.ToString() : string.Empty),
                programmeEpisodeNumberProgId = (node.Element("episode-num") != null ? node.Element("episode-num").Value.ToString() : string.Empty)
            }).Distinct();

            List <programme> programList = new List <programme>();

            foreach (var item in programmesFromXML)
            {
                programme p = new programme();

                p.programmeStart               = item.programmeStart;
                p.programmeStop                = item.programmeStop;
                p.programmeChannel             = item.programmeChannel;
                p.programmeTitle               = item.programmeTitle;
                p.programmeDescription         = item.programmeDescription;
                p.programmeEpisodeNumberSystem = item.programmeEpisodeNumberSystem;
                p.programmeEpisodeNumberProgId = item.programmeEpisodeNumberProgId;

                programList.Add(p);
            }

            // clear the old db data
            clearDbRowsAffected = await App.dsfdd.Db.ExecuteAsync("delete from programme where programmeId > ?", 0);

            numberOfProgrammesAddedToDb = await App.dsfdd.Db.InsertAllAsync(programList.AsEnumerable <programme>());

            if (numberOfProgrammesAddedToDb.Equals(0))
            {
                showUserCancelableMessage("no programmes added to the database");
            }
            else if (numberOfProgrammesAddedToDb.Equals(1))
            {
                showUserCancelableMessage("1 programme added to the database");
            }
            else
            {
                showUserCancelableMessage(numberOfProgrammesAddedToDb.ToString() + " programmes added to the database");
            }
            #endregion
        }