@@ -43,18 +43,15 @@ public EnvironmentInfo GetEnvironmentInfo() {
43
43
}
44
44
45
45
try {
46
- if ( IsUnix )
47
- {
48
- if ( PerformanceCounterCategory . Exists ( "Mono Memory" ) )
49
- {
46
+ if ( IsUnix ) {
47
+ if ( PerformanceCounterCategory . Exists ( "Mono Memory" ) ) {
50
48
var totalPhysicalMemory = new PerformanceCounter ( "Mono Memory" , "Total Physical Memory" ) ;
51
- var availablePhysicalMemory = new PerformanceCounter ( "Mono Memory" , "Available Physical Memory" ) ; //mono 4.0+
52
49
info . TotalPhysicalMemory = Convert . ToInt64 ( totalPhysicalMemory . RawValue ) ;
50
+
51
+ var availablePhysicalMemory = new PerformanceCounter ( "Mono Memory" , "Available Physical Memory" ) ; //mono 4.0+
53
52
info . AvailablePhysicalMemory = Convert . ToInt64 ( availablePhysicalMemory . RawValue ) ;
54
53
}
55
- }
56
- else
57
- {
54
+ } else {
58
55
if ( computerInfo != null ) {
59
56
info . TotalPhysicalMemory = Convert . ToInt64 ( computerInfo . TotalPhysicalMemory ) ;
60
57
info . AvailablePhysicalMemory = Convert . ToInt64 ( computerInfo . AvailablePhysicalMemory ) ;
@@ -98,27 +95,21 @@ public EnvironmentInfo GetEnvironmentInfo() {
98
95
}
99
96
100
97
try {
101
- if ( IsUnix )
102
- {
98
+ if ( IsUnix ) {
103
99
var currentProcess = Process . GetCurrentProcess ( ) ;
104
100
info . ProcessId = currentProcess . Id . ToString ( NumberFormatInfo . InvariantInfo ) ;
105
- }
106
- else
107
- {
101
+ } else {
108
102
info . ProcessId = KernelNativeMethods . GetCurrentProcessId ( ) . ToString ( NumberFormatInfo . InvariantInfo ) ;
109
103
}
110
104
} catch ( Exception ex ) {
111
105
_log . FormattedInfo ( typeof ( EnvironmentInfoCollector ) , "Unable to get process id. Error message: {0}" , ex . Message ) ;
112
106
}
113
107
114
108
try {
115
- if ( IsUnix )
116
- {
109
+ if ( IsUnix ) {
117
110
var currentProcess = Process . GetCurrentProcess ( ) ;
118
111
info . ProcessName = currentProcess . ProcessName ;
119
- }
120
- else
121
- {
112
+ } else {
122
113
info . ProcessName = GetProcessName ( ) ;
123
114
}
124
115
} catch ( Exception ex ) {
@@ -127,13 +118,9 @@ public EnvironmentInfo GetEnvironmentInfo() {
127
118
128
119
try {
129
120
if ( IsUnix )
130
- {
131
- info . ThreadId = System . Threading . Thread . CurrentThread . ManagedThreadId . ToString ( NumberFormatInfo . InvariantInfo ) ;
132
- }
121
+ info . ThreadId = Thread . CurrentThread . ManagedThreadId . ToString ( NumberFormatInfo . InvariantInfo ) ;
133
122
else
134
- {
135
123
info . ThreadId = KernelNativeMethods . GetCurrentThreadId ( ) . ToString ( NumberFormatInfo . InvariantInfo ) ;
136
- }
137
124
} catch ( Exception ex ) {
138
125
_log . FormattedInfo ( typeof ( EnvironmentInfoCollector ) , "Unable to get thread id. Error message: {0}" , ex . Message ) ;
139
126
}
@@ -183,16 +170,10 @@ private static bool Is64BitOperatingSystem() {
183
170
return ( ( methodExist && KernelNativeMethods . IsWow64Process ( KernelNativeMethods . GetCurrentProcess ( ) , out is64 ) ) && is64 ) ;
184
171
}
185
172
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 ) ;
173
+ private static bool IsUnix {
174
+ get {
175
+ int platform = ( int ) Environment . OSVersion . Platform ;
176
+ return platform == 4 || platform == 6 || platform == 128 ;
196
177
}
197
178
}
198
179
}
0 commit comments