public async Task SendEmailUsingBackgroundJobWorkerAndWebApiAndThenPushToReceiver() { IEmailService emailService = A.Fake <IEmailService>(); TaskCompletionSource <bool> emailSent = new TaskCompletionSource <bool>(); A.CallTo(() => emailService.SendEmail(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored)) .Invokes(() => { emailSent.SetResult(true); }); using (BitOwinTestEnvironment testEnvironment = new BitOwinTestEnvironment(new TestEnvironmentArgs { AdditionalDependencies = manager => { manager.RegisterInstance(emailService); } })) { TokenResponse someoneToken = await testEnvironment.Server.Login("SomeOne", "ValidPassword", clientId : "TestResOwner"); TaskCompletionSource <bool> onMessageReceivedCalled = new TaskCompletionSource <bool>(); await testEnvironment.Server.BuildSignalRClient(someoneToken, (messageKey, messageArgs) => { onMessageReceivedCalled.SetResult(true); }); TokenResponse token = await testEnvironment.Server.Login("ValidUserName", "ValidPassword", clientId : "TestResOwner"); ODataClient client = testEnvironment.Server.BuildODataClient(token: token); string jobId = (await client.Controller <TestModelsController, TestModel>() .Action(nameof(TestModelsController.SendEmailUsingBackgroundJobServiceAndPushAfterThat)) .Set(new TestModelsController.EmailParameters { to = "SomeOne", title = "Email title", message = "Email message" }) .ExecuteAsScalarAsync <Guid>()).ToString(); ODataClient bitODataClient = testEnvironment.Server.BuildODataClient(token: token, odataRouteName: "Bit"); JobInfoDto jobInfo = await bitODataClient.Controller <JobsInfoController, JobInfoDto>() .Key(jobId) .FindEntryAsync(); Assert.AreEqual(true, await emailSent.Task); Assert.AreEqual(true, await onMessageReceivedCalled.Task); await Task.Delay(TimeSpan.FromSeconds(1)); jobInfo = await bitODataClient.Controller <JobsInfoController, JobInfoDto>() .Key(jobId) .FindEntryAsync(); Assert.AreEqual("Succeeded", jobInfo.State); } }
public void OnJobAdded(JobInfoDto jobInfo) { lock (_locker) { foreach (var notifier in _notifiers) { Task.Run(() => notifier.OnJobAdded(jobInfo)); } } }
public static TaskOrderAddressInfoResponse ToAddresseInfoResponse(this JobInfoDto jobInfo) { var originAddress = jobInfo.Addresses.FirstOrDefault(a => AddressMatch(a, jobInfo.OriginAddressLabel)); var destinationAddress = jobInfo.Addresses.FirstOrDefault(a => AddressMatch(a, jobInfo.DestinationAddressLabel)); return(new TaskOrderAddressInfoResponse { OriginAddress = Mapper.Map <DutyStationAddressDto>(originAddress), DestinationAddress = Mapper.Map <DutyStationAddressDto>(destinationAddress) }); }
public async Task SendEmailUsingBackgroundJobWorkerAndWebApi() { IEmailService emailService = A.Fake <IEmailService>(); TaskCompletionSource <bool> emailSent = new TaskCompletionSource <bool>(); A.CallTo(() => emailService.SendEmail(A <string> .Ignored, A <string> .Ignored, A <string> .Ignored)) .Invokes(() => { emailSent.SetResult(true); }); using (BitOwinTestEnvironment testEnvironment = new BitOwinTestEnvironment(new TestEnvironmentArgs { AdditionalDependencies = (manager, services) => { manager.RegisterInstance(emailService); } })) { TokenResponse token = await testEnvironment.Server.Login("ValidUserName", "ValidPassword", clientId : "TestResOwner"); IODataClient client = testEnvironment.Server.BuildODataClient(token: token); string jobId = (await client.TestModels() .SendEmailUsingBackgroundJobService("Someone", "Email title", "Email message") .ExecuteAsScalarAsync <Guid>()).ToString(); IODataClient bitODataClient = testEnvironment.Server.BuildODataClient(token: token, odataRouteName: "Bit"); JobInfoDto jobInfo = await bitODataClient.Controller <JobsInfoController, JobInfoDto>() .Key(jobId) .FindEntryAsync(); Assert.AreEqual(true, await emailSent.Task); await Task.Delay(TimeSpan.FromSeconds(1)); jobInfo = await bitODataClient.Controller <JobsInfoController, JobInfoDto>() .Key(jobId) .FindEntryAsync(); Assert.AreEqual("Succeeded", jobInfo.State); } }
public void OnJobAdded(JobInfoDto jobInfo) { //Add event to the database }
internal static JobInfoDto ToJobInfo(Move move) { //var origin = move.OriginShipper; //var destination = move.DestinationShipper; //if (origin == null) //{ // throw new Exception($"origin is null on the moves table. Group_CODE probably doesn't match"); //} //if (destination == null) //{ // throw new Exception($"destination is null on the moves table. Group_CODE probably doesn't match"); //} //var dto = new JobInfoDto //{ // OriginAddressLabel = $"{origin.Street} {origin.City}, {origin.State} {origin.Zip}", // OriginAddressAdditionalInfo = origin.Appartment, // DestinationAddressLabel = $"{destination.Street} {destination.City}, {destination.State} {destination.Zip}", // DestinationAddressAdditionalInfo = destination.Appartment, // Addresses = new List<AddressDto> // { // new AddressDto // { // Type = "Origin", // Address1 = origin.Street, // City = origin.City, // State = origin.State, // PostalCode = origin.Zip, // AdditionalAddressInfo = origin.Appartment, // Country = origin.Country // }, // new AddressDto // { // Type = "Destination", // Address1 = destination.Street, // City = destination.City, // State = destination.State, // PostalCode = destination.Zip, // AdditionalAddressInfo = destination.Appartment, // Country = destination.Country // } // } //}; ////clean origin label //if (string.IsNullOrEmpty(origin.City)) //{ // dto.OriginAddressLabel = $"{origin.State}"; //} ////clean destination label //if (string.IsNullOrEmpty(destination.City)) //{ // dto.DestinationAddressLabel = $"{destination.State}"; //} var originAddress = move.Origin; var destinationAddress = move.Destination; var dto = new JobInfoDto { OriginAddressLabel = $"{originAddress}", DestinationAddressLabel = $"{destinationAddress}", Addresses = new List <AddressDto> { new AddressDto { Type = "Origin", Country = originAddress }, new AddressDto { Type = "Destination", Country = destinationAddress } } }; return(dto); }
/// <summary> /// 添加调度任务 /// </summary> /// <param name="jobName">任务名称</param> /// <param name="jobGroup">任务分组</param> /// <returns></returns> public async Task <ScheduleResult> AddJobAsync(JobInfoDto infoDto) { ScheduleResult result = new ScheduleResult(); try { if (infoDto == null) { result.Code = -3; result.Message = $"参数{typeof(CreateUpdateJobInfoDto)}不能为空"; return(result);//出现异常 } if (infoDto.StarTime == null) { infoDto.StarTime = DateTime.Now; } DateTimeOffset starRunTime = DateBuilder.NextGivenSecondDate(infoDto.StarTime, 1); if (infoDto.EndTime == null) { infoDto.EndTime = DateTime.MaxValue.AddDays(-1); } DateTimeOffset endRunTime = DateBuilder.NextGivenSecondDate(infoDto.EndTime, 1); scheduler = await GetSchedulerAsync(); JobKey jobKey = new JobKey(infoDto.JobName, infoDto.JobGroup); if (await scheduler.CheckExists(jobKey)) { await scheduler.PauseJob(jobKey); await scheduler.DeleteJob(jobKey); } //var jobType =Type.GetType("Czar.AbpDemo.Schedule.LogTestJob,Czar.AbpDemo.Web"); var jobType = Type.GetType(infoDto.JobNamespace + "." + infoDto.JobClassName + "," + infoDto.JobAssemblyName); if (jobType == null) { result.Code = -1; result.Message = "系统找不到对应的任务,请重新设置"; return(result);//出现异常 } IJobDetail job = JobBuilder.Create(jobType) .WithIdentity(jobKey) .Build(); ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create() .StartAt(starRunTime) .EndAt(endRunTime) .UsingJobData("ServerName", scheduler.SchedulerName) .WithIdentity(infoDto.JobName, infoDto.JobGroup) .WithCronSchedule(infoDto.CronExpress) .Build(); await scheduler.ScheduleJob(job, trigger); if (!scheduler.IsStarted) { await scheduler.Start(); } return(result); } catch (Exception ex) { _logger.LogException(ex); result.Code = -4; result.Message = ex.ToString(); return(result);//出现异常 } }
private async Task <IEnumerable <KeyValuePair <string, int> > > SaveAddresses(JobInfoDto jobInfo) { var insertedIds = new List <KeyValuePair <string, int> >(); //We are strictly expecting only 2 address right now. Origin and Destination. _logger.LogInformation("Saving Transferee Address {0}", jobInfo.Addresses); var addresses = _mapper.Map <List <Address> >(jobInfo.Addresses); string addressType = string.Empty; _dbContext.Address.AddRange(addresses); foreach (var address in addresses) { switch (address.Type) { case "Origin": address.AdditionalAddressInfo = jobInfo.OriginAddressAdditionalInfo; address.Display = jobInfo.OriginAddressLabel; break; case "Destination": address.AdditionalAddressInfo = jobInfo.DestinationAddressAdditionalInfo; address.Display = jobInfo.DestinationAddressLabel; break; default: break; } } await _dbContext.SaveChangesAsync(); _logger.LogInformation("Address saved and associated to the job"); return(new[] { new KeyValuePair <string, int>("Origin", addresses.FirstOrDefault(s => s.Type == "Origin").Id), new KeyValuePair <string, int>("Destination", addresses.FirstOrDefault(s => s.Type == "Destination").Id) }); }
public void OnJobAdded(JobInfoDto jobInfo) { Clients.All.SendAsync("addJob", jobInfo); }
public void OnJobAdded(JobInfoDto jobInfo) { //Nothing }
public void OnJobAdded(JobInfoDto jobInfo) { Clients.All.addJob(jobInfo); }