コード例 #1
0
        public override async Task <bool> DeleteAsync(FileProviderDeleteArgs args)
        {
            var configuration = args.Configuration.GetFastDFSConfiguration();

            ConfigurationFactory.AddIfNotContains(configuration);

            var fileId        = FileNameCalculator.Calculate(args);
            var containerName = GetContainerName(configuration, args);

            return(await Client.RemoveFileAsync(containerName, fileId, configuration.ClusterName));
        }
コード例 #2
0
        public override async Task <string> SaveAsync(FileProviderSaveArgs args)
        {
            var configuration = args.Configuration.GetFastDFSConfiguration();

            ConfigurationFactory.AddIfNotContains(configuration);

            var containerName = GetContainerName(configuration, args);
            var storageNode   = await Client.GetStorageNodeAsync(containerName, configuration.ClusterName);

            var fileId = await Client.UploadFileAsync(storageNode, args.FileStream, args.FileExt, configuration.ClusterName);

            return(fileId);
        }
コード例 #3
0
        public override async Task <bool> ExistsAsync(FileProviderExistsArgs args)
        {
            var configuration = args.Configuration.GetFastDFSConfiguration();

            ConfigurationFactory.AddIfNotContains(configuration);

            var fileId        = FileNameCalculator.Calculate(args);
            var containerName = GetContainerName(configuration, args);

            var storageNode = await Client.GetStorageNodeAsync(containerName, configuration.ClusterName);

            var fileInfo = await Client.GetFileInfo(storageNode, fileId, configuration.ClusterName);

            return(fileInfo != null);
        }
コード例 #4
0
        public override Task <string> GetAccessUrlAsync(FileProviderAccessArgs args)
        {
            if (!args.Configuration.HttpAccess)
            {
                return(Task.FromResult(string.Empty));
            }

            var configuration = args.Configuration.GetFastDFSConfiguration();

            ConfigurationFactory.AddIfNotContains(configuration);

            var fileId        = FileNameCalculator.Calculate(args);
            var containerName = GetContainerName(configuration, args);

            var accessUrl = BuildAccessUrl(configuration, containerName, fileId);

            return(Task.FromResult(accessUrl));
        }
コード例 #5
0
        public override async Task <bool> DownloadAsync(FileProviderDownloadArgs args)
        {
            var configuration = args.Configuration.GetFastDFSConfiguration();

            ConfigurationFactory.AddIfNotContains(configuration);

            var fileId        = FileNameCalculator.Calculate(args);
            var containerName = GetContainerName(configuration, args);
            var storageNode   = await Client.GetStorageNodeAsync(containerName, configuration.ClusterName);

            try
            {
                await Client.DownloadFileEx(storageNode, fileId, args.Path, configuration.ClusterName);

                return(true);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex, LogLevel.Error);
                return(false);
            }
        }
コード例 #6
0
        public override async Task <Stream> GetOrNullAsync(FileProviderGetArgs args)
        {
            var configuration = args.Configuration.GetFastDFSConfiguration();

            ConfigurationFactory.AddIfNotContains(configuration);

            var fileId        = FileNameCalculator.Calculate(args);
            var containerName = GetContainerName(configuration, args);
            var storageNode   = await Client.GetStorageNodeAsync(containerName, configuration.ClusterName);

            try
            {
                var content = await Client.DownloadFileAsync(storageNode, fileId, configuration.ClusterName);

                return(new MemoryStream(content));
            }
            catch (Exception ex)
            {
                Logger.LogException(ex, LogLevel.Error);
                return(null);
            }
        }