' Demo form for using the statistics engine 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 ' When using the StatsEngine object, you'll use a singleton and just ' hook its events ' To use this object, you'll need StatsEngine.dll and CityOfHeroesData.dll referenced Private WithEvents engine As HeroStats.StatsEngine.StatsEngine = HeroStats.StatsEngine.Singletons.Statistics ' the Singletons class exposes other objects you can hook, like the scanner ' To use this, you'll need the CityOfHeroes.dll referenced Private WithEvents scanner As CityOfHeroes.Scanner.CohScanner = HeroStats.StatsEngine.Singletons.Scanner #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() InitializeComponent() ' Since we're a WinForms application, we need to set a Control object as the ' synchronizing element for inter-thread message processing HeroStats.StatsEngine.Singletons.SynchronizingUIElement = Me ' events are hooked in the functions below ' Make sure to start the ball rolling HeroStats.StatsEngine.Singletons.Statistics.Scanning = True ' alternatively, could have used Singletons.Scanner.Start() 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 label1 As System.Windows.Forms.Label Friend WithEvents listBox1 As System.Windows.Forms.ListBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.label1 = New System.Windows.Forms.Label Me.listBox1 = New System.Windows.Forms.ListBox Me.SuspendLayout() ' 'label1 ' 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(368, 23) Me.label1.TabIndex = 1 Me.label1.Text = "Output:" Me.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft ' 'listBox1 ' Me.listBox1.Dock = System.Windows.Forms.DockStyle.Fill Me.listBox1.Location = New System.Drawing.Point(0, 23) Me.listBox1.Name = "listBox1" Me.listBox1.Size = New System.Drawing.Size(368, 238) Me.listBox1.TabIndex = 2 ' 'MainForm ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(368, 270) Me.Controls.Add(Me.listBox1) Me.Controls.Add(Me.label1) Me.Name = "MainForm" Me.Text = "Sample Form" Me.ResumeLayout(False) End Sub #End Region Private Sub engine_OnHeroLogin(ByVal hero As CityOfHeroes.HeroData) Handles engine.OnHeroLogin listBox1.Items.Add(String.Format("*** {0} Logged In", hero.Name)) End Sub Private Sub engine_OnHeroLogout(ByVal hero As CityOfHeroes.HeroData) Handles engine.OnHeroLogout listBox1.Items.Add(String.Format("*** {0} Logged Out", hero.Name)) End Sub Private Sub engine_OnGameTimerTick(ByVal elapsedSeconds As Double) Handles engine.OnGameTimerTick ' let's just output the current experience for our online hero. If we're ' not online, output nothing ' grab a reference once, since a call to OnlineHero will recreate a new ' HeroData object everytime it's called Dim onlineHero As CityOfHeroes.HeroData = HeroStats.StatsEngine.Singletons.OnlineHero If Not onlineHero Is Nothing Then listBox1.Items.Add(String.Format("--- {0} has {1} experience", onlineHero.Name, onlineHero.Experience)) End If End Sub Private Sub scanner_OnChatMessage(ByVal message As CityOfHeroes.ChatMessage) Handles scanner.OnChatMessage listBox1.Items.Add(String.Format("At {0}: {1}", message.Timestamp, message.Message)) End Sub Private Sub MainForm_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing ' not absolutely necessary to turn off the scanner, but it's polite engine.Scanning = False End Sub End Class