Skip to content

Commit 9a503d1

Browse files
author
Rogelio Carrillo
committed
POPS-261: Minor adjustment
1 parent 2f59e1d commit 9a503d1

File tree

1 file changed

+32
-35
lines changed

1 file changed

+32
-35
lines changed

Src/StackifyLib/Models/EnvironmentDetail.cs

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -109,30 +109,28 @@ private void GetAzureInfo()
109109

110110
public static string GetDeviceName()
111111
{
112-
var deviceName = Environment.MachineName;
113-
var deviceNodeName = Environment.GetEnvironmentVariable("STACKIFY_DEVICE_NAME");
112+
var deviceName = Environment.GetEnvironmentVariable("STACKIFY_DEVICE_NAME");
113+
if (!String.IsNullOrEmpty(deviceName))
114+
{
115+
return deviceName.Substring(0, deviceName.Length > 60 ? 60 : deviceName.Length);
116+
}
117+
118+
deviceName = Environment.MachineName;
114119

115-
if (!String.IsNullOrEmpty(deviceNodeName))
120+
if (AzureConfig.InAzure && ((AzureConfig.IsWebsite) || (AzureConfig.InAzure && Environment.MachineName.StartsWith("RD"))))
116121
{
117-
deviceName = deviceNodeName;
122+
deviceName = AzureConfig.AzureInstanceName;
118123
}
119124
else
120125
{
121-
if (AzureConfig.InAzure && ((AzureConfig.IsWebsite) || (AzureConfig.InAzure && Environment.MachineName.StartsWith("RD"))))
122-
{
123-
deviceName = AzureConfig.AzureInstanceName;
124-
}
125-
else
126-
{
127-
var isDefaultDeviceNameEc2 = IsEc2MachineName(deviceName);
126+
var isDefaultDeviceNameEc2 = IsEc2MachineName(deviceName);
128127

129-
if (Config.IsEc2 == null || Config.IsEc2 == true || isDefaultDeviceNameEc2)
128+
if (Config.IsEc2 == null || Config.IsEc2 == true || isDefaultDeviceNameEc2)
129+
{
130+
var ec2InstanceId = GetEC2InstanceId();
131+
if (string.IsNullOrWhiteSpace(ec2InstanceId) == false)
130132
{
131-
var ec2InstanceId = GetEC2InstanceId();
132-
if (string.IsNullOrWhiteSpace(ec2InstanceId) == false)
133-
{
134-
deviceName = ec2InstanceId;
135-
}
133+
deviceName = ec2InstanceId;
136134
}
137135
}
138136
}
@@ -202,34 +200,33 @@ public static string GetEC2InstanceId()
202200
#else
203201
public static string GetDeviceName()
204202
{
205-
var deviceName = Environment.MachineName;
206-
var deviceNodeName = Environment.GetEnvironmentVariable("STACKIFY_DEVICE_NAME");
203+
var deviceName = Environment.GetEnvironmentVariable("STACKIFY_DEVICE_NAME");
204+
if (!String.IsNullOrEmpty(deviceName))
205+
{
206+
return deviceName.Substring(0, deviceName.Length > 60 ? 60 : deviceName.Length);
207+
}
208+
209+
deviceName = Environment.MachineName;
207210

208-
if (!String.IsNullOrEmpty(deviceNodeName))
211+
if (AzureConfig.InAzure && ((AzureConfig.IsWebsite) || (AzureConfig.InAzure && Environment.MachineName.StartsWith("RD"))))
209212
{
210-
deviceName = deviceNodeName;
213+
deviceName = AzureConfig.AzureInstanceName;
211214
}
212215
else
213216
{
214-
if (AzureConfig.InAzure && ((AzureConfig.IsWebsite) || (AzureConfig.InAzure && Environment.MachineName.StartsWith("RD"))))
215-
{
216-
deviceName = AzureConfig.AzureInstanceName;
217-
}
218-
else
219-
{
220-
var isDefaultDeviceNameEc2 = IsEc2MachineName(deviceName);
217+
var isDefaultDeviceNameEc2 = IsEc2MachineName(deviceName);
221218

222-
if (Config.IsEc2 == null || Config.IsEc2 == true || isDefaultDeviceNameEc2)
219+
if (Config.IsEc2 == null || Config.IsEc2 == true || isDefaultDeviceNameEc2)
220+
{
221+
var instanceID_task = GetEC2InstanceId();
222+
instanceID_task.Wait();
223+
if (string.IsNullOrWhiteSpace(instanceID_task.Result) == false)
223224
{
224-
var instanceID_task = GetEC2InstanceId();
225-
instanceID_task.Wait();
226-
if (string.IsNullOrWhiteSpace(instanceID_task.Result) == false)
227-
{
228-
deviceName = instanceID_task.Result;
229-
}
225+
deviceName = instanceID_task.Result;
230226
}
231227
}
232228
}
229+
233230
return deviceName.Substring(0, deviceName.Length > 60 ? 60 : deviceName.Length);
234231
}
235232

0 commit comments

Comments
 (0)