private void OnItemGenerationStatus(ItemGenerationStatusEventArgs e) { if (ItemGenerationStatus != null) { ItemGenerationStatus(this, e); } }
private void Generator_ItemGenerationStatus(Generator generator, ItemGenerationStatusEventArgs e) { this.Invoke(new GenericDelegate<ItemGenerationStatusEventArgs>(x => { ListViewItem item = outputsListView.CheckedItems.Cast<ListViewItem>().Single(o => o.Tag == x.Result); if (x.Status == GenerationStatus.Complete) progressBar.Value++; UpdateListViewItemStatus(item, x.Status, x.Error); }), e); }
/// <summary>Processes a single template to one or more output files using the provided project XML.</summary> private Task GenerateOutputAsync(string projectXml, Template template, XslCompiledTransform compiledTransform, TemplateOutputDefinitionFilenameResult output) { // Report status and do sanity checks upfront. OnItemGenerationStatus(ItemGenerationStatusEventArgs.CreateGenerating(template, output)); if (File.Exists(output.Value)) { try { File.Delete(output.Value); } catch (Exception ex) { Generator.Logger.Error(ex); OnItemGenerationStatus(ItemGenerationStatusEventArgs.CreateError(template, output, new ApplicationException("Unable to delete existing file.", ex))); return(Task.CompletedTask); } } try { Directory.CreateDirectory(Path.GetDirectoryName(output.Value)); } catch (Exception ex) { Generator.Logger.Error(ex); OnItemGenerationStatus(ItemGenerationStatusEventArgs.CreateError(template, output, new ApplicationException("Unable to create output directory.", ex))); return(Task.CompletedTask); } // Perform the actual processing async. return(Task.Run(() => { try { using (StringReader stringReader = new StringReader(projectXml)) { XmlReaderSettings xmlReaderSettings = new XmlReaderSettings() { DtdProcessing = DtdProcessing.Parse }; using (XmlReader xmlReader = XmlReader.Create(stringReader, xmlReaderSettings)) { XsltArgumentList arguments = new XsltArgumentList(); arguments.AddParam(Template.Param_Name, string.Empty, template.Name); if (!output.ElementName.IsNullOrEmpty()) { arguments.AddParam(TemplateOutputDefinitionFilenameResult.Param_ElementName, string.Empty, output.ElementName); } using (FileStream outputStream = File.Create(output.Value)) using (XmlWriter xmlWriter = XmlWriter.Create(outputStream, compiledTransform.OutputSettings)) { compiledTransform.Transform(xmlReader, arguments, xmlWriter); } } } PerformPostProcessing(output.Value); } catch (Exception ex) { Generator.Logger.Error(ex); OnItemGenerationStatus(ItemGenerationStatusEventArgs.CreateError(template, output, new ApplicationException("Unable to generate the output. Error writing to the specified path or the template or input XML is not valid.", ex))); return; } OnItemGenerationStatus(ItemGenerationStatusEventArgs.CreateComplete(template, output)); })); }
private void OnItemGenerationStatus(ItemGenerationStatusEventArgs e) { if (ItemGenerationStatus != null) ItemGenerationStatus(this, e); }