public PdfProgressItem(IHttpContextAccessor httpContextAccessor, PdfCreator pdfCreator, SecurityContext securityContext, TenantManager tenantManager) { _contextUrl = httpContextAccessor.HttpContext != null?httpContextAccessor.HttpContext.Request.GetUrlRewriter().ToString() : null; _pdfCreator = pdfCreator; _securityContext = securityContext; _tenantManager = tenantManager; Error = null; Percentage = 0; IsCompleted = false; }
private void UpdateInvoiceFileID(object parameters) { var obj = (NewThreadParams)parameters; var tenant = CoreContext.TenantManager.GetTenant(obj.TenantId); CoreContext.TenantManager.SetCurrentTenant(tenant); SecurityContext.AuthenticateMe(obj.CurrentUser); HttpContext.Current = obj.Ctx; log4net.LogManager.GetLogger("ASC.CRM").DebugFormat("Thread for updating file for Invoice with ID = {0} is working...", obj.InvoiceId); PdfCreator.CreateAndSaveFile(obj.InvoiceId); }
public static ASC.Files.Core.File GetInvoicePdfExistingOrCreate(ASC.CRM.Core.Entities.Invoice invoice) { var existingFile = invoice.GetInvoiceFile(); if (existingFile != null) { return(existingFile); } else { var newFile = PdfCreator.CreateFile(invoice); invoice.FileID = Int32.Parse(newFile.ID.ToString()); Global.DaoFactory.GetInvoiceDao().UpdateInvoiceFileID(invoice.ID, invoice.FileID); Global.DaoFactory.GetRelationshipEventDao().AttachFiles(invoice.ContactID, invoice.EntityType, invoice.EntityID, new[] { invoice.FileID }); return(newFile); } }
public void RunJob() { try { Percentage = 0; Status = PdfProgressStatus.Started; CoreContext.TenantManager.SetCurrentTenant(_tenantId); SecurityContext.AuthenticateMe(_userId); if (HttpContext.Current == null && !WorkContext.IsMono) { HttpContext.Current = new HttpContext( new HttpRequest("hack", _contextUrl, string.Empty), new HttpResponse(new System.IO.StringWriter())); } PdfCreator.CreateAndSaveFile(_invoiceId); Percentage = 100; Status = PdfProgressStatus.Done; } catch (Exception ex) { log4net.LogManager.GetLogger("ASC.Web").Error(ex); Percentage = 0; Status = PdfProgressStatus.Failed; Error = ex.Message; } finally { // fake httpcontext break configuration manager for mono if (!WorkContext.IsMono) { if (HttpContext.Current != null) { new DisposableHttpContext(HttpContext.Current).Dispose(); HttpContext.Current = null; } } IsCompleted = true; } }