This code was downloaded from MOBZystems, Home of Tools. No license, use at will. And at your own risk!
''' 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(
String.Format("http://{0}.codeplex.com/stats/getActivity", projectName)
)
' 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