Skip to content

Commit a000db0

Browse files
committed
EnvironmentInfoCollector coding style changes
1 parent a91bca8 commit a000db0

File tree

3 files changed

+27
-37
lines changed

3 files changed

+27
-37
lines changed

Source/Extras/Exceptionless.Extras.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
<Compile Include="Utility\AssemblyHelper.cs" />
7575
<Compile Include="Storage\FolderObjectStorage.cs" />
7676
<Compile Include="Storage\IsolatedStorageObjectStorage.cs" />
77-
<Compile Include="Utility\EnvironmentHelper.cs" />
7877
<Compile Include="Utility\ExceptionlessTraceListener.cs" />
7978
<Compile Include="Utility\PathHelper.cs" />
8079
<Compile Include="Utility\Run.cs" />

Source/Extras/Services/EnvironmentInfoCollector.cs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using System.Runtime.InteropServices;
88
using System.Text;
99
using System.Threading;
10-
using Exceptionless.Extras.Utility;
1110
using Exceptionless.Logging;
1211
using Exceptionless.Models.Data;
1312
using Microsoft.VisualBasic.Devices;
@@ -35,32 +34,31 @@ public EnvironmentInfo GetEnvironmentInfo() {
3534
}
3635

3736
try {
38-
if (computerInfo != null)
37+
if (computerInfo != null) {
3938
info.OSName = computerInfo.OSFullName;
40-
if (computerInfo != null)
4139
info.OSVersion = computerInfo.OSVersion;
40+
}
4241
} catch (Exception ex) {
4342
_log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get operating system version. Error message: {0}", ex.Message);
4443
}
4544

4645
try {
47-
if (EnvironmentHelper.IsUnix)
46+
if (IsUnix)
4847
{
4948
if (PerformanceCounterCategory.Exists("Mono Memory"))
5049
{
51-
//https://github.com/mono/mono/blob/f0834d5407f492a2a21e2f62f8f8c418d64ba6fa/mono/metadata/mono-perfcounters-def.h
52-
var performanceCounterTotalPhysicalMemory = new PerformanceCounter("Mono Memory", "Total Physical Memory");
53-
var performanceCounterAvailablePhysicalMemory = new PerformanceCounter("Mono Memory", "Available Physical Memory"); //mono 4.0+
54-
info.TotalPhysicalMemory = Convert.ToInt64(performanceCounterTotalPhysicalMemory.RawValue);
55-
info.AvailablePhysicalMemory = Convert.ToInt64(performanceCounterAvailablePhysicalMemory.RawValue);
50+
var totalPhysicalMemory = new PerformanceCounter("Mono Memory", "Total Physical Memory");
51+
var availablePhysicalMemory = new PerformanceCounter("Mono Memory", "Available Physical Memory"); //mono 4.0+
52+
info.TotalPhysicalMemory = Convert.ToInt64(totalPhysicalMemory.RawValue);
53+
info.AvailablePhysicalMemory = Convert.ToInt64(availablePhysicalMemory.RawValue);
5654
}
5755
}
5856
else
5957
{
60-
if (computerInfo != null)
58+
if (computerInfo != null) {
6159
info.TotalPhysicalMemory = Convert.ToInt64(computerInfo.TotalPhysicalMemory);
62-
if (computerInfo != null)
6360
info.AvailablePhysicalMemory = Convert.ToInt64(computerInfo.AvailablePhysicalMemory);
61+
}
6462
}
6563
} catch (Exception ex) {
6664
_log.FormattedInfo(typeof(EnvironmentInfoCollector), "Unable to get physical memory. Error message: {0}", ex.Message);
@@ -100,10 +98,10 @@ public EnvironmentInfo GetEnvironmentInfo() {
10098
}
10199

102100
try {
103-
if (EnvironmentHelper.IsUnix)
101+
if (IsUnix)
104102
{
105103
var currentProcess = Process.GetCurrentProcess();
106-
info.ProcessId = currentProcess.Id.ToString();
104+
info.ProcessId = currentProcess.Id.ToString(NumberFormatInfo.InvariantInfo);
107105
}
108106
else
109107
{
@@ -114,7 +112,7 @@ public EnvironmentInfo GetEnvironmentInfo() {
114112
}
115113

116114
try {
117-
if (EnvironmentHelper.IsUnix)
115+
if (IsUnix)
118116
{
119117
var currentProcess = Process.GetCurrentProcess();
120118
info.ProcessName = currentProcess.ProcessName;
@@ -128,9 +126,9 @@ public EnvironmentInfo GetEnvironmentInfo() {
128126
}
129127

130128
try {
131-
if (EnvironmentHelper.IsUnix)
129+
if (IsUnix)
132130
{
133-
info.ThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString();
131+
info.ThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString(NumberFormatInfo.InvariantInfo);
134132
}
135133
else
136134
{
@@ -184,6 +182,19 @@ private static bool Is64BitOperatingSystem() {
184182

185183
return ((methodExist && KernelNativeMethods.IsWow64Process(KernelNativeMethods.GetCurrentProcess(), out is64)) && is64);
186184
}
185+
186+
/// <summary>
187+
/// Determine current os platform.
188+
/// </summary>
189+
/// <exception cref="InvalidOperationException" accessor="get"></exception>
190+
private static bool IsUnix
191+
{
192+
get
193+
{
194+
int p = (int)Environment.OSVersion.Platform;
195+
return (p == 4) || (p == 6) || (p == 128);
196+
}
197+
}
187198
}
188199

189200
internal static class KernelNativeMethods {

Source/Extras/Utility/EnvironmentHelper.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)