Click here to Skip to main content
15,886,731 members
Articles / Programming Languages / C#

Microsoft Visual Source Safe Client

Rate me:
Please Sign up or sign in to vote.
4.78/5 (29 votes)
20 Sep 2006CPOL3 min read 149.2K   4.1K   96  
Microsoft Visual Source Safe client which can notify of check-ins.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using SourceSafeTypeLib;
using System.Threading;
namespace VSSClient
{
	/// <summary>
	/// Summary description for frmHistory.
	/// </summary>
	public class frmHistory : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.TextBox txtUserName;
		private System.Windows.Forms.Panel panel2;
		private System.Windows.Forms.Splitter splitter1;
		private System.Windows.Forms.ListView lvFileList;
		private System.Windows.Forms.ColumnHeader colProject;
		private System.Windows.Forms.ColumnHeader colName;
		private System.Windows.Forms.ColumnHeader colUser;
		private System.Windows.Forms.ColumnHeader colDateTime;
		private System.Windows.Forms.ColumnHeader colVersion;
		private System.Windows.Forms.ColumnHeader colAction;
		private System.Windows.Forms.Button btnShowHistory;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox txtComments;
		private System.Windows.Forms.DateTimePicker dtTo;
		private System.Windows.Forms.DateTimePicker dtFrom;
		private System.Windows.Forms.StatusBar statusBar1;
		private System.Windows.Forms.CheckBox chkFrom;
		private System.Windows.Forms.CheckBox chkTo;
		private System.Windows.Forms.CheckBox chkName;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmHistory()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			this.Closing+=new CancelEventHandler(frmHistory_Closing);
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.panel1 = new System.Windows.Forms.Panel();
			this.btnShowHistory = new System.Windows.Forms.Button();
			this.dtTo = new System.Windows.Forms.DateTimePicker();
			this.dtFrom = new System.Windows.Forms.DateTimePicker();
			this.txtUserName = new System.Windows.Forms.TextBox();
			this.panel2 = new System.Windows.Forms.Panel();
			this.statusBar1 = new System.Windows.Forms.StatusBar();
			this.txtComments = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.splitter1 = new System.Windows.Forms.Splitter();
			this.lvFileList = new System.Windows.Forms.ListView();
			this.colProject = new System.Windows.Forms.ColumnHeader();
			this.colVersion = new System.Windows.Forms.ColumnHeader();
			this.colName = new System.Windows.Forms.ColumnHeader();
			this.colUser = new System.Windows.Forms.ColumnHeader();
			this.colDateTime = new System.Windows.Forms.ColumnHeader();
			this.colAction = new System.Windows.Forms.ColumnHeader();
			this.chkFrom = new System.Windows.Forms.CheckBox();
			this.chkTo = new System.Windows.Forms.CheckBox();
			this.chkName = new System.Windows.Forms.CheckBox();
			this.panel1.SuspendLayout();
			this.panel2.SuspendLayout();
			this.SuspendLayout();
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.chkName);
			this.panel1.Controls.Add(this.chkTo);
			this.panel1.Controls.Add(this.btnShowHistory);
			this.panel1.Controls.Add(this.dtTo);
			this.panel1.Controls.Add(this.dtFrom);
			this.panel1.Controls.Add(this.txtUserName);
			this.panel1.Controls.Add(this.chkFrom);
			this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
			this.panel1.Location = new System.Drawing.Point(0, 0);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(728, 80);
			this.panel1.TabIndex = 0;
			// 
			// btnShowHistory
			// 
			this.btnShowHistory.Location = new System.Drawing.Point(16, 48);
			this.btnShowHistory.Name = "btnShowHistory";
			this.btnShowHistory.Size = new System.Drawing.Size(88, 23);
			this.btnShowHistory.TabIndex = 6;
			this.btnShowHistory.Text = "Show History";
			this.btnShowHistory.Click += new System.EventHandler(this.btnShowHistory_Click);
			// 
			// dtTo
			// 
			this.dtTo.Location = new System.Drawing.Point(520, 17);
			this.dtTo.Name = "dtTo";
			this.dtTo.Size = new System.Drawing.Size(192, 20);
			this.dtTo.TabIndex = 5;
			// 
			// dtFrom
			// 
			this.dtFrom.Location = new System.Drawing.Point(280, 17);
			this.dtFrom.Name = "dtFrom";
			this.dtFrom.Size = new System.Drawing.Size(184, 20);
			this.dtFrom.TabIndex = 3;
			// 
			// txtUserName
			// 
			this.txtUserName.Location = new System.Drawing.Point(96, 17);
			this.txtUserName.Name = "txtUserName";
			this.txtUserName.Size = new System.Drawing.Size(128, 20);
			this.txtUserName.TabIndex = 1;
			this.txtUserName.Text = "";
			// 
			// panel2
			// 
			this.panel2.Controls.Add(this.statusBar1);
			this.panel2.Controls.Add(this.txtComments);
			this.panel2.Controls.Add(this.label4);
			this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.panel2.Location = new System.Drawing.Point(0, 222);
			this.panel2.Name = "panel2";
			this.panel2.Size = new System.Drawing.Size(728, 152);
			this.panel2.TabIndex = 1;
			// 
			// statusBar1
			// 
			this.statusBar1.Location = new System.Drawing.Point(0, 130);
			this.statusBar1.Name = "statusBar1";
			this.statusBar1.Size = new System.Drawing.Size(728, 22);
			this.statusBar1.TabIndex = 2;
			this.statusBar1.Text = "Ready";
			// 
			// txtComments
			// 
			this.txtComments.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.txtComments.Location = new System.Drawing.Point(80, 8);
			this.txtComments.Multiline = true;
			this.txtComments.Name = "txtComments";
			this.txtComments.ReadOnly = true;
			this.txtComments.Size = new System.Drawing.Size(640, 120);
			this.txtComments.TabIndex = 1;
			this.txtComments.Text = "";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(15, 8);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(64, 16);
			this.label4.TabIndex = 0;
			this.label4.Text = "Comments";
			// 
			// splitter1
			// 
			this.splitter1.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.splitter1.Location = new System.Drawing.Point(0, 219);
			this.splitter1.Name = "splitter1";
			this.splitter1.Size = new System.Drawing.Size(728, 3);
			this.splitter1.TabIndex = 2;
			this.splitter1.TabStop = false;
			// 
			// lvFileList
			// 
			this.lvFileList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																						 this.colProject,
																						 this.colVersion,
																						 this.colName,
																						 this.colUser,
																						 this.colDateTime,
																						 this.colAction});
			this.lvFileList.Dock = System.Windows.Forms.DockStyle.Fill;
			this.lvFileList.FullRowSelect = true;
			this.lvFileList.Location = new System.Drawing.Point(0, 80);
			this.lvFileList.Name = "lvFileList";
			this.lvFileList.Size = new System.Drawing.Size(728, 139);
			this.lvFileList.TabIndex = 5;
			this.lvFileList.View = System.Windows.Forms.View.Details;
			this.lvFileList.SelectedIndexChanged += new System.EventHandler(this.lvFileList_SelectedIndexChanged);
			// 
			// colProject
			// 
			this.colProject.Text = "Project";
			this.colProject.Width = 150;
			// 
			// colVersion
			// 
			this.colVersion.Text = "Version";
			// 
			// colName
			// 
			this.colName.Text = "Name";
			this.colName.Width = 150;
			// 
			// colUser
			// 
			this.colUser.Text = "User";
			this.colUser.Width = 100;
			// 
			// colDateTime
			// 
			this.colDateTime.Text = "Date Time";
			this.colDateTime.Width = 130;
			// 
			// colAction
			// 
			this.colAction.Text = "Action";
			this.colAction.Width = 400;
			// 
			// chkFrom
			// 
			this.chkFrom.Location = new System.Drawing.Point(232, 17);
			this.chkFrom.Name = "chkFrom";
			this.chkFrom.Size = new System.Drawing.Size(56, 24);
			this.chkFrom.TabIndex = 7;
			this.chkFrom.Text = "From";
			// 
			// chkTo
			// 
			this.chkTo.Location = new System.Drawing.Point(480, 17);
			this.chkTo.Name = "chkTo";
			this.chkTo.Size = new System.Drawing.Size(40, 24);
			this.chkTo.TabIndex = 8;
			this.chkTo.Text = "To";
			// 
			// chkName
			// 
			this.chkName.Location = new System.Drawing.Point(16, 17);
			this.chkName.Name = "chkName";
			this.chkName.Size = new System.Drawing.Size(80, 24);
			this.chkName.TabIndex = 9;
			this.chkName.Text = "User Name";
			// 
			// frmHistory
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(728, 374);
			this.Controls.Add(this.lvFileList);
			this.Controls.Add(this.splitter1);
			this.Controls.Add(this.panel2);
			this.Controls.Add(this.panel1);
			this.Name = "frmHistory";
			this.Text = "History";
			this.panel1.ResumeLayout(false);
			this.panel2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private VSSItem item;
		public void ShowHistory(VSSItem childItem)
		{
			this.item = childItem;
			this.ShowDialog();
		}

		private void btnShowHistory_Click(object sender, System.EventArgs e)
		{
			lvFileList.Items.Clear();
			Thread th=new Thread(new ThreadStart(StartLoadHistory));
			th.IsBackground=true;
			th.Start();
		}
		private void StartLoadHistory()
		{
			this.statusBar1.Text="Please wait...";
			LoadHistory(item,item.Parent.Name);
			this.statusBar1.Text="Ready";
		}
		private bool IsAfter(IVSSVersion version,DateTime date)
		{
			TimeSpan ts = date.Subtract(version.Date);
			if(ts.TotalMilliseconds>=0)
				return true;
			return false;
		}
		private double GetDayDiff(DateTime date1, DateTime date2)
		{
			DateTime d1=new DateTime(date1.Year,date1.Month,date1.Day);
			DateTime d2=new DateTime(date2.Year,date2.Month,date2.Day);
			TimeSpan ts= d1.Subtract(d2);
			return ts.TotalDays;
		}
		private bool IsBefore(IVSSVersion version,DateTime date)
		{
			TimeSpan ts = date.Subtract(version.Date);
			if(ts.TotalMilliseconds<=0)
				return true;
			return false;
		}
		private void AddHistory(VSSItem childItem,string ProjectName)
		{
			if (childItem.Type==1)
			{
				IVSSVersions versions = childItem.get_Versions(0);
				bool flag;
				foreach (IVSSVersion version in versions)
				{
					flag=false;
					if(chkName.Checked)
					{
						if(version.Username.ToLower()!=this.txtUserName.Text.ToLower())
							flag=true;
					}
					if(!flag&&chkFrom.Checked)
					{
						if(GetDayDiff(dtFrom.Value,version.Date)>0)
							flag=true;
					}
					if(!flag&&chkTo.Checked)
					{
						if(GetDayDiff(dtTo.Value,version.Date)<0)
							flag=true;
					}
					if(!flag)
					{
						lvFileList.Invoke(new AddItemDelegate(AddItem),new object [] {version,childItem.Name,ProjectName});
					}
				}
			}
		}
		private bool IsStopRequested
		{
			get
			{
				Mutex m=new Mutex(false,"VSS_HISTORY");
				if (m.WaitOne(0,false)==true)
				{
					m.ReleaseMutex();
					return false;
				}
				else
				{
					return true;
				}
			}
			set
			{
				if (value==true)
				{
					Mutex m=new Mutex(false,"VSS_HISTORY");
					m.WaitOne();
					Thread.Sleep(1000);
					m.ReleaseMutex();
				}
			}
		}
		private void LoadHistory(VSSItem item,string ProjectName)
		{
			if (IsStopRequested)
			{
				return;
			}
			AddHistory(item,ProjectName);
			if (item.Type==0)
			{
				IVSSItems childItems = item.get_Items(false);
				if (childItems != null && childItems.Count > 0)
				{
					if (IsStopRequested)
					{
						return;
					}
					foreach(VSSItem childItem in childItems)
					{
						AddHistory(childItem,ProjectName);
						if (childItem.Type==0)
						{
							LoadHistory(childItem,ProjectName+"/"+childItem.Name);
						}
					}
				}
			}
		}
		private void AddItem(IVSSVersion version,string Name,string ProjectName)
		{
			ListViewItem item;
			item = new ListViewItem();
			item.Text=ProjectName+"/";
			item.SubItems.Add(version.VersionNumber.ToString());
			item.Tag=version;
			item.SubItems.Add(Name);
			item.SubItems.Add(version.Username);
			item.SubItems.Add(version.Date.ToString());
			item.SubItems.Add(version.Action);
			lvFileList.Items.Add(item);
			
		}

		private void lvFileList_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (lvFileList.SelectedItems.Count>0)
			{
				IVSSVersion version=(IVSSVersion)lvFileList.SelectedItems[0].Tag;
				this.txtComments.Text=version.Comment;
			}
		}
	
		public delegate void AddItemDelegate(IVSSVersion version,string Name,string ProjectName);

		private void frmHistory_Closing(object sender, CancelEventArgs e)
		{
			IsStopRequested=true;
		}
	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


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

Comments and Discussions