public override async Task <Empty> GenerateRandomCodes(GeneratorRequest request, ServerCallContext context) { var bergoglioService = new BergoglioService(); await bergoglioService.GenerateCodes(request.QuantityPerSerie, request.SerialNumberInit, request.SerialNumberFinal); return(new Empty()); }
public BaseResponse GenerateRequest(GeneratorRequest request) { var response = new BaseResponse(); try { var qr = _paymentDataGenerator.GenerateQR(_sensitiveOpts.AccountOwner, _sensitiveOpts.AccountNo, request.Price, request.ServiceDescription); if (request.SendInvoice) { var invoiceData = new InvoiceData(request.Buyer, request.ServiceDescription, request.Price, qr.FullName); var pdf = _invoiceGenerator.GenerateInvoicePdf(invoiceData); string emailBody = "email body"; if (!string.IsNullOrEmpty(_genOpts.EmailBodyHtmlPath) && System.IO.File.Exists(_genOpts.EmailBodyHtmlPath)) { emailBody = System.IO.File.ReadAllText(_genOpts.EmailBodyHtmlPath); } //_emailSender.SendFile(request.BuyerEmail, $"Fakturka za {request.ServiceDescription}", emailBody, pdf, qr); if (_genOpts.CleanupFiles) { System.IO.File.Delete(qr.FullName); System.IO.File.Delete(pdf.FullName); } } } catch (Exception ex) { response.ErrorMessage = ex.Message; } return(response); }
public AddCustomerResponse AddRandomCustomers([FromBody] GeneratorRequest request) { try { if (request.сount < 0) { throw new ArgumentException("Count less than 0."); } string error = null; for (int i = 0; i < request.сount; i++) { try { error = _customerService.AddCustomer(CustomerService.GenerateCustomer()); } catch (Exception ex) { i--; } } return(new AddCustomerResponse { Error = error }); } catch (Exception ex) { return(new AddCustomerResponse { Error = ex.Message }); } }
public async Task <string> Post([FromBody] GeneratorRequest generatorRequest) { var sw = Stopwatch.StartNew(); using var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Generators.GeneratorsClient(channel); await client.GenerateRandomCodesAsync(generatorRequest); return(sw.ElapsedMilliseconds.ToString()); }
public string GeneratePreviewHtmlFromTemplate(GeneratorRequest generatorRequest) { var template = File.ReadAllText("preview-template.html"); template = template.Replace("[FOLDER]", $"{generatorRequest.ImagesFolderName}/"); template = template.Replace("[OVERLAP]", $"{generatorRequest.OverlapPx}"); template = template.Replace("[TILESIZE]", $"{generatorRequest.TileSizePx}"); template = template.Replace("[WIDTH]", $"{generatorRequest.ImageWidth}"); template = template.Replace("[HEIGHT]", $"{generatorRequest.ImageHeight}"); return(template); }
public async Task <IActionResult> Post(GeneratorRequest model) { model.IpAddress = HttpContext.Connection.RemoteIpAddress.ToString(); GeneratorResponse response = await _itemBusiness.GenerateAsync(model); if (response.IsSuccess) { return(Ok(new Uri(Request.Scheme + "://" + Request.Host.Value + Request.PathBase + "/" + response.Segment).ToString())); } return(BadRequest(response.Message)); }
public void GeneratePreviewHtmlFromTemplate_Valid_ReplacesTexts(GeneratorRequest request, PreviewGenerator sut) { // Arrange // Act var output = sut.GeneratePreviewHtmlFromTemplate(request); // Assert Assert.Contains($"{request.ImagesFolderName}/", output); Assert.Contains($"{request.OverlapPx}", output); Assert.Contains($"{request.TileSizePx}", output); Assert.Contains($"{request.ImageWidth}", output); Assert.Contains($"{request.ImageHeight}", output); }
public async Task <GeneratorResponse> GenerateAsync(GeneratorRequest model) { var response = new GeneratorResponse(); try { if (model == null) { response.IsSuccess = false; response.Message = "Empty model"; return(response); } if (string.IsNullOrWhiteSpace(model.OriginUrl)) { response.IsSuccess = false; response.Message = "Empty origin url"; return(response); } Item entity = await _itemQueryHandler.GetByOriginUrlAsync(model.OriginUrl); string segment = entity?.Segment; if (string.IsNullOrWhiteSpace(segment)) { // generate new segment segment = KeyGeneratorExtension.GetUniqueKey(8); await _itemCommandHandler.ExecuteAsync(new CreateItemCommand { IpAddress = model.IpAddress, ExpiredDate = model.ExpiredDate, OriginUrl = model.OriginUrl, Segment = segment }); } response.IsSuccess = true; response.Segment = segment; } catch (Exception exception) { response.IsSuccess = false; response.Message = exception.Message; } return(response); }
public object Get(GeneratorRequest request) { Static.Generate(Paths.Output, Paths.Data, Delete); return(new HttpResult(HttpStatusCode.OK, "Page was generated")); }