[Tween-svn] [1057] 短縮URL解決で例外が発生することがあったのを ( 多分 ) 修正

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 11月 12日 (金) 19:25:37 JST


Revision: 1057
          http://sourceforge.jp/projects/tween/svn/view?view=rev&revision=1057
Author:   syo68k
Date:     2010-11-12 19:25:37 +0900 (Fri, 12 Nov 2010)

Log Message:
-----------
短縮URL解決で例外が発生することがあったのを(多分)修正

Modified Paths:
--------------
    trunk/Tween/ShortUrl.vb


-------------- next part --------------
Modified: trunk/Tween/ShortUrl.vb
===================================================================
--- trunk/Tween/ShortUrl.vb	2010-11-10 17:29:21 UTC (rev 1056)
+++ trunk/Tween/ShortUrl.vb	2010-11-12 10:25:37 UTC (rev 1057)
@@ -52,6 +52,8 @@
     Private Shared _bitlyKey As String = ""
     Private Shared _isresolve As Boolean = True
 
+    Private Shared ReadOnly _lockObj As New Object
+
     Public Shared WriteOnly Property BitlyId() As String
         Set(ByVal value As String)
             _bitlyId = value
@@ -76,7 +78,11 @@
     Public Shared Function Resolve(ByVal orgData As String) As String
         If _isresolve Then
             Static urlCache As New Dictionary(Of String, String)
-            If urlCache.Count > 500 Then urlCache.Clear() '定期的にリセット
+            SyncLock _lockObj
+                If urlCache.Count > 500 Then
+                    urlCache.Clear() '定期的にリセット
+                End If
+            End SyncLock
 
             Dim m As MatchCollection = Regex.Matches(orgData, "<a href=""(?<svc>http://.+?/)(?<path>[^""]+)""", RegexOptions.IgnoreCase)
             Dim urlList As New List(Of String)
@@ -85,7 +91,9 @@
                 Dim orgUrlPath As String = orgUrlMatch.Result("${path}")
                 If Array.IndexOf(_ShortUrlService, orgUrl) > -1 AndAlso _
                    Not urlList.Contains(orgUrl + orgUrlPath) Then
-                    urlList.Add(orgUrl + orgUrlPath)
+                    SyncLock _lockObj
+                        urlList.Add(orgUrl + orgUrlPath)
+                    End SyncLock
                 End If
             Next
             For Each orgUrl As String In urlList
@@ -106,7 +114,9 @@
                         If retUrlStr.StartsWith("http") Then
                             retUrlStr = retUrlStr.Replace("""", "%22")  'ダブルコーテーションがあるとURL終端と判断されるため、これだけ再エンコード
                             orgData = orgData.Replace("<a href=""" + orgUrl + """", "<a href=""" + retUrlStr + """")
-                            urlCache.Add(orgUrl, retUrlStr)
+                            SyncLock _lockObj
+                                urlCache.Add(orgUrl, retUrlStr)
+                            End SyncLock
                         End If
                     Catch ex As Exception
                         'Through



Tween-svn メーリングリストの案内
Back to archive index