-
Notifications
You must be signed in to change notification settings - Fork 0
/
BranchConfig.cs
121 lines (97 loc) · 3.25 KB
/
BranchConfig.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//-----------------------------------------------------------------------
// <copyright file="BranchConfig.cs" company="Agilysys">
// Copyright (c) Agilysys Corporation. All rights reserved.
// </copyright>
// <summary>
// Class that models the the configuration for the branch.
// </summary>
//-----------------------------------------------------------------------
using System;
using System.IO;
using System.Threading.Tasks;
namespace BranchSwitcher
{
/// <summary>
/// Models the configuration for the branch.
/// </summary>
public class BranchConfig
{
/// <summary>
/// Branch name.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Branch root i.e. C:\TFS\8.7
/// </summary>
public string BranchRoot {get; set;}
/// <summary>
/// Sub path - C:\TFS\8.7\[Dev]
/// </summary>
public string BranchLeafPath { get; set; }
/// <summary>
/// The BranchRoot and BranchLeafPath combined. Full path to the "BranchRoot".
/// </summary>
public string FullPath
{
get
{
if (String.IsNullOrWhiteSpace(BranchRoot))
{
return string.Empty;
}
if (string.IsNullOrWhiteSpace(BranchLeafPath))
{
return BranchRoot;
}
else
{
return Path.Combine(BranchRoot, BranchLeafPath);
}
}
}
public BranchConfig(string branchName, string branchRoot, string branchLeafPath)
{
if (String.IsNullOrWhiteSpace(branchName))
{
throw new ArgumentNullException("branchName");
}
if (String.IsNullOrWhiteSpace(branchRoot))
{
throw new ArgumentNullException("branchRoot");
}
// BranchLeaf Path can be empty and we assume Main.
Name = branchName;
BranchRoot = branchRoot;
BranchLeafPath = branchLeafPath;
}
/// <summary>
/// Runs the SetBranch method asynchrounously.
/// </summary>
public void SetBranchAsync()
{
Task task = Task.Run((Action)SetBranch);
}
/// <summary>
/// Sets the environment variable for BranchRoot and BranchLeafPath if defined.
/// </summary>
public void SetBranch()
{
if (string.IsNullOrEmpty(BranchRoot))
{
Environment.SetEnvironmentVariable(Constants.BranchRoot, null, EnvironmentVariableTarget.User);
}
else
{
Environment.SetEnvironmentVariable(Constants.BranchRoot, BranchRoot, EnvironmentVariableTarget.User);
}
if (string.IsNullOrEmpty(BranchLeafPath))
{
Environment.SetEnvironmentVariable(Constants.BranchLeafPath, null, EnvironmentVariableTarget.User);
}
else
{
Environment.SetEnvironmentVariable(Constants.BranchLeafPath, BranchLeafPath, EnvironmentVariableTarget.User);
}
}
}
}