/// <summary> /// Used to to instantiate and return the chain of stream based filters. /// </summary> /// <param name="physicalTextReader">The <see cref="PhysicalTextReader" /> that is the source of input to the filter chain.</param> /// <remarks> /// The <paramref name="physicalTextReader" /> is the first <see cref="Filter" /> /// in the chain, which is based on a physical stream that feeds the chain. /// </remarks> /// <returns> /// The last <see cref="Filter" /> in the chain. /// </returns> internal Filter GetBaseFilter(PhysicalTextReader physicalTextReader) { // if there is no a PhysicalTextReader then the chain is empty if (physicalTextReader == null) { return(null); } // the physicalTextReader must be the base filter (Based on a physical stream) if (!physicalTextReader.Base) { throw new BuildException(ResourceUtils.GetString("String_UseBaseFilter"), Location); } // build the chain and place the base filter at the beginning. Filter parentFilter = physicalTextReader; // iterate through the collection of filter elements and instantiate each filter. foreach (Filter filter in Filters) { if (filter.IfDefined && !filter.UnlessDefined) { filter.Chain(parentFilter); filter.InitializeFilter(); parentFilter = filter; } } return(parentFilter); }
private void WriteWithFilters() { StreamReader FileReader = null; StreamWriter Writer = null; StringReader Reader = null; PhysicalTextReader ChainedReader = null; try { FileReader = this.File.OpenText(); Reader = new StringReader(FileReader.ReadToEnd()); FileReader.Close(); FileReader = null; Writer = this.File.CreateText(); ChainedReader = new PhysicalTextReader(Reader); Filter FilterReader = this.Filter.GetBaseFilter(ChainedReader); while (!false) { int Focus = FilterReader.Read(); if (!(Focus > -1)) { break; // TODO: might not be correct. Was : Exit Do } Writer.Write((Char)Focus); } } finally { if (FileReader != null) { FileReader.Close(); } if (Writer != null) { Writer.Close(); } if (ChainedReader != null) { ChainedReader.Close(); } if (Reader != null) { Reader.Close(); } } }
private void WriteWithFilters() { TextWriter Writer = null; StringReader Reader = null; PhysicalTextReader ChainedReader = null; try { Writer = this.GetWriter(); Reader = new StringReader(this.Text.Value); ChainedReader = new PhysicalTextReader(Reader); Filter FilterReader = this.Filter.GetBaseFilter(ChainedReader); while (!false) { int Focus = FilterReader.Read(); if (!(Focus > -1)) { break; // TODO: might not be correct. Was : Exit Do } Writer.Write((Char)Focus); } this.Properties[this.OutProperty] = Writer.ToString(); } finally { if (Writer != null) { Writer.Close(); } if (ChainedReader != null) { ChainedReader.Close(); } if (Reader != null) { Reader.Close(); } } }
/// <summary> /// Used to to instantiate and return the chain of stream based filters. /// </summary> /// <param name="physicalTextReader">The <see cref="PhysicalTextReader" /> that is the source of input to the filter chain.</param> /// <remarks> /// The <paramref name="physicalTextReader" /> is the first <see cref="Filter" /> /// in the chain, which is based on a physical stream that feeds the chain. /// </remarks> /// <returns> /// The last <see cref="Filter" /> in the chain. /// </returns> internal Filter GetBaseFilter(PhysicalTextReader physicalTextReader) { // if there is no a PhysicalTextReader then the chain is empty if (physicalTextReader == null) { return null; } // the physicalTextReader must be the base filter (Based on a physical stream) if (!physicalTextReader.Base) { throw new BuildException(ResourceUtils.GetString("String_UseBaseFilter"), Location); } // build the chain and place the base filter at the beginning. Filter parentFilter = physicalTextReader; // iterate through the collection of filter elements and instantiate each filter. foreach (Filter filter in Filters) { if (filter.IfDefined && !filter.UnlessDefined) { filter.Chain(parentFilter); filter.InitializeFilter(); parentFilter = filter; } } return parentFilter; }