public virtual ActionResult GenerateReportsAndSendToIDBDocs(PMRPublicReportModel model)
        {
            if (string.IsNullOrEmpty(model.Operations))
            {
                return(null);
            }

            if (!IDBContext.Current.HasRole(Role.RM_ADMINISTRATOR))
            {
                Logger.GetLogger().WriteMessage(
                    "PMRPublicController",
                    "No RM Administrator in PMR Public. Security issue?");
                throw new Exception("You don't have permissions to use PMR Public");
            }

            try
            {
                string[] operationsToSend = model.Operations.Split('|');

                int ini, buildReportTime, createDocTime, addDocToDBTime;

                foreach (string operation in operationsToSend)
                {
                    var reportResponse = new ReportResponse();

                    //Parse the operation information sent
                    string[] operationInfo   = operation.Split(';');
                    string   operationId     = operationInfo[0];
                    string   operationNumber = operationInfo[1];

                    ini = Environment.TickCount;

                    var reportCognos = new CognosReportBuilder();

                    var reportParameter = new GenerationParameter
                    {
                        OutputFormat     = CognosGlobalValues.FORMAT_PDF,
                        ReportParameters = new Dictionary <string, string>
                        {
                            { CognosGlobalValues.P_OPER_NUMBER, operationNumber },
                            { CognosGlobalValues.P_CYCLE, model.PmrCycleId },
                            { CognosGlobalValues.P_SECTION, CognosGlobalValues.ALL_SECTIONS }
                        }
                    };

                    reportResponse = reportCognos.Generate(reportParameter);

                    if (!reportResponse.IsValid)
                    {
                        throw new Exception(reportResponse.ErrorMessage);
                    }

                    buildReportTime = Environment.TickCount;

                    string docNum = CreateIDBDocsDocument(
                        new UploadDocumentRequest
                    {
                        OperationNumber = operationNumber,
                        FileStream      = reportResponse.Data,
                        FileName        =
                            operationNumber + " " + model.PmrCycleName + "-Public Report.pdf",
                        TrusteeList       = TRUSTEE_LIST,
                        BusinessAreaCode  = BusinessAreaCodeEnum.BA_PMR,
                        AccessInformation = AccessInformationCategoryEnum.PUBLIC,
                        StageCode         = "PMR PUBLIC",
                        TypeId            = "Report"
                    });

                    createDocTime = Environment.TickCount;

                    if (!CreateDocumentInDatabase(
                            operationId, operationNumber, docNum, model.PmrCycleId))
                    {
                        DeleteDocumentInIDBDocs(new DeleteDocumentRequest
                        {
                            DocumentNumber = docNum,
                            VersionId      = string.Empty
                        });

                        throw new Exception(
                                  "An error occurred when saving the document in the database." +
                                  " Refer to the log for further information");
                    }

                    addDocToDBTime = Environment.TickCount;

                    Logger.GetLogger().WriteDebug("PMRPublicController", string.Format(
                                                      "--- TOTAL TIME GENERATING PMR DOCUMENT FOR OPERATION {0} ---",
                                                      operationNumber));
                    Logger.GetLogger().WriteDebug("PMRPublicController", string.Format(
                                                      "TOTAL: {0}s", (addDocToDBTime - ini) / 1000));
                    Logger.GetLogger().WriteDebug("PMRPublicController", string.Format(
                                                      "GENERATE REPORT: {0}s", (buildReportTime - ini) / 1000));
                    Logger.GetLogger().WriteDebug("PMRPublicController", string.Format(
                                                      "CREATE DOC IN IDBDOCS: {0}s", (createDocTime - buildReportTime) / 1000));
                    Logger.GetLogger().WriteDebug("PMRPublicController", string.Format(
                                                      "CREATE ENTRY IN DATABASE: {0}s", (addDocToDBTime - createDocTime) / 1000));
                }

                PMRPublicReportModel resultModel = CreateFilteredModel(model);

                return(PartialView(
                           "~/Areas/Administration/Views/PMRPublic/Partial/_PMRPublicTablePartial.cshtml",
                           resultModel));
            }
            catch (Exception e)
            {
                Logger.GetLogger().WriteError(
                    "PMRPublicController", "Error when uploading Cognos report", e);
                throw;
            }
        }
        public virtual FileResult GeneratePDFCompositeReport(string reportParametersPDF)
        {
            if (!IDBContext.Current.HasRole(Role.RM_ADMINISTRATOR))
            {
                Logger.GetLogger().WriteMessage(
                    "PMRPublicController",
                    "No RM Administrator in PMR Public. Security issue?");
                throw new Exception("You don't have permissions to use PMR Public");
            }

            try
            {
                int pmrCycleId = GetPmrCycleId(reportParametersPDF);

                string pmrCycleName = GetPmrCycleName(pmrCycleId);

                ReportResponse reportResponse;
                string         reportName = string.Empty;

                string cookieDomain   = ConfigurationManager.AppSettings["cookie:Domain"].ToString();
                bool   cookieHttpOnly = bool.Parse(ConfigurationManager.AppSettings["cookie:HttpOnly"].ToString());
                bool   cookieSecure   = bool.Parse(ConfigurationManager.AppSettings["cookie:Secure"].ToString());

                Response.AppendCookie(new HttpCookie(
                                          PMRGlobalValues.COOKIE_REPORT_READY_PMR_PUBLIC_PDF_COMPOSITE,
                                          PMRGlobalValues.COOKIE_REPORT_READY_PMR_PUBLIC_PDF_COMPOSITE)
                {
                    Domain   = cookieDomain,
                    HttpOnly = cookieHttpOnly,
                    Secure   = cookieSecure
                });

                List <string> operationNumbers = GetOperations(reportParametersPDF);

                Document fullDoc = new Document();

                License license     = new License();
                string  licenseFile = Path.Combine(HttpRuntime.AppDomainAppPath, "Aspose.Total.lic");
                license.SetLicense(licenseFile);

                foreach (var operationNumber in operationNumbers)
                {
                    var reportCognos = new CognosReportBuilder();

                    var reportParameter = new GenerationParameter
                    {
                        OutputFormat     = CognosGlobalValues.FORMAT_PDF,
                        ReportParameters = new Dictionary <string, string>
                        {
                            { CognosGlobalValues.P_OPER_NUMBER, operationNumber },
                            { CognosGlobalValues.P_CYCLE, pmrCycleId.ToString() },
                            { CognosGlobalValues.P_SECTION, CognosGlobalValues.ALL_SECTIONS }
                        }
                    };

                    reportResponse = reportCognos.Generate(reportParameter);

                    if (!reportResponse.IsValid)
                    {
                        throw new Exception(reportResponse.ErrorMessage);
                    }

                    reportName = operationNumber + " " + pmrCycleName + "-Public Report.pdf";

                    if (operationNumbers.Count == 1)
                    {
                        return(File(
                                   reportResponse.Data,
                                   FileContentTypeEnum.Pdf.GetEnumDescription(),
                                   reportName));
                    }

                    MemoryStream str = new MemoryStream(reportResponse.Data);
                    Document     doc = new Document(str);
                    fullDoc.Pages.Add(doc.Pages);
                }

                using (MemoryStream fullstr = new MemoryStream())
                {
                    fullDoc.Save(fullstr, SaveFormat.Pdf);
                    return(File(
                               fullstr.ToArray(),
                               FileContentTypeEnum.Pdf.GetEnumDescription(),
                               "PMR Public Composite.pdf"));
                }
            }
            catch (Exception ex)
            {
                Logger.GetLogger().WriteError(
                    "PMRPublicController", "Error when generating Cognos report", ex);
                throw;
            }
        }