. NET operations in Visual SourceSafe

Source: Internet
Author: User
Tags deprecated

Recently collated some information, found a piece of code previously written, provides some operations on Microsoft's version management software Visual SourceSafe. The following is referred to as VSS.

Think of the time before writing, because the information is scarce, can only study side test, took a lot of detours.

For some personal reasons (a little forgetful, a little lazy), has not been shared. Today, while a little empty, brush blog.

PS: The previous drawing of the C language header file containing the diagram of the gadget (http://www.cnblogs.com/geeking/p/4021044.html), I do not know that we found that there are many bugs. The main focus is on header file circular references and a large number of node draws. (experiments have found that when plotting a large number of nodes, the TREEGX control is best visible false.) A "System.InvalidOperationException" error is raised when a node is added, as if the control would trigger an internal flush operation when adding a "visible" node. The new version v2.0 updated later.

Anyway

In. NET for VSS operations, refer to Interop.SourceSafeTypeLib.dll first, and namespace using Sourcesafetypelib;

Well, the computer is too garbage, I will not open vs. Attach the project document for reference:

<reference include= "Interop.sourcesafetypelib, version=5.2.0.0, culture=neutral, ProcessorArchitecture=MSIL" > <SpecificVersion>False</SpecificVersion>

I extract the specific actions for VSS in the VSSHelper.cs file.

Using system;using system.collections.generic;using system.linq;using system.text;using SourceSafeTypeLib;using system.io;using system.windows.forms;namespace docksample{public static class Vsshelper {public static stri        ng Workpath = "";        private static string root = "$/";        private static Vssdatabaseclass db = new Vssdatabaseclass (); <summary>///Check whether VSS is turned on, turned on returns true, not turned back false///</summary>//&LT;RETURNS&GT;&LT;/R                eturns> public static bool Checkvssopen () {try {//vss does not provide a field for which the flag is open So call the Get_vssitem method, if the exception code thrown 2147210253 proves that the open//non-throwing exception proves that the connection has been opened VSSItem VSSItem                = Db.get_vssitem (root, false);                VSSItem = null;            return true; }//catch (System.Runtime.InteropServices.COMException Comex)//{//if (Comex.     ErrorCode = =-2147210253)//{       MessageBox.Show ("You have not logged in vss\r\n please login and retry", "error");            }//return false; } catch (Exception ex) {System.Diagnostics.Debug.WriteLine (ex.                Message);            return false; }}///<summary>//Open VSS, return True open successfully, false not opened////&LT;PA Ram Name= "Vssinipath" ></param>//<param name= "user" ></param>//<param name= "pwd" ></param>//<returns></returns> public static bool Openvss (string Vssinipath, String                User, string pwd) {try {//Avoid repeated open error if (!checkvssopen ()) {db.                Open (Vssinipath, user, PWD);                } else {MessageBox.Show ("Connection already open \ r \ n Do not repeat open", "hint");            #region Test Code:    Creatsub (@ "F:\ceshi", root);                creat (@ "F:\ceshi");            #endregion return true; } catch (System.Runtime.InteropServices.COMException Comex) {System.Diagnostics.Debu G.writeline (Comex.                Message);            return false; } catch (Exception ex) {System.Diagnostics.Debug.WriteLine (ex.                Message);            return false; }} #region deprecated//public static void creat (String parentpath)//{////if (Workpath = = String.        Empty)////{////return;        }//DirectoryInfo dirinfo = new DirectoryInfo (Parentpath);        Try//{//VSSItem VSSItem = Db.get_vssitem (root, false);        Vssitem.newsubproject (Dirinfo.name, "created"); }//catch (Exception ex)//{//System.diagnosTics. Debug.WriteLine (ex.        Message);        }//Creatsub (Parentpath, Root); } #endregion public static bool Creatsub (string path, string vssroot) {if (Directory.ex                ists (Path)) {DirectoryInfo dirinfo = new DirectoryInfo (path);                fileinfo[] Fileinfos = Dirinfo.getfiles ();                directoryinfo[] Subdirinfos = Dirinfo.getdirectories ();                VSSItem VSSItem = Db.get_vssitem (Vssroot, false); Add all files in the directory (exclude. scc files) to VSS foreach (FileInfo FileInfo in Fileinfos) {T                            ry {if (fileInfo.Extension.ToLower () = ". SCC") {                        Add local files to VSS Vssitem.add (Fileinfo.fullname, "add", 0); }} catch (Exception ex) {System. Diagnostics.Debug.WriteLine (ex.                        Message);                    return false; }}//Use recursion to create a VSS engineering directory structure based on the local directory structure foreach (DirectoryInfo subdirinfo in Subdirinf                        OS) {try {//Create VSS Sub-project (subdirectory)                        Vssitem.newsubproject (Subdirinfo.name, "created");                        Recursive call to build the underlying directory structure (engineering structure) of the current processing directory if (!creatsub (subdirinfo.fullname, vssroot + subdirinfo.name + "/"))                        {return false; }} catch (Exception ex) {System.diagnost Ics. Debug.WriteLine (ex.                        Message);                    return false;            }} return true;         } else {MessageBox.Show ("directory:" + path + "does not exist", "error");       return false;  }} public static bool CheckOut (string Vsspath, String localPath) {return Execmd (Vsspath,            LocalPath, "Checkout");            #region Discard//try//{//VSSItem VSSItem = Db.get_vssitem (Vsspath, false); Type==0 project folder, type==1 project file//////If the current checkout is a single file, then checkout directly returns//if (VSSItem. Type = = 1)//{//VSSItem.            Checkout ("Checkout", LocalPath, 0);            return true; }////If checkout is a directory, then all files in the recursive directory,///Include files in subdirectories.            And put all files checkout//Ivssitems Ivssitems = Vssitem.get_items (false); Prevent path structure error//LocalPath = Localpath.endswith (@ "\")?            Localpath:localpath + @ "\"; Vsspath = Vsspath.endswith ("/")?            Vsspath:vsspath + "/"; foreach (Ivssitem ivssitem in Ivssitems)//{            if (Ivssitem. Type = = 1)//{////project file, direct checkout//Ivssitem. Checkout ("Checkout", LocalPath + Ivssitem.            Name, 0); }//Else if (ivssitem. Type = = 0)//{////project folder, recursive call checkout function//bool temp = che Ckout (Vsspath + ivssitem. Name, LocalPath + ivssitem.            Name);            if (!temp)//{//return false;            }//}//}//return true; }//catch (Exception ex)//{//System.Diagnostics.Debug.WriteLine (ex.            Message);            return false;        } #endregion} private static bool Execmd (string Vsspath, String localPath, string cmd) {try {VSSItem VSSItem = Db.get_vssitem (Vsspath, false); Type==0 project folder, type==1 project file if (VSSItem. Type = = 1) {switch (cmd). ToLower ()) {case "checkout": if (VSSItem. Ischeckedout = = 0) {VSSItem.                                Checkout (cmd, localPath, 0);                            return true;                            } MessageBox.Show ("Do not repeat checkout", "hint");                        return false; Case "Checkin": if (VSSItem. Ischeckedout! = 0) {VSSItem.                                Checkin (cmd, localPath, 0);                            return true;                            } MessageBox.Show ("Please checkout First", "hint");                        return false;                       Case "GET":     VSSItem.                            Get (ref localPath, 0);                        return true;                    Default:break;                }} Ivssitems Ivssitems = Vssitem.get_items (false); Prevent path structure Error LocalPath = Localpath.endswith (@ "\")?                Localpath:localpath + @ "\"; Vsspath = Vsspath.endswith ("/")?                Vsspath:vsspath + "/"; foreach (Ivssitem ivssitem in Ivssitems) {if (Ivssitem. Type = = 1)//project file {string Tmplocalpath = LocalPath + Ivssitem.                        Name; Switch (cmd. ToLower ()) {case "checkout": if (ivssite M.ischeckedout = = 0) {Ivssitem.                                Checkout (cmd, tmplocalpath, 0);                                }Break Case "Checkin": if (Ivssitem. Ischeckedout! = 0) {Ivssitem.                                Checkin (cmd, tmplocalpath, 0);                            } break; Case "get": Ivssitem.                                Get (ref tmplocalpath, 0);                            Break                        Default:break; }} else if (Ivssitem. Type = = 0)//project folder {//recursive call checkin function bool temp = EXECM D (Vsspath + ivssitem. Name, LocalPath + ivssitem.                        Name, CMD);                        if (!temp) {return false;            }}} return true; } catch (SystEm.Runtime.InteropServices.COMException Comex) {if (Comex.                    ErrorCode = = -2147210253) {MessageBox.Show ("You have not logged in vss\r\n please login and retry", "error");                    Frmvsslogin frm = new Frmvsslogin (); frm.                ShowDialog ();            } return false; } catch (Exception ex) {System.Diagnostics.Debug.WriteLine (ex.                Message);            return false; }} public static bool CheckIn (string Vsspath, String localPath) {return Execmd (Vsspath,            LocalPath, "checkin");            #region Discard//try//{//VSSItem VSSItem = Db.get_vssitem (Vsspath, false); if (VSSItem.            Type = = 1)//{////ischeckedout==0 not checkout////If checkout, then checkin if (VSSItem.   Ischeckedout! = 0)//{//         VSSItem. VSSItem.            Checkin ("Checkin", LocalPath, 0);            return true;            }//}//Ivssitems Ivssitems = Vssitem.get_items (false); Prevent path structure error//LocalPath = Localpath.endswith (@ "\")?            Localpath:localpath + @ "\"; Vsspath = Vsspath.endswith ("/")?            Vsspath:vsspath + "/"; foreach (Ivssitem ivssitem in Ivssitems)//{//if (Ivssitem. Type = = 1)//{//if (Ivssitem. Ischeckedout! = 0)//{//Ivssitem. Checkin ("Checkin", LocalPath + Ivssitem.            Name, 0); }//}//Else if (ivssitem. Type = = 0)//{////project folder, recursive call checkin function//BOOL temp = CHEC KIn (Vsspath + ivssitem. Name, LocalPath + ivssiteM.name);            if (!temp)//{//return false;            }//}//}//return true; }//catch (Exception ex)//{//System.Diagnostics.Debug.WriteLine (ex.            Message);            return false; } #endregion} public static bool Get (string Vsspath, String localPath) {RE        Turn Execmd (Vsspath, LocalPath, "get"); } #region deprecated//public static bool CheckOut (string Vsspath, String LocalPath, String selectfilename)/        /{//try//{//VSSItem VSSItem = Db.get_vssitem (Vsspath, false);        Ivssitems Ivssitems = Vssitem.get_items (false); LocalPath = Localpath.endswith (@ "\")?        Localpath:localpath + @ "\";    foreach (Ivssitem ivssitem in Ivssitems)//    {//if (Ivssitem. Name = = selectfilename)//{//Ivssitem. Checkout ("Checkout", LocalPath + Ivssitem.        Name, 0);        }//}//return true; }//catch (Exception ex)//{//System.Diagnostics.Debug.WriteLine (ex.        Message);        return false; }//} #endregion}}

 

private void Btnbrowse_click (object sender, EventArgs e) {OpenFileDialog ofd = new OpenFileDialog ()            {Filter = "VSS config file |*.ini", Title = "Open VSS database File"}; if (OFD. ShowDialog () = = DialogResult.OK) {Tboxvss.text = ofd.            FileName;                                     }} private void Btnlogin_click (object sender, EventArgs e) {string[] Messboxtext ={ "VSS Open Error!" \ r \ n Please check configuration retry. "," The VSS configuration file does not exist!            "                                  };            if (Tboxvss.text = = "") {return; } if (System.IO.File.Exists (Tboxvss.text)) {//Open VSS if (vsshelper.ope Nvss (Tboxvss.text, Tboxusername.text, Tboxpassword.text)) {this.                Close (); } else {//if (MeSsagebox.show (messboxtext[0], "error", Messageboxbuttons.retrycancel, messageboxicon.error)! = DialogResult.Retry) {//this.                    Close ();                } MessageBox.Show (Messboxtext[0], "error", MessageBoxButtons.OK, Messageboxicon.error); }} else {MessageBox.Show (messboxtext[1], "error", MessageBoxButtons.OK, Mes            SAGEBOXICON.ERROR); }        }

. NET operations in Visual SourceSafe

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.