private void Deploy()
{
TfsTeamProjectCollection collection;
// if setting "Domen" in config file initialized - it means that test run on the local machine,
// otherwise means that test run on the specialized testing machine
if (string.IsNullOrEmpty(ConfigHelper.Instance.Domen))
collection = new TfsTeamProjectCollection(new Uri(ConfigHelper.Instance.TestCollection));
else
collection = new TfsTeamProjectCollection(
new Uri(ConfigHelper.Instance.TestCollection),
new NetworkCredential(ConfigHelper.Instance.Login, ConfigHelper.Instance.Password, ConfigHelper.Instance.Domen));
var vcs = collection.GetService<VersionControlServer>();
TeamProject tp = vcs.GetTeamProject(ConfigHelper.Instance.TestCollectionProject);
const string workspaceName = "MyWorkspace";
Workspace[] workspaces = vcs.QueryWorkspaces(workspaceName, vcs.AuthorizedUser, Workstation.Current.Name);
foreach (var workspace in workspaces)
{
foreach (var workingFolder in workspace.Folders)
{
if (Directory.Exists(workingFolder.LocalItem))
{
var files = Directory.GetFiles(workingFolder.LocalItem, "*.*", SearchOption.AllDirectories);
foreach (var file in files)
File.SetAttributes(file, File.GetAttributes(file) & ~FileAttributes.ReadOnly);
Directory.Delete(workingFolder.LocalItem, true);
}
workspace.DeleteMapping(workingFolder);
}
vcs.DeleteWorkspace(workspace.Name, vcs.AuthorizedUser);
}
string projectPath = tp.ServerItem;
string workingDirectory = ClonedRepoFolder;
Directory.CreateDirectory(workingDirectory);
_workspace = vcs.CreateWorkspace(workspaceName, vcs.AuthorizedUser, "Test Workspace");
try
{
_workspace.Map(projectPath, workingDirectory);
GetRequest request = new GetRequest(new ItemSpec(projectPath, RecursionType.Full), VersionSpec.Latest);
GetStatus status = _workspace.Get(request, GetOptions.GetAll | GetOptions.Overwrite);
}
catch
{
throw;
}
}