Esempio n. 1
0
        /// <summary>
        /// 获取文件系统相对路径
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        protected virtual string GetFileSystemRelativePath(string path)
        {
            // 去除完整路径中的文件系统根目录
            var fileSystemConfiguration = GetFileSystemBlobProviderConfiguration();
            var blobPath = fileSystemConfiguration.BasePath;

            // 去除租户或宿主目录
            if (CurrentTenant.Id == null)
            {
                blobPath = Path.Combine(blobPath, "host");
            }
            else
            {
                blobPath = Path.Combine(blobPath, "tenants", CurrentTenant.Id.Value.ToString("D"));
            }
            // 去除完整路径中的容器根目录
            var containerName = BlobContainerNameAttribute.GetContainerName <FileSystemContainer>();

            if (path.Contains(containerName))
            {
                blobPath = Path.Combine(blobPath, containerName);
            }
            path = path.Replace(blobPath, "");
            path = path.Replace('/', Path.DirectorySeparatorChar);
            path = path.Replace('\\', Path.DirectorySeparatorChar);
            return(path);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取文件系统存储路径
        /// </summary>
        /// <returns></returns>
        protected virtual string GetFileSystemBashPath()
        {
            var fileSystemConfiguration = GetFileSystemBlobProviderConfiguration();
            var blobPath = fileSystemConfiguration.BasePath;

            blobPath = Path.Combine(Directory.GetCurrentDirectory(), blobPath);
            if (CurrentTenant.Id == null)
            {
                blobPath = Path.Combine(blobPath, "host");
            }
            else
            {
                blobPath = Path.Combine(blobPath, "tenants", CurrentTenant.Id.Value.ToString("D"));
            }
            var containerName = BlobContainerNameAttribute.GetContainerName <FileSystemContainer>();

            blobPath = Path.Combine(blobPath, containerName);

            if (!Directory.Exists(blobPath))
            {
                Directory.CreateDirectory(blobPath);
            }

            return(blobPath);
        }
    public static IBlobProvider Get <TContainer>(
        [NotNull] this IBlobProviderSelector selector)
    {
        Check.NotNull(selector, nameof(selector));

        return(selector.Get(BlobContainerNameAttribute.GetContainerName <TContainer>()));
    }
 /// <summary>
 /// Gets a named container.
 /// </summary>
 /// <param name="blobContainerFactory">The blob container manager</param>
 /// <param name="cancellationToken">Cancellation token</param>
 /// <returns>
 /// The container object.
 /// </returns>
 public static IBlobContainer Create <TContainer>(
     this IBlobContainerFactory blobContainerFactory
     )
 {
     return(blobContainerFactory.Create(
                BlobContainerNameAttribute.GetContainerName <TContainer>()
                ));
 }
Esempio n. 5
0
 public BlobContainerConfigurations Configure <TContainer>(
     Action <BlobContainerConfiguration> configureAction)
 {
     return(Configure(
                BlobContainerNameAttribute.GetContainerName <TContainer>(),
                configureAction
                ));
 }
Esempio n. 6
0
 public BlobContainerConfigurations()
 {
     _containers = new Dictionary <string, BlobContainerConfiguration>
     {
         //Add default container
         [BlobContainerNameAttribute.GetContainerName <DefaultContainer>()] = new BlobContainerConfiguration()
     };
 }
Esempio n. 7
0
 private void ConfigureFileManagement(IWebHostEnvironment hostingEnvironment)
 {
     Configure <AbpBlobStoringOptions>(options =>
     {
         options.Containers.Configure <LocalFileSystemBlobContainer>(container =>
         {
             container.IsMultiTenant = true;
             container.UseFileSystem(fileSystem =>
             {
                 fileSystem.BasePath = Path.Combine(hostingEnvironment.ContentRootPath, "my-files");
             });
         });
     });
     Configure <FileManagementOptions>(options =>
     {
         options.DefaultFileDownloadProviderType = typeof(LocalFileDownloadProvider);
         options.Containers.Configure <CommonFileContainer>(container =>
         {
             // private container never be used by non-owner users (except user who has the "File.Manage" permission).
             container.FileContainerType                 = FileContainerType.Public;
             container.AbpBlobContainerName              = BlobContainerNameAttribute.GetContainerName <LocalFileSystemBlobContainer>();
             container.AbpBlobDirectorySeparator         = "/";
             container.RetainUnusedBlobs                 = false;
             container.EnableAutoRename                  = true;
             container.MaxByteSizeForEachFile            = 5 * 1024 * 1024;
             container.MaxByteSizeForEachUpload          = 10 * 1024 * 1024;
             container.MaxFileQuantityForEachUpload      = 2;
             container.AllowOnlyConfiguredFileExtensions = false;
             //container.FileExtensionsConfiguration.Add(".jpg", true);
             //container.FileExtensionsConfiguration.Add(".png", true);
             // container.FileExtensionsConfiguration.Add(".exe", false);
             container.GetDownloadInfoTimesLimitEachUserPerMinute = 10;
         });
         options.Containers.Configure <TempFileContainer>(container =>
         {
             container.FileContainerType                          = FileContainerType.Public;
             container.AbpBlobContainerName                       = BlobContainerNameAttribute.GetContainerName <LocalFileSystemBlobContainer>();
             container.AbpBlobDirectorySeparator                  = "/";
             container.RetainUnusedBlobs                          = false;
             container.EnableAutoRename                           = true;
             container.MaxByteSizeForEachFile                     = 5 * 1024 * 1024;
             container.MaxByteSizeForEachUpload                   = 10 * 1024 * 1024;
             container.MaxFileQuantityForEachUpload               = 2;
             container.AllowOnlyConfiguredFileExtensions          = false;
             container.GetDownloadInfoTimesLimitEachUserPerMinute = 10;
         });
     });
 }
Esempio n. 8
0
 public static BlobContainerConfiguration Get <TContainer>(
     this IBlobContainerConfigurationProvider configurationProvider)
 {
     return(configurationProvider.Get(BlobContainerNameAttribute.GetContainerName <TContainer>()));
 }
Esempio n. 9
0
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var hostingEnvironment = context.Services.GetHostingEnvironment();
            var configuration      = context.Services.GetConfiguration();

            Configure <AbpDbContextOptions>(options =>
            {
                options.UseSqlServer();
            });

            if (hostingEnvironment.IsDevelopment())
            {
                //Configure<AbpVirtualFileSystemOptions>(options =>
                //{
                //    options.FileSets.ReplaceEmbeddedByPhysical<FileManagementDomainSharedModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}EasyAbp.FileManagement.Domain.Shared", Path.DirectorySeparatorChar)));
                //    options.FileSets.ReplaceEmbeddedByPhysical<FileManagementDomainModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}EasyAbp.FileManagement.Domain", Path.DirectorySeparatorChar)));
                //    options.FileSets.ReplaceEmbeddedByPhysical<FileManagementApplicationContractsModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}EasyAbp.FileManagement.Application.Contracts", Path.DirectorySeparatorChar)));
                //    options.FileSets.ReplaceEmbeddedByPhysical<FileManagementApplicationModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}EasyAbp.FileManagement.Application", Path.DirectorySeparatorChar)));
                //    options.FileSets.ReplaceEmbeddedByPhysical<FileManagementWebModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}EasyAbp.FileManagement.Web", Path.DirectorySeparatorChar)));
                //});
            }

            context.Services.AddSwaggerGen(
                options =>
            {
                options.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "FileManagement API", Version = "v1"
                });
                options.DocInclusionPredicate((docName, description) => true);
                options.CustomSchemaIds(type => type.FullName);
            });

            Configure <AbpLocalizationOptions>(options =>
            {
                options.Languages.Add(new LanguageInfo("cs", "cs", "Čeština"));
                options.Languages.Add(new LanguageInfo("en", "en", "English"));
                options.Languages.Add(new LanguageInfo("pt-BR", "pt-BR", "Português (Brasil)"));
                options.Languages.Add(new LanguageInfo("ru", "ru", "Русский"));
                options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe"));
                options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
                options.Languages.Add(new LanguageInfo("zh-Hant", "zh-Hant", "繁體中文"));
            });

            Configure <AbpMultiTenancyOptions>(options =>
            {
                options.IsEnabled = MultiTenancyConsts.IsEnabled;
            });

            Configure <AbpBlobStoringOptions>(options =>
            {
                options.Containers.Configure <LocalFileSystemBlobContainer>(container =>
                {
                    container.IsMultiTenant = true;
                    container.UseFileSystem(fileSystem =>
                    {
                        // fileSystem.BasePath = "C:\\my-files";
                        fileSystem.BasePath = Path.Combine(hostingEnvironment.ContentRootPath, "my-files");
                    });
                });
            });

            Configure <FileManagementOptions>(options =>
            {
                options.DefaultFileDownloadProviderType = typeof(LocalFileDownloadProvider);
                options.Containers.Configure <CommonFileContainer>(container =>
                {
                    // private container never be used by non-owner users (except user who has the "File.Manage" permission).
                    container.FileContainerType         = FileContainerType.Public;
                    container.AbpBlobContainerName      = BlobContainerNameAttribute.GetContainerName <LocalFileSystemBlobContainer>();
                    container.AbpBlobDirectorySeparator = "/";

                    container.RetainDeletedBlobs = false;
                    container.EnableAutoRename   = true;

                    container.MaxByteSizeForEachFile       = 5 * 1024 * 1024;
                    container.MaxByteSizeForEachUpload     = 10 * 1024 * 1024;
                    container.MaxFileQuantityForEachUpload = 2;

                    container.AllowOnlyConfiguredFileExtensions = true;
                    container.FileExtensionsConfiguration.Add(".jpg", true);
                    container.FileExtensionsConfiguration.Add(".png", true);
                    // container.FileExtensionsConfiguration.Add(".exe", false);

                    container.GetDownloadInfoTimesLimitEachUserPerMinute = 10;
                });
            });
        }
Esempio n. 10
0
 public BlobContainerConfiguration GetConfiguration <TContainer>()
 {
     return(GetConfiguration(BlobContainerNameAttribute.GetContainerName <TContainer>()));
 }
Esempio n. 11
0
 public void Should_Get_Specified_Name()
 {
     BlobContainerNameAttribute
     .GetContainerName <TestContainer2>()
     .ShouldBe("Test2");
 }
Esempio n. 12
0
 public void Should_Get_Full_Class_Name_If_Not_Specified()
 {
     BlobContainerNameAttribute
     .GetContainerName <TestContainer1>()
     .ShouldBe(typeof(TestContainer1).FullName);
 }