Example #1
0
        /// <summary>
        /// Gets the catalog dto, checks permissions and caches results.
        /// </summary>
        /// <param name="siteGuid">The site GUID.</param>
        /// <param name="responseGroup">The response group.</param>
        /// <returns></returns>
        public static CatalogDto GetCatalogDto(Guid siteGuid, CatalogResponseGroup responseGroup)
        {
            /*
             * // Checks roles first
             * if (!SecurityManager.CheckPermission(new string[] { CatalogRoles.CatalogAdminRole, CatalogRoles.CatalogManagerRole, CatalogRoles.CatalogViewerRole }))
             *  return new CatalogDto();
             * */

            // Assign new cache key, specific for site guid and response groups requested
            string cacheKey = CatalogCache.CreateCacheKey("catalogs", responseGroup != null ? responseGroup.CacheKey : "", siteGuid.ToString());

            CatalogDto dto = null;

            // check cache first
            object cachedObject = CatalogCache.Get(cacheKey);

            if (cachedObject != null)
            {
                dto = (CatalogDto)cachedObject;
            }

            // Load the object
            if (dto == null)
            {
                CatalogAdmin catalog = new CatalogAdmin();
                catalog.Load(siteGuid);
                dto = catalog.CurrentDto;

                // Insert to the cache collection
                CatalogCache.Insert(cacheKey, dto, CatalogConfiguration.Instance.Cache.CatalogCollectionTimeout);
            }

            // Continue with security checks and other operations

            /*
             * foreach (CatalogDto.CatalogRow row in dto.Catalog.Rows)
             * {
             *
             * // Check Security
             * IDataReader reader = DataHelper.CreateDataReader(dto.CatalogSecurity, String.Format("CatalogId = -1 or CatalogId = {0}", row.CatalogId));
             * PermissionRecordSet recordSet = new PermissionRecordSet(PermissionHelper.ConvertReaderToRecords(reader));
             * if (!PermissionManager.CheckPermission(SecurityScope.Catalog.ToString(), Permission.Read, recordSet))
             * {
             * row.Delete();
             * continue;
             * }
             *
             * }
             * */

            //dto.AcceptChanges();

            return(dto);
        }
Example #2
0
        /// <summary>
        /// Returns the collection of catalogs with data populated that is specified in the responseGroup parameter.
        /// The data is cached according to the configuration.
        /// </summary>
        /// <param name="siteGuid">The site GUID.</param>
        /// <param name="responseGroup">The response group.</param>
        /// <returns></returns>
        public static SiteCatalogs GetCatalogs(Guid siteGuid, CatalogResponseGroup responseGroup)
        {
            // Retrieve dto
            CatalogDto dto = GetCatalogDto(siteGuid, responseGroup);

            // Continue with security checks and other operations
            SiteCatalogs       nodes     = new SiteCatalogs();
            List <SiteCatalog> nodeArray = new List <SiteCatalog>();

            foreach (CatalogDto.CatalogRow row in dto.Catalog.Rows)
            {
                nodeArray.Add(DtoToObjectMapper.CreateSiteCatalog(row));
            }

            nodes.Catalog = nodeArray.ToArray();
            return(nodes);
        }