public void CommonSetCoreChannelPropertiesUsingHelperMethods(Rss20 rss, string optionalTitle = "")
        {
            RssChannel chan = rss.channel;

            string default_title = "TEST CHANNEL CREATED WITH HELPER METHODS";
            string title         = optionalTitle.Length > 0 ? optionalTitle : default_title;



            chan.AddTitle(title);
            chan.AddLink("http://something.com/rss");
            chan.AddPubDate(DateTime.Today);
            chan.AddLastBuildDate(DateTime.Today);

            chan.AddDescription("This is a channel that is created for sirpenski.syndication.rss20 testing purposes");
            chan.AddLanguage("en");
            chan.AddCopyright("Copyright " + DateTime.Today.ToString("yyyy") + ". All Rights Reserved");
            chan.AddManagingEditor("*****@*****.**");
            chan.AddWebMaster("*****@*****.**");
            chan.AddCategory("TEST", "http://something.com");
            chan.AddCategory("RSS");
            chan.AddGenerator("sirpenski.syndication.rss20");
            chan.AddDocs("http://something.com/format_of_this_channel");
            chan.AddCloud("http://something.com", 11092, "/path/to/service", "notifyChannelUpdate", "xml-rpc");
            chan.AddTtl(1440);

            chan.AddImage("http://something.com/images/rss/rss_channel_logo_88x88.gif", "Channel Icon", "http://something.com", 88, 88);

            chan.AddSkipHour(1);
            chan.AddSkipHour(2);
            chan.AddSkipHour(3);

            chan.AddSkipDay(RssChannelSkipDays.DAY_SATURDAY);
            chan.AddSkipDay(RssChannelSkipDays.DAY_SUNDAY);
        }
        public void CommonSetExtendedChannelPropertiesUsingHelperMethods(Rss20 rss)
        {
            RssChannel chan = rss.channel;

            chan.AddAtomLink("http://something.com", "self", "application/rss+xml", chan.title, "en", 102293);
            chan.AddCreativeCommonsLicense("http://creativecommons.org/useitall");
        }
        public void CreateChannelWithExtendedPropertiesUsingObjects(Rss20 rss)
        {
            // create the channel
            CommonSetCoreChannelPropertiesUsingObjects(rss, "CREATE CHANNEL WITH EXTENDED PROPERTIES USING OBJECTS");

            // set using extended properties objects, no media
            CommonSetExtendedChannelPropertiesUsingObjects(rss);
        }
        public void CreateChannelWithExtendedPropertiesUsingHelperMethods(Rss20 rss)
        {
            // create the channel
            CommonSetCoreChannelPropertiesUsingObjects(rss, "CREATE CHANNEL WITH EXTENDED PROPERTIES USING HELPER METHODS");

            // set using extended properties helper methods, no media
            CommonSetExtendedChannelPropertiesUsingHelperMethods(rss);
        }
