This code was downloaded from MOBZystems, Home of Tools. No license, use at will. And at your own risk!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | ''' This file contains the source code for a simple console application ''' that collects and displays Codeplex statistics (page views, visits, and downloads) ''' for a group of projects. Option Strict On Option Explicit On Imports System.Net Imports System.Text Imports System.IO ' Use JSON.NET to parse the JSON response from GetActivity Imports Newtonsoft.Json Module CodeplexStats ''' <summary> ''' Data returned from GetActivity ''' </summary> Private Class ActivityInfo Public pageViews As Integer Public visits As Integer Public downloads As Integer End Class ''' <summary> ''' Download and show Codeplex statistics on a series of projects ''' </summary> Sub Main() ' Show header Console.WriteLine( String .Format( "{0,-40} {1,15} {2,15} {3,15}" , "Project:" , "Page views:" , "Visits:" , "Downloads:" ) ) ' Loop over projects For Each projectName As String In { "MOBZHash" , "MOBZHunt" , "MOBZKeys" , "MOBZoom" , "MOBZPing" , "MOBZRuler" , "MOBZync" , "QuickCode" , "RegFind" , "RegName" , "RunNET" , "SeeThroughWindows" , "ShellRunner" } ' Get activity information for a project ' Note: -1 is 'All' Dim actInfo As ActivityInfo = GetActivityForProject(projectName, -1) ' Show activity info Console.WriteLine( String .Format( "{0,-40} {1,15} {2,15} {3,15}" , projectName, actInfo.pageViews, actInfo.visits, actInfo.downloads ) ) Next End Sub ''' <summary> ''' Get the activity information for a Codeplex project ''' </summary> ''' <param name="projectName">The name of the project (as in [projectname].codeplex.com)</param> ''' <param name="period">7, 30 or -1 ("All")</param> ''' <returns>A populated ActivityInfo object</returns> ''' <remarks>No error handling!</remarks> Private Function GetActivityForProject( projectName As String , period As Integer ) As ActivityInfo ' Set up a WebRequest Dim request As WebRequest = WebRequest.Create( ) ' Use POST to supply the parameters request.Method = "POST" request.ContentType = "application/x-www-form-urlencoded" ' Set up the POST data Dim postData As String = String .Format( "period={0}" , period) ' Write it to the request stream in UTF8 format Dim byteArray As Byte () = Encoding.UTF8.GetBytes(postData) ' Set Content length BEFORE writing request.ContentLength = byteArray.Length Using dataStream As Stream = request.GetRequestStream() dataStream.Write(byteArray, 0, byteArray.Length) End Using ' Get and process the response Using response As WebResponse = request.GetResponse() Using dataStream As Stream = response.GetResponseStream() Using reader As New StreamReader(dataStream) Dim responseFromServer As String = reader.ReadToEnd() ' Return an ActivityInfo from the content of the response Return JsonConvert.DeserializeObject(Of ActivityInfo)( responseFromServer ) End Using End Using End Using End Function End Module |