' 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. Public Class MainForm Inherits System.Windows.Forms.Form Private WithEvents scanner As CityOfHeroes.Scanner.CohScanner #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() ' 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 ' and we're ready to start the scanner. Note that this is a user action in this ' application, under the 'Scanner' submenu End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents miScannerStart As System.Windows.Forms.MenuItem Friend WithEvents miScannerResume As System.Windows.Forms.MenuItem Friend WithEvents pnlLeft As System.Windows.Forms.Panel Friend WithEvents lbStatus As System.Windows.Forms.ListBox Friend WithEvents label1 As System.Windows.Forms.Label Friend WithEvents miScanner As System.Windows.Forms.MenuItem Friend WithEvents miScannerStop As System.Windows.Forms.MenuItem Friend WithEvents menuItem6 As System.Windows.Forms.MenuItem Friend WithEvents miScannerPause As System.Windows.Forms.MenuItem Friend WithEvents mainMenu1 As System.Windows.Forms.MainMenu Friend WithEvents miFile As System.Windows.Forms.MenuItem Friend WithEvents miFileExit As System.Windows.Forms.MenuItem Friend WithEvents pnlRight As System.Windows.Forms.Panel Friend WithEvents lbMessages As System.Windows.Forms.ListBox Friend WithEvents label2 As System.Windows.Forms.Label Friend WithEvents splitter1 As System.Windows.Forms.Splitter <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.miScannerStart = New System.Windows.Forms.MenuItem Me.miScannerResume = New System.Windows.Forms.MenuItem Me.pnlLeft = New System.Windows.Forms.Panel Me.lbStatus = New System.Windows.Forms.ListBox Me.label1 = New System.Windows.Forms.Label Me.miScanner = New System.Windows.Forms.MenuItem Me.miScannerStop = New System.Windows.Forms.MenuItem Me.menuItem6 = New System.Windows.Forms.MenuItem Me.miScannerPause = New System.Windows.Forms.MenuItem Me.mainMenu1 = New System.Windows.Forms.MainMenu Me.miFile = New System.Windows.Forms.MenuItem Me.miFileExit = New System.Windows.Forms.MenuItem Me.pnlRight = New System.Windows.Forms.Panel Me.lbMessages = New System.Windows.Forms.ListBox Me.label2 = New System.Windows.Forms.Label Me.splitter1 = New System.Windows.Forms.Splitter Me.pnlLeft.SuspendLayout() Me.pnlRight.SuspendLayout() Me.SuspendLayout() ' 'miScannerStart ' Me.miScannerStart.Index = 0 Me.miScannerStart.Text = "Star&t" ' 'miScannerResume ' Me.miScannerResume.Enabled = False Me.miScannerResume.Index = 4 Me.miScannerResume.Text = "&Resume" ' 'pnlLeft ' Me.pnlLeft.Controls.Add(Me.lbStatus) Me.pnlLeft.Controls.Add(Me.label1) Me.pnlLeft.Dock = System.Windows.Forms.DockStyle.Left Me.pnlLeft.Location = New System.Drawing.Point(0, 0) Me.pnlLeft.Name = "pnlLeft" Me.pnlLeft.Size = New System.Drawing.Size(240, 326) Me.pnlLeft.TabIndex = 3 ' 'lbStatus ' Me.lbStatus.Dock = System.Windows.Forms.DockStyle.Fill Me.lbStatus.IntegralHeight = False Me.lbStatus.Location = New System.Drawing.Point(0, 23) Me.lbStatus.Name = "lbStatus" Me.lbStatus.ScrollAlwaysVisible = True Me.lbStatus.Size = New System.Drawing.Size(240, 303) Me.lbStatus.TabIndex = 1 ' 'label1 ' Me.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.label1.Dock = System.Windows.Forms.DockStyle.Top Me.label1.Location = New System.Drawing.Point(0, 0) Me.label1.Name = "label1" Me.label1.Size = New System.Drawing.Size(240, 23) Me.label1.TabIndex = 0 Me.label1.Text = "Status" Me.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft ' 'miScanner ' Me.miScanner.Index = 1 Me.miScanner.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.miScannerStart, Me.miScannerStop, Me.menuItem6, Me.miScannerPause, Me.miScannerResume}) Me.miScanner.Text = "&Scanner" ' 'miScannerStop ' Me.miScannerStop.Enabled = False Me.miScannerStop.Index = 1 Me.miScannerStop.Text = "Sto&p" ' 'menuItem6 ' Me.menuItem6.Index = 2 Me.menuItem6.Text = "-" ' 'miScannerPause ' Me.miScannerPause.Enabled = False Me.miScannerPause.Index = 3 Me.miScannerPause.Text = "&Pause" ' 'mainMenu1 ' Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.miFile, Me.miScanner}) ' 'miFile ' Me.miFile.Index = 0 Me.miFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.miFileExit}) Me.miFile.Text = "&File" ' 'miFileExit ' Me.miFileExit.Index = 0 Me.miFileExit.Text = "E&xit" ' 'pnlRight ' Me.pnlRight.Controls.Add(Me.lbMessages) Me.pnlRight.Controls.Add(Me.label2) Me.pnlRight.Dock = System.Windows.Forms.DockStyle.Fill Me.pnlRight.Location = New System.Drawing.Point(246, 0) Me.pnlRight.Name = "pnlRight" Me.pnlRight.Size = New System.Drawing.Size(218, 326) Me.pnlRight.TabIndex = 5 ' 'lbMessages ' Me.lbMessages.Dock = System.Windows.Forms.DockStyle.Fill Me.lbMessages.IntegralHeight = False Me.lbMessages.Location = New System.Drawing.Point(0, 23) Me.lbMessages.Name = "lbMessages" Me.lbMessages.ScrollAlwaysVisible = True Me.lbMessages.Size = New System.Drawing.Size(218, 303) Me.lbMessages.TabIndex = 1 ' 'label2 ' Me.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.label2.Dock = System.Windows.Forms.DockStyle.Top Me.label2.Location = New System.Drawing.Point(0, 0) Me.label2.Name = "label2" Me.label2.Size = New System.Drawing.Size(218, 23) Me.label2.TabIndex = 0 Me.label2.Text = "Chat Messages" Me.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft ' 'splitter1 ' Me.splitter1.Location = New System.Drawing.Point(240, 0) Me.splitter1.Name = "splitter1" Me.splitter1.Size = New System.Drawing.Size(6, 326) Me.splitter1.TabIndex = 4 Me.splitter1.TabStop = False ' 'MainForm ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(464, 326) Me.Controls.Add(Me.pnlRight) Me.Controls.Add(Me.splitter1) Me.Controls.Add(Me.pnlLeft) Me.Menu = Me.mainMenu1 Me.Name = "MainForm" Me.Text = "Form1" Me.pnlLeft.ResumeLayout(False) Me.pnlRight.ResumeLayout(False) Me.ResumeLayout(False) End Sub #End Region #Region "Form Event Handlers" Private Sub miFileExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles miFileExit.Click Close() End Sub Private Sub miScannerPause_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles miScannerPause.Click scanner.Pause() End Sub Private Sub miScannerResume_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles miScannerResume.Click scanner.Resume() End Sub Private Sub miScannerStart_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles miScannerStart.Click scanner.Start() End Sub Private Sub miScannerStop_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles miScannerStop.Click scanner.Stop() End Sub #End Region #Region "Scanner Event Handlers" Private Sub scanner_OnHeroLogin(ByVal hero As CityOfHeroes.HeroData) Handles scanner.OnHeroLogin lbStatus.Items.Add(String.Format("Hero '{0}' just logged in", hero.Name)) End Sub Private Sub scanner_OnHeroLogout(ByVal hero As CityOfHeroes.HeroData) Handles scanner.OnHeroLogout lbStatus.Items.Add(String.Format("Hero '{0}' just logged out", hero.Name)) End Sub Private Sub scanner_OnScanningError(ByVal msg As String) Handles scanner.OnScanningError lbStatus.Items.Add(String.Format("A scanning error occurred. {0}", msg)) End Sub Private Sub scanner_OnScanningPaused() Handles scanner.OnScanningPaused lbStatus.Items.Add("The scanner has been paused") End Sub Private Sub scanner_OnScanningResumed() Handles scanner.OnScanningResumed lbStatus.Items.Add("Scanning is resumed") End Sub Private Sub scanner_OnScanningStart() Handles scanner.OnScanningStart lbStatus.Items.Add("The scanner has been started") End Sub Private Sub scanner_OnScanningStop() Handles scanner.OnScanningStop lbStatus.Items.Add("The scanner has been stopped") End Sub Private Sub scanner_OnChatMessage(ByVal message As CityOfHeroes.ChatMessage) Handles scanner.OnChatMessage lbStatus.Items.Add(String.Format("ChatMessage from {0} at {1}: {2}", message.Channel, message.Timestamp, message.Message)) lbStatus.Items.Add(String.Format(" Category: {0}", message.Category)) End Sub #End Region End Class