/// <summary> /// Executes the processor on the specified configuration. /// </summary> public override async Task ExecuteAsync(IAssetContext context) { var env = (IHostingEnvironment)context.HttpContext.RequestServices.GetService(typeof(IHostingEnvironment)); var fileProvider = context.Asset.GetFileProvider(env); var content = new Dictionary <string, byte[]>(); if (!EnsureNodeFiles("WebOptimizer.TypeScript.node_files.zip")) { return; } string module = Path.Combine(InstallDirectory, "typescript.js"); foreach (string route in context.Content.Keys) { var file = fileProvider.GetFileInfo(route); var input = context.Content[route].AsString(); var result = await NodeServices.InvokeAsync <string>(module, input, file.PhysicalPath); content[route] = result.AsByteArray(); } context.Content = content; }
private async Task <DM.Citation> CreateCitationAsync(DE.Style style, DE.Format format, DM.ContentItem contentItem) { ExpandoObject request = new ExpandoObject(); List <PM.ContentItem> requestList = new List <PM.ContentItem>(); requestList.Add(PF.CiteProcFactory.Build("0", contentItem)); requestList = _overrideManager.PreProcessCitation(style, requestList); requestList.ForEach(x => request.TryAdd(x.ID, x)); using (StringAsTempFile file = new StringAsTempFile(GetContents(), CancellationToken.None)) { string result = await NodeServices.InvokeAsync <string>(file.FileName, GetLibrary(), PL.Locale.GetLocale(), PD.Definition.GetDefinition(style), PF.CiteProcFactory.Build(format), JObject.Parse(request.ToSerializedJSON())); PM.Citation citation = JsonConvert.DeserializeObject <PM.Citation>(result); citation.ProcessExceptions(); citation = _overrideManager.PostProcessCitation(style, citation); DM.Citation response = PF.CiteProcFactory.Build(citation); return(response); } }
private async Task <DM.Bibliography> CreateBibliographyAsync(DE.Style style, DE.Format format, List <DM.ContentItem> contentItems) { ExpandoObject request = new ExpandoObject(); List <PM.ContentItem> requestList = new List <PM.ContentItem>(); requestList.AddRange(contentItems.Select((x, i) => PF.CiteProcFactory.Build(i.ToString(), x))); requestList = _overrideManager.PreProcessBibliography(style, requestList); requestList.ForEach(x => request.TryAdd(x.ID, x)); using (StringAsTempFile file = new StringAsTempFile(GetContents(), CancellationToken.None)) { string result = await NodeServices.InvokeAsync <string>(file.FileName, GetLibrary(), PL.Locale.GetLocale(), PD.Definition.GetDefinition(style), PF.CiteProcFactory.Build(format), JObject.Parse(request.ToSerializedJSON())); PM.Bibliography bibliography = JsonConvert.DeserializeObject <PM.Bibliography>(result); bibliography.ProcessExceptions(); bibliography = _overrideManager.PostProcessBibliography(style, bibliography); DM.Bibliography response = PF.CiteProcFactory.Build(bibliography); return(response); } }