forked from sergiisyrovatchenko/SQLIndexManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerInfo.cs
More file actions
74 lines (63 loc) · 2.66 KB
/
Copy pathServerInfo.cs
File metadata and controls
74 lines (63 loc) · 2.66 KB
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
namespace SQLIndexManager {
public class ServerInfo {
public readonly string ServerName;
private readonly string ProductLevel;
private readonly string ProductUpdateLevel;
private readonly string Edition;
public readonly bool IsSysAdmin;
private readonly string Version;
public readonly int MajorVersion;
private readonly int MinorVersion;
private readonly int PatchVersion;
public bool IsAzure => Edition == "SQL Azure";
private bool IsMaxEdititon => Edition.StartsWith("Enterprise") || Edition.StartsWith("Developer");
public override string ToString() => $"SQL Server {ProductVersion} " +
$"{(string.IsNullOrEmpty(ProductUpdateLevel) ? ProductLevel : $"{ProductLevel} {ProductUpdateLevel}")} " +
$"({Version}) {Edition}";
public bool IsColumnstoreAvailable => IsAzure
|| (MajorVersion >= ServerVersion.Sql2014 && IsMaxEdititon)
|| (MajorVersion == ServerVersion.Sql2016 && PatchVersion >= 4001)
|| MajorVersion >= ServerVersion.Sql2017;
public bool IsCompressionAvailable => IsAzure
|| (MajorVersion >= ServerVersion.Sql2008 && IsMaxEdititon)
|| (MajorVersion == ServerVersion.Sql2016 && PatchVersion >= 4001)
|| MajorVersion >= ServerVersion.Sql2017;
public bool IsOnlineRebuildAvailable => IsAzure
|| (MajorVersion >= ServerVersion.Sql2008 && IsMaxEdititon);
private string ProductVersion {
get {
switch (MajorVersion) {
case ServerVersion.Sql2005:
return "2005";
case ServerVersion.Sql2008:
return MinorVersion == 50 ? "2008 R2" : "2008";
case ServerVersion.Sql2012:
return "2012";
case ServerVersion.Sql2014:
return "2014";
case ServerVersion.Sql2016:
return "2016";
case ServerVersion.Sql2017:
return "2017";
case ServerVersion.Sql2019:
return "2019";
case ServerVersion.Sql2021:
return "2021";
default:
return "?";
}
}
}
public ServerInfo(string serverName, string productLevel, string productUpdateLevel, string edition, string serverVersion, bool isSysAdmin) {
ServerName = serverName;
ProductLevel = productLevel;
ProductUpdateLevel = productUpdateLevel;
Edition = edition;
Version = serverVersion;
IsSysAdmin = isSysAdmin;
MajorVersion = int.Parse(serverVersion.Split('.')[0]);
MinorVersion = int.Parse(serverVersion.Split('.')[1]);
PatchVersion = int.Parse(serverVersion.Split('.')[2]);
}
}
}