コード例 #1
0
        public async Task <Object> InvokeAsync(Int64 UserId, Int32 TenantId, Int64 Id, String Report, String Model, String Schema)
        {
            var dm = await _dbContext.LoadModelAsync(String.Empty, $"[{Schema}].[{Model}.Report]", new { UserId, TenantId, Id });

            using (Stream stream = CreateStream(dm, Report))
            {
                using (var rep = new ExcelReportGenerator(stream))
                {
                    rep.GenerateReport(dm);
                    Byte[] bytes = File.ReadAllBytes(rep.ResultFile);
                    if (bytes == null || bytes.Length == 0)
                    {
                        throw new InvalidProgramException("There are no bytes to save");
                    }
                    using (var ms = new MemoryStream(bytes))
                    {
                        AttachmentUpdateInfo ai = new AttachmentUpdateInfo()
                        {
                            UserId   = UserId,
                            TenantId = TenantId,
                            Id       = Id,
                            Mime     = MimeTypes.Application.Excel,
                            Stream   = ms,
                            Name     = Path.GetFileNameWithoutExtension(Report)
                        };
                        if (String.IsNullOrEmpty(ai.Name))
                        {
                            ai.Name = "Attachment";
                        }
                        var aout = await _dbContext.ExecuteAndLoadAsync <AttachmentUpdateInfo, AttachmentUpdateOutput>
                                       (String.Empty, $"[{Schema}].[{Model}.SaveAttachment]", ai);

                        return(new { aout.Id, Token = _tokenProvider.GenerateToken(aout.Token) });
                    }
                }
            }
        }
コード例 #2
0
ファイル: AttachStiReport.cs プロジェクト: alex-kukhtin/A2v10
        public async Task <Object> InvokeAsync(Int64 UserId, Int32 TenantId, Int64 Id, String Report, String Model, String Schema)
        {
            _reportHelper.SetupLicense();
            var dm = await _dbContext.LoadModelAsync(String.Empty, $"[{Schema}].[{Model}.Report]", new { UserId, TenantId, Id });

            using (var stream = CreateStream(dm, Report))
            {
                using (var ms = new MemoryStream())
                {
                    String repName = await _reportHelper.ExportDocumentAsync(stream, dm, ms);

                    ms.Seek(0, SeekOrigin.Begin);
                    AttachmentUpdateInfo ai = new AttachmentUpdateInfo()
                    {
                        UserId   = UserId,
                        TenantId = TenantId,
                        Id       = Id,
                        Mime     = MimeTypes.Application.Pdf,
                        Stream   = ms,
                        Name     = repName
                    };
                    if (String.IsNullOrEmpty(ai.Name))
                    {
                        ai.Name = "Attachment";
                    }
                    var aout = await _dbContext.ExecuteAndLoadAsync <AttachmentUpdateInfo, AttachmentUpdateOutput>
                                   (String.Empty, $"[{Schema}].[{Model}.SaveAttachment]", ai);

                    if (aout == null)
                    {
                        throw new InvalidOperationException($"'[{Schema}].[{Model}.SaveAttachment]' procedure did not return result");
                    }
                    return(new { aout.Id, Token = _tokenProvider.GenerateToken(aout.Token) });
                }
            }
        }
コード例 #3
0
        public async Task <Object> InvokeAsync(Int64 UserId, Int32 TenantId, Int64 Id, String Report, String Model, String Schema)
        {
            var dm = await _dbContext.LoadModelAsync(String.Empty, $"[{Schema}].[{Model}.Report]", new { UserId, TenantId, Id });

            using (Stream stream = CreateStream(dm, Report))
            {
                using (var rep = new ExcelReportGenerator(stream))
                {
                    rep.GenerateReport(dm);
                    Byte[] bytes = File.ReadAllBytes(rep.ResultFile);
                    if (bytes == null || bytes.Length == 0)
                    {
                        throw new InvalidProgramException("There are no bytes to save");
                    }
                    using (var ms = new MemoryStream(bytes))
                    {
                        AttachmentUpdateInfo ai = new AttachmentUpdateInfo()
                        {
                            UserId   = UserId,
                            TenantId = TenantId,
                            Id       = Id,
                            Mime     = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                            Stream   = ms,
                            Name     = Path.GetFileNameWithoutExtension(Report)
                        };
                        if (String.IsNullOrEmpty(ai.Name))
                        {
                            ai.Name = "Attachment";
                        }
                        await _dbContext.ExecuteAsync(String.Empty, $"[{Schema}].[{Model}.SaveAttachment]", ai);

                        return(new { ai.Id });
                    }
                }
            }
        }