Beispiel #1
0
 public async Task <CdnDownloadResult> MongoCdn_Download(string fileId, CdnFileSelect.PostProcess postProcess = CdnFileSelect.PostProcess.None)
 {
     return(await MongoCdn_Download(new CdnFileSelect()
     {
         FileId = fileId
     }, postProcess));
 }
Beispiel #2
0
        public async Task <CdnDownloadResult> MongoCdn_Download(long mongoFileId, CdnFileSelect.PostProcess postProcess = CdnFileSelect.PostProcess.None)
        {
            int    _id    = (int)mongoFileId;
            string fileId = repo.AllReadonly <MongoFile>().Where(x => x.Id == _id).Select(x => x.FileId).FirstOrDefault();

            return(await MongoCdn_Download(fileId, postProcess));
        }
Beispiel #3
0
        private async Task <CdnDownloadResult> GetFileById(CdnItemVM fileItem, CdnFileSelect.PostProcess postProcess = CdnFileSelect.PostProcess.None)
        {
            using (var file = await gridFsBucket.OpenDownloadStreamAsync(ObjectId.Parse(fileItem.FileId)))
            {
                byte[] fileContent = new byte[(int)file.Length];
                file.Read(fileContent, 0, (int)file.Length);
                byte[] newContent = fileContent;
                if (fileItem.FileName.EndsWith(".pdf", StringComparison.InvariantCultureIgnoreCase))
                {
                    try
                    {
                        switch (postProcess)
                        {
                        case CdnFileSelect.PostProcess.Flatten:

                        {
                            string addText        = "";
                            int[]  actSourceTypes = { SourceTypeSelectVM.CaseSessionActPdf, SourceTypeSelectVM.CaseSessionActDepersonalized };
                            if (actSourceTypes.Contains(fileItem.SourceType))
                            {
                                int actId    = int.Parse(fileItem.SourceId);
                                var actModel = repo.AllReadonly <CaseSessionAct>().Where(x => x.Id == actId).FirstOrDefault();
                                if (actModel != null)
                                {
                                    if (actModel.ActDeclaredDate != null)
                                    {
                                        addText = $" Актът е постановен на {actModel.ActDeclaredDate:dd.MM.yyyy}";
                                    }
                                }
                            }
                            newContent = flattenSignatures(fileContent, addText);
                        }
                        break;
                        }
                    }
                    catch { }
                }

                CdnDownloadResult result = new CdnDownloadResult()
                {
                    FileId            = fileItem.FileId,
                    ContentType       = file.FileInfo.Metadata.GetValue("contentType").AsString,
                    FileName          = file.FileInfo.Filename,
                    FileContentBase64 = Convert.ToBase64String(newContent)
                };

                await file.CloseAsync();

                return(result);
            }
        }
Beispiel #4
0
        public async Task <CdnDownloadResult> MongoCdn_Download(CdnFileSelect request, CdnFileSelect.PostProcess postProcess = CdnFileSelect.PostProcess.None)
        {
            string fileId   = request.FileId;
            string title    = String.Empty;
            var    fileItem = Select(request.SourceType, request.SourceId, request.FileId).FirstOrDefault();

            if (fileItem == null)
            {
                return(null);
            }
            title = fileItem.Title;


            CdnDownloadResult downloadInfo = await GetFileById(fileItem, postProcess);

            downloadInfo.FileTitle = title;

            return(downloadInfo);
        }