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();
        }
        private void CreateExcelFilesForCoreProfiles(int profileId, int areaTypeId, int subnationalAreaTypeId)
        {
            try
            {
                var profile = _profileReader.GetProfile(profileId);
                var parentAreas = new List<ParentArea> { new ParentArea(AreaCodes.England, areaTypeId) };
                var subnationalAreaType = AreaTypeFactory.New(_areasReader, subnationalAreaTypeId);

                var comparatorMap = new ComparatorMapBuilder(parentAreas).ComparatorMap;

                var dummyListOfprofileIds = new List<int>();

                IWorkbook workbook = new ProfileDataBuilder(comparatorMap, profile, dummyListOfprofileIds,
                        parentAreas, subnationalAreaType).BuildWorkbook();

                if (workbook != null)
                {
                    BaseExcelFileInfo fileInfo = new ProfileFileInfo(profileId,
                        parentAreas.Select(x => x.AreaCode), areaTypeId, subnationalAreaType.Id);

                    new ExcelFileWriter
                    {
                        UseFileCache = ApplicationConfiguration.UseFileCache
                    }.Write(fileInfo, workbook);
                }
            }
            catch (Exception ex)
            {
                var message = "Failed to create excel file " +
                    GetProfileDetailsText(profileId, subnationalAreaTypeId, areaTypeId);
                _logger.Error(message);
                NLogHelper.LogException(_logger, ex);
                ExceptionLog.LogException(new FingertipsException(message, ex), null);
            }
        }