public StateMachineState(string id, StateMachine stateMachine)
        {
            if (id == null) throw new ArgumentNullException(nameof(id));
            if (stateMachine == null) throw new ArgumentNullException(nameof(stateMachine));

            Id = id;
            _stateMachine = stateMachine;
        }
        protected override void OnStateMachineStateChanged(StateMachine stateMachine, StateMachineStateChangedEventArgs eventArgs, TimeSpan previousStateDuration)
        {
            JsonObject startData = CreateDataPackage(stateMachine.Id, EventType.OutputActuatorStateChanged);
            startData.SetNamedValue("state", JsonValue.CreateStringValue(eventArgs.NewValue));
            startData.SetNamedValue("kind", JsonValue.CreateStringValue("Start"));
            Task.Run(() => SendToAzureEventHubAsync(startData));

            JsonObject endData = CreateDataPackage(stateMachine.Id, EventType.OutputActuatorStateChanged);
            endData.SetNamedValue("state", JsonValue.CreateStringValue(eventArgs.OldValue));
            endData.SetNamedValue("kind", JsonValue.CreateStringValue("End"));
            endData.SetNamedValue("duration", JsonValue.CreateNumberValue(previousStateDuration.TotalSeconds));
            Task.Run(() => SendToAzureEventHubAsync(endData));
        }
 protected virtual void OnStateMachineStateChanged(StateMachine stateMachine, StateMachineStateChangedEventArgs eventArgs, TimeSpan previousStateDuration)
 {
 }
        private void HandleStateMachineOutputActuator(StateMachine stateMachine)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            stateMachine.StateChanged += (s, e) =>
            {
                TimeSpan previousStateDuration = stopwatch.Elapsed;
                stopwatch.Restart();

                OnStateMachineStateChanged(stateMachine, e, previousStateDuration);
            };
        }