Ejemplo n.º 1
0
        private async Task PersistentAsync(
            string name,
            Stream stream,
            bool overrideExisting = false,
            CancellationToken cancellationToken = default)
        {
            var blobInfoStoreType = Configuration.GetConfigurationOrDefault(
                DigniteAbpBlobContainerConfigurationNames.BlobInfoStore,
                typeof(NullBlobInfoStore)
                );

            using (var scope = ServiceProvider.CreateScope())
            {
                var blobInfoStore = scope.ServiceProvider
                                    .GetRequiredService(blobInfoStoreType)
                                    .As <IBlobInfoStore>();

                if (blobInfoStore is NullBlobInfoStore)
                {
                    // 保存到容器中
                    await base.SaveAsync(name, stream, overrideExisting, cancellationToken);
                }
                else
                {
                    // 计算stream hash
                    var hash     = stream.ToMd5();
                    var blobInfo = new BasicBlobInfo(ContainerName, name)
                    {
                    };
                    if (await blobInfoStore.HashExistsAsync(ContainerName, hash, cancellationToken))
                    {
                        // 如果存在相同hash的blob,则创建其副本
                        var mainBlob = await blobInfoStore.FindByHashAsync(ContainerName, hash, cancellationToken);

                        blobInfo.ReferBlobName = mainBlob.BlobName;

                        // 记录Blob信息
                        await blobInfoStore.CreateAsync(blobInfo, cancellationToken);
                    }
                    else
                    {
                        blobInfo.BinarySize = stream.Length;
                        blobInfo.Hash       = hash;

                        // 记录Blob信息;
                        //这里是在保存blob stream 前创建数据库记录,当后续发生异常时,希望能自动回滚本次操作;
                        await blobInfoStore.CreateAsync(blobInfo, cancellationToken);

                        // 保存到容器中
                        await base.SaveAsync(name, stream, overrideExisting, cancellationToken);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public Task CreateAsync(BasicBlobInfo blobInfo, CancellationToken cancellationToken = default)
 {
     return(Task.CompletedTask);
 }
Ejemplo n.º 3
0
        public async Task <IBlobInfo> FindByHashAsync(string containerName, string hash, CancellationToken cancellationToken = default)
        {
            BasicBlobInfo blobInfo = null;

            return(await Task.FromResult(blobInfo));
        }