/// <summary>
        /// Invoke this method before calling Execute(), to initialize the actor
        /// with details like the device id. SetupAsync() should be called only once.
        /// </summary>
        public void Setup(
            string deviceId,
            IDeviceStateActor deviceStateActor,
            IDeviceConnectionActor deviceConnectionActor,
            PropertiesLoopSettings loopSettings)
        {
            if (this.status != ActorStatus.None)
            {
                this.log.Error("The actor is already initialized",
                               () => new { CurrentDeviceId = this.deviceId });
                throw new DeviceActorAlreadyInitializedException();
            }

            this.deviceId              = deviceId;
            this.deviceStateActor      = deviceStateActor;
            this.deviceConnectionActor = deviceConnectionActor;
            this.loopSettings          = loopSettings;

            this.updatePropertiesLogic.Setup(this, this.deviceId);
            this.deviceSetDeviceTagLogic.Setup(this, this.deviceId);

            this.updatePropertiesLogic.Setup(this, this.deviceId);
            this.actorLogger.Setup(deviceId, "Properties");

            this.status = ActorStatus.ReadyToStart;
        }
        /// <summary>
        /// Invoke this method before calling Execute(), to initialize the actor
        /// with details like the device model and message type to simulate.
        /// Setup() should be called only once.
        /// </summary>
        public void Setup(
            string deviceId,
            DeviceModel deviceModel,
            DeviceModel.DeviceModelMessage message,
            IDeviceStateActor deviceStateActor,
            IDeviceConnectionActor deviceConnectionActor)
        {
            if (this.status != ActorStatus.None)
            {
                this.log.Error("The actor is already initialized",
                               () => new { CurrentDeviceId = this.deviceId, NewDeviceModelName = deviceModel.Name });
                throw new DeviceActorAlreadyInitializedException();
            }

            this.deviceModel           = deviceModel;
            this.Message               = message;
            this.deviceId              = deviceId;
            this.deviceStateActor      = deviceStateActor;
            this.deviceConnectionActor = deviceConnectionActor;

            this.sendTelemetryLogic.Setup(this, this.deviceId, this.deviceModel);
            this.actorLogger.Setup(deviceId, "Telemetry");

            this.status = ActorStatus.ReadyToStart;
        }
        /// <summary>
        /// Invoke this method before calling Execute(), to initialize the actor
        /// with details like the device model and message type to simulate.
        /// </summary>
        public async Task Init(ISimulationContext simulationContext,
                               string deviceId,
                               DeviceModel deviceModel,
                               IDeviceConnectionActor context)
        {
            this.instance.InitOnce();

            this.simulationContext = simulationContext;
            this.deviceModel       = deviceModel;
            this.deviceId          = deviceId;
            this.deviceContext     = context;
            this.actorLogger.Init(deviceId, "Replay");

            string fileId = simulationContext.ReplayFileId;

            try
            {
                if (!string.IsNullOrEmpty(fileId))
                {
                    var data = await this.replayFileService.GetAsync(fileId);

                    this.file       = data.Content;
                    this.fileReader = new StringReader(this.file);
                    this.status     = ActorStatus.ReadLine;
                }
            }
            catch (Exception e)
            {
                this.log.Error("Failed to read line", () => new { this.deviceId, e });
            }

            this.instance.InitComplete();
        }
        public async Task SetupAsync(IDeviceConnectionActor context, string deviceId, DeviceModel deviceModel)
        {
            this.context  = context;
            this.deviceId = deviceId;

            // TODO: to be removed once SimulationContext is introduced
            await this.devices.InitAsync();
        }
Exemplo n.º 5
0
        public void Init(IDeviceConnectionActor context, string deviceId, DeviceModel deviceModel)
        {
            this.instance.InitOnce();

            this.deviceContext = context;
            this.deviceId      = deviceId;

            this.instance.InitComplete();
        }
        /// <summary>
        /// Invoke this method before calling Execute(), to initialize the actor
        /// with details like the device id.
        /// </summary>
        public void Init(
            ISimulationContext simulationContext,
            string deviceId,
            IDeviceStateActor deviceStateActor,
            IDeviceConnectionActor deviceConnectionActor,
            PropertiesLoopSettings loopSettings)
        {
            this.instance.InitOnce();

            this.simulationContext     = simulationContext;
            this.deviceId              = deviceId;
            this.deviceStateActor      = deviceStateActor;
            this.deviceConnectionActor = deviceConnectionActor;
            this.updatePropertiesLogic.Init(this, this.deviceId);
            this.actorLogger.Init(deviceId, "Properties");
            this.status = ActorStatus.ReadyToStart;

            this.instance.InitComplete();
        }
        public DevicePropertiesActor(
            ILogger logger,
            IActorsLogger actorLogger,
            IRateLimiting rateLimiting,
            UpdateReportedProperties updatePropertiesLogic,
            SetDeviceTag deviceSetDeviceTagLogic)
        {
            this.log                     = logger;
            this.actorLogger             = actorLogger;
            this.rateLimiting            = rateLimiting;
            this.updatePropertiesLogic   = updatePropertiesLogic;
            this.deviceSetDeviceTagLogic = deviceSetDeviceTagLogic;

            this.status                = ActorStatus.None;
            this.deviceId              = null;
            this.deviceStateActor      = null;
            this.deviceConnectionActor = null;

            this.failedTwinUpdatesCount = 0;
        }
        public DevicePropertiesActor(
            ILogger logger,
            IActorsLogger actorLogger,
            UpdateReportedProperties updatePropertiesLogic,
            SetDeviceTag deviceSetDeviceTagLogic,
            IInstance instance)
        {
            this.log                     = logger;
            this.actorLogger             = actorLogger;
            this.updatePropertiesLogic   = updatePropertiesLogic;
            this.deviceSetDeviceTagLogic = deviceSetDeviceTagLogic;
            this.instance                = instance;

            this.status           = ActorStatus.None;
            this.deviceId         = null;
            this.deviceStateActor = null;
            this.deviceContext    = null;

            this.failedTwinUpdatesCount = 0;
        }
        /// <summary>
        /// Invoke this method before calling Execute(), to initialize the actor
        /// with details like the device model and message type to simulate.
        /// </summary>
        public void Init(
            ISimulationContext simulationContext,
            string deviceId,
            DeviceModel deviceModel,
            DeviceModel.DeviceModelMessage message,
            IDeviceStateActor deviceStateActor,
            IDeviceConnectionActor context)
        {
            this.instance.InitOnce();

            this.simulationContext = simulationContext;
            this.deviceModel       = deviceModel;
            this.Message           = message;
            this.deviceId          = deviceId;
            this.deviceStateActor  = deviceStateActor;
            this.deviceContext     = context;

            this.sendTelemetryLogic.Init(this, this.deviceId, this.deviceModel);
            this.actorLogger.Init(deviceId, "Telemetry");

            this.status = ActorStatus.ReadyToStart;

            this.instance.InitComplete();
        }
 public void Setup(IDeviceConnectionActor context, string deviceId, DeviceModel deviceModel)
 {
     this.context  = context;
     this.deviceId = deviceId;
 }