The Labs \ Source Viewer \ SSCLI \ System.Xml.Xsl.XsltOld \ MessageAction

  1. //------------------------------------------------------------------------------
  2. // <copyright file="MessageAction.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.Xml.Xsl.XsltOld
  16. {
  17.     using Res = System.Xml.Utils.Res;
  18.     using System;
  19.     using System.IO;
  20.     using System.Globalization;
  21.     using System.Diagnostics;
  22.     using System.Xml;
  23.     using System.Xml.XPath;
  24.    
  25.     internal class MessageAction : ContainerAction
  26.     {
  27.         bool _Terminate;
  28.        
  29.         internal override void Compile(Compiler compiler)
  30.         {
  31.             CompileAttributes(compiler);
  32.            
  33.             if (compiler.Recurse()) {
  34.                 CompileTemplate(compiler);
  35.                 compiler.ToParent();
  36.             }
  37.         }
  38.        
  39.         internal override bool CompileAttribute(Compiler compiler)
  40.         {
  41.             string name = compiler.Input.LocalName;
  42.             string value = compiler.Input.Value;
  43.             if (Keywords.Equals(name, compiler.Atoms.Terminate)) {
  44.                 _Terminate = compiler.GetYesNo(value);
  45.             }
  46.             else {
  47.                 return false;
  48.             }
  49.            
  50.             return true;
  51.         }
  52.        
  53.         internal override void Execute(Processor processor, ActionFrame frame)
  54.         {
  55.             Debug.Assert(processor != null && frame != null);
  56.             switch (frame.State) {
  57.                 case Initialized:
  58.                     TextOnlyOutput output = new TextOnlyOutput(processor, new StringWriter(CultureInfo.InvariantCulture));
  59.                     processor.PushOutput(output);
  60.                     processor.PushActionFrame(frame);
  61.                     frame.State = ProcessingChildren;
  62.                     break;
  63.                 case ProcessingChildren:
  64.                    
  65.                     TextOnlyOutput recOutput = processor.PopOutput() as TextOnlyOutput;
  66.                     Debug.Assert(recOutput != null);
  67.                     Console.WriteLine(recOutput.Writer.ToString());
  68.                    
  69.                     if (_Terminate) {
  70.                         throw XsltException.Create(Res.Xslt_Terminate, recOutput.Writer.ToString());
  71.                     }
  72.                     frame.Finished();
  73.                     break;
  74.                 default:
  75.                    
  76.                     Debug.Fail("Invalid MessageAction execution state");
  77.                     break;
  78.             }
  79.         }
  80.     }
  81. }

Developer Fusion