コード例 #1
0
ファイル: CrmService.cs プロジェクト: rhw1111/DCEM
        /// <summary>
        /// 删除文件类型属性的文件
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="fileAttributeName"></param>
        public async Task DeleteAttributeFileData(CrmEntityReference entityID, string fileAttributeName, Guid?proxyUserId = null)
        {
            CrmFileAttributeDeleteDataRequestMessage request = new CrmFileAttributeDeleteDataRequestMessage()
            {
                EntityName    = entityID.EntityName,
                EntityId      = entityID.Id,
                AttributeName = fileAttributeName,
            };

            await this.Execute(request);
        }
コード例 #2
0
ファイル: CrmService.cs プロジェクト: rhw1111/DCEM
        /// <summary>
        /// 为文件类型属性上传文件
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="fileAttributeName"></param>
        /// <param name="fileName"></param>
        /// <param name="fileStream"></param>
        public async Task UploadAttributeFile(CrmEntityReference entityID, string fileAttributeName, string fileName, string fileMimeType, Stream fileStream, Guid?proxyUserId = null)
        {
            CrmGetFileAttributeUploadInfoRequestMessage getRequest = new CrmGetFileAttributeUploadInfoRequestMessage()
            {
                EntityName    = entityID.EntityName,
                EntityId      = entityID.Id,
                AttributeName = fileAttributeName,
                FileName      = fileName
            };


            var getResponse = (CrmGetFileAttributeUploadInfoResponseMessage)await this.Execute(getRequest);

            int perSize     = getResponse.PerSize;
            int currentSize = perSize;

            using (var buffOwner = MemoryPool <byte> .Shared.Rent(perSize))
            {
                var           buff     = buffOwner.Memory;
                List <string> blockIDs = new List <string>();
                int           position = 0;
                while (currentSize == perSize)
                {
                    currentSize = await fileStream.ReadAsync(buff);

                    if (currentSize != 0)
                    {
                        var blockID = Guid.NewGuid().ToString();
                        blockIDs.Add(blockID);

                        CrmFileAttributeUploadChunkingRequestMessage uploadRequest = new CrmFileAttributeUploadChunkingRequestMessage()
                        {
                            UploadUrl = getResponse.UploadUrl,
                            Data      = buff.Slice(0, currentSize).ToArray(),
                            FileName  = fileName,
                            Start     = position,
                            End       = currentSize - 1,
                            Total     = fileStream.Length
                        };

                        position += currentSize;
                        await this.Execute(uploadRequest);
                    }
                }
            }
        }
コード例 #3
0
ファイル: CrmService.cs プロジェクト: rhw1111/DCEM
        /// <summary>
        /// 下载文件类型属性的文件
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="fileAttributeName"></param>
        /// <param name="action"></param>
        public async Task DownloadAttributeFile(CrmEntityReference entityID, string fileAttributeName, Func <string, Stream, Task> action, Guid?proxyUserId = null)
        {
            CrmFileAttributeDownloadChunkingRequestMessage request = new CrmFileAttributeDownloadChunkingRequestMessage()
            {
                EntityName    = entityID.EntityName,
                EntityId      = entityID.Id,
                AttributeName = fileAttributeName,
                Start         = 0,
                End           = 1
            };

            var response = (CrmFileAttributeDownloadChunkingResponseMessage)await this.Execute(request);

            await using (var stream = new CrmFileBlocksStream(entityID.EntityName, entityID.Id, response.FileName, response.Total, this, proxyUserId))
            {
                await action(response.FileName, stream);
            }
        }