コード例 #1
0
        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);
        }
コード例 #2
0
        public virtual FileContainerConfiguration ToConfiguration(FileStoringContainer container)
        {
            var fileProviderConfiguration = Options.Providers.GetConfiguration(container.Provider);

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

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

            foreach (var item in container.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);
        }
コード例 #3
0
        public virtual async Task <Guid> CreateAsync(CreateContainerDto input)
        {
            //Validate provider values
            var keyValuePairs = input.Items.ToDictionary(x => x.Name, y => y.Value);

            ContainerManager.ValidateProviderValues(input.Provider, keyValuePairs);

            //Validate name
            await ContainerManager.ValidateNameAsync(CurrentTenant.Id, input.Name, null);

            var container = new FileStoringContainer(
                GuidGenerator.Create(),
                CurrentTenant.Id,
                input.IsMultiTenant,
                input.Provider,
                input.Name,
                input.Title,
                input.HttpAccess);

            foreach (var item in input.Items)
            {
                container.Items.Add(new FileStoringContainerItem(
                                        GuidGenerator.Create(),
                                        item.Name,
                                        item.Value,
                                        container.Id));
            }

            await FileStoringContainerRepository.InsertAsync(container);

            return(container.Id);
        }
コード例 #4
0
        public virtual async Task <Guid> CreateAsync(CreateContainerDto input)
        {
            var valuesValidator = GetFileProviderValuesValidator(input.Provider);

            var dict   = input.Items.ToDictionary(x => x.Name, y => y.Value);
            var result = valuesValidator.Validate(dict);

            if (result.Errors.Any())
            {
                throw new AbpValidationException("Create Container validate failed.", result.Errors);
            }

            await CheckContainer(input.TenantId, input.Name, null);

            var container = new FileStoringContainer(
                GuidGenerator.Create(),
                input.TenantId,
                input.IsMultiTenant,
                input.Provider,
                input.Name,
                input.Title,
                input.HttpAccess);

            foreach (var item in input.Items)
            {
                container.Items.Add(new FileStoringContainerItem(
                                        GuidGenerator.Create(),
                                        item.Name,
                                        item.Value,
                                        container.Id));
            }

            await FileStoringContainerRepository.InsertAsync(container);

            return(container.Id);
        }