All methods except AddFortressItem will work with either the Vault or Fortress API, AddFortressItem requires Fortress.
Code: Select all
using System;
using System.Collections.Generic;
using System.Text;
using VaultClientIntegrationLib;
using VaultClientOperationsLib;
using VaultLib;
using MantisLib;
using System.IO;
using System.Xml;
namespace Examples
{
class Program
{
static void Main(string[] args)
{
// Call a method here to test it out after changing the relevant variables.
}
static void BasicSourceControl()
{
string url = "http://VaultServer/VaultService";
string username = "username";
string password = "password";
string repository = "Your Repository";
// Set the login options and login/connect to a repository.
ServerOperations.client.LoginOptions.URL = url;
ServerOperations.client.LoginOptions.User = username;
ServerOperations.client.LoginOptions.Password = password;
ServerOperations.client.LoginOptions.Repository = repository;
ServerOperations.Login();
//Create a folder.
string pathToANewFolder = "$/path/to/a/newFolder";
ServerOperations.ProcessCommandCreateFolder(pathToANewFolder);
//Add two files to the new folder.
string pathToFile1 = "c:/path/to/a/file";
string pathToFile2 = "c:/path/to/another/file";
string folderToAddItemsTo = "$/path/to/a/folder/";
ServerOperations.client.AutoCommit = true;
ServerOperations.ProcessCommandAdd(folderToAddItemsTo, new string[] { pathToFile1, pathToFile2 });
}
static void MoreBasicSourceControl()
{
string url = "http://VaultServer/VaultService";
string username = "username";
string password = "password";
string repository = "Your Repository";
// Set the login options and login/connect to a repository.
ServerOperations.client.LoginOptions.URL = url;
ServerOperations.client.LoginOptions.User = username;
ServerOperations.client.LoginOptions.Password = password;
ServerOperations.client.LoginOptions.Repository = repository;
ServerOperations.Login();
// Set a working folder.
string repositoryFolderPath = "$/path/to/a/repository/folder/";
string diskPath = "c:/path/to/a/working/folder/";
bool bCreateDiskPath = true;
ServerOperations.SetWorkingFolder(repositoryFolderPath, diskPath, bCreateDiskPath);
// Do a get on the working folder.
GetOptions getOptions = new GetOptions();
getOptions.Recursive = true;
GetOperations.ProcessCommandGet(new string[] { diskPath }, getOptions);
// Exclusively check out a file.
getOptions = new GetOptions();
string filePath = "$/path/to/a/file";
bool bExclusive = true;
bool bGetLatest = true;
ServerOperations.ProcessCommandCheckout(new string[] { filePath }, bExclusive, bGetLatest, getOptions);
// List all checkouts.
VaultClientCheckOutList coList = ServerOperations.ProcessCommandListCheckOuts();
// output the checkout list
StringWriter sw = new StringWriter();
System.Xml.XmlTextWriter xml = new XmlTextWriter(sw);
xml.Formatting = System.Xml.Formatting.Indented;
xml.WriteStartElement("root");
xml.WriteStartElement("ListCheckOuts");
XmlHelper.XmlOutput(xml, coList);
xml.WriteEndElement();
// Check in the file we just checked out, set the unchanged handler to check in the item (the default unchanged op is Undo Checkout).
bool bKeepCheckedOut = false;
ServerOperations.ProcessCommandCheckIn(new string[] { filePath }, UnchangedHandler.Checkin, bKeepCheckedOut, LocalCopyType.Leave);
//Query the file history so we can view the check in.
bool bRecursive = false;
int beginVersion = -1;
int endVersion = -1;
VaultHistoryItem[] items = ServerOperations.ProcessCommandHistory(filePath, bRecursive, DateSortOption.desc, null, null, VaultDate.EmptyDate().ToString(), VaultDate.EmptyDate().ToString(), null, null, beginVersion, endVersion, 10);
// output the history items
xml.WriteStartElement("root");
xml.WriteStartElement("History");
XmlHelper.XmlOutput(xml, items);
xml.WriteEndElement();
xml.Close();
Console.Out.WriteLine(sw.ToString());
}
public static void WildcardTasks()
{
string url = "http://VaultServer/VaultService";
string username = "username";
string password = "password";
string repository = "Your Repository";
// Set the login options and login/connect to a repository.
ServerOperations.client.LoginOptions.URL = url;
ServerOperations.client.LoginOptions.User = username;
ServerOperations.client.LoginOptions.Password = password;
ServerOperations.client.LoginOptions.Repository = repository;
ServerOperations.Login();
ServerOperations.client.AutoCommit = true;
// add some files to use with wildcard tasks
string pathToFile1 = "c:/path/to/wildcard1.txt";
string pathToFile2 = "c:/path/to/wildcard2.txt";
string pathToFile3 = "c:/path/to/wildcardWithLetters.txt";
string folderPath = "$/a/folder/";
ServerOperations.ProcessCommandAdd(folderPath, new string[] { pathToFile1, pathToFile2, pathToFile3 });
// get all three wildcards to a nonworking folder
string wildcardStr = "wildcard*.txt";
GetOptions getOptions = new GetOptions();
string nonworkingFolderPath = "c:/path/to/nonworkingFolderForWildcards/";
GetOperations.ProcessCommandGetWildcardToNonWorkingFolder(folderPath, new string[] { wildcardStr }, getOptions, nonworkingFolderPath);
// get wildcard1.txt and wildcard2.txt to a working folder
wildcardStr = "wildcard?.txt";
string workingFolderPath = "c:/path/to/aWorkingFolder/";
GetOperations.ProcessCommandGetWildcard(workingFolderPath, new string[] {wildcardStr}, getOptions);
}
public static void LabelTasks()
{
string url = "http://VaultServer/VaultService";
string username = "username";
string password = "password";
string repository = "Your Repository";
// Set the login options and login/connect to a repository.
ServerOperations.client.LoginOptions.URL = url;
ServerOperations.client.LoginOptions.User = username;
ServerOperations.client.LoginOptions.Password = password;
ServerOperations.client.LoginOptions.Repository = repository;
ServerOperations.Login();
ServerOperations.client.AutoCommit = true;
// Label the current version of a folder
string objectPath = "$/path/to/a/folderToLabel/";
string labelName = "LabeledFolder";
long versionID = -1; //pass -1 to get the current version
ServerOperations.ProcessCommandLabel(objectPath, labelName, versionID);
// Get label to a location on disk
GetOptions getOptions = new GetOptions();
string destPath = "c:/path/to/labeledFolder/";
GetOperations.ProcessCommandGetLabelToLocationOutsideWorkingFolder(objectPath, labelName, null, getOptions, destPath);
}
public static void AddFortressItem()
{
string url = "http://FortressServer/VaultService";
string username = "username";
string password = "password";
// Set the login options and login/connect to a repository.
ServerOperations.client.LoginOptions.URL = url;
ServerOperations.client.LoginOptions.User = username;
ServerOperations.client.LoginOptions.Password = password;
ServerOperations.Login();
// List the open fortress items
string projectName = "aProject";
MantisItemExpanded[] openItems = ItemTrackingOperations.ProcessCommandListOpenFortressItems(projectName);
// output the items
StringWriter sw = new StringWriter();
System.Xml.XmlTextWriter xml = new XmlTextWriter(sw);
xml.Formatting = System.Xml.Formatting.Indented;
xml.WriteStartElement("root");
xml.WriteStartElement("ListOpenFortressItems");
XmlHelper.XmlOutput(xml, openItems);
xml.WriteEndElement();
// Make a new fortress item
FortressItemExpanded newItem = new FortressItemExpanded();
newItem.ProjectName = projectName;
newItem.Description = "A new item.";
newItem.Details = "Some details about the new item.";
newItem.Status = "Open";
newItem.Assignee = "someUser";
newItem.Resolver = "anotherUser";
newItem.Platform = "Unknown";
newItem.ItemType = "Bug";
newItem.TimeEstimate = "Unknown";
newItem.Priority = "Low";
newItem.Validate(); // Call Validate after setting all your strings for your item and before you pass the item to a method.
// Add the new item
ItemTrackingOperations.ProcessCommandAddFortressItem(newItem);
// List the open fortress items again
openItems = ItemTrackingOperations.ProcessCommandListOpenFortressItems(projectName);
// output the items
xml.WriteStartElement("root");
xml.WriteStartElement("ListOpenFortressItems");
XmlHelper.XmlOutput(xml, openItems);
xml.WriteEndElement();
xml.Close();
Console.Out.WriteLine(sw.ToString());
}
}
}