I am explaining how to connect to Borland StarTeam Version Control System programmatically using C# console application and checkout files to local machine.
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
C# and Borland StarTeam Connectivity
1. C# and Borland-StarTeam Connectivity
Here I will explain-
What is Version ControlSystem.
What is Borland StarTeam.
How to connect to Borland StarTeam fromC# and Check Out Files to local
machine.
Version Control System:
Version Control is a systemthat records changes to a file or set of files over
time so that you can recall specific versions later.
A version controlsystemis mostly based around one concept, tracking
changes that happen within directories or files.
Ithelps teams to coordinate more effectively and team members to work in
parallel.
With version control systems you can do things like-
1. File Locking.
2. Branching and Merging.
3. Reverting back to older version of files.
For more information on version control please refer to this LINK.
Borland StarTeam
StarTeam is a versioncontrol system used in softwaredevelopment,
especially when a projectinvolves multiple teams in different locations.
StarTeam is created by StarbaseCorporation, which was acquired by
Borland in January 2003 which was acquired by Micro Focus after some
time.
StarTeam supports allthese features- branching and three-way merging,
difference analysis, advanced user access and security management,
checkpoints, end user and administrator auditing, view and revision labels,
promotion states and customization features.
2. For more information Go To StarTeam Site.
Connect to Borland StarTeam from C# and Check Out Files to local
machine
Now I will explain how you can connect to Starteam from C# and checkout the
files.
Few points to note-
StarTeam is a licensed product.you can register for a trial license here.
After registration you will get a usernameand password which you can use
to download .Net SDK for StarTeam.
SDK defers for the server version you are using. HereI am focusing on
StarTeam 2008 R2 which supports st-sdk-10.4.8.57-net-win.
With SDK you will get sampleapplication which you can refer to work on
your application.
Itwill create a help file by the name StarTeamSDK for .NET.chm
Now it is coding time ----------->I am writing a console application
//Create a console application
//Add reference to the dlls as shown below.
//These dlls you will get after installing SDK
using System;
3. using System.Collections.Generic;
using System.Linq;
using System.Web;
using StarTeam;
public class StarTeamHelper
{
//Declare Needed variables
//Indicates that all item types should be displayed.
public conststring ALL_TYPES = "*";
//Indicates that all views should be searched.
public conststring ALL_VIEWS ="*";
//Server TCP/IP address -- server fromwhich you wantto checkout files
private string m_strServer = "servername";
//Server port number
private int m_nPort= “PortNumber”;
//Logon user name --usernameto login to the server
private string m_strUser = "username";
//Logon password
private string m_strPassword ="password";
4. //Project name; null searches all projects
private string m_strProject= null;
//View name; null searches default view
private string m_strView = null;
//Folder path; null searches the root folder
private string m_strFolder = null;
//true if subfolders aresearched recursively
private bool m_bRecursive= true;
//List items last modified since this date
private DateTime m_cutoffDate = DateTime.Now;
//True to filter by m_cuttoffDate
private bool m_bUseDateFilter = false;
public static void Main(string[] args)
{
//Create the Server object.
Server stServer = new Server(m_strServer, m_nPort);
//LogOn to the server.
stServer.LogOn(m_strUser, m_strPassword);
5. // For each project on this server ...--itwill give list of projects to which we
have access
foreach (ProjectstProject in stServer.Projects)
{
// If no projectname was specified, search all projects.
if (m_strProject== null)
{
//use default view
View stView = stProject.DefaultView;
//To check out files we need to take help of CheckoutManager class
//create CheckoutManager object
CheckoutManager objCheckoutManager =
stView.CreateCheckoutManager();
//if file to be checked out with an exclusive lock
//(so no one else could checkout it while it is checked out).
objCheckoutManager.Options.LockType=Item.LockType.EXCLUSIVE;
/**********CHECKING OUTSINGLEFILE***************/
//By default, startsearching fromthe root folder.
Folder stFolder = stView.RootFolder;
6. //To check out single file useStarTeamFinder class's FindFile method
to find your file
//Syntax:File StarTeamFinder.FindFile(Folder source, string name, bool
matchCase);
File file = StarTeamFinder.FindFile(stFolder, "YourFileName", false);
//create the Target File
System.IO.FileInfo objFileInfo =new
System.IO.FileInfo("D:TargetFIle");
//Finally CHECK OUT the File
objCheckoutManager.CheckoutTo(file, objFileInfo);
/***********CHECKING OUT MULTIPLEFILES************/
/*Folder stFolder = stView.FindByName("FolderName",
true).RootFolder;
ItemCollection stItem= stFolder.GetItems("File");
//checks out file to default working folder. Wecan see this default
working folder using starteam client
objCheckoutManager.Checkout(stItem);*/
}
}
// Finally Disconnectfromserver.
stServer.Disconnect();