private void downloadProject() { var getGame = new DownloadProjectRequest(onlineProject.Id, onlineProject.Hash, store); getGame.Success += game => ImportAction?.Invoke(onlineProject); getGame.Progressed += progress => editButton.Progress = progress; api.Queue(getGame); }
public void WhenTokenIsNotExist_CustomApiExceptionOccurs() { DownloadProjectRequest downloadProjectRequest = new DownloadProjectRequest() { Token = Guid.NewGuid().ToString() }; var customApiException = Assert.Throws <CustomApiException>(() => _sut.Download(downloadProjectRequest)); Assert.Equal($"{downloadProjectRequest.Token} not valid", customApiException.FriendlyMessage); }
public void WhenTokenIsValid_ResponseShouldNotBeEmpty() { var generateTest = new GenerateTest(); string token = generateTest.WhenOperationCompleted_FileShoulBeExistWithNameofToken(); var downloadProjectRequest = new DownloadProjectRequest() { Token = token }; FileContentResult fileContentResult = _sut.Download(downloadProjectRequest); Assert.NotNull(fileContentResult); Assert.Equal(token, fileContentResult.FileDownloadName); }
public FileContentResult Download([FromBody] DownloadProjectRequest request) { if (!request.IsValid(out string validationMessage)) { throw new CustomApiException(validationMessage, HttpStatusCode.BadRequest); } SolutionGenerator solutionGenerater = new SolutionGenerator(); byte[] zipBytes = solutionGenerater.Download(request.Token); return(new FileContentResult(zipBytes, CONTENT_TYPE) { FileDownloadName = request.Token }); }
public void DownloadProject(string robotName, string projectName) { var request = new DownloadProjectRequest { TMRobotName = robotName, ProjectName = projectName, }; var reply = client.DownloadProject(request); Console.WriteLine("DownloadProject|" + JsonSerializer.Serialize(reply, new JsonSerializerOptions { WriteIndented = true })); _logger.LogInformation("DownloadProject|" + JsonSerializer.Serialize(reply, new JsonSerializerOptions { WriteIndented = true })); }
public void WhenRequestIsInvalid_CustomApiExceptionOccurs(DownloadProjectRequest downloadProjectRequest) { var customApiException = Assert.Throws <CustomApiException>(() => _sut.Download(downloadProjectRequest)); Assert.Equal(HttpStatusCode.BadRequest, customApiException.ReturnHttpStatusCode); }
public TaskCompletionSource <bool> DownloadGame(OnlineGame game) { var completionSource = new TaskCompletionSource <bool>(); var files = store.GetStorageForDirectory("files").GetFiles(""); var getFilenamesForGame = new GetFileListForGameRequest(game.Id); getFilenamesForGame.Success += gameFiles => { var missingFiles = new Queue <string>(gameFiles.Except(files).ToArray()); if (missingFiles.Count == gameFiles.Count) { var getGame = new DownloadProjectRequest(game.Id, game.Hash, store); getGame.Success += g => { completionSource.SetResult(true); importGame(game.Hash); }; getGame.Progressed += _ => { infoOverlay.Show(@"Descargando juego...", Colour4.Turquoise); }; getGame.Failure += _ => failure(); api.Queue(getGame); } else { Task.Run(() => { while (missingFiles.Count > 0) { var getFile = new DownloadSpecificFileRequest(missingFiles.Dequeue(), store); var fileDownloaded = false; getFile.Success += () => { fileDownloaded = true; }; getFile.Progressed += current => { Schedule(() => infoOverlay.Show(@$ "Descargando archivos faltantes (faltan {missingFiles.Count + 1})...", Colour4.Turquoise)); }; getFile.Failure += _ => { missingFiles.Clear(); failure(); }; api.Queue(getFile); while (!fileDownloaded && missingFiles.Count > 0) { } } completionSource.SetResult(true); }); } }; getFilenamesForGame.Failure += _ => failure(); api.Queue(getFilenamesForGame); return(completionSource); void failure() { completionSource.SetResult(false); infoOverlay.Show(@"Error al descargar el juego!", Colour4.DarkRed); } }