• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得windowscocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

OpenTweenのfork


Commit MetaInfo

修訂c7ba09592ace5c340387f0b9408413d94e0e58bf (tree)
時間2012-02-18 23:19:56
作者kiri_feather <kiri_feather@user...>
CommiterKimura Youichi

Log Message

GA処理をキューイングして裏で定期的に動かすように

Change Summary

差異

--- a/Tween/Google.vb
+++ b/Tween/Google.vb
@@ -28,6 +28,7 @@ Imports System.Net
2828 Imports System.Runtime.Serialization
2929 Imports System.Runtime.Serialization.Json
3030 Imports System.Web
31+Imports System.Threading
3132
3233 Public Class Google
3334
@@ -341,6 +342,33 @@ Public Class Google
341342 System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height)
342343 Me._screenColorDepth = String.Format("{0}-bit",
343344 System.Windows.Forms.Screen.PrimaryScreen.BitsPerPixel)
345+ Dim proc As ThreadStart
346+ proc = Sub()
347+ Threading.Thread.CurrentThread.Priority = ThreadPriority.Lowest
348+ While Not _endingFlag
349+ If Me.gaQueue.Count > 0 Then
350+ Dim param As Dictionary(Of String, String)
351+ SyncLock Me.syncObj
352+ param = Me.gaQueue.Dequeue()
353+ End SyncLock
354+ Try
355+ Dim req As HttpWebRequest = CreateRequest(GetMethod, New Uri(GA_GIF_URL), param, False)
356+ req.AllowAutoRedirect = True
357+ req.Accept = "*/*"
358+ req.Referer = "http://apps.tweenapp.org/foo.html"
359+ req.Headers.Add("Accept-Language", "ja-JP")
360+ req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; MALC)"
361+ req.Headers.Add("Accept-Encoding", "gzip, deflate")
362+ Dim img As Bitmap = Nothing
363+ Dim res = Me.GetResponse(req, img, Nothing, False)
364+ Catch ex As Exception
365+ 'nothing to do
366+ End Try
367+ End If
368+ Thread.Sleep(5000)
369+ End While
370+ End Sub
371+ proc.BeginInvoke(Nothing, Nothing)
344372 End Sub
345373
346374 Private Sub Init()
@@ -411,36 +439,14 @@ Public Class Google
411439 params("utmr") = "0"
412440 End If
413441
414- Me.GetAsync(params, New Uri(GA_GIF_URL))
442+ 'Me.GetAsync(params, New Uri(GA_GIF_URL))
443+ SyncLock syncObj
444+ Me.gaQueue.Enqueue(params)
445+ End SyncLock
415446 End Sub
416447
417- Private Sub GetAsync(ByVal params As Dictionary(Of String, String), ByVal url As Uri)
418- Try
419- Dim req As HttpWebRequest = CreateRequest(GetMethod, url, params, False)
420- req.AllowAutoRedirect = True
421- req.Accept = "*/*"
422- req.Referer = "http://apps.tweenapp.org/foo.html"
423- req.Headers.Add("Accept-Language", "ja-JP")
424- req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; MALC)"
425- req.Headers.Add("Accept-Encoding", "gzip, deflate")
426-
427- Dim r As IAsyncResult = CType(req.BeginGetResponse(New AsyncCallback(AddressOf GetAsyncResponse), req), IAsyncResult)
428- Catch ex As Exception
429- 'nothing to do
430- End Try
431- End Sub
432-
433- Private Sub GetAsyncResponse(ByVal ar As IAsyncResult)
434- Dim res As HttpWebResponse = Nothing
435- Try
436- res = CType(CType(ar.AsyncState, HttpWebRequest).EndGetResponse(ar), HttpWebResponse)
437- Catch ex As Exception
438- 'nothing to do
439- Finally
440- If res IsNot Nothing Then res.Close()
441- End Try
442- RaiseEvent Sent()
443- End Sub
448+ Private syncObj As New Object
449+ Private gaQueue As New Queue(Of Dictionary(Of String, String))
444450
445451 Public Sub TrackPage(ByVal page As String, ByVal userId As Long)
446452 Me.SendRequest(New Dictionary(Of String, String) From {{"page", page}}, userId)