Lompat ke konten utama

How do you use PropertySelector in a DeviceStatusInfo Search?

DFenn-1143
Pembuat Postingan Asli

In the below code, how do I replace ExcludeExceptionEvents property as its being deprecated? and how do I use PropertySelector in this case?

 

private object[][] BuildDeviceStatusInfoCalls(List<Device> devices)

{

object[][] logRecordCalls = new object[devices.Count][];

 

PropertySelector prop = new PropertySelector();

prop.Fields = new List<string>();

prop.Fields.Add("exceptionEvents");

prop.IsIncluded = true;

 

for (int i = 0; i < devices.Count; i++)

{

logRecordCalls[i] = new object[4];

logRecordCalls[i][0] = "Get";

logRecordCalls[i][1] = typeof(DeviceStatusInfo);

logRecordCalls[i][2] = new

{

search = new DeviceStatusInfoSearch()

{

DeviceSearch = new DeviceSearch()

{

Id = devices[i].Id

},

ExcludeExceptionEvents = true

}

};

logRecordCalls[i][3] = typeof(List<DeviceStatusInfo>);

}

 

return logRecordCalls;

}

Bergabunglah dalam percakapan

You need to be logged in to reply to this post and participate in the Geotab Community discussions.

Jawaban Teratas

What you have crossed out in your example is pretty close. You would build that PropertySelector and make sure to include it with every Get call you're making, but set `IsIncluded` to `false`. That will make it so any fields you specify are excluded from the result.

// Make your DeviceStatusInfoSearch objects the same way, but // without `ExcludeExceptionEvents` set search = new DeviceStatusInfoSearch { DeviceSearch = new DeviceSearch(devices[i].Id) };   // Then wherever you're making the Get calls, make this PropertySelector var propertySelector = new PropertySelector { Fields = [ nameof(DeviceStatusInfo.ExceptionEvents) ], IsIncluded = false // this will ensure the Fields you specify *are not* included };   // You can use the same property selector with each of your searches foreach (var search in searches) { var result = await api.CallAsync<List<DeviceStatusInfo>>( "Get", typeof(DeviceStatusInfo), new { search, propertySelector } );   // ... do something with the result }

 

2 Balasan

What you have crossed out in your example is pretty close. You would build that PropertySelector and make sure to include it with every Get call you're making, but set `IsIncluded` to `false`. That will make it so any fields you specify are excluded from the result.

// Make your DeviceStatusInfoSearch objects the same way, but // without `ExcludeExceptionEvents` set search = new DeviceStatusInfoSearch { DeviceSearch = new DeviceSearch(devices[i].Id) };   // Then wherever you're making the Get calls, make this PropertySelector var propertySelector = new PropertySelector { Fields = [ nameof(DeviceStatusInfo.ExceptionEvents) ], IsIncluded = false // this will ensure the Fields you specify *are not* included };   // You can use the same property selector with each of your searches foreach (var search in searches) { var result = await api.CallAsync<List<DeviceStatusInfo>>( "Get", typeof(DeviceStatusInfo), new { search, propertySelector } );   // ... do something with the result }

 

DFenn-1143
Pembuat Postingan Asli

This is the full solution in C# for a multi-Call:

private object[][] BuildDeviceStatusInfoCalls(List<Device> devices)

{

object[][] logRecordCalls = new object[devices.Count][];

 

PropertySelector prop = new PropertySelector

{

Fields = [nameof(DeviceStatusInfo.ExceptionEvents)],

IsIncluded = false // this will ensure the Fields specified are NOT included

};

 

for (int i = 0; i < devices.Count; i++)

{

logRecordCalls[i] = new object[4];

logRecordCalls[i][0] = "Get";

logRecordCalls[i][1] = typeof(DeviceStatusInfo);

logRecordCalls[i][2] = new

{

search = new DeviceStatusInfoSearch()

{

DeviceSearch = new DeviceSearch()

{

Id = devices[i].Id

}

},

PropertySelector = prop

};

logRecordCalls[i][3] = typeof(List<DeviceStatusInfo>);

}

 

return logRecordCalls;

}

 

 

Masih ada pertanyaan?