public void GenerateOutput(AbstractOutputFile outputFile) { IOutputWriter outputStream = outputFile.GetOutputStream(); // Process each section in the output foreach (OutputSectionKeys section in outputFile.GetOutputSections()) { OutputSection sectionConfig = OutputSectionsConfig.Sections.First(s => s.key == section); // If the section has a header declaration, do it if (sectionConfig.header != null) { outputStream.WriteLine(sectionConfig.header); outputStream.WriteLine(); } // Get the element providers and compile each element IEnumerable <ICompilableElementProvider> elementProviders = this.collectorFactory.GetCollectorForOutputSection(section) .GetCompilableElements(); OutputGroup currentDataGroup = new OutputGroup("INITIAL"); foreach (ICompilableElementProvider provider in elementProviders) { foreach (ICompilableElement element in provider.GetCompilableElements()) { if ( sectionConfig.printDataGroupings && outputGroups.TryGetForDefinitionFile(element.GetDefinition(), out OutputGroup group) && !group.Equals(currentDataGroup) ) { currentDataGroup = group; outputStream.WriteLine(new Comment(group.HeaderDescription).ToString()); } element.Compile(sectorElements, outputStream); } } // Write a newline at the end of a new section outputStream.WriteLine(); outputStream.Flush(); } // Flush the file to make sure it's written outputStream.Flush(); }
public bool WriteData(object data, string id = null, string @event = null, int?retry = null) { if (_first) { _writer.ContentType(MimeType.EventStream); _first = false; } var builder = new StringBuilder(); if (@event.IsNotEmpty()) { builder.Append(Id); builder.Append(id); builder.Append("/"); builder.Append(@event); builder.Append("\n"); } else { writeProp(builder, Id, id); } writeProp(builder, Retry, retry); writeProp(builder, Data, data); builder.Append("\n"); _writer.Write(builder.ToString()); try { _writer.Flush(); return(true); } // It is possible to receive this exception if the client connection has been lost. catch (HttpException) { return(false); } // Another connectivity issue catch (AccessViolationException) { return(false); } }