Ejemplo n.º 5
0
        public void GeneratRssFeedFiles(IList <ProductVariant> products)
        {
            try
            {
                var rssFeeds = CreateRssFeeds(products);

                var path = RssFeedHelper.GetFilePath("");
                Directory.CreateDirectory(path);

                var xmlSettings = new XmlWriterSettings();
                xmlSettings.Indent   = true;
                xmlSettings.Encoding = Encoding.UTF8;

                foreach (var local in _rssFeedSettings.Locales)
                {
                    var    fileName    = Path.Combine(path, local.FileName);
                    string fileNameAll = Path.Combine(path, Path.GetFileNameWithoutExtension(local.FileName) + "-all." + Path.GetExtension(local.FileName));

                    var tt1      = DateTime.Now.Ticks;
                    var feedsAll = rssFeeds[local.LanguageId];
                    var feedsWithoutCallForPrice = new Rss20()
                    {
                        Version = feedsAll.Version,
                        Channel = new Rss20Channel()
                        {
                            Title       = feedsAll.Channel.Title,
                            Link        = feedsAll.Channel.Link,
                            Description = feedsAll.Channel.Description,
                            Items       = feedsAll.Channel.Items.Where(x => x.CallForPrice == false).ToList(),
                        },
                    };

                    XmlSerializer serializer = new XmlSerializer(typeof(Rss20));
                    var           ns         = new XmlSerializerNamespaces();
                    ns.Add("g", RssFeedHelper.GoogleNamespce);

                    using (var stream = XmlWriter.Create(fileNameAll, xmlSettings))
                    {
                        serializer.Serialize(stream, feedsAll, ns);
                        stream.Close();
                        _logger.Information($"RssFeed: the file {fileNameAll} has been saved");
                    }
                    using (var stream = XmlWriter.Create(fileName, xmlSettings))
                    {
                        serializer.Serialize(stream, feedsWithoutCallForPrice, ns);
                        stream.Close();
                        _logger.Information($"RssFeed: the file {fileName} has been saved");
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("RssFeed: error occured in generating XML files", ex);
                throw;
            }
        }
        public void CreateChannelWithOneCoreItemHelperMethods(Rss20 rss)
        {
            // create the channel
            CommonSetCoreChannelPropertiesUsingHelperMethods(rss, "CREATE CHANNEL WITH ONE ITEM (CORE PROPERTIES ONLY) USING HELPER METHODS");

            RssItem itm = new RssItem();

            //
            CommonSetCoreItemPropertiesUsingHelperMethods(itm);

            rss.channel.AddItem(itm);
        }
        private void CreateChannelWithOneCoreItem(Rss20 rss)
        {
            // create the base channel
            CommonSetCoreChannelPropertiesUsingObjects(rss, "CREATE CHANNEL WITH ONE ITEM (CORE PROPERTIES ONLY) USING OBJECTS");


            RssItem itm = new RssItem();

            // set the core item properties
            CommonSetCoreItemPropertiesUsingObjects(itm);


            // add the item to the channel
            rss.channel.AddItem(itm);
        }
Ejemplo n.º 8
0
        protected Dictionary <int, Rss20> CreateRssFeeds(IList <ProductVariant> products)
        {
            var dic = new Dictionary <int, Rss20>();

            if (_rssFeedSettings.Locales.Count == 0)
            {
                throw new Exception("The RssFeed plugin is not configured");
            }

            _logger.Information($"RssFeed: Start generating feeds for {products.Count} products");

            var t1 = DateTime.Now.Ticks;

            _urlHelper = null; // reset

            foreach (var L in _rssFeedSettings.Locales)
            {
                CleanInvalidXmlChars(L.Title);
                CleanInvalidXmlChars(L.Link);
                CleanInvalidXmlChars(L.Description);
                var rss = new Rss20(L.Title, L.Link, L.Description);
                dic[L.LanguageId] = rss;
            }

            int cntr = 0;

            foreach (var p in products)
            {
                cntr++;
                var item = CreateProductRssItems(p, _rssFeedSettings.Locales);
                if (cntr % 1000 == 0)
                {
                    _logger.Information($"RssFeed: {cntr} products has been processed so far.");
                }

                foreach (var k in item.Keys)
                {
                    dic[k].Channel.Items.Add(item[k]);
                }
            }

            var t2   = DateTime.Now.Ticks;
            var time = TimeSpan.FromTicks(t2 - t1);

            _logger.Information("RssFeed: Rss20 object is created within " + time);

            return(dic);
        }
        public void CommonSetExtendedChannelPropertiesUsingObjects(Rss20 rss)
        {
            RssAtomLink lnk = new RssAtomLink();

            lnk.href     = "http://something.com";
            lnk.hreflang = "en";
            lnk.title    = rss.channel.title;
            lnk.type     = "application/rss+xml";
            lnk.rel      = "self";
            lnk.length   = 102293;
            rss.channel.AddAtomLink(lnk);

            RssCreativeCommonsLicense lic = new RssCreativeCommonsLicense();

            lic.license = "http://creativecommons.org/useitall";
            rss.channel.AddCreativeCommonsLicense(lic);
        }
        public void CreateOneItemWithMediaContentAndMediaOptions(Rss20 rss)
        {
            // create the channel
            CommonSetCoreChannelPropertiesUsingObjects(rss, "CREATE CHANNEL WITH EXTENDED PROPERTIES PLUS ONE ITEM WITH EXTENSION AND ONE MEDIA CONTENT ITEM PLUS MEDIA OPTIONS");

            // set using extended properties objects, no media
            CommonSetExtendedChannelPropertiesUsingObjects(rss);

            // define new item
            RssItem itm = new RssItem();

            // add the core item
            CommonSetCoreItemPropertiesUsingObjects(itm);

            // add the extended item objects
            CommonSetExtendedItemPropertiesUsingObjects(itm);

            // Create the media content item
            RssMediaContent mc = new RssMediaContent();

            mc.url          = "http://something.com/media/movie.mp4";
            mc.fileSize     = 1000000;
            mc.type         = "video/mp4";
            mc.medium       = "video";
            mc.isDefault    = true;
            mc.expression   = "full";
            mc.bitrate      = 128;
            mc.frameRate    = 30;
            mc.samplingrate = 44.1;
            mc.channels     = 2;
            mc.duration     = 185;
            mc.width        = 400;
            mc.height       = 200;
            mc.lang         = "en";

            CommonSetMediaPropertiesUsingObjects(mc);


            itm.AddMediaContentItem(mc);



            // add the item
            rss.channel.AddItem(itm);
        }
 private void CreateChannelUsingHelperMethods(Rss20 rss)
 {
     CommonSetCoreChannelPropertiesUsingHelperMethods(rss, "CREATE CHANNEL (CORE PROPERTIES ONLY) USING HELPER METHODS");
 }
 private void CreateChannelUsingObjects(Rss20 rss)
 {
     CommonSetCoreChannelPropertiesUsingObjects(rss, "CREATE CHANNEL (CORE PROPERTIES ONLY) USING OBJECTS");
 }
        // *****************************************************************************
        // TEST CODE BEGINS HERE
        // *****************************************************************************



        #region CommonSetCoreChannelPropertiesUsingObjects
        public void CommonSetCoreChannelPropertiesUsingObjects(Rss20 rss, string optionalTitle = "")
        {
            RssChannel chan = rss.channel;

            string default_title = "TEST CHANNEL CREATED WITH HELPER METHODS";
            string title         = optionalTitle.Length > 0 ? optionalTitle : default_title;



            chan.title          = title;
            chan.link           = "http://something.com/rss";
            chan.pubDate        = DateTime.Now.ToUniversalTime();
            chan.lastBuildDate  = chan.pubDate;
            chan.description    = "This is a channel that is created for sirpenski.syndication.rss20 testing purposes";
            chan.language       = "en";
            chan.copyright      = "Copyright " + DateTime.Today.ToString("yyyy") + ". All Rights Reserved";
            chan.managingEditor = "*****@*****.**";
            chan.webMaster      = "*****@*****.**";

            // add categories
            RssChannelCategory ctg = new RssChannelCategory();

            ctg.category = "TEST";
            ctg.domain   = "http://something.com";
            chan.categories.Add(ctg);

            ctg          = new RssChannelCategory();
            ctg.category = "RSS";
            ctg.domain   = "";
            chan.categories.Add(ctg);

            // feed generator
            chan.generator = "sirpenski.syndication.rss20";

            // documentation url that defines spec for this channel
            chan.docs = "http://something.com/format_of_this_channel";

            // cloud
            RssChannelCloud c = new RssChannelCloud();

            c.domain            = "http://something.com";
            c.path              = "/path/to/service";
            c.port              = 11092;
            c.protocol          = "xml-rpc";
            c.registerProcedure = "notifyChannelUpdate";
            chan.cloud.Add(c);

            // time to live
            chan.ttl = 1440;

            // channel icon
            RssChannelImage img = new RssChannelImage();

            img.link   = "http://something.com/images/rss/rss_channel_logo_88x88.gif";
            img.title  = "Channel Logo";
            img.url    = "http://something.com";
            img.width  = 88;
            img.height = 88;
            chan.image = img;


            // skip hours ie don't look for updates to channel during these hours
            RssChannelSkipHours skipHours = new RssChannelSkipHours();

            skipHours.Hours.Add(1);
            skipHours.Hours.Add(2);
            skipHours.Hours.Add(3);
            chan.skipHours = skipHours;

            // skip days
            RssChannelSkipDays skipDays = new RssChannelSkipDays();

            skipDays.Days.Add(RssChannelSkipDays.DAY_SATURDAY);
            skipDays.Days.Add(RssChannelSkipDays.DAY_SUNDAY);
            chan.skipDays = skipDays;
        }
        /// <summary>
        /// Creates test feeds
        /// </summary>
        /// <param name="TEST_ID"></param>
        /// <param name="OUTPUT_FORMAT"></param>
        /// <returns></returns>

        public IActionResult CreateFeedSubmit(Nullable <int> TEST_ID, Nullable <int> OUTPUT_FORMAT)
        {
            IActionResult rslt = new BadRequestResult();



            // if id has test value, proceed
            if (TEST_ID.HasValue)
            {
                // get the int
                int nTestID = Convert.ToInt32(TEST_ID);

                // get the output value
                int nOutputFormat = 0;
                if (OUTPUT_FORMAT.HasValue)
                {
                    nOutputFormat = Convert.ToInt32(OUTPUT_FORMAT);
                }


                // save the session;
                session.SessionVariables.LastCreateTestID       = nTestID;
                session.SessionVariables.LastCreateOutputFormat = nOutputFormat;
                session.Save();


                // create a new feed
                Rss20 rss = new Rss20();

                // switch the test
                switch (TEST_ID)
                {
                case TEST_CREATE_CHANNEL_USING_OBJECTS:
                    CreateChannelUsingObjects(rss);
                    break;

                case TEST_CREATE_CHANNEL_USING_HELPER_METHODS:
                    CreateChannelUsingHelperMethods(rss);
                    break;

                case TEST_CREATE_ONE_CORE_ITEM:
                    CreateChannelWithOneCoreItem(rss);
                    break;

                case TEST_CREATE_ONE_CORE_ITEM_USING_HELPER_METHODS:
                    CreateChannelWithOneCoreItemHelperMethods(rss);
                    break;

                case TEST_CREATE_CHANNEL_WITH_EXT_PROPS_USING_OBJECTS:
                    CreateChannelWithExtendedPropertiesUsingObjects(rss);
                    break;

                case TEST_CREATE_CHANNEL_WITH_EXT_PROPS_USING_HELPER_METHODS:
                    CreateChannelWithExtendedPropertiesUsingHelperMethods(rss);
                    break;

                case TEST_CREATE_CHANNEL_WITH_EXT_PROPS_MEDIA_USING_OBJECTS:
                    CreateChannelWithExtendedPropertiesAndMediaUsingObjects(rss);
                    break;

                case TEST_CREATE_CHANNEL_WITH_EXT_PROPS_MEDIA_USING_HELPER_METHODS:
                    CreateChannelWithExtendedPropertiesAndMediaUsingHelperMethods(rss);
                    break;

                case TEST_CREATE_CHANNEL_WITH_EXT_PLUS_ONE_EXT_ITEM_USING_OBJECTS:
                    CreateChannelWithExtendedPropertiesAndOneItemWithExtendedPropertiesNoMediaUsingObjects(rss);
                    break;

                case TEST_CREATE_CHANNEL_WITH_EXT_PLUS_ONE_EXT_ITEM_WITH_MEDIA_USING_OBJECTS:
                    CreateChannelWithExtendedPropertiesAndOneItemWithExtendedPropertiesAndMediaUsingObjeccts(rss);
                    break;

                case TEST_CREATE_ONE_ITEM_WITH_MEDIA_CONTENT:
                    CreateOneItemWithMediaContent(rss);
                    break;

                case TEST_CREATE_ONE_ITEM_WITH_MEDIA_CONTENT_AND_MEDIA_OPTIONS:
                    CreateOneItemWithMediaContentAndMediaOptions(rss);
                    break;

                case TEST_CREATE_ONE_ITEM_WITH_MEDIA_GROUP:
                    CreateOneItemWithMediaGroup(rss);
                    break;

                case TEST_CREATE_ONE_ITEM_WITH_MEDIA_GROUP_WITH_MEDIA_OPTIONS:
                    CreateOneItemWithMediaGroupAndMediaOptions(rss);
                    break;
                }



                // do the dump
                switch (nOutputFormat)
                {
                case 0:
                    rslt = Content(rss.GetXml(), "application/xml");
                    break;

                case 1:
                    string json = JsonConvert.SerializeObject(rss, Formatting.Indented, new JsonSerializerSettings {
                        ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                    });
                    rslt = Content(json, "application/json");
                    break;
                } // switch
            }     // end if not string null or empty

            return(rslt);
        }
        /// <summary>
        /// ReadFeedSubmit handles the submission
        /// </summary>
        /// <param name="COMBOBOX_FEED_URL"></param>
        /// <param name="OUTPUT_FORMAT"></param>
        /// <returns></returns>

        public async Task <IActionResult> ReadFeedSubmit(string COMBOBOX_FEED_URL, Nullable <int> OUTPUT_FORMAT)
        {
            IActionResult rslt = new BadRequestResult();

            int nOutputFormat = 0;

            if (OUTPUT_FORMAT.HasValue)
            {
                nOutputFormat = Convert.ToInt32(OUTPUT_FORMAT);
            }

            if (!string.IsNullOrEmpty(COMBOBOX_FEED_URL))
            {
                string url = COMBOBOX_FEED_URL.Trim();
                if (url.Length > 0)
                {
                    // create a new feed
                    Rss20 rss = new Rss20();
                    rss.PersistResponseXml = true;
                    rss.SortItemsOnLoad    = true;
                    HttpStatusCode r = await rss.LoadUrl(url);


                    // set the session variables
                    session.SessionVariables.LastReadUrl          = url;
                    session.SessionVariables.LastReadOutputFormat = nOutputFormat;
                    session.Save();


                    if (rss.ResponseStatusCode == HttpStatusCode.OK)
                    {
                        switch (nOutputFormat)
                        {
                        case 0:
                            rslt = View("~/Views/Home/ReadFeedDisplay.cshtml", rss);
                            break;

                        case 1:
                            rslt = Content(rss.GetXml(), "application/xml");
                            break;

                        case 2:
                            rslt = Content(rss.ResponseXml, "application/xml");
                            break;

                        case 3:
                            rslt = Content(rss.ResponseRawXml, "application/xml");
                            break;


                        case 4:
                            string json = JsonConvert.SerializeObject(rss, Formatting.Indented, new JsonSerializerSettings {
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                            });
                            rslt = Content(json, "application/json");
                            break;
                        }   // switch
                    }
                }
            }

            return(rslt);
        }
        public void CreateChannelWithExtendedPropertiesAndOneItemWithExtendedPropertiesAndMediaUsingObjeccts(Rss20 rss)
        {
            // create the channel
            CommonSetCoreChannelPropertiesUsingObjects(rss, "CREATE CHANNEL WITH EXTENDED PROPERTIES PLUS ONE ITEM WITH EXTENSION AND MEDIA USING OBJECTS");

            // set using extended properties objects, no media
            CommonSetExtendedChannelPropertiesUsingObjects(rss);

            // define new item
            RssItem itm = new RssItem();

            // add the core item
            CommonSetCoreItemPropertiesUsingObjects(itm);

            // add the extended item objects
            CommonSetExtendedItemPropertiesUsingObjects(itm);

            CommonSetMediaPropertiesUsingObjects(itm);

            // add the item
            rss.channel.AddItem(itm);
        }