forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPSUserAgent.cs
More file actions
180 lines (166 loc) · 5.52 KB
/
Copy pathPSUserAgent.cs
File metadata and controls
180 lines (166 loc) · 5.52 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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
using System;
using System.Management.Automation;
using System.Globalization;
namespace Microsoft.PowerShell.Commands
{
/// <summary>
/// Construct the Useragent string
/// </summary>
public static class PSUserAgent
{
internal static string UserAgent
{
get
{
// format the user-agent string from the various component parts
string userAgent = string.Format(CultureInfo.InvariantCulture,
"{0} ({1}; {2}; {3}) {4}",
Compatibility, Platform, OS, Culture, App);
return (userAgent);
}
}
/// <summary>
/// Useragent string for InternetExplorer (9.0)
/// </summary>
public static string InternetExplorer
{
get
{
// format the user-agent string from the various component parts
string userAgent = string.Format(CultureInfo.InvariantCulture,
"{0} (compatible; MSIE 9.0; {1}; {2}; {3})",
Compatibility, Platform, OS, Culture);
return (userAgent);
}
}
/// <summary>
/// Useragent string for Firefox (4.0)
/// </summary>
public static string FireFox
{
get
{
// format the user-agent string from the various component parts
string userAgent = string.Format(CultureInfo.InvariantCulture,
"{0} ({1}; {2}; {3}) Gecko/20100401 Firefox/4.0",
Compatibility, Platform, OS, Culture);
return (userAgent);
}
}
/// <summary>
/// Useragent string for Chrome (7.0)
/// </summary>
public static string Chrome
{
get
{
// format the user-agent string from the various component parts
string userAgent = string.Format(CultureInfo.InvariantCulture,
"{0} ({1}; {2}; {3}) AppleWebKit/534.6 (KHTML, like Gecko) Chrome/7.0.500.0 Safari/534.6",
Compatibility, Platform, OS, Culture);
return (userAgent);
}
}
/// <summary>
/// Useragent string for Opera (9.0)
/// </summary>
public static string Opera
{
get
{
// format the user-agent string from the various component parts
string userAgent = string.Format(CultureInfo.InvariantCulture,
"Opera/9.70 ({0}; {1}; {2}) Presto/2.2.1",
Platform, OS, Culture);
return (userAgent);
}
}
/// <summary>
/// Useragent string for Safari (5.0)
/// </summary>
public static string Safari
{
get
{
// format the user-agent string from the various component parts
string userAgent = string.Format(CultureInfo.InvariantCulture,
"{0} ({1}; {2}; {3}) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16",
Compatibility, Platform, OS, Culture);
return (userAgent);
}
}
internal static string Compatibility
{
get
{
return ("Mozilla/5.0");
}
}
internal static string App
{
get
{
string app = string.Format(CultureInfo.InvariantCulture,
"WindowsPowerShell/{0}", PSVersionInfo.PSVersion);
return (app);
}
}
internal static string Platform
{
get
{
return ("Windows NT");
}
}
internal static string OS
{
get
{
#if CORECLR
return System.Runtime.InteropServices.RuntimeInformation.OSDescription;
#else
OperatingSystem os = Environment.OSVersion;
string platform = GetOSName(os.Platform);
string formattedOS = string.Format(CultureInfo.InvariantCulture,
"{0} {1}.{2}", platform, os.Version.Major, os.Version.Minor);
return (formattedOS);
#endif
}
}
internal static string Culture
{
get
{
return (CultureInfo.CurrentCulture.Name);
}
}
#if !CORECLR
private static string GetOSName(PlatformID platformId)
{
string platform;
switch (platformId)
{
case PlatformID.Win32NT: // is this really the only valid option?
platform = "Windows NT";
break;
case PlatformID.Win32Windows:
platform = "Windows";
break;
case PlatformID.Win32S:
case PlatformID.WinCE:
case PlatformID.Xbox:
case PlatformID.MacOSX:
case PlatformID.Unix:
default:
// TODO: should we be doing something more robust here?
platform = platformId.ToString();
break;
}
return (platform);
}
#endif
}
}