@@ -262,36 +262,60 @@ public void HandleEvent(ActorEvents e)
262262 public void Stop ( )
263263 {
264264 this . status = ActorStatus . Stopped ;
265+ this . log . Debug ( "Telemetry stopped" ,
266+ ( ) => new
267+ {
268+ this . deviceId ,
269+ Status = this . status . ToString ( )
270+ } ) ;
265271 }
266272
267273 private void Reset ( )
268274 {
269275 this . status = ActorStatus . ReadyToStart ;
270- }
271-
272- private void ScheduleTelemetry ( )
273- {
274- // Considering the throttling settings, when can the message be sent
275- var availableSchedule = Now + this . simulationContext . RateLimiting . GetPauseForNextMessage ( ) ;
276-
277- // Looking at the device model, when should the message be sent
278- // note: this.whenToRun contains the time when the last msg was sent
279- var optimalSchedule = this . whenToRun + ( long ) this . Message . Interval . TotalMilliseconds ;
280-
281- // TODO: review this approach: when choosing optimalSchedule the app might overload the hub and cause throttling
282- this . whenToRun = Math . Max ( optimalSchedule , availableSchedule ) ;
283- this . status = ActorStatus . ReadyToSend ;
284-
285- this . actorLogger . TelemetryScheduled ( this . whenToRun ) ;
286- this . log . Debug ( "Telemetry scheduled" ,
276+ this . log . Debug ( "Telemetry reset" ,
287277 ( ) => new
288278 {
289279 this . deviceId ,
290- Status = this . status . ToString ( ) ,
291- When = this . log . FormatDate ( this . whenToRun )
280+ Status = this . status . ToString ( )
292281 } ) ;
293282 }
294283
284+ private void ScheduleTelemetry ( )
285+ {
286+ if ( this . deviceStateActor . IsDeviceActive )
287+ {
288+ // Considering the throttling settings, when can the message be sent
289+ var availableSchedule = Now + this . simulationContext . RateLimiting . GetPauseForNextMessage ( ) ;
290+
291+ // Looking at the device model, when should the message be sent
292+ // note: this.whenToRun contains the time when the last msg was sent
293+ var optimalSchedule = this . whenToRun + ( long ) this . Message . Interval . TotalMilliseconds ;
294+
295+ // TODO: review this approach: when choosing optimalSchedule the app might overload the hub and cause throttling
296+ this . whenToRun = Math . Max ( optimalSchedule , availableSchedule ) ;
297+ this . status = ActorStatus . ReadyToSend ;
298+
299+ this . actorLogger . TelemetryScheduled ( this . whenToRun ) ;
300+ this . log . Debug ( "Telemetry scheduled" ,
301+ ( ) => new
302+ {
303+ this . deviceId ,
304+ Status = this . status . ToString ( ) ,
305+ When = this . log . FormatDate ( this . whenToRun )
306+ } ) ;
307+ }
308+ else
309+ {
310+ this . log . Debug ( "Device is not active, skipping telemetry send action." ,
311+ ( ) => new
312+ {
313+ this . deviceId ,
314+ Status = this . status . ToString ( )
315+ } ) ;
316+ }
317+ }
318+
295319 private void PauseForQuotaExceeded ( )
296320 {
297321 this . status = ActorStatus . WaitingForQuota ;
0 commit comments