' Demo class for using the scanner in your own application.
' 
' Note that this solution has a file called ChatMessageRegexs.dat attached to it.
' This file needs to be copied into the run directory (the same directory as the
' executable) in order for the ChatMessage class to read the regular expressions
' it needs to categorize the incoming messages.
'
' In the C# project, we set up a post-build event for the project. VB.NET doesn't have
' such a thing, so you need to ensure that the file is copied manually.
Module ConsoleMain

   ' We need to declare this at module level because we'll be handling events.
   ' in VB.NET, WithEvents variables must be module-level
   Private WithEvents scanner As CityOfHeroes.Scanner.CohScanner

   Sub Main()
      ' first, instantiate the scanner object
      scanner = New CityOfHeroes.Scanner.CohScanner

      ' now, initialize the chat message subsystem. Note that these last two 
      ' items don't have to be done in this order
      '
      ' Also note that, strictly speaking, this doesn't have to be called. If
      ' you fail to do so, the chat message subsystem will initialize the first
      ' time it's needed. Unfortunately, that can take some time (up to 10 seconds
      ' or so), so it's better to initialize it up front when you're doing the rest
      ' of your application setup so as to not have an ugly pause in the processing
      ' of your first chat message
      CityOfHeroes.ChatMessage.Initialize()

      ' by default, it will scan the chat channels that contain the 
      ' information it needs. You can add additional channels as desired
      '
      ' e.g., Broadcast is not selected by default, but let's get its messages too.
      scanner.BroadcastChannel = True

      ' event handlers are done below.

      ' we're all set up. Start the scanner
      scanner.Start()

      ' let's manipulate the scanner a bit now
      Console.WriteLine("Hit return to pause the scanner...")
      Console.ReadLine()
      scanner.Pause()

      Console.WriteLine("Hit return to resume scanning...")
      Console.ReadLine()
      scanner.Resume()

      Console.WriteLine("Hit return to quit...")
      Console.ReadLine()
      scanner.Stop()
   End Sub

#Region "Scanner Event Handlers"

   Private Sub scanner_OnHeroLogin(ByVal hero As CityOfHeroes.HeroData) Handles scanner.OnHeroLogin
      Console.WriteLine("Hero '{0}' just logged in", hero.Name)
   End Sub

   Private Sub scanner_OnHeroLogout(ByVal hero As CityOfHeroes.HeroData) Handles scanner.OnHeroLogout
      Console.WriteLine("Hero '{0}' just logged out", hero.Name)
   End Sub

   Private Sub scanner_OnScanningError(ByVal msg As String) Handles scanner.OnScanningError
      Console.WriteLine("A scanning error occurred. {0}", msg)
   End Sub

   Private Sub scanner_OnScanningPaused() Handles scanner.OnScanningPaused
      Console.WriteLine("The scanner has been paused")
   End Sub

   Private Sub scanner_OnScanningResumed() Handles scanner.OnScanningResumed
      Console.WriteLine("Scanning is resumed")
   End Sub

   Private Sub scanner_OnScanningStart() Handles scanner.OnScanningStart
      Console.WriteLine("The scanner has been started")
   End Sub

   Private Sub scanner_OnScanningStop() Handles scanner.OnScanningStop
      Console.WriteLine("The scanner has been stopped")
   End Sub

   Private Sub scanner_OnChatMessage(ByVal message As CityOfHeroes.ChatMessage) Handles scanner.OnChatMessage
      Console.WriteLine("ChatMessage from {0} at {1}: {2}", message.Channel, message.Timestamp, message.Message)
      Console.WriteLine("   Category: {0}", message.Category)
   End Sub

#End Region
End Module