-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #284 from EasyPost/backport_user_agent
Backport User-Agent to V2
- Loading branch information
Showing
9 changed files
with
151 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Reflection; | ||
|
||
namespace EasyPost | ||
{ | ||
public static class RuntimeInfo | ||
{ | ||
internal struct ApplicationInfo | ||
{ | ||
/// <summary> | ||
/// Get the version of the application as a string. | ||
/// </summary> | ||
/// <returns>The version of the application as a string.</returns> | ||
internal static string ApplicationVersion | ||
{ | ||
get | ||
{ | ||
try | ||
{ | ||
Assembly assembly = typeof(ApplicationInfo).Assembly; | ||
FileVersionInfo info = FileVersionInfo.GetVersionInfo(assembly.Location); | ||
return info.FileVersion ?? "Unknown"; | ||
} | ||
catch (Exception) | ||
{ | ||
return "Unknown"; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Get the .NET framework version as a string. | ||
/// </summary> | ||
/// <returns>The .NET framework version as a string.</returns> | ||
internal static string DotNetVersion | ||
{ | ||
get | ||
{ | ||
Version dotNetVersion = Environment.Version; | ||
if (dotNetVersion == null) | ||
{ | ||
/* | ||
* We're on a pre-4.0 .NET Framework version, where Environment.Version is null. | ||
*/ | ||
return "3.5-"; | ||
} | ||
|
||
string versionString = dotNetVersion.ToString(); | ||
if (versionString == "4.0.30319.42000") | ||
{ | ||
/* | ||
* We're on a v4.6+ version (or pre-.NET Core 3.0, which we don't support), | ||
* but we can't get the exact version. | ||
* See: https://docs.microsoft.com/en-us/dotnet/api/system.environment.version?view=net-6.0#remarks | ||
*/ | ||
versionString = "4.6+"; | ||
} | ||
|
||
return versionString; | ||
} | ||
} | ||
} | ||
|
||
internal struct OperationSystemInfo | ||
{ | ||
/// <summary> | ||
/// Get details about the operating system. | ||
/// </summary> | ||
/// <returns>Details about the operating system.</returns> | ||
private static OperatingSystem OperatingSystem | ||
{ | ||
get { return Environment.OSVersion; } | ||
} | ||
|
||
/// <summary> | ||
/// Get the name of the operating system. | ||
/// </summary> | ||
/// <returns>Name of the operating system.</returns> | ||
internal static string Name | ||
{ | ||
get | ||
{ | ||
switch (OperatingSystem.Platform) | ||
{ | ||
case PlatformID.Win32S: | ||
case PlatformID.Win32Windows: | ||
case PlatformID.Win32NT: | ||
case PlatformID.WinCE: | ||
return "Windows"; | ||
case PlatformID.Unix: | ||
return "Linux"; | ||
case PlatformID.MacOSX: // in newer versions, Mac OS X is PlatformID.Unix unfortunately | ||
return "Darwin"; | ||
default: | ||
return "Unknown"; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Get the version of the operating system. | ||
/// </summary> | ||
/// <returns>Version of the operating system.</returns> | ||
internal static string Version | ||
{ | ||
get { return OperatingSystem.Version.ToString(); } | ||
} | ||
|
||
/// <summary> | ||
/// Get the architecture of the operating system. | ||
/// </summary> | ||
/// <returns>Architecture of the operating system.</returns> | ||
internal static string Architecture | ||
{ | ||
get | ||
{ | ||
// Because of how this library uses parent files, we can't easily target different frameworks and use different functions to get the architecture. | ||
return "Unknown"; | ||
} | ||
} | ||
} | ||
} | ||
} |