Ensure non-device-owned properties are not overwritten by the device.

This commit is contained in:
clecompt 2015-12-07 15:21:03 -08:00
Родитель 60528dd8c4
Коммит 7b755b0bf0
2 изменённых файлов: 13 добавлений и 1 удалений

Просмотреть файл

@ -33,6 +33,11 @@
public const string UPDATED_TIME = "UpdatedTime";
public const string HOST_NAME = "HostName";
public const string ICCID = "ICCID";
/// <summary>
/// The list of properties not owned by the device.
/// </summary>
public static readonly string[] External = { ICCID };
}
public static class CommandModelConstants

Просмотреть файл

@ -235,10 +235,17 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Infr
dynamic existingDevice = await GetDeviceAsync(DeviceSchemaHelper.GetDeviceID(device));
// Save the command history and the original created date of the existing device
if (DeviceSchemaHelper.GetDeviceProperties(existingDevice) != null)
dynamic existingDeviceProperties = DeviceSchemaHelper.GetDeviceProperties(existingDevice);
if (existingDeviceProperties != null)
{
dynamic deviceProperties = DeviceSchemaHelper.GetDeviceProperties(device);
deviceProperties.CreatedTime = DeviceSchemaHelper.GetCreatedTime(existingDevice);
// Save existing external properties to the updated device
foreach (string ext in DevicePropertiesConstants.External)
{
D.Dynamic.InvokeSet(deviceProperties, ext, D.Dynamic.InvokeGet(existingDeviceProperties, ext));
}
}
device.CommandHistory = existingDevice.CommandHistory;