-
Notifications
You must be signed in to change notification settings - Fork 0
/
VariableViewModel.cs
42 lines (35 loc) · 1.4 KB
/
VariableViewModel.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
using Octopus.Client.Model;
using System;
using System.Collections.Generic;
using System.Linq;
public class VariableViewModel
{
public string VariableSetName { get; set; }
public string Name { get; set; }
public string Value { get; set; }
public string Scope { get; set; }
public VariableViewModel(VariableResource variable, string variableSetName, Dictionary<String, String> scopeNames)
{
Name = variable.Name;
Value = variable.Value;
VariableSetName = variableSetName;
var nonLookupRoles =
variable.Scope.Where(s => s.Key != ScopeField.Environment & s.Key != ScopeField.Machine & s.Key != ScopeField.Channel & s.Key != ScopeField.Action)
.ToDictionary(dict => dict.Key, dict => dict.Value);
foreach (var scope in nonLookupRoles)
{
if (string.IsNullOrEmpty(Scope))
Scope = String.Join(",", scope.Value, Scope);
}
var lookupRoles =
variable.Scope.Where(s => s.Key == ScopeField.Environment || s.Key == ScopeField.Machine || s.Key == ScopeField.Channel || s.Key == ScopeField.Action)
.ToDictionary(dict => dict.Key, dict => dict.Value);
foreach (var role in lookupRoles)
{
foreach (var scope in role.Value)
{
Scope = String.Join(",", scopeNames[scope], Scope);
}
}
}
}