public ActionResult DownloadNotaDebito(int country, int office, DateTime date, int invoice) { Guid id = CommTools.ToGuid(country, office, date.ToInt(), invoice); ObjectFileCache cache = new ObjectFileCache(Config.FILECACHEFOLDER); var buffer = cache.Get("pdf_" + id, () => ScanServiceAccess.Instance.DownloadNotaDebitoReport(country, office, date, invoice)); string fileName = string.Format("{0}_{1}_{2:dd-MM-yyyy}_{3}.pdf", country, office, date, invoice); return(base.File(buffer, "application/pdf", fileName)); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AuthConfig.RegisterAuth(); BarcodeDecoder.Run(); ObjectFileCache cache = new ObjectFileCache(Config.FILECACHEFOLDER); cache.Reset(); }
public ActionResult ShowDetails(int country, int office, DateTime date, int invoice) { Guid id = CommTools.ToGuid(country, office, date.ToInt(), invoice); ObjectFileCache cache = new ObjectFileCache(Config.FILECACHEFOLDER); string bodyFileName = string.Concat("body_", id); string styleFileName = string.Concat("style_", id); string body = cache.Get(bodyFileName, () => { var buffer1 = ScanServiceAccess.Instance.DownloadNotaDebitoReport(country, office, date, invoice, "XML"); string xml = Encoding.UTF8.GetString(buffer1); var buffer2 = ScanServiceAccess.Instance.DownloadNotaDebitoReport(country, office, date, invoice, "HTML4.0", "&rc:Toolbar=False&rc:Section=0"); var html = Encoding.UTF8.GetString(buffer2); string bodyTag = html.GetTags("body").FirstOrDefault(); if (bodyTag == null) { throw new ArgumentException("Body tag empty"); } var builder = new StringBuilder(bodyTag); foreach (string v_number in xml.Search("inv_v_number2\\s*=\\s*\"(?<value>[0-9]+)\"", (Match m) => m.Groups["value"].Value)) { builder.Replace(v_number, string.Concat("<a href=", Config.SITEROOT, "/Voucher/ShowBy?iso_id=", country, "&v_number=", v_number, " >", v_number, "</a>")); } bodyTag = builder.ToString(); bodyTag = bodyTag.ReplaceTags("img", new MatchEvaluator(ImgMatchEvaluator)); var styleTag = html.GetTags("style").FirstOrDefault(); cache.Set(styleFileName, styleTag); return(bodyTag); }); string style = cache.Get(styleFileName, () => string.Empty); return(View(new string[] { body, style })); }