@@ -110,21 +110,29 @@ private void GetAzureInfo()
110110 public static string GetDeviceName ( )
111111 {
112112 var deviceName = Environment . MachineName ;
113+ var deviceNodeName = Environment . GetEnvironmentVariable ( "STACKIFY_DEVICE_NAME" ) ;
113114
114- if ( AzureConfig . InAzure && ( ( AzureConfig . IsWebsite ) || ( AzureConfig . InAzure && Environment . MachineName . StartsWith ( "RD" ) ) ) )
115+ if ( ! String . IsNullOrEmpty ( deviceNodeName ) )
115116 {
116- deviceName = AzureConfig . AzureInstanceName ;
117+ deviceName = deviceNodeName ;
117118 }
118119 else
119120 {
120- var isDefaultDeviceNameEc2 = IsEc2MachineName ( deviceName ) ;
121-
122- if ( Config . IsEc2 == null || Config . IsEc2 == true || isDefaultDeviceNameEc2 )
121+ if ( AzureConfig . InAzure && ( ( AzureConfig . IsWebsite ) || ( AzureConfig . InAzure && Environment . MachineName . StartsWith ( "RD" ) ) ) )
122+ {
123+ deviceName = AzureConfig . AzureInstanceName ;
124+ }
125+ else
123126 {
124- var ec2InstanceId = GetEC2InstanceId ( ) ;
125- if ( string . IsNullOrWhiteSpace ( ec2InstanceId ) == false )
127+ var isDefaultDeviceNameEc2 = IsEc2MachineName ( deviceName ) ;
128+
129+ if ( Config . IsEc2 == null || Config . IsEc2 == true || isDefaultDeviceNameEc2 )
126130 {
127- deviceName = ec2InstanceId ;
131+ var ec2InstanceId = GetEC2InstanceId ( ) ;
132+ if ( string . IsNullOrWhiteSpace ( ec2InstanceId ) == false )
133+ {
134+ deviceName = ec2InstanceId ;
135+ }
128136 }
129137 }
130138 }
@@ -195,26 +203,33 @@ public static string GetEC2InstanceId()
195203 public static string GetDeviceName ( )
196204 {
197205 var deviceName = Environment . MachineName ;
206+ var deviceNodeName = Environment . GetEnvironmentVariable ( "STACKIFY_DEVICE_NAME" ) ;
198207
199- if ( AzureConfig . InAzure && ( ( AzureConfig . IsWebsite ) || ( AzureConfig . InAzure && Environment . MachineName . StartsWith ( "RD" ) ) ) )
208+ if ( ! String . IsNullOrEmpty ( deviceNodeName ) )
200209 {
201- deviceName = AzureConfig . AzureInstanceName ;
210+ deviceName = deviceNodeName ;
202211 }
203212 else
204213 {
205- var isDefaultDeviceNameEc2 = IsEc2MachineName ( deviceName ) ;
206-
207- if ( Config . IsEc2 == null || Config . IsEc2 == true || isDefaultDeviceNameEc2 )
214+ if ( AzureConfig . InAzure && ( ( AzureConfig . IsWebsite ) || ( AzureConfig . InAzure && Environment . MachineName . StartsWith ( "RD" ) ) ) )
208215 {
209- var instanceID_task = GetEC2InstanceId ( ) ;
210- instanceID_task . Wait ( ) ;
211- if ( string . IsNullOrWhiteSpace ( instanceID_task . Result ) == false )
216+ deviceName = AzureConfig . AzureInstanceName ;
217+ }
218+ else
219+ {
220+ var isDefaultDeviceNameEc2 = IsEc2MachineName ( deviceName ) ;
221+
222+ if ( Config . IsEc2 == null || Config . IsEc2 == true || isDefaultDeviceNameEc2 )
212223 {
213- deviceName = instanceID_task . Result ;
224+ var instanceID_task = GetEC2InstanceId ( ) ;
225+ instanceID_task . Wait ( ) ;
226+ if ( string . IsNullOrWhiteSpace ( instanceID_task . Result ) == false )
227+ {
228+ deviceName = instanceID_task . Result ;
229+ }
214230 }
215231 }
216232 }
217-
218233 return deviceName . Substring ( 0 , deviceName . Length > 60 ? 60 : deviceName . Length ) ;
219234 }
220235
0 commit comments