public void ProcessRequest(HttpContext context)
        {
            try
            {
                DataDownloadParameters parameters = new DataDownloadParameters(context.Request.Params);

                int profileId = parameters.ProfileId;
                List<int> profileIds = parameters.RestrictResultsToProfileIdList;

                var profile = ReaderFactory.GetProfileReader().GetProfile(profileId);
                int areaTypeId = parameters.AreaTypeId;
                var parentAreas = GetParentAreas(parameters, areaTypeId);
                var subnationalAreaType = AreaTypeFactory.New(areasReader, parameters.SubnationalAreaTypeId);

                ComparatorMap comparatorMap = new ComparatorMapBuilder(parentAreas).ComparatorMap;
                BaseExcelFileInfo fileInfo;
                IWorkbook workbook = null;
                ExcelFileWriter writer = new ExcelFileWriter
                {
                    UseFileCache = ApplicationConfiguration.UseFileCache
                };
                byte[] bytes = null;
                if (parameters.UseIndicatorIds)
                {
                    fileInfo = new SearchResultsFileInfo();
                    workbook = new ProfileDataBuilder(comparatorMap, profile, profileIds,
                        parameters.IndicatorIds, parentAreas, subnationalAreaType).BuildWorkbook();
                }
                else
                {
                    fileInfo = new ProfileFileInfo(profileId, parentAreas.Select(x => x.AreaCode), areaTypeId, subnationalAreaType.Id);

                    if (ApplicationConfiguration.UseFileCache && fileInfo.DoesFileExist)
                    {
                        bytes = File.ReadAllBytes(fileInfo.FilePath);
                    }
                    else
                    {
                        workbook = new ProfileDataBuilder(comparatorMap, profile, profileIds,
                             parentAreas, subnationalAreaType).BuildWorkbook();
                    }
                }

                if (workbook != null)
                {
                    bytes = writer.Write(fileInfo, workbook);
                }

                HttpResponseBase response = new HttpContextWrapper(context).Response;
                ExportHelper.SetResponseAsExcelFile(response, DownloadedFileName + "." + fileInfo.FileExtension);
                response.BinaryWrite(bytes);
            }
            catch (Exception ex)
            {
                ExceptionLog.LogException(ex, context.Request.Url.AbsoluteUri);
            }

            context.Response.Flush();
        }
 public void TestFileFormat()
 {
     var fileInfo = new SearchResultsFileInfo();
     Assert.AreEqual(FileFormat.OpenXMLWorkbook, fileInfo.FileFormat);
 }
 public void TestFileExtension1()
 {
     var fileInfo = new SearchResultsFileInfo();
     Assert.AreEqual("xlsx", fileInfo.FileExtension);
 }