예제 #1
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);
            }
        }
예제 #2
0
        public async Task <CdnDownloadResult> DownloadInfo(string id)
        {
            var file = await mongoService.DownloadAsync(ObjectId.Parse(id));

            byte[] fileContent = new byte[(int)file.Length];
            file.Read(fileContent, 0, (int)file.Length);

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

            return(result);
        }
예제 #3
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);
        }
예제 #4
0
        private async Task <CdnDownloadResult> GetFileById(string fileId)
        {
            using (var file = await gridFsBucket.OpenDownloadStreamAsync(ObjectId.Parse(fileId)))
            {
                byte[] fileContent = new byte[(int)file.Length];
                file.Read(fileContent, 0, (int)file.Length);

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

                await file.CloseAsync();

                return(result);
            }
        }
예제 #5
0
        public async Task <CdnDownloadResult> MongoCdn_Download(CdnFileSelect request)
        {
            string fileId = request.FileId;
            string title  = String.Empty;

            if (string.IsNullOrEmpty(fileId))
            {
                var file = Select(request.SourceType, request.SourceId).FirstOrDefault();

                if (file == null)
                {
                    return(null);
                }

                fileId = file.FileId;
                title  = file.Title;
            }

            CdnDownloadResult downloadInfo = await GetFileById(fileId);

            downloadInfo.FileTitle = title;

            return(downloadInfo);
        }
예제 #6
0
        private async Task <Act> initModel(int id)
        {
            var actInfo = repo.AllReadonly <CaseSessionAct>()
                          .Include(x => x.CaseSession)
                          .Where(x => x.Id == id)
                          .Select(x => new
            {
                CaseId     = x.CaseId,
                ActTypeId  = x.ActTypeId,
                CaseTypeId = x.Case.CaseTypeId,
                CaseNumber = x.Case.ShortNumberValue ?? 0,
                CaseYear   = x.Case.RegDate.Year,
                CourtId    = x.Case.CourtId,
                JudgeName  = x.CaseSession.CaseLawUnits
                             .Where(l => l.JudgeRoleId == NomenclatureConstants.JudgeRole.JudgeReporter)
                             .Select(l => l.LawUnit.FullName)
                             .FirstOrDefault(),
                StartDate  = x.ActDeclaredDate,
                LegalDate  = x.ActInforcedDate,
                MotiveDate = x.ActMotivesDeclaredDate,
                ActNumber  = x.RegNumber,
                EcliCode   = x.EcliCode,
                ActYear    = x.RegDate.Value.Year
            }).FirstOrDefault();

            var docTemplates  = repo.AllReadonly <DocumentTemplate>();
            var migrationInfo = repo.AllReadonly <CaseMigration>()
                                .Where(x => x.CaseSessionActId == id && x.CaseMigrationTypeId == NomenclatureConstants.CaseMigrationTypes.SendNextLevel)
                                .Where(x => x.SendToCourtId > 0)
                                .OrderByDescending(x => x.Id)
                                .Select(x => new
            {
                MigrationId   = x.Id,
                HigherCourtId = x.SendToCourtId,
                OutDocumentId = docTemplates.Where(d => d.SourceType == SourceTypeSelectVM.CaseMigration && d.SourceId == x.Id)
                                .Where(d => d.DocumentId > 0)
                                .Select(d => d.DocumentId)
                                .FirstOrDefault()
            }).FirstOrDefault();



            var model = new Act()
            {
                UID        = AppendUpdateIntegrationKey(SourceTypeSelectVM.CaseSessionAct, id),
                ActKind    = GetNomValueInt(EpepConstants.Nomenclatures.ActTypes, actInfo.ActTypeId),
                CaseKind   = GetNomValueInt(EpepConstants.Nomenclatures.CaseTypes, actInfo.CaseTypeId),
                CaseNumber = actInfo.CaseNumber,
                Court      = GetNomValueInt(EpepConstants.Nomenclatures.Courts, actInfo.CourtId),
                Judge      = actInfo.JudgeName,
                LegalDate  = actInfo.LegalDate,
                StartDate  = actInfo.StartDate,
                MotiveDate = actInfo.MotiveDate,
                Number     = int.Parse(actInfo.ActNumber),
                EcliCode   = actInfo.EcliCode,
                Year       = actInfo.ActYear
            };

            //Липсва мапинг за изходящите документи в ЕПЕП!!!!!
            if (false && migrationInfo != null && migrationInfo.OutDocumentId != null)
            {
                var outDocument = repo.GetById <Document>(migrationInfo.OutDocumentId);
                model.DataForHigherCourt = new DataForHigherCourt()
                {
                    Court          = GetNomValueInt(EpepConstants.Nomenclatures.Courts, migrationInfo.HigherCourtId),
                    OutputNumber   = outDocument.DocumentNumberValue.Value,
                    DateOfDispatch = outDocument.DocumentDate,
                    TypeOfDocument = GetNomValueInt(EpepConstants.Nomenclatures.OutgoingDocumentTypes, outDocument.DocumentTypeId),
                    Year           = outDocument.DocumentDate.Year
                };
            }

            CdnDownloadResult actFile = await cdnService.MongoCdn_Download(new CdnFileSelect()
            {
                SourceType = SourceTypeSelectVM.CaseSessionActDepersonalized,
                SourceId   = id.ToString()
            });

            if (actFile != null && !string.IsNullOrEmpty(actFile.FileContentBase64))
            {
                model.ActTextType = actFile.ContentType;
                model.ActText     = Convert.FromBase64String(actFile.FileContentBase64);
            }

            if (model.MotiveDate.HasValue)
            {
                CdnDownloadResult motiveFile = await cdnService.MongoCdn_Download(new CdnFileSelect()
                {
                    SourceType = SourceTypeSelectVM.CaseSessionActMotiveDepersonalized,
                    SourceId   = id.ToString()
                });

                if (motiveFile != null && !string.IsNullOrEmpty(motiveFile.FileContentBase64))
                {
                    model.MotiveTextType = motiveFile.ContentType;
                    model.MotiveText     = Convert.FromBase64String(motiveFile.FileContentBase64);
                }
                else
                {
                    model.MotiveDate = null;
                }
            }

            return(model);
        }