예제 #1
0
        protected void nodes_rss(Guid?nodeTypeId, string title, string description, int?count, long?lowerBoundary,
                                 string searchText, bool?isDocument, bool?isKnowledge, bool?sitemap)
        {
            if (!count.HasValue || count.Value <= 0)
            {
                count = 20;
            }
            if (count.HasValue && count > 5000)
            {
                count = 5000;
            }

            List <Node> nodes = nodeTypeId.HasValue ?
                                CNController.get_nodes(paramsContainer.Tenant.Id, nodeTypeId.Value, null, searchText,
                                                       isDocument, isKnowledge, null, null, count.Value, lowerBoundary, false) :
                                CNController.get_nodes(paramsContainer.Tenant.Id,
                                                       searchText, isDocument, isKnowledge, null, null, count.Value, lowerBoundary, false);

            if (sitemap.HasValue && sitemap.Value)
            {
                paramsContainer.xml_response(
                    "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">" +
                    ProviderUtil.list_to_string <string>(nodes.Select(
                                                             u => "<url>" +
                                                             "<loc>" +
                                                             PublicConsts.get_complete_url(paramsContainer.Tenant.Id, PublicConsts.NodePage) +
                                                             "/" + u.NodeID.Value.ToString() +
                                                             "</loc>" +
                                                             "<changefreq>weekly</changefreq>" +
                                                             "<lastmod>" + String.Format("{0:yyyy-MM-dd}", DateTime.Now) + "</lastmod>" +
                                                             //"<priority>0.8</priority>" +
                                                             "</url>").ToList(), null) +
                    "</urlset>"
                    );

                return;
            }

            List <RSSItem> rssItems = new List <RSSItem>();

            foreach (Modules.CoreNetwork.Node _nd in nodes)
            {
                rssItems.Add(new RSSItem()
                {
                    Title = _nd.Name,
                    Link  = PublicConsts.get_complete_url(paramsContainer.Tenant.Id, PublicConsts.NodePage) +
                            "/" + _nd.NodeID.Value.ToString()
                });
            }

            RSSUtilities.send_feed(HttpContext.Current, rssItems, title, description);
        }
예제 #2
0
        protected void external(List <KeyValuePair <string, string> > urls, int?count,
                                Guid?storeAsNodeTypeId, ref string responseText)
        {
            if (!count.HasValue || count.Value <= 0)
            {
                count = 20;
            }
            if (count.HasValue && count.Value > 5000)
            {
                count = 5000;
            }

            List <RSSItem> items = new List <RSSItem>();

            DateTime now      = DateTime.Now;
            TimeSpan fiveMins = now.AddMinutes(5) - now;

            int maxCount = count.Value * 2 / urls.Count;

            List <KeyValuePair <RSSItem, string> > hashLinks = new List <KeyValuePair <RSSItem, string> >();

            foreach (KeyValuePair <string, string> u in urls)
            {
                if (!externalRssFeeds.ContainsKey(u.Value) || !(now - externalRssFeeds[u.Value].Key <= fiveMins))
                {
                    externalRssFeeds[u.Value] =
                        new KeyValuePair <DateTime, List <RSSItem> >(now, RSSUtilities.get_feed(u.Value, u.Key));

                    if (storeAsNodeTypeId.HasValue)
                    {
                        hashLinks.AddRange(externalRssFeeds[u.Value].Value
                                           .Select(x => new KeyValuePair <RSSItem, string>(x, PublicMethods.sha1(x.Link))));
                    }
                }

                items.AddRange(externalRssFeeds[u.Value].Value.OrderByDescending(v => v.PublicationDate).Take(maxCount));
            }

            items = items.OrderByDescending(u => u.PublicationDate).Take(count.Value).ToList();

            if (storeAsNodeTypeId.HasValue)
            {
                List <KeyValuePair <string, Guid> > guids = GlobalController.get_guids(paramsContainer.Tenant.Id,
                                                                                       hashLinks.Select(u => u.Value).ToList(), "RSS", false, true);

                List <KeyValuePair <Guid, RSSItem> > toBeStored =
                    guids.Select(u => new KeyValuePair <Guid, RSSItem>(u.Value, hashLinks.Where(v => v.Value == u.Key).Select(y => y.Key).FirstOrDefault())).ToList();

                List <Node> nodes = toBeStored.Select(
                    u => new Modules.CoreNetwork.Node()
                {
                    NodeID       = u.Key,
                    NodeTypeID   = storeAsNodeTypeId.Value,
                    Name         = u.Value.Title,
                    CreationDate = u.Value.PublicationDate.HasValue ? u.Value.PublicationDate : DateTime.Now,
                    Description  = (!u.Value.PublicationDate.HasValue ? string.Empty :
                                    "<div style='text-align:center; margin-bottom:20px;'>" + PublicMethods.get_local_date(u.Value.PublicationDate.Value, true) + "</div>") +
                                   (string.IsNullOrEmpty(u.Value.Description) ? u.Value.Summary : u.Value.Description) +
                                   (string.IsNullOrEmpty(u.Value.Link) ? string.Empty : "<div style='margin-top:12px;'><span style='margin:0px 4px 0px 4px;'>@[[Dic:Dic:" + Base64.encode("Source") + "]]:</span><a href='" + u.Value.Link + "'>" + u.Value.Link + "</a></div>")
                }).ToList();

                System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(_rss_to_nodes), nodes);
            }

            responseText = "{\"Items\":[" + ProviderUtil.list_to_string <string>(items.Select(
                                                                                     u => "{\"ID\":\"" + u.ID + "\"" +
                                                                                     ",\"Title\":\"" + Base64.encode(u.Title) + "\"" +
                                                                                     ",\"Summary\":\"" + (string.IsNullOrEmpty(u.Summary) ? string.Empty :
                                                                                                          Base64.encode(u.Summary.Substring(0, Math.Min(u.Summary.Length, 300)))) + "\"" +
                                                                                     ",\"Description\":\"" + (string.IsNullOrEmpty(u.Description) ? string.Empty :
                                                                                                              Base64.encode(u.Description.Substring(0, Math.Min(u.Description.Length, 300)))) + "\"" +
                                                                                     ",\"Link\":\"" + Base64.encode(u.Link) + "\"" +
                                                                                     ",\"PublicationDate\":\"" + (u.PublicationDate.HasValue ?
                                                                                                                  PublicMethods.get_local_date(u.PublicationDate.Value, true) : string.Empty) + "\"" +
                                                                                     "}").ToList()) +
                           "]}";
        }