Beispiel #1
0
        /// <summary>
        /// Get the number of packages in the CKAN group.
        /// </summary>
        /// <returns></returns>
        public static int GetPackageCount()
        {
            var searchParameters = new PackageSearchParameters();

            searchParameters.Groups.Add(SettingsHelper.GetCatalogGroup());
            searchParameters.Limit = 0;

            int count = CkanHelper.GetClient().SearchPackages <string>(searchParameters, new CacheSettings(SettingsHelper.GetPackageCountCacheDuration(), SettingsHelper.GetPackageCountCacheBackgroundUpdate())).Count;

            return(count);
        }
Beispiel #2
0
        /// <summary>
        /// Get all packages from the CKAN group.
        /// </summary>
        /// <returns></returns>
        public static List <Package> GetAllPackages()
        {
            CacheSettings settings = new CacheSettings(SettingsHelper.GetAllPackagesCacheDuration(), SettingsHelper.GetAllPackagesCacheBackgroundUpdate());

            // Create the CKAN search parameters
            var searchParameters = new PackageSearchParameters();

            searchParameters.Groups.Add(SettingsHelper.GetCatalogGroup());
            searchParameters.Limit = GetPackageCount();

            // Collect the results
            PackageSearchResponse <Package> response = CkanHelper.GetClient().SearchPackages <Package>(searchParameters, settings);

            return(response.Results);
        }
Beispiel #3
0
        /// <summary>
        /// Get search suggestions for all packages in the catalog group.  Uses the all packages cache
        /// to build a search index that is also cached for performance.
        /// </summary>
        /// <param name="prefix"></param>
        /// <returns></returns>
        public static List <string> GetPackageSearchSuggestions(string prefix)
        {
            CacheSettings settings = new CacheSettings(SettingsHelper.GetAllPackagesCacheDuration(), SettingsHelper.GetAllPackagesCacheBackgroundUpdate());

            // Create the CKAN search parameters to get all packages in the group
            var searchParameters = new PackageSearchParameters();

            searchParameters.Groups.Add(SettingsHelper.GetCatalogGroup());
            searchParameters.Limit = GetPackageCount();

            // Get a list of search suggestions
            List <string> suggestions = CkanHelper.GetClient().GetPackageSearchSuggestions(prefix, searchParameters, settings);

            return(suggestions);
        }
Beispiel #4
0
        /// <summary>
        /// Provides support for auto-start.  See
        /// http://weblogs.asp.net/scottgu/archive/2009/09/15/auto-start-asp-net-applications-vs-2010-and-net-4-0-series.aspx
        /// </summary>
        /// <param name="parameters"></param>
        public void Preload(string[] parameters)
        {
            // Configure log4net
            log4net.Config.XmlConfigurator.Configure();

            log.Debug("Preloading application.");

            // Start caching of auto-cached CKAN requests if we aren't in offline mode
            try
            {
                if (!SettingsHelper.GetOfflineEnabled())
                {
                    log.Debug("Preloading package count cache.");
                    if (SettingsHelper.GetPackageCountCacheBackgroundUpdate())
                    {
                        CkanHelper.GetPackageCount();
                    }

                    log.Debug("Preloading all packages cache.");
                    if (SettingsHelper.GetAllPackagesCacheBackgroundUpdate())
                    {
                        CkanHelper.GetAllPackages();
                    }

                    log.Debug("Preloading all licenses cache.");
                    if (SettingsHelper.GetAllLicensesCacheBackgroundUpdate())
                    {
                        CkanHelper.GetLicenses();
                    }
                }
                else
                {
                    log.Debug("Application is offline.  Cache will not be preloaded.");
                }
            }
            catch (Exception ex)
            {
                // If any errors occur while trying to start caching, log this and clear the error.
                // Any new page request will re-attempt to start the caching process
                log.Error("Unable to starting background caching on preload", ex);
            }

            log.Debug("Preloading application complete.");
        }
Beispiel #5
0
        /// <summary>
        /// Get all tags from the CKAN group.
        /// </summary>
        /// <returns></returns>
        public static List <Tag> GetAllTags(int limit)
        {
            CacheSettings settings = new CacheSettings(SettingsHelper.GetAllPackagesCacheDuration(), SettingsHelper.GetAllPackagesCacheBackgroundUpdate());

            // Create the CKAN search parameters
            var searchParameters = new PackageSearchParameters();

            searchParameters.Groups.Add(SettingsHelper.GetCatalogGroup());

            // Collect the results
            List <Tag> tags = CkanHelper.GetClient().SearchPackagesGetTagCounts(searchParameters, settings);

            // Remove filtered tags
            tags = TagHelper.FilterTags(tags);

            if (limit > 0)
            {
                tags = TagHelper.LimitTags(tags, limit);
            }

            return(tags);
        }
Beispiel #6
0
        /// <summary>
        /// Get the licenses from the repository.  Caches
        /// the licenses for 1 hour as these don't update frequently.
        /// TODO: Implement common caching proxy for cachable requests.
        /// </summary>
        /// <returns></returns>
        public static List <License> GetLicenses()
        {
            CacheSettings settings = new CacheSettings(SettingsHelper.GetAllLicensesCacheDuration(), SettingsHelper.GetAllLicensesCacheBackgroundUpdate());

            return(CkanHelper.GetClient().GetLicenses(settings));
        }