private void ReportResults(IntegratorUser integratorUser, IHasId <Guid> jobPoster, Report report) { const string method = "ReportResults"; _jobAdIntegrationReportsCommand.CreateJobAdIntegrationEvent(new JobAdImportPostEvent { Success = true, IntegratorUserId = integratorUser.Id, PosterId = jobPoster.Id, JobAds = report.JobAds, Closed = report.Closed, Duplicates = report.Duplicates, Failed = report.Failed, Posted = report.Posted, Updated = report.Updated, Ignored = report.Ignored, }); var message = string.Format("Processing complete. {0} job ads created, {1} updated," + " {2} closed, {3} failed, {4} were ignored as duplicates of those from another source," + " {5} were ignored as coming from the ignored source.", report.Posted, report.Updated, report.Closed, report.Failed, report.Duplicates, report.Ignored); _logger.Raise(Event.Information, method, message); }
PostReport IJobAdPostsManager.PostJobAds(IntegratorUser integratorUser, IEmployer jobPoster, IEmployer integratorJobPoster, IEnumerable <JobAd> jobAds, bool closeAllOtherJobAds) { // Read the jobads. var report = new PostReport(); // Process them. jobPoster = jobPoster ?? integratorJobPoster; foreach (var jobAd in jobAds) { ProcessJobAd(integratorUser.Id, jobPoster, jobAd, report); } if (!closeAllOtherJobAds) { return(report); } var jobAdIds = _jobAdIntegrationQuery.GetJobAdIds(integratorUser.Id, jobPoster.Id); var closeJobAdIds = jobAdIds.Except(report.ProcessedJobAdIds).ToList(); var closeJobAds = _jobAdsQuery.GetJobAds <JobAd>(closeJobAdIds); foreach (var closeJobAd in closeJobAds) { _jobAdsCommand.CloseJobAd(closeJobAd); } report.Closed += closeJobAdIds.Count(); return(report); }
protected JobAd AssertJobAd(IntegratorUser integratorUser, Guid employerId, string externalReferenceId, JobAdStatus expectedStatus) { var jobAds = _jobAdsQuery.GetJobAds <JobAd>(_jobAdIntegrationQuery.GetJobAdIds(integratorUser.Id, employerId, externalReferenceId)); Assert.AreEqual(1, jobAds.Count); return(AssertJobAd(jobAds[0], integratorUser, externalReferenceId, expectedStatus)); }
public void TestValidUserWithoutPermissions() { var ats = _integrationQuery.GetIntegrationSystem <Ats>(_jobG8Query.GetIntegratorUser().IntegrationSystemId); var integratorUser = new IntegratorUser { LoginId = "JobAdFeedTestUser", PasswordHash = LoginCredentials.HashToString(Password), Permissions = IntegratorPermissions.GetJobApplication, IntegrationSystemId = ats.Id, }; _integrationCommand.CreateIntegratorUser(integratorUser); var request = new PostAdvertRequestMessage { UserCredentials = new Credentials { Username = "******", Password = Password } }; var employer = CreateEmployer(0); PostAdvert(employer, request); }
private void CheckUser(Credentials credentials, out IntegratorUser integratorUser, out IEmployer jobPoster) { const string method = "CheckUser"; try { if (credentials == null) { throw new ServiceEndUserException("UserCredentials are not specified."); } integratorUser = _serviceAuthenticationManager.AuthenticateRequest(credentials.Username, credentials.Password, IntegratorPermissions.PostJobAds); jobPoster = GetJobPoster(_jobPosterUserId); } catch (ServiceEndUserException e) { var ex = new FaultException(e.Message); EventSource.Raise(Event.Error, method, ex, null); throw ex; } catch (UserException e) { var ex = new FaultException(e.Message); EventSource.Raise(Event.Error, method, ex, null); throw ex; } catch (Exception e) { EventSource.Raise(Event.Error, method, e, null); throw; } }
private static byte[] GetData(ReadOnlyUrl url, IntegratorUser user, string password) { var request = (HttpWebRequest)WebRequest.Create(url.AbsoluteUri); request.Method = "GET"; request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0)"; request.ContentLength = 0; request.Expect = ""; request.Timeout = Debugger.IsAttached ? -1 : 300000; request.Headers.Add("X-LinkMeUsername", user.LoginId); request.Headers.Add("X-LinkMePassword", password); using (var response = (HttpWebResponse)request.GetResponse()) { var responseStream = response.GetResponseStream(); var stream = new MemoryStream(); var buffer = new byte[65536]; int read; do { read = responseStream.Read(buffer, 0, buffer.Length); stream.Write(buffer, 0, read); } while (read != 0); stream.Seek(0, SeekOrigin.Begin); var data = new byte[stream.Length]; stream.Read(data, 0, (int)stream.Length); return(data); } }
protected JobAd PostJobAd(IEmployer employer, IntegratorUser integratorUser, string companyName, string contactCompanyName, bool hideContactDetails, bool hideCompany) { var jobAd = PostJobAd(employer); jobAd.ContactDetails = new ContactDetails { FirstName = FirstName, LastName = LastName, CompanyName = contactCompanyName, EmailAddress = EmailAddress, FaxNumber = FaxNumber, PhoneNumber = PhoneNumber, SecondaryEmailAddresses = SecondaryEmailAddresses }; jobAd.Description.CompanyName = companyName; jobAd.Visibility.HideContactDetails = hideContactDetails; jobAd.Visibility.HideCompany = hideCompany; if (integratorUser != null) { jobAd.Integration.IntegratorUserId = integratorUser.Id; } _jobAdsCommand.UpdateJobAd(jobAd); return(jobAd); }
protected JobAd AssertJobAd(JobAd jobAd, IntegratorUser integratorUser, string externalReferenceId, JobAdStatus expectedStatus) { Assert.IsNotNull(jobAd); Assert.AreEqual(integratorUser.Id, jobAd.Integration.IntegratorUserId); Assert.AreEqual(externalReferenceId, jobAd.Integration.ExternalReferenceId); Assert.AreEqual(expectedStatus, jobAd.Status); return(jobAd); }
void IIntegrationRepository.CreateIntegratorUser(IntegratorUser user) { using (var dc = CreateContext()) { dc.IntegratorUserEntities.InsertOnSubmit(user.Map()); dc.SubmitChanges(); } }
public ActionResult JobAds() { const string method = "JobAds"; IntegratorUser user = null; try { // Authenticate. user = _serviceAuthenticationManager.AuthenticateRequest(HttpContext, IntegratorPermissions.PostJobAds); // Load the request. var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(GetRequestXml()); var xmlNsMgr = new XmlNamespaceManager(xmlDoc.NameTable); xmlNsMgr.AddNamespace(XmlNamespacePrefix, XmlNamespace); var xmlNode = xmlDoc.SelectSingleNode("/" + XmlNamespacePrefix + ":PostJobAdsRequest", xmlNsMgr); // Extract values. var jobPoster = GetJobPoster(xmlNode, xmlNsMgr); var integratorJobPoster = jobPoster == null ? _externalJobAdsQuery.GetJobPoster(user) : null; var closeAllOtherJobAds = jobPoster != null && GetCloseAllOtherAds(xmlNode, xmlNsMgr); var jobAds = GetJobAds(xmlNode, xmlNsMgr, jobPoster == null ? JobAdStatus.Draft : (JobAdStatus?)null); // Process. var report = _jobAdPostsManager.PostJobAds(user, jobPoster, integratorJobPoster, jobAds.Where(j => j != null), closeAllOtherJobAds); // Record it, including read failures. report.Failed += jobAds.Count(j => j == null); _jobAdIntegrationReportsCommand.CreateJobAdIntegrationEvent(new JobAdImportPostEvent { Success = true, IntegratorUserId = user.Id, PosterId = (jobPoster ?? integratorJobPoster).Id, JobAds = jobAds.Count(j => j != null), Closed = report.Closed, Failed = report.Failed, Posted = report.Posted, Updated = report.Updated }); return(Xml(new PostJobAdsResponse(GetResponseXml(report), report.Errors.ToArray()))); } catch (Exception ex) { EventSource.Raise(ex.Message.EndsWith("disabled.") ? (Event)Event.NonCriticalError : Event.Error, method, "Cannot process the request.", ex, new StandardErrorHandler()); if (user != null) { _jobAdIntegrationReportsCommand.CreateJobAdIntegrationEvent(new JobAdImportPostEvent { Success = false, IntegratorUserId = user.Id }); } return(Xml(new PostJobAdsResponse(ex))); } }
private JobAd PostJobAd(IEmployer jobPoster, IntegratorUser integratorUser) { var jobAd = jobPoster.CreateTestJobAd(); jobAd.Integration.IntegratorUserId = integratorUser.Id; jobAd.Integration.ExternalApplyUrl = "http://test.external/ad"; _jobAdsCommand.PostJobAd(jobAd); return(jobAd); }
protected JobAd CreateJobAd(IEmployer employer, IntegratorUser integratorUser) { var jobAd = base.CreateJobAd(employer); jobAd.Integration.ExternalApplyUrl = "http://www.google.com.au/"; jobAd.Integration.IntegratorUserId = integratorUser.Id; _jobAdsCommand.UpdateJobAd(jobAd); return(jobAd); }
private void TestLocation(IntegratorUser integratorUser, Employer jobPoster, int index, string location, string expected) { var jobAd = CreateJobAd(index, j => { j.Location = location; j.Postcode = null; }); PostJobAds(integratorUser, jobPoster, false, new[] { jobAd }, 1, 0, 0, 0); var found = AssertJobAd(integratorUser, jobPoster.Id, jobAd.ExternalReferenceId, JobAdStatus.Open); AssertJobAd(jobAd, found); TestLocation(found.Id, expected); }
private Guid CreateJobAd(IntegratorUser integratorUser, Guid employerId, JobAdElement jobAdElement) { var jobAd = jobAdElement.Map(_industriesQuery, _locationQuery); jobAd.PosterId = employerId; jobAd.Integration.IntegratorUserId = integratorUser.Id; _jobAdsCommand.CreateJobAd(jobAd); _jobAdsCommand.OpenJobAd(jobAd); return(jobAd.Id); }
private string Post(ReadOnlyUrl url, IntegratorUser user, string password, string requestXml) { Browser.RequestHeaders = new WebHeaderCollection { { "X-LinkMeUsername", user.LoginId }, { "X-LinkMePassword", password } }; return(Post(url, "text/xml", requestXml)); }
public static IntegratorUserEntity Map(this IntegratorUser user) { return(new IntegratorUserEntity { id = user.Id, username = user.LoginId, password = user.PasswordHash, integratorId = user.IntegrationSystemId, permissions = (short)user.Permissions, }); }
public JobAdExporter(IChannelManager <IPublicVacancy> channelManager, IDewrQuery dewrQuery, IJobAdsQuery jobAdsQuery, IJobAdExportCommand exportCommand, IIndustriesQuery industriesQuery, IEmployersQuery employersQuery, IIntegrationQuery integrationQuery, IJobAdIntegrationReportsCommand jobAdIntegrationReportsCommand) { _channelManager = channelManager; _jobAdsQuery = jobAdsQuery; _integrationQuery = integrationQuery; _exportCommand = exportCommand; _employersQuery = employersQuery; _jobAdIntegrationReportsCommand = jobAdIntegrationReportsCommand; _mapper = new JobAdMapper(industriesQuery); _integratorUser = dewrQuery.GetIntegratorUser(); }
private void AssertJobAds(IntegratorUser integratorUser, Guid employerId, params JobAdElement[] expectedJobAds) { var jobAds = _jobAdsQuery.GetJobAds <JobAd>(_jobAdIntegrationQuery.GetJobAdIds(integratorUser.Id, employerId)); Assert.AreEqual(expectedJobAds.Length, jobAds.Count); foreach (var expectedJobAd in expectedJobAds) { AssertJobAd(integratorUser, JobAdStatus.Open, expectedJobAd, jobAds); } }
public JobAdPosterTask(IChannelManager <ISyndicate> channelManager, IHrCareersQuery hrCareersQuery, ILocationQuery locationQuery, IExecuteJobAdSearchCommand jobAdSearch, IIntegrationQuery integrationQuery, IJobAdIntegrationReportsCommand jobAdIntegrationReportsCommand, IWebSiteQuery webSiteQuery, IJobAdsQuery jobAdsQuery) : base(Logger) { _serviceManager = channelManager; _jobAdsQuery = jobAdsQuery; _integrationQuery = integrationQuery; _jobAdIntegrationReportsCommand = jobAdIntegrationReportsCommand; _integratorUser = hrCareersQuery.GetIntegratorUser(); _searcher = new HrJobAdSearcher(jobAdSearch); _mapper = new JobAdMapper(locationQuery, webSiteQuery); }
public async Task <IdentityResult> InsertUserAsync(IntegratorUser NewUser, string password) { IdentityResult CreatedSuccessfully; using (var serviceScope = _serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var _userManager = serviceScope.ServiceProvider.GetService <UserManager <IntegratorUser> >(); var success = await _userManager.CreateAsync(NewUser, password); CreatedSuccessfully = success; } return(CreatedSuccessfully);// _userManager.Create(NewUser, password); ; }
public ActionResult CloseJobAds() { const string method = "CloseJobAds"; IntegratorUser user = null; try { // Authenticate. user = _serviceAuthenticationManager.AuthenticateRequest(HttpContext, IntegratorPermissions.PostJobAds); // Load the request. var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(GetRequestXml()); var xmlNsMgr = new XmlNamespaceManager(xmlDoc.NameTable); xmlNsMgr.AddNamespace(XmlNamespacePrefix, XmlNamespace); var xmlNode = xmlDoc.SelectSingleNode("/" + XmlNamespacePrefix + ":CloseJobAdsRequest", xmlNsMgr); // Extract values. var jobPoster = GetJobPoster(xmlNode, xmlNsMgr); var externalReferenceIds = GetExternalReferenceIds(xmlNode, xmlNsMgr); // Close. var report = _jobAdPostsManager.CloseJobAds(user.Id, jobPoster, externalReferenceIds); // Record it, including read failures. _jobAdIntegrationReportsCommand.CreateJobAdIntegrationEvent(new JobAdImportCloseEvent { IntegratorUserId = user.Id, Success = true, JobAds = externalReferenceIds.Count, Closed = report.Closed, Failed = report.Failed }); return(Xml(new CloseJobAdsResponse(GetResponseXml(report), report.Errors.ToArray()))); } catch (Exception ex) { EventSource.Raise(ex.Message.EndsWith("disabled.") ? (Event)Event.NonCriticalError : Event.Error, method, "Cannot process the request.", ex, new StandardErrorHandler()); if (user != null) { _jobAdIntegrationReportsCommand.CreateJobAdIntegrationEvent(new JobAdImportCloseEvent { IntegratorUserId = user.Id, Success = false }); } return(Xml(new CloseJobAdsResponse(ex))); } }
protected void PostJobAdsFailure(IntegratorUser integratorUser, Employer jobPoster, bool closeAllOtherAds, IEnumerable <JobAdElement> jobAds, params string[] errorSubStrings) { // Create request. var requestXml = CreatePostRequestXml(jobPoster, closeAllOtherAds, jobAds); // Invoke. var responseXml = Post(_jobAdsUrl, integratorUser, Password, requestXml); // Assert. AssertFailure(responseXml, "PostJobAdsResponse", errorSubStrings); }
private static readonly Encoding Encoding = Encoding.GetEncoding(28591); // Latin-1 protected static string Get(ReadOnlyUrl url, IntegratorUser user, string password, bool useHeaders) { if (!useHeaders) { var newUrl = url.AsNonReadOnly(); newUrl.QueryString["LinkMeUsername"] = user.LoginId; newUrl.QueryString["LinkMePassword"] = password; url = newUrl; } var request = (HttpWebRequest)WebRequest.Create(url.AbsoluteUri); request.Method = "GET"; request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0)"; request.ContentLength = 0; request.Expect = ""; request.Timeout = Debugger.IsAttached ? -1 : 300000; if (useHeaders) { request.Headers.Add("X-LinkMeUsername", user.LoginId); request.Headers.Add("X-LinkMePassword", password); } try { using (var response = (HttpWebResponse)request.GetResponse()) { var encoding = string.IsNullOrEmpty(response.ContentEncoding) ? Encoding : Encoding.GetEncoding(response.ContentEncoding); using (var reader = new StreamReader(response.GetResponseStream(), encoding)) { return(reader.ReadToEnd()); } } } catch (WebException e) { if (e.Response == null) { throw; } if (((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.NotFound) { throw new NotFoundException(e.Response.ResponseUri); } throw; } }
private Employer CreateEmployer(IntegratorUser integratorUser) { // Create an employer with the same user name as the integrator. var employer = _employerAccountsCommand.CreateTestEmployer(integratorUser.LoginId, _organisationsCommand.CreateTestOrganisation(0)); _allocationsCommand.CreateAllocation(new Allocation { CreditId = _creditsQuery.GetCredit <JobAdCredit>().Id, InitialQuantity = null, OwnerId = employer.Id }); _allocationsCommand.CreateAllocation(new Allocation { CreditId = _creditsQuery.GetCredit <ApplicantCredit>().Id, InitialQuantity = null, OwnerId = employer.Id }); return(employer); }
protected void CloseJobAds(IntegratorUser integratorUser, Employer jobPoster, IEnumerable <JobAdElement> jobAds, int closed, int failed, params string[] errorSubStrings) { // Create request. var requestXml = CreateCloseRequestXml(jobPoster.GetLoginId(), jobAds); // Invoke. var responseXml = Post(_closeUrl, integratorUser, Password, requestXml); // Assert. AssertResponse(responseXml, "CloseJobAdsResponse", -1, -1, closed, failed, errorSubStrings); }
public static IntegratorUser CreateTestIntegratorUser(this IIntegrationCommand integrationCommand, string loginId, string password, IntegratorPermissions permissions) { var system = new Ats { Name = loginId + " Integration System" }; integrationCommand.CreateIntegrationSystem(system); var user = new IntegratorUser { LoginId = loginId, PasswordHash = HashToString(password), Permissions = permissions, IntegrationSystemId = system.Id }; integrationCommand.CreateIntegratorUser(user); return(user); }
string IJobAdApplicationsManager.SetApplicationStatuses(IntegratorUser integratorUser, string requestXml, List <string> errors) { var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(requestXml); var xmlNsMgr = new XmlNamespaceManager(xmlDoc.NameTable); xmlNsMgr.AddNamespace(XmlNamespacePrefix, XmlNamespace); var xmlNode = xmlDoc.SelectSingleNode("/" + XmlNamespacePrefix + ":SetJobApplicationStatusRequest", xmlNsMgr); var applicationIds = GetApplicationIds(xmlNode, xmlNsMgr, errors); // Set them. return(SetApplicationStatuses(integratorUser, applicationIds, errors)); }
public ActionResult JobAds(string industries, string modifiedSince, string modifiedInLastDays) { const string method = "JobAds"; IntegratorUser user = null; try { // Authenticate. user = _serviceAuthenticationManager.AuthenticateRequest(HttpContext, IntegratorPermissions.GetJobAds); // Attempt to get saved searches for this integrator user. In this context saved searches act as the basis for the feed var searches = _jobAdSearchesQuery.GetJobAdSearches(user.Id); // Process. var industryIds = GetIndustryIds(industries); var modifiedDate = GetModifiedSince(modifiedSince, modifiedInLastDays); var jobAds = (searches != null && searches.Count > 0) ? _jobAdFeedsManager.GetJobAdFeed(from s in searches select s.Criteria, industryIds, modifiedDate) : _jobAdFeedsManager.GetJobAdFeed(industryIds, modifiedDate); // Record it. _jobAdIntegrationReportsCommand.CreateJobAdIntegrationEvent(new JobAdExportFeedEvent { IntegratorUserId = user.Id, Success = true, JobAds = jobAds.Count }); return(Xml(new JobAdsResponse(GetResponseXml(jobAds)))); } catch (Exception ex) { EventSource.Raise(Event.Error, method, "Cannot process the request.", ex, new StandardErrorHandler()); if (user != null) { _jobAdIntegrationReportsCommand.CreateJobAdIntegrationEvent(new JobAdExportFeedEvent { IntegratorUserId = user.Id, Success = false, JobAds = 0 }); } return(Xml(new JobAdsResponse(ex))); } }
private async Task LoadSharedKeyAndQrCodeUriAsync(IntegratorUser user) { // Load the authenticator key & QR code URI to display on the form var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user); if (string.IsNullOrEmpty(unformattedKey)) { await _userManager.ResetAuthenticatorKeyAsync(user); unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user); } SharedKey = FormatKey(unformattedKey); var email = await _userManager.GetEmailAsync(user); AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey); }
protected override void SetUp() { base.SetUp(); ClearSearchIndexes(); _integratorUser = _integrationCommand.CreateTestIntegratorUser(); const string testUserId = "employer"; _employer = _employersCommand.CreateTestEmployer(testUserId, _organisationsCommand.CreateTestOrganisation(0)); _jobAd = _employer.CreateTestJobAd(); _jobAd.JobDescription.Summary = "Summary"; _jobAd.Status = JobAdStatus.Open; _jobAd.JobDescription.Industries.Clear(); _jobAd.JobDescription.Industries.Add(Container.Current.Resolve <IIndustriesCommand>().GetIndustries()[0]); _jobAdsCommand.PostJobAd(_jobAd); }