Click here to Skip to main content
15,881,882 members
Articles / Programming Languages / VBScript

Auto Notify Your Team Members with Email, when Performing Visual Source Safe Operations

Rate me:
Please Sign up or sign in to vote.
4.23/5 (12 votes)
20 Jan 2006CPOL3 min read 78.2K   884   25   17
A Visual Source Safe Addin written in VB with the help of which you can auto-email your team members about the operations (Add, Check in, check out...) you performed on VSS

Introduction

Me and five of my friends are working on a project. We use Visual Source Safe for our code. Last week, an unfortunate incident happened with us, just a day before our project release. I found that the code which I checked in VSS a day before was missing. When I asked my friends about this, we found that, one of them had unknowingly overwritten that piece of code in VSS with the one that he was working on.

Then we thought it would be better if in future we can auto-notify each other about our code add/checking in VSS through some way. Then I read an article in MSDN written in VC++ describing how we can intercept VSS events, while we perform any operation on them. Moreover I learnt about Outlook Redemption Library which helps us to send emails programmatically bypassing security alert dialog boxes. With the help of this all, I developed this simple VSS addin in Visual Basic.

After installing (which is as simple as this addin) this addin, whenever you perform any operation on VSS, an email will be sent to all your friends. The email will be sent when you logout from VSS and will consist of a summary of operations you have performed during that VSS session. The email will be sent using the default email account configured in your Outlook. Moreover no security check dialog boxes will be shown during all these operations.

Prerequisite

  1. Outlook Redemption Library

Installation

  1. Copy the VSSVBAddin.dll into the %SystemRoot%\System32 folder.
  2. From a command prompt, register VSSVBAddin.dll with the following command:
    RegSvr32 VSSVBAddin.dll 
  3. Create a file named Ssaddin.ini in the VSS\Win32 folder where the Ssapi.dll file is registered (in other words, the folder where you installed Visual SourceSafe). This folder should also be the folder that the following registry key points to:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SourceSafe\SCCServerPath
  4. Open the Ssaddin.ini file and add the following line to it:
    VB.NET
    VSSVBAddin.AddinClass = 1
  5. Create a file named maillist.txt in the folder where your Visual Source Safe Database srcsafe.ini is placed.
  6. Open the file and write the email id of all your team members, one on each new line. e.g.<
    pradeep@xyz.com
    
    sudeep@pqr.com
    
    ....

Using the Code

Visual source safe provides a method to trap and control its various events such as BeforeAdd, BeforeCheckIn, .... through the use of addins. This code implements these events and whenever a operation is performed on VSS, it adds the details related to those operations to a global string variable str.

VBScript
'Event fired after addition of any item.
Sub VSSHandler_AfterAdd(ByVal Item As IVSSItem, ByVal LocalSpec As _
String, ByVal Comment As String)
    'Check if any comment is added. then include that.
    If Comment <> "" Then
        str = str & vbCrLf & "Added: " & _
              Item.Parent.Spec & "/" & Item.Name & _
              " at : " & Now & ", Commented : " & Comment
    Else
        str = str & vbCrLf & "Added: " & _
              Item.Parent.Spec & "/" & _
              Item.Name & " at : " & Now
    End If
End Sub

Later on, when user exits the VSS, Class_Terminate is called. Here we read the mail id of all the recipients from maillist.txt file placed on the same path as srcsafe.ini file of VSS database itself. Then we send a mail to all those recipients using Redemption Library (which uses your default email account configured on Outlook).

