andrew4582

NotificationTextWriter

Aug 4th, 2010
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1.  using System;
  2.  using System.Diagnostics;
  3.  using System.IO;
  4.  using System.Text;
  5.  
  6.  namespace  BA.Core.IO {
  7.      /// <summary>
  8.      /// Used for handling notification on a TextWriter
  9.      /// </summary>
  10.      public  class  NotificationTextWriter :TextWriter  {
  11.          public  event  TextNotificationHandler  TextNotification;
  12.  
  13.          public  NotificationTextWriter() { }
  14.          public  NotificationTextWriter(TextNotificationHandler  notificationFunc) {
  15.              TextNotification += notificationFunc;
  16.          }
  17.          
  18.          protected  void  OnTextNotification(TextNotificationArgs  args) {
  19.              if (TextNotification != null )
  20.                  TextNotification(this ,args);
  21.          }
  22.          public  override  void  Write(char [] buffer,int  index,int  count) {
  23.              this .Write(new  String (buffer,index,count));
  24.          }
  25.          public  override  void  Write(string  value) {
  26.              OnTextNotification(new  TextNotificationArgs () { Output = value });
  27.          }
  28.          public  override  Encoding  Encoding {
  29.              get  { return  Encoding .Default; }
  30.          }
  31.      }
  32.      public  delegate  void  TextNotificationHandler (object  sender,TextNotificationArgs  e);
  33.  
  34.      public  class  TextNotificationArgs :EventArgs  {
  35.          public  string  Output { get ; set ; }
  36.      }
  37.  }
Advertisement
Add Comment
Please, Sign In to add comment