Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinrayenglish/53bd0e7d43fcbc7f23ce6c64662516aa to your computer and use it in GitHub Desktop.
Save martinrayenglish/53bd0e7d43fcbc7f23ce6c64662516aa to your computer and use it in GitHub Desktop.
public override void Flush()
{
var numArray = _internalStream.ToArray();
if (numArray.Length == 0)
{
return;
}
if (HttpContext.Current?.Server.GetLastError() != null)
{
const string msg = Constants.NonEditingHtml.ExceptionMessage;
Log.SingleWarn(msg, this);
TransmitData(numArray);
}
else
{
var html = Encoding?.GetString(numArray) ?? string.Empty;
var doc = new HtmlDocument();
doc.LoadHtml(html);
var nodes = new Queue<HtmlNode>(doc.DocumentNode.Descendants().Where(n => n.Attributes.Contains(Constants.NonEditingHtmlElementAttribute.DataExpOff)));
while (nodes.Count > 0)
{
var node = nodes.Dequeue();
var parentNode = node.ParentNode;
parentNode.RemoveChild(node);
}
var bytes = Encoding?.GetBytes(doc.DocumentNode.InnerHtml);
if (bytes != null)
{
TransmitData(bytes);
}
else
{
throw new InvalidOperationException();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment