Beispiel #1
0
        /// <summary>
        /// Reads primary element details.
        /// </summary>
        /// <param name="tenantId">Tenant that element associated with.</param>
        /// <param name="elementId">Element identifier.</param>
        /// <param name="loadCustomSettings">Set false to retrieve only those settings common to all elements. Set true to retrieve settings common to all elements and element specific settings.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        /// <returns>Element setings (null if element not found).</returns>
        public IElementSettings Read(long tenantId, long elementId, bool loadCustomSettings, IUnitOfWork unitOfWork = null)
        {
            // Get core element details
            IElementSettings elementSettings = _elementRepository.Read(tenantId, elementId, unitOfWork);

            if (elementSettings == null)
            {
                return(null);
            }

            // Now we know the type of element requested, we can get custom element settings
            IBasicElementService customElementService  = _elementFactory.GetElementService(elementSettings.ElementTypeId);
            IElementSettings     customElementSettings = customElementService.New(elementSettings.TenantId);

            customElementSettings.ElementId = elementSettings.ElementId;
            customElementSettings.Name      = elementSettings.Name;

            // If "advanced" element, populate custom settings
            if (loadCustomSettings && customElementService is IAdvancedElementService)
            {
                ((IAdvancedElementService)customElementService).Read(customElementSettings, unitOfWork);
            }

            // Return fully populated element settings
            return(customElementSettings);
        }
        public IActionResult ReadUpload(long elementId, long uploadId, string format)
        {
            // Get element service
            long                 tenantId        = _authenticationService.TenantId;
            IElementSettings     elementSettings = _elementService.Read(tenantId, elementId, false);
            IBasicElementService elementService  = _elementFactory.GetElementService(elementSettings.ElementTypeId);

            // If images not supported, go no further
            if (!(elementService is IUploadElementService))
            {
                return(null);
            }

            // Get specified image
            if (format == null)
            {
                format = "preview";
            }
            Upload upload = ((IUploadElementService)elementService).ReadUpload(tenantId, elementId, uploadId, format);

            if (upload == null)
            {
                return(null);
            }

            // Return file content result
            return(new FileContentResult(upload.Content, upload.ContentType)
            {
                FileDownloadName = upload.Name
            });
        }
Beispiel #3
0
 /// <summary>
 /// For the list of supplied element key values, this method works out which elements are to do with site navigation and then
 /// registers the navigation pages with those elements. In this way, elements such as nav bars can be populated with pages.
 /// </summary>
 /// <param name="tenantId">The tenant whose navigation elements are updated.</param>
 /// <param name="elementKeyValues">List of element key values.</param>
 /// <param name="navigationPages">Pages that are to be added to site navigation elements.</param>
 /// <param name="unitOfWork">Unit of work.</param>
 public void AddNavigationPages(long tenantId, List <ElementKeyValue> elementKeyValues, List <Page> navigationPages, IUnitOfWork unitOfWork = null)
 {
     foreach (ElementKeyValue elementKeyValue in elementKeyValues)
     {
         IBasicElementService customElementService = _elementFactory.GetElementService(elementKeyValue.ElementTypeId);
         if (customElementService is INavigationElementService)
         {
             ((INavigationElementService)customElementService).AddNavigationPages(tenantId, elementKeyValue.ElementId, navigationPages, unitOfWork);
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// Populates dictionary of element sevices keyed by element type ID. Looks for all types that implement IBasicElementService, creates instances of them and
        /// registers them against their element type IDs.
        /// </summary>
        /// <returns>Element services keyed by element type ID.</returns>
        private Dictionary <Guid, IBasicElementService> GetElementServices()
        {
            Dictionary <Guid, IBasicElementService> elementServiceDict = new Dictionary <Guid, IBasicElementService>();
            IEnumerable <Type> elementServiceTypes = _listElementServices.ListTypes();

            foreach (Type type in elementServiceTypes)
            {
                IBasicElementService elementService = _injectionService.CreateType <IBasicElementService>(type);
                elementServiceDict.Add(elementService.ElementTypeId, elementService);
            }
            return(elementServiceDict);
        }
Beispiel #5
0
        /// <summary>
        /// Gets element details.
        /// </summary>
        /// <param name="tenantId">Identifies the tenant that element belongs to.</param>
        /// <param name="elementTypeId">The type of the element.</param>
        /// <param name="elementId">Identifies the element to return.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        /// <returns>Element settings (or null if element not found).</returns>
        public IElementSettings Read(long tenantId, Guid elementTypeId, long elementId, IUnitOfWork unitOfWork = null)
        {
            // Construct instance of element settings
            IBasicElementService customElementService = _elementFactory.GetElementService(elementTypeId);
            IElementSettings     settings             = customElementService.New(tenantId);

            // Populate element ID
            settings.ElementId = elementId;

            // Populate for advanced elements
            if (customElementService is IAdvancedElementService)
            {
                // Populate element with common settings
                _elementRepository.Read(settings, unitOfWork);

                // Populate with custom settings
                ((IAdvancedElementService)customElementService).Read(settings, unitOfWork);
            }

            // Return fully populated element
            return(settings);
        }
Beispiel #6
0
        /// <summary>
        /// Retrieves dynamic element content.
        /// </summary>
        /// <param name="settings">Contains element settings.</param>
        /// <param name="pageContext">Page context.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        /// <returns>Element content.</returns>
        public IElementContent GetContent(IElementSettings settings, IPageContext pageContext, IUnitOfWork unitOfWork = null)
        {
            IBasicElementService customElementService = _elementFactory.GetElementService(settings.ElementTypeId);

            return(customElementService.GetContent(settings, pageContext, unitOfWork));
        }