' Demo class 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. Module ConsoleMain ' We need to declare these at module level because we'll be handling events. ' in VB.NET, WithEvents variables must be module-level ' 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 Private logoutEvent As System.Threading.ManualResetEvent = New System.Threading.ManualResetEvent(False) Sub Main() ' the events we're interested in are listed below ' Make sure to start the ball rolling engine.Scanning = True ' alternatively, could have used scanner.Start() ' for this example, we'll wait for a logout and then terminate logoutEvent.WaitOne() ' not absolutely necessary to turn off the scanner, but it's polite engine.Scanning = False End Sub Private Sub engine_OnHeroLogin(ByVal hero As CityOfHeroes.HeroData) Handles engine.OnHeroLogin Console.WriteLine("*** {0} Logged In", hero.Name) End Sub Private Sub engine_OnHeroLogout(ByVal hero As CityOfHeroes.HeroData) Handles engine.OnHeroLogout Console.WriteLine("*** {0} Logged Out", hero.Name) End Sub Private Sub scanner_OnChatMessage(ByVal message As CityOfHeroes.ChatMessage) Handles scanner.OnChatMessage Console.WriteLine("At {0}: {1}", message.Timestamp, message.Message) 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 Console.WriteLine("--- {0} has {1} experience", onlineHero.Name, onlineHero.Experience) End If End Sub End Module