VBScript
Private Sub Class_Terminate()
    On Error GoTo Mailing_Error
    'Check if any operation is done. else this string will be empty
    If str <> "" Then
        Dim SafeItem, oItem

        'Creates a mail item to be mailed.
        Set Application = CreateObject("Outlook.Application")
        Set Namespace = Application.GetNamespace("MAPI")
        Namespace.Logon

        Set SafeItem = CreateObject("Redemption.SafeMailItem")
        Set oItem = Application.CreateItem(0)
        SafeItem.Item = oItem

        'Reads maillist.txt file for recipient address.
        Dim nFileNum As Integer, sNextLine As String
        'Get free file number
        nFileNum = FreeFile

        'Opens the file
        Open Left$(VSSHandler.VSSDatabase.SrcSafeIni, _
             Len(VSSHandler.VSSDatabase.SrcSafeIni) - 11) _
             & "maillist.txt" For Input As nFileNum
        Do While Not EOF(nFileNum)
            'Read recipient mail id
            Line Input #nFileNum, sNextLine

            'Add email recipient
            SafeItem.Recipients.Add sNextLine
        Loop

        ' Close the file
        Close nFileNum

        'Resolves email ids
        SafeItem.Recipients.ResolveAll
    
        'Create the subject of mail
        SafeItem.Subject = "VSS Notification - " & _
                            VSSHandler.VSSDatabase.SrcSafeIni

        'Create the body of email
        str = "This is an auto generated message." & vbCrLf & _
              "User :" & VSSHandler.VSSDatabase.Username & _
              ", performed the following operations on VSS Database " _
              & vbCrLf & str
        SafeItem.Body = str

        'Send the email
        SafeItem.Send

        'Used in case of non Exchange Server mailids e.g. pop-smtp... _
        to immediately deliver mail
        Set Utils = CreateObject("Redemption.MAPIUtils")
        Utils.DeliverNow
    End If

    Exit Sub
    'Handle any error here.
Mailing_Error:
    MsgBox "Error " & Err.Number & " while sending mail" & vbCrLf & Err.Description
End Sub

Related Links

History

  • 20th January, 2006: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionAutomation error Pin
jude_aj3-Apr-12 9:45
jude_aj3-Apr-12 9:45 
Generalmaintaining different source code base for different customers Pin
Ravi Tejas15-Dec-09 20:29
Ravi Tejas15-Dec-09 20:29 
QuestionAutomatically refresh Solution Explorer source control status icon ? Pin
Alexandru Matei3-Oct-09 21:54
Alexandru Matei3-Oct-09 21:54 
GeneralQuite Simple and useful ! Pin
alobroj2-Mar-09 5:36
alobroj2-Mar-09 5:36 
GeneralQuestion Pin
Jasmin Ahuja24-Sep-08 1:20
Jasmin Ahuja24-Sep-08 1:20 
GeneralRe: Question Pin
Tofiq Khan24-Sep-08 1:21
Tofiq Khan24-Sep-08 1:21 
GeneralRe: Question Pin
Shahrukh Beg Ali24-Sep-08 1:25
Shahrukh Beg Ali24-Sep-08 1:25 
GeneralGood One! Pin
Rajesh Kumar Bhalla24-Sep-08 1:18
Rajesh Kumar Bhalla24-Sep-08 1:18 
GeneralTool to send automated mails for VSS Pin
Shane828212-Oct-07 7:43
Shane828212-Oct-07 7:43 
GeneralRe: Tool to send automated mails for VSS Pin
hagarwal27-Aug-08 5:49
hagarwal27-Aug-08 5:49 
GeneralNo mails received Pin
Arvind1528-Feb-07 0:52
Arvind1528-Feb-07 0:52 
QuestionSource Safe Pin
me_ranjit31-Jul-06 1:53
me_ranjit31-Jul-06 1:53 
Generalquestion Pin
karthieyan26-Mar-06 21:39
karthieyan26-Mar-06 21:39 
GeneralQuestion Pin
carlop()25-Jan-06 6:31
carlop()25-Jan-06 6:31 
GeneralRe: Question Pin
hagarwal25-Jan-06 8:22
hagarwal25-Jan-06 8:22 
GeneralNice thought !! Pin
Tittle Joseph20-Jan-06 22:12
Tittle Joseph20-Jan-06 22:12 
GeneralRe: Nice thought !! Pin
Brad Bruce21-Jan-06 1:11
Brad Bruce21-Jan-06 1:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.