I imagine that lots of folks are going to want to fix the UrlDecode and Links problems in ESPNScoreboard (note that these are already fixed in ScoreboardFeed). These were never bugs at all until ESPN changed their format recently. Anyways, this is the fix that I've done in ScoreboardFeed, so you can probably implement it in ESPNScoreboard.
Bug Description
The bug has two parts. The first is the Url Decoding that ESPN introduced recently. Here's a snippet of one of their datafeeds:
g1t1=NC%20State&g1t2=UConn&
g1s1=65&g1s2=62&g1status=Final+Sun&
g1url=http://sports.espn.go.com/ncb/recap'gameId=254000028&g1winner=t1
I've added the line breaks for readability. Notice that instead of 'NC State', 'NC%20State' is entered. This is called url encoding and is referred to as the UrlDecode bug for ESPNScoreboard's purposes.
The second part of the bug has to do with the way that the game url is parsed. Since the parsing of each element is based on splitting the terms on the equals sign (=), the second equals sign in the url string breaks the logic since the string is actually split into an array with 3 items rather than 2. This flawed logic occurs on the following line in the ESPNScoreboard.ascx.vb:
ScoreboardRow(Url) = CleanString(GameAttributes(5).Split("="c)(1))
The outcome of this bug is that the link displayed is not correct. It is missing the actual value of the gameId (i.e. everything after second equals sign). This bug is referred to as the Link bug for ESPNScoreboard.
Fixing the Bug
To fix the UrlDecode bug, you need to clean the text. I've added a function called Cleanstring to ScoreboardFeed to accommodate this. Here's the code:
Private Function CleanString(ByVal DirtyString As String) As String
Dim InputString As String = DirtyString
InputString = InputString.Replace("+", " ")
InputString = Server.UrlDecode(InputString)
Return InputString
End Function
The Link bug isn't as easy to fix. You could probably work on combining the 2nd and 3rd elements of the array that's created when the url line is split. I wasn't a big fan of the split calls anyways, so I went a different way. I used a regex with named matches to pull out the name/value pairs. This allowed me to eliminate any reliance on looking for specific equals signs. Here's the code:
1 Private Function GetGames(ByVal DataString As String) As ArrayList
2 Dim ScoreboardList As New ArrayList
3 Dim Game As GameInfo
4
5 Dim GamePattern As String = "g\d+t1.*'url=[^&]*"
6 Dim GameMatch As Match = Regex.Match(DataString, GamePattern)
7
8 Dim GameAttributePattern As String = "^g\d+t1=('<team1>.*')&g\d+t2=('<team2>.*')&g\d+s1=('<score1>.*')&g\d+s2=('<score2>.*')&g\d+status=('<status>.*')&g\d+url=('<url>.*')$"
9 Dim GameAttributeMatch As Match
10
11 While (GameMatch.Success)
12 GameAttributeMatch = Regex.Match(GameMatch.Value, GameAttributePattern)
13 While (GameAttributeMatch.Success)
14 Game = New GameInfo
15 Game.Team1 = CleanString(GameAttributeMatch.Groups("team1").Value)
16 Game.Team2 = CleanString(GameAttributeMatch.Groups("team2").Value)
17 Game.Score1 = CleanString(GameAttributeMatch.Groups("score1").Value)
18 Game.Score2 = CleanString(GameAttributeMatch.Groups("score2").Value)
19 Game.Status = CleanString(GameAttributeMatch.Groups("status").Value)
20 Game.Url = CleanString(GameAttributeMatch.Groups("url").Value)
21 ScoreboardList.Add(Game)
22 GameAttributeMatch = GameAttributeMatch.NextMatch
23 End While
24 GameMatch = GameMatch.NextMatch
25 End While
26 Return ScoreboardList
27 End Function
I've made a few changes in the code. First among those is that I'm not using a datatable anymore like I did in ESPNScoreboard. I've now created a class to contain my Game information. Each instance of the class is added to an ArrayList which is then bound to the repeater. I like this format better than building a datatable row by row.
Note the huge regex on line 8. This is the regex that parses through the string for each game. Thank god for The Regulator - it was a huge help in writing the regex since I'm a beginner at it. I've used named groups in the regex. This allows the code in lines 15 to 20 an easy way to pick out the text.
This code could still work well with the old datatable in ESPNScoreboard. Just replace all of the Game references with the ScoreboardRow syntax and add each ScoreboardRow to ScoreboardTable within the inner loop. Don't forget to also change the return type of GetGames from an ArrayList to a DataTable
The Future
I'm not sure what plans the future has for ScoreboardFeed. There isn't a lot that can be added to this other than localization support. If I can find some other web sites that have easily consumable sports scores, then I might extend ScoreboardFeed to have some way to configure the scoreboard retrieval process.
Hopefully this has been useful to some folks. If not, at least I'm creating some new content to pollute the Internet!