public virtual ActionResult Feed(int?page, int?pageSize)
        {
            var blogRoot = EnsureTrailingSlash(Configuration.GetSiteRoot(AppHarbor.IsSecureConnection(HttpContext))) + "blog";

            var posts = GetPostsByMostRecentFirst();

            if (page != null && pageSize != null)
            {
                int skip = page.GetValueOrDefault() * pageSize.GetValueOrDefault(1);
                posts = posts.Skip(skip).Take(pageSize.GetValueOrDefault(1));
            }
            else if (pageSize != null)
            {
                posts = posts.Take(pageSize.GetValueOrDefault(1));
            }

            var feed = new SyndicationFeed("Chocolatey Blog", "The official blog for Chocolatey, the package manager for Windows!", new Uri(blogRoot));

            feed.Copyright = new TextSyndicationContent("Chocolatey copyright RealDimensions Software, LLC, posts copyright original author or authors.");
            feed.Language  = "en-US";
            feed.Authors.Add(new SyndicationPerson(string.Empty, "The Chocolatey Team", string.Empty));

            var items = new List <SyndicationItem>();

            foreach (var post in posts.OrEmptyListIfNull())
            {
                var blogUrl = blogRoot + "/" + post.UrlPath;
                var item    = new SyndicationItem(post.Title, post.Post, new Uri(blogUrl), post.UrlPath, post.Published.GetValueOrDefault());
                item.PublishDate = post.Published.GetValueOrDefault();
                item.Authors.Add(new SyndicationPerson(string.Empty, post.Author, string.Empty));
                item.Copyright = new TextSyndicationContent("Copyright RealDimensions Software LLC and original author(s).");

                items.Add(item);
            }

            try
            {
                var mostRecent = posts.FirstOrDefault();
                feed.LastUpdatedTime = mostRecent == null ? DateTime.UtcNow : mostRecent.Published.GetValueOrDefault();
            }
            catch (Exception)
            {
                feed.LastUpdatedTime = DateTime.UtcNow;
            }

            feed.Items = items;

            return(new RSSActionResult
            {
                Feed = feed
            });

            //remove a10 - http://stackoverflow.com/a/15971300/18475
        }
        public virtual ActionResult Feed(int?page, int?pageSize)
        {
            var siteRoot = EnsureTrailingSlash(Configuration.GetSiteRoot(AppHarbor.IsSecureConnection(HttpContext)));

            IEnumerable <Package> packageVersions = Cache.Get(string.Format("packageVersions-False"),
                                                              DateTime.UtcNow.AddMinutes(Cache.DEFAULT_CACHE_TIME_MINUTES),
                                                              () => packageSvc.GetPackagesForListing(includePrerelease: false).OrderByDescending(p => p.Published).ToList()
                                                              );

            if (page != null && pageSize != null)
            {
                int skip = page.GetValueOrDefault() * pageSize.GetValueOrDefault(1);
                packageVersions = packageVersions.Skip(skip).Take(pageSize.GetValueOrDefault(1));
            }
            else if (pageSize != null)
            {
                packageVersions = packageVersions.Take(pageSize.GetValueOrDefault(1));
            }

            var feed = new SyndicationFeed("Chocolatey", "Chocolatey Packages", new Uri(siteRoot));

            feed.Copyright = new TextSyndicationContent("Chocolatey copyright RealDimensions Software, LLC, Packages copyright original maintainer(s), Products copyright original author(s).");
            feed.Language  = "en-US";

            var items = new List <SyndicationItem>();

            foreach (Package package in packageVersions.ToList().OrEmptyListIfNull())
            {
                string title      = string.Format("{0} ({1})", package.PackageRegistration.Id, package.Version);
                var    galleryUrl = siteRoot + "packages/" + package.PackageRegistration.Id + "/" + package.Version;
                var    item       = new SyndicationItem(title, package.Summary, new Uri(galleryUrl), package.PackageRegistration.Id + "." + package.Version, package.Published);
                item.PublishDate = package.Published;

                items.Add(item);
            }

            try
            {
                var mostRecentPackage = packageVersions.FirstOrDefault();
                feed.LastUpdatedTime = mostRecentPackage == null ? DateTime.UtcNow : mostRecentPackage.Published;
            } catch (Exception)
            {
                feed.LastUpdatedTime = DateTime.UtcNow;
            }

            feed.Items = items;

            return(new RSSActionResult {
                Feed = feed
            });
        }
Exemple #3
0
        public static string PackageDownload(this UrlHelper url, int feedVersion, string id, string version)
        {
            string routeName = "v" + feedVersion + RouteName.DownloadPackage;

            string protocol  = AppHarbor.IsSecureConnection(url.RequestContext.HttpContext) ? "https" : "http";
            string returnUrl = url.RouteUrl(
                routeName,
                new
            {
                Id      = id,
                Version = version
            },
                protocol: protocol);

            //hack, replace removing port
            //return Regex.Replace(returnUrl, @"\:\d+\/", "/");

            // Ensure trailing slashes for versionless package URLs, as a fix for package filenames that look like known file extensions
            return(version == null?EnsureTrailingSlash(returnUrl) : returnUrl);
        }
Exemple #4
0
 protected virtual bool UseHttps()
 {
     return(AppHarbor.IsSecureConnection(HttpContext));
 }