示例#1
0
        public static string RunRule(RSSListener.Data.Model.Rule2 rule, XMLDefinition definition, WrappedXMLDef definitionelement, XmlNode node)
        {
            string input = "";

            switch (definitionelement)
            {
            case WrappedXMLDef.DescriptionTag:
                input = node.SelectSingleNode(definition.DescriptionTag).InnerText;
                break;

            case WrappedXMLDef.EnclosureTag:
                input = node.SelectSingleNode(definition.EnclosureTag).OuterXml;
                break;

            case WrappedXMLDef.PublishedTag:
                input = node.SelectSingleNode(definition.PublishedTag).InnerText;
                break;

            case WrappedXMLDef.TitleTag:
                input = node.SelectSingleNode(definition.TitleTag).InnerText;
                break;

            case WrappedXMLDef.URLTag:
                input = node.SelectSingleNode(definition.URLTag).InnerText;
                break;

            default:
                throw new Exception("The tag does not exist");
            }
            return(RunRule(rule, input));
        }
示例#2
0
        private void fetchPodCastsFromXML(PodCast p, string pathtoxml)
        {
            XMLDefinition definition = DBContext.getDefinitionByPodcast(p);

            if (definition != null)
            {
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(pathtoxml);
                    PodcastXMLData pxml = new PodcastXMLData();
                    pxml.fk_podcast    = p.id.ToString();
                    pxml.lastbuilddate = doc.SelectSingleNode(definition.xpathToLastBuildDate).InnerText;
                    pxml.podcastdata   = System.IO.File.ReadAllText(pathtoxml);
                    DBContext.InsertPodcastXMLData(pxml);
                    XmlNodeList nl = doc.SelectNodes(definition.xpathToItems);
                    //int count = 0;
                    List <Show> shows = new List <Show>();
                    foreach (XmlNode n in nl)
                    {
                        //if (count == 5) { return; }
                        try
                        {
                            string showtitle      = "";
                            string artist         = "";
                            string readinrecorded = "";
                            string url            = "";
                            string description    = "";
                            if (definition.TitleRule != null && !String.IsNullOrWhiteSpace(definition.TitleTag))
                            {
                                try
                                {
                                    showtitle = RSSListener.Rules.RuleEngineV2.RunRule(definition.TitleRule, definition, RSSListener.Rules.RuleEngineV2.WrappedXMLDef.TitleTag, n);
                                }
                                catch
                                {
                                    showtitle = n.SelectSingleNode(definition.TitleTag).InnerText;
                                }
                            }
                            else
                            {
                                showtitle = n.SelectSingleNode(definition.TitleTag).InnerText;
                            }
                            if (p.useDefault)
                            {
                                artist = p.DefaultArtistName;
                            }
                            else
                            {
                                if (definition.ArtistRule != null)
                                {
                                    artist = RSSListener.Rules.RuleEngineV2.RunRule(definition.ArtistRule, definition, RSSListener.Rules.RuleEngineV2.WrappedXMLDef.TitleTag, n);
                                }
                                else
                                {
                                    artist = "Unknown";
                                }
                            }
                            if (definition.PublishedRule != null)
                            {
                                readinrecorded = RSSListener.Rules.RuleEngineV2.RunRule(definition.PublishedRule, n.SelectSingleNode(definition.PublishedTag).InnerText);
                            }
                            else
                            {
                                readinrecorded = DateTime.MinValue.ToString();
                            }
                            DateTime recorded = DateTime.Parse(readinrecorded);
                            if (definition.EnclosureRule != null && !String.IsNullOrWhiteSpace(definition.EnclosureTag))
                            {
                                url = RSSListener.Rules.RuleEngineV2.RunRule(definition.EnclosureRule, definition, RSSListener.Rules.RuleEngineV2.WrappedXMLDef.EnclosureTag, n);
                            }
                            else
                            {
                                throw new Exception("Could not disassemble url!\r\n" + n.OuterXml + "\r\nRule:\r\n" + definition.EnclosureRule.id.ToString() + "\r\n" + "Podcast: " + p.PodcastName + " {" + p.id + "}");
                            }
                            if (definition.DescriptionRule != null && !String.IsNullOrWhiteSpace(definition.DescriptionTag))
                            {
                                description = RSSListener.Rules.RuleEngineV2.RunRule(definition.DescriptionRule, n.SelectSingleNode(definition.DescriptionTag).InnerText);
                            }
                            Artist artistobj = DBContext.getArtistByName(artist, true);
                            Genre  g         = DBContext.getGenreByID(Guid.Parse(p.fk_genre));
                            Show   show      = new Show(showtitle, artistobj, p.PodcastName, url, g, description, p.podcastpath, logger, p);
                            show.Recorded = recorded;
                            DBContext.InsertShow(show);
                            shows.Add(show);
                        }
                        catch (Exception ex2)
                        {
                            logger.addEvent(new cEvent(Severity.Error, "There was an error trying to parse:\r\n" + n.InnerXml + "\r\n\r\nWith Defition: " + definition.id + "\r\n" + "For Podcast: " + p.PodcastName, ex2));
                        }
                    }
                    p.shows = shows;
                }
                catch (Exception ex)
                {
                    logger.addEvent(new cEvent(Severity.Error, "There was an error during processing of an xml for podcast: " + p.PodcastName, ex));
                }
            }
            else
            {
                logger.addEvent(new cEvent(Severity.Warning, "There is no definition for this podcast: " + p.PodcastName + " {" + p.id + "}"));
            }
        }