public Report GetReportFileByGUID(Guid reportGUID, bool deleteFile) { Report report = GetReportByGUID(reportGUID); if (report != null) { if (report.ReportGenerationStatus && report.StoreReportInDB) { _dbFileStream = new BDFileStream.BDFileStream(_fsConnectionString); report.ReportFile = _dbFileStream.GetFileByGuid(report.ReportGuid); if(deleteFile) _dbFileStream.DeleteFileByGuid(report.ReportGuid); } } return report; }
private Report RenderReportItem(ReportsContainer reportsContainer, Report reportItem) { try { byte[] reportFile = null; string ReportDbFilestreamPathName = string.Empty; //Verificando se o arquivo será armazenado no BD para gerar seu GUID e seu DBPathName (necessário para o filestream) if (reportItem.StoreReportInDB) { //Instanciando a classe BDFileStream _dbFileStream = new BDFileStream.BDFileStream(_fsConnectionString); Dictionary<string, string> placeholderInfo = _dbFileStream.GenerateFilePlaceholder(); reportItem.ReportGuid = new Guid(placeholderInfo["GUIDFile"]); ReportDbFilestreamPathName = placeholderInfo["bdPathName"]; } if (reportsContainer.LogReports) { //Salva as informações sobre o relatório no Banco de dados SaveReportInformation(reportItem, reportsContainer); } //Renderiza o relatório reportFile = RenderReport(reportItem); //Define a variável do status de renderização do relatório reportItem.ReportGenerationStatus = true; if (reportItem.StoreReportInDB) { //Utilizando o método que armazena o relatório no SQL _dbFileStream.StoreFileByDbPathName(reportFile, ReportDbFilestreamPathName); } if (reportsContainer.LogReports) { //Atualiza o status do relatório UpdateReportStatus(reportItem); } //Armazena o arquivo no objeto Report reportItem.ReportFile = reportFile; } catch(Exception ex) { if (reportItem.StoreReportInDB && reportItem.ReportGuid != new Guid()) _dbFileStream.DeleteFileByGuid(reportItem.ReportGuid); throw ex; } return reportItem; }