private async Task NetworkReceive() { try { while (!_cancellationTokenSource.IsCancellationRequested && _connected) { await ReadBlock(0, 8); var encryptedChecksumByte = _readBuffer[3]; CryptographyService.Decrypt(_readBuffer, 0, 8); ushort length = (ushort)(_readBuffer[6] | (_readBuffer[7] << 8)); await ReadBlock(8, length + (_alignBuffer ? 1 : 0)); if (length >= _readBuffer.Length) { throw new Exception("Desynchronization error."); } CryptographyService.Decrypt(_readBuffer, 8, length); if (_alignBuffer) { var v = (byte)(encryptedChecksumByte ^ _readBuffer[8 + length]); length -= v; _readBuffer[6] = (byte)(length & 0xFF); _readBuffer[7] = (byte)((length >> 8) & 0xFF); } ushort recvChecksum = (ushort)(_readBuffer[2] | (_readBuffer[3] << 8)); if (_messageChecksumService.Validate(_readBuffer, 0, recvChecksum)) { #if DEBUG LogPacket(_readBuffer, 0, length + 8, "Recv"); #endif var _ = ProcessReceive(_networkMessageFactory.Create(_readBuffer, 0, length + 8)); } else { #if DEBUG LogPacket(_readBuffer, 0, length + 8, "{I} Recv"); #endif } } } catch (SocketException ex) { await DisconnectAsync(); Logger.LogTrace(ex.Message, "ProcessReceive"); } catch (IOException ex) { await DisconnectAsync(); Logger.LogTrace(ex.Message, "ProcessReceive"); } catch (Exception ex) { Logger.LogError(ex, "ProcessReceive"); } }
public UserLogin CreateUserLogin(UserLoginEntity userLoginEntity) { NullArgumentChecker.CheckIfNull(userLoginEntity, "userLoginEntity"); string hintAnswer = string.Empty; if (!string.IsNullOrEmpty(userLoginEntity.HintAnswer)) { hintAnswer = _cryptographyService.Decrypt(userLoginEntity.HintAnswer); } return(new UserLogin(userLoginEntity.UserLoginId) { UserName = userLoginEntity.UserName, Password = userLoginEntity.Password, Salt = userLoginEntity.Salt, Locked = userLoginEntity.IsLocked, FailedAttempts = (long)userLoginEntity.LoginAttempts, IsSecurityQuestionVerified = userLoginEntity.IsSecurityQuestionVerified, UserVerified = userLoginEntity.UserVerified, HintAnswer = hintAnswer, HintQuestion = userLoginEntity.HintQuestion, LastLogged = userLoginEntity.LastLogged, DateCreated = userLoginEntity.DateCreated, DateModified = userLoginEntity.DateModified, IsActive = userLoginEntity.IsActive, LastPasswordChangeDate = userLoginEntity.LastPasswordChangeDate, IsTwoFactorAuthrequired = userLoginEntity.IsTwoFactorAuthrequired, LastLoginAttemptAt = userLoginEntity.LastLoginAttemptAt }); }
public void should_be_able_to_decrypt_the_string() { var encryptedString = Crypto.Encrypt(ClearString); var decryptedString = Crypto.Decrypt(encryptedString); decryptedString.ShouldNotBeEmpty(); decryptedString.ShouldBe(ClearString); }
public void RequiresStringToDecrypt() { //Arrange string stringToDecrypt = null; var cryptoService = new CryptographyService <string>(provider); //Act && Assert Assert.Throws <ArgumentNullException>(() => cryptoService.Decrypt(stringToDecrypt)); }
public void Decrypt_DataListNull_ThrowsArgumentNullException() { var factory = Substitute.For <ICryptographyProcessorFactory>(); var svc = new CryptographyService(factory); var e = Assert.Throws <ArgumentNullException>(() => svc.Decrypt((List <byte[]>)null)); Assert.That(e.Message, Does.Contain("data")); }
public void Decrypt_Settings_test() { var cryptographyService = new CryptographyService(WinRTCrypto.CryptographicEngine, WinRTCrypto.SymmetricKeyAlgorithmProvider, WinRTCrypto.HashAlgorithmProvider, new Logger()); var valueByte = new byte[] { 56, 99, 56, 132, 151, 253, 216, 41, 121, 141, 13, 158, 180, 215, 74, 5 }; var decrypted = cryptographyService.Decrypt(valueByte); var decryptedWithoutPcl = SettingsEncryptorWithoutPcl.Decrypt(valueByte); Assert.AreEqual(decrypted, decryptedWithoutPcl); }
public void RoundTrip() { //Arrange var original = new Fixture().Create <NestedComplexObject>(); var cryptoService = new CryptographyService <NestedComplexObject>(provider); //Act var encrypted = cryptoService.Encrypt(original); var roundtrip = cryptoService.Decrypt(encrypted); //Assert roundtrip.ShouldBeEquivalentTo(original); }
public void Decrypt_DataValid_EncryptionProcessorReceivedCall() { var factory = Substitute.For <ICryptographyProcessorFactory>(); var encryptionProcessor = Substitute.For <IEncryptionProcessor>(); factory.GetEncryptionProcessor().Returns(encryptionProcessor); var svc = new CryptographyService(factory); var testArray = new byte[8]; svc.Decrypt(testArray); encryptionProcessor.Received().Decrypt(testArray); }
/// <summary> /// Called when [authorize request]. /// </summary> public static void CookieDecryptionOnAuthorizeRequest(object sender, System.EventArgs e) { ICryptographyService service = new CryptographyService(); HttpCookie cookie = HttpContext.Current.Request.Cookies[CookieName]; HttpCookie calEmaCookie = new HttpCookie(CookieName); if (cookie != null) { calEmaCookie.Value = service.Decrypt(cookie.Value); } HttpContext.Current.Items[CookieName] = calEmaCookie; }
public void Configure(EntityTypeBuilder <User> builder) { builder.ToContainer("Users"); builder.HasNoDiscriminator(); var converter = new ValueConverter <string, string>( value => CryptographyService.Encrypt(value, _appSettings.EncryptionKey), value => CryptographyService.Decrypt(value, _appSettings.EncryptionKey)); builder.Property(user => user.Name).HasConversion(converter); builder.Property(user => user.Surname).HasConversion(converter); builder.Property(user => user.CellphoneNumber).HasConversion(converter); builder.Property(user => user.EmailAddress).HasConversion(converter); builder.Property(user => user.Password).HasConversion(converter); builder.Property(user => user.PasswordSalt).HasConversion(converter); }
public void Decrypt_DataListContainsThreeValidItems_EncryptionProcessorReceivedThreeCalls() { var factory = Substitute.For <ICryptographyProcessorFactory>(); var encryptionProcessor = Substitute.For <IEncryptionProcessor>(); factory.GetEncryptionProcessor().Returns(encryptionProcessor); var svc = new CryptographyService(factory); var testList = new List <byte[]>() { new byte[8], new byte[8], new byte[8], }; svc.Decrypt(testList); encryptionProcessor.Received(3).Decrypt(Arg.Any <byte[]>()); }
protected void Page_Load(object sender, EventArgs e) { long eventId; string key; string fileType; string fileRequest; string[] keyAll; if (Request["Key"] != null && Convert.ToString(Request["Key"]) != "") { var currentSesion = IoC.Resolve <ISessionContext>().UserSession; if (currentSesion == null) { ShowErrorMessage("Unauthorized Access, Please login into application to access any digital resource."); return; } var currentUserContext = currentSesion.CurrentOrganizationRole; key = Request["Key"]; key = key.Replace(" ", "+"); string decryptedKey = _cryptographyService.Decrypt(key); if (key.Equals(decryptedKey)) { ShowErrorMessage("Unauthorized Access"); return; } fileType = EPDFType.ClinicalForm.ToString(); keyAll = decryptedKey.Split('~'); long customerId; if (keyAll.Length > 3) { fileType = keyAll[0]; eventId = Convert.ToInt64(keyAll[1]); customerId = Convert.ToInt64(keyAll[2]); fileRequest = keyAll[3]; } else { ShowErrorMessage(decryptedKey); return; } string fileName = string.Empty; var mediaRepository = IoC.Resolve <IMediaRepository>(); if ((!string.IsNullOrEmpty(fileType)) && (fileType.Equals(EPDFType.ClinicalForm.ToString()) || fileType.Equals(EPDFType.ResultPdf.ToString()) || fileType.Equals(EPDFType.ResultPdfWithImages.ToString()) || fileType.Equals(EPDFType.ViewResult.ToString()) || fileType.Equals(EPDFType.All.ToString()) || fileType.Equals(EPDFType.PaperOnly.ToString()) || fileType.Equals(EPDFType.OnlineOnly.ToString()) || fileType.Equals(EPDFType.CdContent.ToString()) || fileType.Equals(EPDFType.PcpResultReport.ToString()) || fileType.Equals(EPDFType.AllPcpResultReportOnly.ToString()) || fileType.Equals(EPDFType.EAwvPreventionPlanReport.ToString()) || fileType.Equals(EPDFType.AllEawvPreventionPlanReportOnly.ToString()) || fileType.Equals(EPDFType.HealthPlanReport.ToString()) || fileType.Equals(EPDFType.AllHealthPlanReportOnly.ToString()) || fileType.Equals(EPDFType.IpResultPdf.ToString()))) { if ((!string.IsNullOrEmpty(fileRequest)) && (eventId > 0)) { if (fileRequest.ToUpper().Equals("ALL") && (currentUserContext.GetSystemRoleId == (long)Roles.FranchisorAdmin || currentUserContext.GetSystemRoleId == (long)Roles.FranchiseeAdmin || currentUserContext.GetSystemRoleId == (long)Roles.Technician)) { string zipUrl = string.Empty; if (fileType.Equals(EPDFType.All.ToString())) { fileName = mediaRepository.GetAllPremiumPdfName(eventId) + ".zip"; zipUrl = mediaRepository.GetResultPacketMediaLocation(eventId).Url + fileName; } else if (fileType.Equals(EPDFType.PaperOnly.ToString())) { fileName = mediaRepository.GetAllPremiumPdfPaperCopyOnly(eventId) + ".zip"; zipUrl = mediaRepository.GetResultPacketMediaLocation(eventId).Url + fileName; } else if (fileType.Equals(EPDFType.OnlineOnly.ToString())) { fileName = mediaRepository.GetAllPremiumPdfOnlineOnly(eventId) + ".zip"; zipUrl = mediaRepository.GetResultPacketMediaLocation(eventId).Url + fileName; } else if (fileType.Equals(EPDFType.AllPcpResultReportOnly.ToString())) { fileName = mediaRepository.GetAllPremiumPdfPcpOnly(eventId) + ".zip"; zipUrl = mediaRepository.GetResultPacketMediaLocation(eventId).Url + fileName; } else if (fileType.Equals(EPDFType.AllEawvPreventionPlanReportOnly.ToString())) { fileName = mediaRepository.GetAllPremiumPdfEawvReportOnly(eventId) + ".zip"; zipUrl = mediaRepository.GetResultPacketMediaLocation(eventId).Url + fileName; } else if (fileType.Equals(EPDFType.AllHealthPlanReportOnly.ToString())) { fileName = mediaRepository.GetAllPremiumPdfHealthPlanReportOnly(eventId) + ".zip"; zipUrl = mediaRepository.GetResultPacketMediaLocation(eventId).Url + fileName; } else if (fileType.Equals(EPDFType.CdContent.ToString())) { fileName = eventId + ".zip"; zipUrl = mediaRepository.GetResultPacketMediaLocation(eventId, false).Url + fileName; //ResumableFile(zipUrl, fileName); //DownloadZipFile(zipUrl, fileName); } WriteZipFile(zipUrl, fileName); } else if (fileRequest.ToUpper().Equals("SINGLE")) { if (currentUserContext.CheckRole((long)Roles.Customer) || currentUserContext.CheckRole((long)Roles.Technician) || currentUserContext.CheckRole((long)Roles.FranchiseeAdmin) || currentUserContext.CheckRole((long)Roles.FranchisorAdmin) || currentUserContext.CheckRole((long)Roles.HospitalPartnerCoordinator) || currentUserContext.CheckRole((long)Roles.HospitalFacilityCoordinator) || currentUserContext.CheckRole((long)Roles.NursePractitioner) || currentUserContext.CheckRole((long)Roles.CorporateAccountCoordinator)) { string pdfUrl = string.Empty; if (fileType.Equals(EPDFType.ClinicalForm.ToString())) { fileName = mediaRepository.GetPdfFileNameForResultReport(); pdfUrl = mediaRepository.GetClinicalFormResultPdfLocation(eventId, customerId).Url + fileName; } else if (fileType.Equals(EPDFType.ResultPdf.ToString())) { fileName = mediaRepository.GetPdfFileNameForResultReport(); pdfUrl = mediaRepository.GetPremiumVersionResultPdfLocation(eventId, customerId).Url + fileName; } else if (fileType.Equals(EPDFType.ResultPdfWithImages.ToString())) { fileName = mediaRepository.GetPdfFileNameForResultReportWithImages(); pdfUrl = mediaRepository.GetPremiumVersionResultPdfLocation(eventId, customerId).Url + fileName; } else if (fileType.Equals(EPDFType.ResultPdfPaperBack.ToString())) { fileName = mediaRepository.GetPdfFileNameForResultReportPaperBack(); pdfUrl = mediaRepository.GetPremiumVersionResultPdfLocation(eventId, customerId).Url + fileName; } else if (fileType.Equals(EPDFType.PcpResultReport.ToString())) { fileName = mediaRepository.GetPdfFileNameForPcpResultReport(); pdfUrl = mediaRepository.GetPremiumVersionResultPdfLocation(eventId, customerId).Url + fileName; } else if (fileType.Equals(EPDFType.EAwvPreventionPlanReport.ToString())) { fileName = mediaRepository.GetPdfFileNameForEawvPreventionPlanReport(); pdfUrl = mediaRepository.GetPremiumVersionResultPdfLocation(eventId, customerId).Url + fileName; } else if (fileType.Equals(EPDFType.HealthPlanReport.ToString())) { fileName = mediaRepository.GetPdfFileNameForHealthPlanResultReport(); pdfUrl = mediaRepository.GetPremiumVersionResultPdfLocation(eventId, customerId).Url + fileName; } else if (fileType.Equals(EPDFType.CdContent.ToString())) { fileName = customerId + ".zip"; pdfUrl = mediaRepository.GetCdContentFolderLocation(eventId).Url + fileName; WriteZipFile(pdfUrl, fileName); } else if (fileType.Equals(EPDFType.ViewResult.ToString())) { var viewResultUrl = "/App/Common/Results.aspx?eventId=" + eventId + "&customerid=" + customerId; Server.Transfer(viewResultUrl); return; } else if (fileType.Equals(EPDFType.IpResultPdf.ToString())) { var customer = IoC.Resolve <ICustomerRepository>().GetCustomer(customerId); var eventData = IoC.Resolve <Falcon.App.Core.Scheduling.Interfaces.IEventRepository>().GetById(eventId); fileName = mediaRepository.GetPdfFileNameForIpResultPdf(customer.CustomerId, customer.AcesId, customer.Name.FirstName, customer.Name.LastName, eventData.EventDate.Year); pdfUrl = mediaRepository.GetIpResultPdfLocation(eventId, customerId).Url + fileName; } if (currentUserContext.CheckRole((long)Roles.Customer)) { SaveDigitalAccessTrackingDetail(fileType.Replace("_", " "), pdfUrl); } WritePdfFile(pdfUrl, fileName); } } else { ShowErrorMessage("Unauthorized Access"); return; } } } else { ShowErrorMessage("Unauthorized Access"); return; } } else { ShowErrorMessage("Unauthorized Access"); return; } }
public void Create(IEnumerable <EventCustomerResultEntity> eventCustomerResultEntities, IEnumerable <OrderedPair <long, long> > orgRoleUserIdUserIdPairs, IEnumerable <UserEntity> userEntities, IEnumerable <Address> addresses, IEnumerable <CustomerProfileEntity> customerProfileEntities, IEnumerable <EventsEntity> eventsEntities, IEnumerable <CustomerHealthInfoEntity> customerHealthInfoEntities, IEnumerable <OrderedPair <long, long> > eventIdPodIdPairs, IEnumerable <PodDetailsEntity> podDetailsEntities, IEnumerable <OrderedPair <long, long> > eventIdHospitalPartnerIdPairs, IEnumerable <OrderedPair <long, string> > hospitalPartnerIdNamePairs, IEnumerable <EventCustomerBasicBioMetricEntity> basicBioMetricEntities, IEnumerable <EventCustomersEntity> eventCustomersEntities, IEnumerable <EventAppointmentEntity> eventAppointmentEntities, IEnumerable <HospitalPartnerCustomerEntity> hospitalPartnerCustomerEntities, IEnumerable <OrderedPair <long, string> > careCoordinatorIdNamePair, IEnumerable <CustomerPrimaryCarePhysicianEntity> primaryCarePhysicianEntities, string destinationPath, IEnumerable <long> hafQuestionIds) { long totalRecords = eventCustomerResultEntities.Count(); long counter = 1; PcpResultExportHelper.Questions = PcpResultExportHelper.AllQuestions.Where(aq => hafQuestionIds.Contains(aq.FirstValue)).Select(aq => aq).ToArray(); _logger.Info("Total Records : " + totalRecords); WriteCsvHeader(destinationPath); foreach (var eventCustomerResultEntity in eventCustomerResultEntities) { try { _logger.Info(string.Format("Creating Model for event {0} and customer {1}", eventCustomerResultEntity.EventId, eventCustomerResultEntity.CustomerId)); var userId = orgRoleUserIdUserIdPairs.Where(oru => oru.FirstValue == eventCustomerResultEntity.CustomerId).Select(oru => oru.SecondValue).Single(); var user = userEntities.Where(u => u.UserId == userId).Select(u => u).Single(); var address = addresses.Where(a => a.Id == user.HomeAddressId).Select(a => a).Single(); var customer = customerProfileEntities.Where(cp => cp.CustomerId == eventCustomerResultEntity.CustomerId).Select(cp => cp).Single(); var eventData = eventsEntities.Where(e => e.EventId == eventCustomerResultEntity.EventId).Select(e => e).Single(); var podIds = eventIdPodIdPairs.Where(ep => ep.FirstValue == eventData.EventId).Select(ep => ep.SecondValue).ToArray(); var podName = string.Join(",", podDetailsEntities.Where(pd => podIds.Contains(pd.PodId)).Select(pd => pd.Name).ToArray()); var hospitalPartnerId = eventIdHospitalPartnerIdPairs.Where(ehp => ehp.FirstValue == eventData.EventId).Select(ehp => ehp.SecondValue).SingleOrDefault(); var hopitalPartnerName = hospitalPartnerIdNamePairs.Where(hp => hp.FirstValue == hospitalPartnerId).Select(hp => hp.SecondValue).SingleOrDefault(); var eventCustomer = eventCustomersEntities.Where(ec => ec.EventCustomerId == eventCustomerResultEntity.EventCustomerResultId).Select(ec => ec).Single(); var eventAppointment = eventAppointmentEntities.Where(ea => ea.AppointmentId == eventCustomer.AppointmentId).Select(ea => ea).Single(); var primaryCarePhysician = primaryCarePhysicianEntities.Where(pcp => pcp.CustomerId == eventCustomerResultEntity.CustomerId).Select(pcp => pcp).FirstOrDefault(); var basicBimetric = basicBioMetricEntities.Where(bb => bb.EventCustomerId == eventCustomerResultEntity.EventCustomerResultId).Select(bb => bb).FirstOrDefault(); var hafAnswers = customerHealthInfoEntities.Where(chi => chi.EventCustomerId == eventCustomerResultEntity.EventCustomerResultId).Select(chi => chi).ToArray(); var answers = new List <OrderedPair <long, string> >(); foreach (var question in PcpResultExportHelper.Questions) { var hafAnswer = hafAnswers.Where(ha => ha.CustomerHealthQuestionId == question.FirstValue).Select(ha => ha).FirstOrDefault(); if (hafAnswer != null) { answers.Add(new OrderedPair <long, string>(question.FirstValue, hafAnswer.HealthQuestionAnswer)); } else { answers.Add(new OrderedPair <long, string>(question.FirstValue, "")); } } var age = string.Empty; if (user.Dob.HasValue) { var now = DateTime.Now; var checkCurrentLeapYear = new DateTime(now.Year, 3, 1); var birth = user.Dob.Value; var checkBirthLeapYear = new DateTime(birth.Year, 3, 1); var currentDayOfYear = now.DayOfYear; if (checkCurrentLeapYear.DayOfYear == 61 && now.Month >= checkCurrentLeapYear.Month && checkBirthLeapYear.DayOfYear != 61) { currentDayOfYear = now.DayOfYear - 1; } else if (checkCurrentLeapYear.DayOfYear != 61 && now.Month >= checkCurrentLeapYear.Month && checkBirthLeapYear.DayOfYear == 61) { currentDayOfYear = now.DayOfYear + 1; } var years = now.Year - birth.Year - ((currentDayOfYear < birth.DayOfYear) ? 1 : 0); var months = (12 + now.Month - birth.Month - ((now.Day < birth.Day) ? 1 : 0)) % 12; var days = now.Day - birth.Day; if (days < 0) { days = new DateTime(now.Year, now.Month, 1).AddDays(-1).AddDays(days).Day; } age = years.ToString(); } var ssn = "N/A"; if (!string.IsNullOrEmpty(user.Ssn)) { ssn = _cryptographyService.Decrypt(user.Ssn); if (ssn.Length >= 9) { ssn = ssn.Substring(0, 3) + "-" + ssn.Substring(3, 2) + "-" + ssn.Substring(ssn.Length - 4); } } var model = new PcpResultExportModel { CustomerId = customer.CustomerId, FirstName = user.FirstName, LastName = user.LastName, Address1 = address.StreetAddressLine1, City = address.City, State = address.State, Zip = address.ZipCode.Zip, Dob = user.Dob, Age = age, Height = customer.Height, Weight = customer.Weight > 0 ? customer.Weight.ToString() : "", Gender = customer.Gender, Race = customer.Race != "-1" ? customer.Race : "", Email = user.Email1, Phone = user.PhoneHome, Ssn = ssn, MemberId = string.IsNullOrEmpty(customer.InsuranceId) ? "" : customer.InsuranceId, Hicn = string.IsNullOrEmpty(customer.Hicn) ? "" : customer.Hicn, EventId = eventData.EventId, EventDate = eventData.EventDate, Pod = podName, HospitalPartner = hopitalPartnerName, Hipaa = ((RegulatoryState)eventCustomer.Hipaastatus).GetDescription(), CheckinTime = eventAppointment.CheckinTime.HasValue ? eventAppointment.CheckinTime.Value.ToShortTimeString() : "", CheckoutTime = eventAppointment.CheckoutTime.HasValue ? eventAppointment.CheckoutTime.Value.ToShortTimeString() : "", HealthAssesmentAnswer = answers, ResultSummary = eventCustomerResultEntity.ResultSummary.HasValue ? ((ResultInterpretation)eventCustomerResultEntity.ResultSummary).GetDescription() : "" }; if (primaryCarePhysician != null) { model.PrimaryPhysicianName = new Name(primaryCarePhysician.FirstName, primaryCarePhysician.MiddleName, primaryCarePhysician.LastName).FullName; } if (hospitalPartnerId > 0) { model.PartnerRelease = eventCustomer.PartnerRelease > 0 ? ((RegulatoryState)eventCustomer.PartnerRelease).GetDescription() : ""; var hospitalPartnerCustomer = hospitalPartnerCustomerEntities.LastOrDefault(hpc => hpc.EventId == eventCustomerResultEntity.EventId && hpc.CustomerId == eventCustomerResultEntity.CustomerId); model.CareCoordinatorStatus = hospitalPartnerCustomer != null ? ((HospitalPartnerCustomerStatus)hospitalPartnerCustomer.Status).GetDescription() : HospitalPartnerCustomerStatus.NotCalled.GetDescription(); model.CareCoordinatorOutcome = hospitalPartnerCustomer != null ? ((HospitalPartnerCustomerOutcome)hospitalPartnerCustomer.Outcome).GetDescription() : HospitalPartnerCustomerOutcome.NotScheduledNotInterested.GetDescription(); model.CareCoordinator = hospitalPartnerCustomer != null ? careCoordinatorIdNamePair.First(cc => cc.FirstValue == hospitalPartnerCustomer.CareCoordinatorOrgRoleUserId).SecondValue : "N/A"; model.CareCoordinatorNotes = hospitalPartnerCustomer != null ? hospitalPartnerCustomer.Notes : ""; } else { model.PartnerRelease = "N/A"; model.CareCoordinatorStatus = "N/A"; model.CareCoordinatorOutcome = "N/A"; model.CareCoordinator = "N/A"; model.CareCoordinatorNotes = "N/A"; } if (model.EventId > 0) { var theEvent = _eventRepository.GetById(model.EventId); if (theEvent.AccountId.HasValue && theEvent.AccountId > 0) { var organization = _organizationRepository.GetOrganizationbyId(theEvent.AccountId.Value); model.CorporateAccount = organization.Name; } if (theEvent.HostId > 0) { var host = _hostRepository.GetHostForEvent(theEvent.Id); model.EventLocation = host.OrganizationName + " @ " + host.Address; } } if (basicBimetric != null) { model.BloodPressure = (basicBimetric.SystolicPressure.HasValue ? basicBimetric.SystolicPressure.Value.ToString() : "0") + "/" + (basicBimetric.DiastolicPressure.HasValue ? basicBimetric.DiastolicPressure.Value.ToString() : "0"); model.PulseRate = basicBimetric.PulseRate.HasValue ? basicBimetric.PulseRate.Value.ToString() : ""; model.IsAbnormalBloodPressure = basicBimetric.IsBloodPressureElevated.HasValue && basicBimetric.IsBloodPressureElevated.Value ? PhysicianPartnerResultExportHelper.YesString : PhysicianPartnerResultExportHelper.NoString; } ITestResultRepository testResultRepository; var isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvAAA); if (isTestPurchased) { _logger.Info("Setting Awv Aaa data."); testResultRepository = new AwvAaaTestRepository(); var awvAaaTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId); if (awvAaaTestResult != null) { model = _awvAaaFactory.SetAwvAaaData(model, awvAaaTestResult as AwvAaaTestResult); } } isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvEcho); if (isTestPurchased) { _logger.Info("Setting Awv Echo data."); testResultRepository = new AwvEchocardiogramTestRepository(); var awvEchoTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId); if (awvEchoTestResult != null) { model = _awvEchoFactory.SetAwvEchoData(model, awvEchoTestResult as AwvEchocardiogramTestResult); } } isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvCarotid); if (isTestPurchased) { _logger.Info("Setting Awv Carotid data."); testResultRepository = new AwvCarotidTestRepository(); var awvCarotidTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId); if (awvCarotidTestResult != null) { model = _awvCarotidFactory.SetAwvCarotidData(model, awvCarotidTestResult as AwvCarotidTestResult); } } isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvSpiro); if (isTestPurchased) { _logger.Info("Setting AWV Spiro data."); testResultRepository = new AwvSpiroTestRepository(); var awvSpiroTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId); if (awvSpiroTestResult != null) { model = _awvSpiroFactory.SetAwvSpiroData(model, awvSpiroTestResult as AwvSpiroTestResult); } } isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvABI); if (isTestPurchased) { _logger.Info("Setting Awv ABI data."); testResultRepository = new AwvAbiTestRepository(); var awvAbiTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId); if (awvAbiTestResult != null) { model = _awvAbiFactory.SetAwvAbiData(model, awvAbiTestResult as AwvAbiTestResult); } } isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.AwvEkg); if (isTestPurchased) { _logger.Info("Setting Awv EKG data."); testResultRepository = new AwvEkgTestRepository(); var awvEkgTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId); if (awvEkgTestResult != null) { model = _awvEkgFactory.SetAwvEkgData(model, awvEkgTestResult as AwvEkgTestResult); } } isTestPurchased = _testResultService.IsTestPurchasedByCustomer(eventData.EventId, customer.CustomerId, (long)TestType.Vision); if (isTestPurchased) { _logger.Info("Setting Vision data."); testResultRepository = new VisionTestRepository(); var visionTestResult = testResultRepository.GetTestResults(customer.CustomerId, eventData.EventId); if (visionTestResult != null) { model = _visionFactory.SetVisionData(model, visionTestResult as VisionTestResult); } } WriteCsv(model, destinationPath); _logger.Info(counter + " completed out of " + totalRecords); //if (counter > 10) // break; counter++; } catch (Exception ex) { _logger.Error(string.Format("\n\nFor Event {0} and Customer {1} \n Error:{2}", eventCustomerResultEntity.EventId, eventCustomerResultEntity.CustomerId, ex.Message)); } } }