private static void Train_ErrorCreatingBuild(Assert assert) { var httpClient = new MockHttpClient(); var engineDto = new EngineDto { Id = "engine1" }; httpClient.Requests.Add(new MockRequest { Method = HttpRequestMethod.Get, Url = "translation/engines/project:project1", ResponseText = JsonConvert.SerializeObject(engineDto, RestClientBase.SerializerSettings) }); httpClient.Requests.Add(new MockRequest { Method = HttpRequestMethod.Post, Url = "translation/builds", ErrorStatus = 500 }); var engine = new TranslationEngine("http://localhost/", "project1", httpClient); Action done = assert.Async(); engine.Train( progress => {}, success => { assert.Equal(success, false); done(); }); }
public async Task ListenForTrainingStatusAsync(string projectId, Action <ProgressStatus> progress, CancellationToken ct = default(CancellationToken)) { EngineDto engineDto = await GetEngineAsync(projectId); await PollBuildProgressAsync("engine", engineDto.Id, 0, progress, ct); }
public async Task TrainAsync(string projectId, Action <ProgressData> progress, CancellationToken ct) { EngineDto engineDto = await GetEngineAsync(projectId); BuildDto buildDto = await CreateBuildAsync(engineDto.Id); progress(CreateProgressData(buildDto)); await PollBuildProgressAsync(engineDto.Id, buildDto.Revision + 1, progress, ct); }
private static void ListenForTrainingStatus_NoErrors(Assert assert) { var httpClient = new MockHttpClient(); var engineDto = new EngineDto { Id = "engine1" }; httpClient.Requests.Add(new MockRequest { Method = HttpRequestMethod.Get, Url = "translation/engines/project:project1", ResponseText = JsonConvert.SerializeObject(engineDto, RestClientBase.SerializerSettings) }); var buildDto = new BuildDto { Id = "build1", StepCount = 10 }; httpClient.Requests.Add(new MockRequest { Method = HttpRequestMethod.Get, Url = "translation/builds/engine:engine1?minRevision=0", Action = (body, ct) => Delay(10, ct), ResponseText = JsonConvert.SerializeObject(buildDto, RestClientBase.SerializerSettings) }); for (int i = 0; i < 10; i++) { buildDto.CurrentStep++; buildDto.Revision++; httpClient.Requests.Add(new MockRequest { Method = HttpRequestMethod.Get, Url = string.Format("translation/builds/engine:engine1?minRevision={0}", buildDto.Revision), Action = (body, ct) => Delay(10, ct), ResponseText = JsonConvert.SerializeObject(buildDto, RestClientBase.SerializerSettings) }); } var engine = new TranslationEngine("http://localhost/", "project1", httpClient); Action done = assert.Async(); int expectedStep = -1; engine.ListenForTrainingStatus( progress => { expectedStep++; assert.Equal(progress.CurrentStep, expectedStep); }, success => { assert.Equal(expectedStep, 10); assert.Equal(success, true); done(); }); }
public static Engine FromDtoToDomainObject(EngineDto source) { Engine target = new Engine(); target.DisplayName = source.DisplayName; target.Family = EngineFamilyAssembler.FromDtoToObject(source.Family); target.FuelType = (FuelType)source.FuelType; target.InjectionType = (InjectionType)source.InjectionType; target.Type = (EngineType)source.Type; return(target); }
public static EngineDto FromObjectToDto(Engine source) { EngineDto target = new EngineDto(); target.DisplayName = source.DisplayName; target.Family = EngineFamilyAssembler.FromObjectToDto(source.Family); target.FuelType = (int)source.FuelType; target.InjectionType = (int)source.InjectionType; target.Type = (int)source.Type; return(target); }
public void Execute(EngineDto request) { var engine = Context.Engines.Find(request.Id); if (Context.Engines.Any(e => e.Name.ToLower() == request.Name.ToLower())) { throw new EntityAlreadyExistsException("Engine"); } engine.Name = request.Name; engine.CC = request.CC; Context.SaveChanges(); }
public ActionResult Post([FromBody] EngineDto dto) { try { _add.Execute(dto); return(StatusCode(201)); } catch (EntityAlreadyExistsException e) { return(Conflict(e)); } catch (Exception e) { Console.WriteLine(e.Message); return(StatusCode(500)); } }
public ActionResult Put([FromBody] EngineDto dto) { try { _edit.Execute(dto); return(StatusCode(204)); } catch (EntityNotFoundException e) { return(NotFound(e.Message)); } catch (EntityAlreadyExistsException e) { return(Conflict(e)); } catch (Exception e) { Console.WriteLine(e.Message); return(Conflict(e.Message)); } }
private static void ListenForTrainingStatus_Close(Assert assert) { var httpClient = new MockHttpClient(); var engineDto = new EngineDto { Id = "engine1" }; httpClient.Requests.Add(new MockRequest { Method = HttpRequestMethod.Get, Url = "translation/engines/project:project1", ResponseText = JsonConvert.SerializeObject(engineDto, RestClientBase.SerializerSettings) }); var buildDto = new BuildDto { Id = "build1", StepCount = 10 }; httpClient.Requests.Add(new MockRequest { Method = HttpRequestMethod.Get, Url = "translation/builds/engine:engine1?minRevision=0", Action = (body, ct) => Delay(1000, ct), ResponseText = JsonConvert.SerializeObject(buildDto, RestClientBase.SerializerSettings) }); var engine = new TranslationEngine("http://localhost/", "project1", httpClient); Action done = assert.Async(); engine.ListenForTrainingStatus( progress => { }, success => { assert.Equal(success, false); done(); }); engine.Close(); }
public async Task StartTrainingAsync(string projectId) { EngineDto engineDto = await GetEngineAsync(projectId); await CreateBuildAsync(engineDto.Id); }
public IEngine convert(EngineDto engineDto) { throw new System.NotImplementedException(); }