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 Respond()
        {
            try
            {
                DataDownloadBespokeParameters parameters = new DataDownloadBespokeParameters(Context.Request.Params);

                var fileInfo = new PracticeProfileFileInfo(parameters.ProfileKey,
                    parameters.GroupIds,
                    parameters.AreaCode);

                byte[] bytes;

                if (ApplicationConfiguration.UseFileCache && fileInfo.DoesFileExist)
                {
                    bytes = File.ReadAllBytes(fileInfo.FilePath);
                }
                else
                {
                    PracticeProfileDataBuilder builder = new PracticeProfileDataBuilder(UsePopulationData(parameters))
                    {
                        AreaCode = parameters.AreaCode,
                        GroupIds = parameters.GroupIds,
                        AreaTypeId = parameters.AreaTypeId
                    };

                    var workBook = builder.BuildWorkbook();
                    ExcelFileWriter writer = new ExcelFileWriter
                    {
                        UseFileCache = ApplicationConfiguration.UseFileCache
                    };
                    bytes = writer.Write(fileInfo, workBook);
                }

                var response = Context.Response;
                ExportHelper.SetResponseAsExcelFile(response,
                    GetDataDownload.DownloadedFileName + "." + fileInfo.FileExtension);
                response.BinaryWrite(bytes);
            }
            catch (Exception ex)
            {
                Context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                ExceptionLog.LogException(ex, Context.Request.Url.AbsoluteUri);
            }

            Context.Response.Flush();
        }