public static FileStoringContainerCacheItem AsCacheItem([NotNull] this FileStoringContainer container)
        {
            Check.NotNull(container, nameof(container));
            if (container == null || container == default)
            {
                return(null);
            }

            var cacheItem = new FileStoringContainerCacheItem(
                container.Id,
                container.TenantId,
                container.IsMultiTenant,
                container.Provider,
                container.Name,
                container.Title,
                container.HttpAccess);

            foreach (var item in container.Items)
            {
                cacheItem.Items.Add(new FileStoringContainerItemCacheItem(
                                        item.Id,
                                        item.Name,
                                        item.Value,
                                        item.ContainerId));
            }

            return(cacheItem);
        }
Example #2
0
        /// <summary>
        /// Convert 'FileStoringContainerCacheItem' to 'FileContainerConfiguration'
        /// </summary>
        /// <param name="cacheItem"></param>
        /// <returns></returns>
        public virtual FileContainerConfiguration ToConfiguration(FileStoringContainerCacheItem cacheItem)
        {
            var fileProviderConfiguration = Options.Providers.GetConfiguration(cacheItem.Provider);

            Check.NotNull(fileProviderConfiguration, nameof(fileProviderConfiguration));

            var configuration = new FileContainerConfiguration()
            {
                Provider      = fileProviderConfiguration.Provider,
                IsMultiTenant = cacheItem.IsMultiTenant,
                HttpAccess    = cacheItem.HttpAccess
            };

            foreach (var item in cacheItem.Items)
            {
                var type  = fileProviderConfiguration.GetValue(item.Name).Type;
                var value = TypeHelper.ConvertFromString(type, item.Value);
                configuration.SetConfiguration(item.Name, value);
            }

            foreach (var namingNormalizer in fileProviderConfiguration.DefaultNamingNormalizers)
            {
                configuration.NamingNormalizers.Add(namingNormalizer);
            }

            return(configuration);
        }