/// <summary> /// Generates the output file. /// </summary> /// <param name="data">The processing data.</param> /// <returns></returns> private string GenerateOutputFile(ProcessingModel data) { var progressReporter = new Progress <int>(); progressReporter.ProgressChanged += (sender, percent) => { data.Percent = percent; this.StoreGenerationProgress(data); }; var serializer = this.Encoder; var imageManipulator = new ImageManipulator(this.Environment); var excelManipulator = new ExcelManipulator(serializer, imageManipulator, progressReporter); var sourceFilePath = HomeController.GetTempInputFilePath(data.RequestId); var templateFilePath = Path.Combine(this.Environment.WebRootPath, "platobne_predpisy.xltx"); var outputFilePath = HomeController.GetTempOutputFilePath(data.RequestId); // another request tries to download the same file? if (System.IO.File.Exists(outputFilePath)) { // wait for the other thread to complete while (true) { try { using (System.IO.File.OpenWrite(outputFilePath)) { break; } } catch { // wait a while Thread.Sleep(5000); } } return(outputFilePath); } // read source data (string paymentPurpose, var bySquareDocuments) = excelManipulator.ReadPaymentList(sourceFilePath); // create the output return(excelManipulator.CreateOutputFile(templateFilePath, outputFilePath, paymentPurpose, bySquareDocuments)); }
public IActionResult SampleFile() { var serializer = new BySquareXmlSerializer(); var encoder = new BySquareInternalEncoder(); var imageManipulator = new ImageManipulator(this.Environment); var excelManipulator = new ExcelManipulator(encoder, imageManipulator, null); var filePath = Path.Combine(this.Environment.ContentRootPath, "Samples", "platobny_harok.xlsx"); (_, var bySquareDocuments) = excelManipulator.ReadPaymentList(filePath); // alter date to current date bySquareDocuments[0].Payments[0].PaymentDueDate = DateTime.Today.AddDays(1); ViewData["XML"] = serializer.SerializeAsXml(bySquareDocuments[0]); // generate QR code var qrstring = this.Encoder.Encode(bySquareDocuments[0]); var image = imageManipulator.CreateQrCodeWithLogo(qrstring); ViewData["IMAGE"] = imageManipulator.EncodeImageAsBase64String(image); return(View("Sample")); }