Click here to Skip to main content
15,888,610 members
Articles / Programming Languages / Visual Basic

Visual SourceSafe Journal Monitor Service

Rate me:
Please Sign up or sign in to vote.
4.94/5 (12 votes)
27 Jan 200412 min read 152K   853   59  
VMS is a windows service developed in .Net that monitors a Microsoft Visual SourceSafe (VSS) database. Customized alerts may be sent based on the defined filters.
Imports System.Xml.Serialization
Imports System.Data.SqlClient
Imports VMS.Framework

' Class used to store and retrieve entries from an SQL server database.
' You must install the Database.SQL file that came with this source code
' in order for this to work properly.

Public Class SqlServer
	Inherits VMS.Framework.DataStore.BaseDataStore

	Public Overrides Sub CacheEntries(ByVal EntryData As EntryData)

		Dim Connection As New SqlConnection
		Dim Command As New SqlCommand
		Dim Adapter As New SqlDataAdapter

		Try
			Connection.ConnectionString = ConnectionString

			' setup command to insert events
			Command.Connection = Connection
			Command.CommandType = CommandType.StoredProcedure
			Command.CommandText = "[dbo].[spr_CacheEntry]"

			' When adding parameters, map each one to a field in the datatable
			Command.Parameters.Add("@Logged", SqlDbType.SmallDateTime, 4, "Logged")
			Command.Parameters.Add("@Date", SqlDbType.SmallDateTime, 4, "Date")
			Command.Parameters.Add("@Path", SqlDbType.VarChar, 256, "Path")
			Command.Parameters.Add("@Version", SqlDbType.Int, 4, "Version")
			Command.Parameters.Add("@Action", SqlDbType.VarChar, 128, "Action")
			Command.Parameters.Add("@User", SqlDbType.VarChar, 32, "User")
			Command.Parameters.Add("@Event", SqlDbType.VarChar, 16, "Event")
			Command.Parameters.Add("@Comment", SqlDbType.Text, Int32.MaxValue, "Comment")

			' Add all events with one update
			Adapter.InsertCommand = Command
			Adapter.Update(EntryData.Entries)
		Finally
			If Not Adapter Is Nothing Then
				Adapter.Dispose()
				Adapter = Nothing
			End If

			If Not Command Is Nothing Then
				Command.Dispose()
				Command = Nothing
			End If

			If Not Connection Is Nothing Then
				If Connection.State = ConnectionState.Open Then
					Connection.Close()
				End If
				Connection.Dispose()
				Connection = Nothing
			End If
		End Try

	End Sub

	<XmlIgnore()> Private ReadOnly Property ConnectionString() As String
		Get
			' Create a connection string based on properties provided

			Dim Server As String = DataStore("Server").Replace("=", "==")
			Dim Catalog As String = DataStore("Catalog").Replace("=", "==")
			Dim Username As String = DataStore("Username").Replace("=", "==")
			Dim Password As String = DataStore("Password").Replace("=", "==")
			Dim Trusted As Boolean = False
			If Not DataStore("Trusted") = "" Then
				Trusted = CType(DataStore("Trusted"), Boolean)
			End If

			Dim Text As New System.Text.StringBuilder
			Text.Append("Persist Security Info=False;")
			If Trusted Then
				Text.Append("Integrated Security=SSPI;")
			Else
				Text.Append("Password=" & Password & ";")
				Text.Append("User ID=" & Username & ";")
			End If
			Text.Append("Initial Catalog=" & Catalog & ";")
			Text.Append("server=" & Server & ";")
			Text.Append("Application Name=VssMonitorService;")

			Return Text.ToString

		End Get
	End Property

	Public Overrides Function FilterEntries(ByVal alert As Config.Alerts.Service.Alert) As EntryData

		' Filter Entries expects an SQL Query that will return the 
		' following fields and data type in the order they are
		' specified

		' Logged	smalldatetime
		' Date		smalldatetime
		' Path		varchar(256)
		' Version	int
		' Action	varchar(128)
		' User		varchar(32)
		' Event		varchar(16)
		' Comment	text

		' In addition, you may use a varialbe called @LastAlerted
		' that will be replaced with the date that the last email
		' was sent for this particular alert.

		Dim Connection As New SqlConnection
		Dim Command As New SqlCommand
		Dim Adapter As New SqlDataAdapter
		Dim EntryData As New EntryData
		Try
			Connection.ConnectionString = ConnectionString

			Command.Connection = Connection
			Command.CommandType = CommandType.Text

			Command.CommandText = alert.Filter.Content
			Command.Parameters.Add("@LastAlerted", alert.LastSent)

			Adapter.SelectCommand = Command
			Adapter.Fill(EntryData.Entries)
			Return EntryData
		Finally
			If Not Adapter Is Nothing Then
				Adapter.Dispose()
				Adapter = Nothing
			End If

			If Not Command Is Nothing Then
				Command.Dispose()
				Command = Nothing
			End If

			If Not Connection Is Nothing Then
				If Connection.State = ConnectionState.Open Then
					Connection.Close()
				End If
				Connection.Dispose()
				Connection = Nothing
			End If
		End Try

	End Function
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
If you got this far, you are probably interested in who exactly I am and are eager to pick some knowledge out of my head.

I am a programmer - no doubt. I grew up with an Atari 400 using BASIC and PILOT and saving my programs to a casset tape. Over the years, I would rush to the library looking for books with source code of computer games in them that I could create with basic. After long hours of coding, I would save, then load, and then spend the next few days figuring out where I made a mistake - and even the book for that matter! What I'm trying to say is, you got to learn by doing. Don't give up, and always get help from someone else - wether it be source code, a book, or actually communicating with them on a one-on-one relationship.

I'll admit it - I'm a book worm. I have a shelf full of red books (if you know what I mean), and tons of other shelves of other books. I can't recommend just one, but I have found that Wrox is the best for me. After that, I have O'Reilly and Sams in third.

As far as source code goes, I have my own personal site with source code (and lots of working demos), and other sites that I post code to.

Ok, so we are down to contact info. I have ICQ. If you need the number it is 364308. Pretty low eh? I've been a die hard at this computer stuff for years on end. I even ran my own BBS and was a SysOp on many other BBS's in the Pittsburgh area when the Internet was still known as a toy called "the information super highway".

Ok, I'll close with that and let you go on your way. If you see my code - please vote. If it is bad, put up some feedback letting me know. And if you want to see more to me then just code (I'm an artist too), then just visit my web site.

Comments and Discussions