How to: Create a C# Test Project Add-In -wisdom

 

Visual SourceSafe 

How to: Create a C# Test Project Add-In 

The following sections explain how to create and run C# project add-in for trapping events in Visual SourceSafe.

Create a C# Test Project Add-In

To create a test project in C# add-in that demonstrates how to trap the SourceSafe Events, do the following:

1.     Open Visual Studio and, from the Start page, choose New Project.

2.     Select Visual C# Projects from the tree view on the left side of the screen.

3.     Select Class Library as the project template.

4.     Set the name of the app  lication to VSSEvents and click OK to create the project.

5.     Highlight the file called Class1.cs in the Solution Explorer window and rename it to IvssEventSample.cs. Completely delete the code inserted by Visual Studio into this file.

6.     In project properties Build Configuration set Register for COM Interop to true.

7.     To use the Runtime Callable Wrapper (RCW) for the SSAPI.DLL COM component, select References under VSSEvents Project, use right mouse button and then select Add Reference. Make sure that the .NET tab is selected, and use Select button to select IVSS Microsoft.VisualStudio.SourceSafe.Interop.dll PIA. This will add the component to the Selected Components list. Click OK.

8.     To have access to System.Windows.Forms namespace classes, select References under VSSEvents Project, use right mouse button and then select Add Reference. Make sure that the .NET tab is selected, and use Select button to select System.Windows.Forms.dll. This will add the component to the Selected Components list. Click OK.

Add Sample Code

The following example demonstrates how to trap VSS events

  • Paste the code below into IvssEventSample.cs:

Copy Code

using System;

using System.Runtime.InteropServices;

using System.Runtime.InteropServices.ComTypes;

using System.Windows.Forms;

using Microsoft.VisualStudio.SourceSafe.Interop;

 

namespace IvssEventSample

{

      // Use attributes to declare a fixed Prog ID and Guid for the Add-In.

      [ProgId("Microsoft.SourceSafe.EventSample")]

      [Guid("E1916BD8-A8AA-47b7-A862-C1AF995E64EF")]

      [ComVisible(true)]

      public class IvssEventSample : IVSSEventHandler, IVSSEvents

      {

            private VSSApp vssApp;

            IConnectionPoint vssEvents;

            int cookie;

 

            public IvssEventSample()

            {

            }

 

            ~IvssEventSample()

            { }

 

            public void Init(VSSApp app)

            {

                  MessageBox.Show("Init");

 

                  // by saving the VSSApp pointer you can drive the database during events

                  this.vssApp = app;

 

                  // Wire up the COM connection point manually

                  IConnectionPointContainer cpc = (IConnectionPointContainer)app;

                  Guid guid = typeof(IVSSEvents).GUID;

                  cpc.FindConnectionPoint(ref guid, out vssEvents);

                  vssEvents.Advise(this, out cookie);

            }

 

            public void AfterAdd(VSSItem vssItem, string localSpec, string comment)

            {

                  MessageBox.Show("AfterAdd");

            }

 

            public void AfterBranch(VSSItem vssItem, string comment)

            {

                  MessageBox.Show("AfterBranch");

            }

 

            public void AfterCheckin(VSSItem vssItem, string localSpec, string comment)

            {

                  MessageBox.Show("AfterCheckin");

            }

 

            public void AfterCheckout(VSSItem vssItem, string localSpec, string comment)

            {

                  MessageBox.Show("AfterCheckout");

            }

 

            public void AfterEvent(int eventNum, VSSItem vssItem, string str, object var)

            {

                  // Use of this event is deprecated

            }

 

            public void AfterRename(VSSItem vssItem, string oldName)

            {

                  MessageBox.Show("AfterRename");

            }

 

            public void AfterUndoCheckout(VSSItem vssItem, string localSpec)

            {

                  MessageBox.Show("AfterUndoCheckout");

            }

 

            public bool BeforeAdd(VSSItem vssItem, string localSpec, string comment)

            {

                  MessageBox.Show("BeforeAdd");

                  return true;

            }

 

            public bool BeforeBranch(VSSItem vssItem, string comment)

            {

                  MessageBox.Show("BeforeBranch");

                  return true;

            }

 

            public bool BeforeCheckin(VSSItem vssItem, string localSpec, string comment)

            {

                  MessageBox.Show("BeforeCheckin");

                  System.Threading.Thread.Sleep(10000);

                  return true;

            }

 

            public bool BeforeCheckout(VSSItem vssItem, string localSpec, string comment)

            {

                  MessageBox.Show("BeforeCheckout");

                  return true;

            }

 

            public bool BeforeEvent(int eventNum, VSSItem vssItem, string str, object var)

            {

                  // Use of this event is deprecated

                  return true;

            }

 

            public bool BeforeRename(VSSItem vssItem, string oldName)

            {

                  MessageBox.Show("BeforeRename");

                  return true;

            }

 

            public bool BeforeUndoCheckout(VSSItem vssItem, string localSpec)

            {

                  MessageBox.Show("BeforeUndoCheckout");

                  return true;

            }

 

            public bool BeginCommand(int unused)

            {

                  // use of this event is deprecated

                  return true;

            }

 

            public void EndCommand(int unused)

            {

                  // Use of this event is deprecated

            }

      }

}

Configure Visual SourceSafe

To configure Visual SourceSafe do the following:

1.     Create a file named ssaddin.ini that contains the following statement:

Copy Code

Microsoft.SourceSafe.EventSample = 1

Double check that the ProgID in IvssEventSample.cs is the same as this statement in your ssaddin.ini file.

2.     Place this file into the same folder as ssapi.dll (usually /Microsoft Visual Studio/VSS/win32).

Test the Application

To test the application do the following:

1.     Build the VSSEvents DLL.

2.     Start Visual SourceSafe Explorer. While performing the operations that have corresponding event handlers in IvssEventSample.cs you should be able to observe message boxes pop up. For example, while checking out a file you will observe two dialogs. The first dialog will contain “BeforeCheckout” message, the second dialog – “AfterCheckout”.

Note: this add-in can be effective even when using it in Visual studio 2005.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值