/// <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)); }
private ActionResult ProcessingPrivate(ProcessingModel model) { if (model == null) { throw new System.ArgumentNullException("model"); } if (model.claimId == 0) { throw new System.ArgumentException("claimid"); } PaymentMode paymentMode = ( from m in BookingProvider.GetPaymentModes(UrlLanguage.CurrentLanguage, model.claimId) where m.id == model.paymentId select m).FirstOrDefault <PaymentMode>(); if (paymentMode == null) { throw new System.Exception(string.Format("payment mode id '{0}' not found", model.paymentId)); } string text = (paymentMode.processing ?? "").ToLowerInvariant(); if (text != null) { switch (text) { case "paypal": return(this.Processing_PayPal(model.claimId, paymentMode)); case "uniteller": return(this.Processing_Uniteller(model.claimId, paymentMode)); case "payu": return(this.Processing_PayU(model.claimId, paymentMode)); case "cash": return(new RedirectResult(base.Url.Action("howtopay", "info"))); default: break; } } throw new System.Exception(string.Format("unsupported processing system '{0}'", paymentMode.processing)); }
public ActionResult GetProccesing(int sourceMaterialId, int subgroupId, int sourceId) { string sessionId = System.Web.HttpContext.Current.Session["TotalMateriaSession"].ToString(); ProcessingModel model = new ProcessingModel(); if (sourceId == 2) { IService service = new TotalMateriaService(); model.HeatTreatment = service.GetHeatTreatmentFromService(sessionId, sourceMaterialId, subgroupId); model.Metallography = service.GetMetallographyPropertiesFromService(sessionId, sourceMaterialId, subgroupId); model.Machinability = service.GetMachinabilityPropertiesFromService(sessionId, sourceMaterialId); } if (sourceId == 3) { TMPlusService plusService = new TMPlusService(); model.Manufacturing = _materialDetailsBinder.GetManufacturing(sessionId, sourceMaterialId, subgroupId, materialContextUow, plusService); } return(Json(ResponseStatus.Success, RenderPartialViewToString("Processing", model), JsonRequestBehavior.AllowGet)); }
public IActionResult UploadFile(IFormFile inputFile) { var data = new ProcessingModel { RequestId = Guid.NewGuid().ToString("D") }; // copy the input file to temp var filePath = HomeController.GetTempInputFilePath(data.RequestId); using (var file = System.IO.File.OpenWrite(filePath)) { inputFile.OpenReadStream().CopyTo(file); } // stores the progress this.StoreGenerationProgress(data); // redirects to file processing return(RedirectToAction(nameof(ProcessFile), new { id = data.RequestId })); }
protected static void AddModelToCache(string key, ProcessingModel model) { MemoryCache.Default.Add(key, model, DateTimeOffset.Now.AddDays(1)); }
public static void SubmitModel(ProcessingModel model) { AddModelToCache(model.ProcessingKey, model); }
/// <summary> /// Stores the download progress. /// </summary> /// <param name="data">The data.</param> public void StoreGenerationProgress(ProcessingModel data) { this.HttpContext?.Session?.SetString(data.RequestId, JsonConvert.SerializeObject(data)); this.HttpContext?.Session?.CommitAsync().Wait(); }