public DeviceConnectionActor(
            ILogger logger,
            IActorsLogger actorLogger,
            IRateLimiting rateLimiting,
            CredentialsSetup credentialsSetupLogic,
            FetchFromRegistry fetchFromRegistryLogic,
            Register registerLogic,
            Connect connectLogic,
            Deregister deregisterLogic,
            Disconnect disconnectLogic)
        {
            this.log          = logger;
            this.actorLogger  = actorLogger;
            this.rateLimiting = rateLimiting;

            this.credentialsSetupLogic  = credentialsSetupLogic;
            this.fetchFromRegistryLogic = fetchFromRegistryLogic;
            this.registerLogic          = registerLogic;
            this.connectLogic           = connectLogic;
            this.deregisterLogic        = deregisterLogic;
            this.disconnectLogic        = disconnectLogic;

            this.Message = null;
            this.Client  = null;
            this.Device  = null;

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

            this.failedDeviceConnectionsCount = 0;
            this.failedRegistrationsCount     = 0;
            this.failedFetchCount             = 0;
        }
Beispiel #2
0
        public DeviceConnectionActor(
            ILogger logger,
            IActorsLogger actorLogger,
            IRateLimiting rateLimiting,
            Fetch fetchLogic,
            Register registerLogic,
            Connect connectLogic)
        {
            this.log          = logger;
            this.actorLogger  = actorLogger;
            this.rateLimiting = rateLimiting;

            this.fetchLogic    = fetchLogic;
            this.registerLogic = registerLogic;
            this.connectLogic  = connectLogic;

            this.Message = null;
            this.Client  = null;
            this.Device  = null;

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

            this.failedDeviceConnectionsCount = 0;
            this.failedRegistrationsCount     = 0;
            this.failedFetchCount             = 0;
        }
        /// <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;
        }
Beispiel #4
0
            /// <summary>Map a service model to the corresponding API model</summary>
            public DeviceModelMessageApiModel(DeviceModel.DeviceModelMessage message) : this()
            {
                if (message == null)
                {
                    return;
                }

                this.Interval        = message.Interval.ToString("c");
                this.MessageTemplate = message.MessageTemplate;
                this.MessageSchema   = new DeviceModelMessageSchemaApiModel(message.MessageSchema);
            }
        // Map service model to API model
        public static DeviceModelTelemetry FromServiceModel(DeviceModel.DeviceModelMessage value)
        {
            if (value == null)
            {
                return(null);
            }

            var result = new DeviceModelTelemetry
            {
                Interval        = value.Interval.ToString("c"),
                MessageTemplate = value.MessageTemplate,
                MessageSchema   = DeviceModelTelemetryMessageSchema.FromServiceModel(value.MessageSchema)
            };

            return(result);
        }
Beispiel #6
0
        private void SetupDeviceConnectionActor()
        {
            string DEVICE_ID   = "01";
            var    deviceModel = new DeviceModel {
                Id = DEVICE_ID
            };
            var message = new DeviceModel.DeviceModelMessage();

            this.SetupRateLimitingConfig();

            this.target.Setup(
                DEVICE_ID,
                deviceModel,
                this.deviceStateActor.Object,
                this.loopSettings.Object);
        }
        private void SetupDeviceTelemetryActor()
        {
            string DEVICE_ID   = "01";
            var    deviceModel = new DeviceModel {
                Id = DEVICE_ID
            };
            var message = new DeviceModel.DeviceModelMessage();

            this.deviceConnectionActor.SetupGet(x => x.Connected).Returns(true);

            this.target.Setup(
                DEVICE_ID,
                deviceModel,
                message,
                this.deviceStateActor.Object,
                this.deviceConnectionActor.Object);
        }
        private DeviceModel.DeviceModelMessage GetDeviceModelMessage()
        {
            var telemetry = new DeviceModel.DeviceModelMessage()
            {
                Interval        = TimeSpan.Parse("00:10:00"),
                MessageTemplate = "{\"cargotemperature\":${cargotemperature},\"cargotemperature_unit\":\"${cargotemperature_unit}\"}",
                MessageSchema   = new DeviceModel.DeviceModelMessageSchema()
                {
                    Name   = "truck",
                    Format = DeviceModel.DeviceModelMessageSchemaFormat.JSON,
                    Fields = new Dictionary <string, DeviceModel.DeviceModelMessageSchemaType>()
                    {
                        { "cargotemperature", DeviceModel.DeviceModelMessageSchemaType.Double }
                    }
                }
            };

            return(telemetry);
        }
        public DeviceTelemetryActor(
            ILogger logger,
            IActorsLogger actorLogger,
            SendTelemetry sendTelemetryLogic,
            IInstance instance)
        {
            this.log                = logger;
            this.actorLogger        = actorLogger;
            this.sendTelemetryLogic = sendTelemetryLogic;
            this.instance           = instance;

            this.Message = null;

            this.status              = ActorStatus.None;
            this.deviceModel         = null;
            this.deviceId            = null;
            this.deviceStateActor    = null;
            this.totalMessagesCount  = 0;
            this.failedMessagesCount = 0;
        }
        public DeviceTelemetryActor(
            ILogger logger,
            IActorsLogger actorLogger,
            IRateLimiting rateLimiting,
            SendTelemetry sendTelemetryLogic)
        {
            this.log                = logger;
            this.actorLogger        = actorLogger;
            this.rateLimiting       = rateLimiting;
            this.sendTelemetryLogic = sendTelemetryLogic;

            this.Message = null;

            this.status              = ActorStatus.None;
            this.deviceModel         = null;
            this.deviceId            = null;
            this.deviceStateActor    = null;
            this.totalMessagesCount  = 0;
            this.failedMessagesCount = 0;
        }
        private void SetupDeviceTelemetryActor()
        {
            string DEVICE_ID   = "01";
            var    deviceModel = new DeviceModel {
                Id = DEVICE_ID
            };
            var message = new DeviceModel.DeviceModelMessage();

            this.mockDeviceContext.SetupGet(x => x.Connected).Returns(true);

            var simulationContext = new SimulationContext(
                this.devices.Object,
                this.rateLimiting.Object,
                this.mockInstance.Object);

            this.target.Init(
                simulationContext,
                DEVICE_ID,
                deviceModel,
                message,
                this.deviceStateActor.Object,
                this.mockDeviceContext.Object);
        }
        /// <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(IDeviceTelemetryActor context, string deviceId, DeviceModel deviceModel)
 {
     this.context  = context;
     this.deviceId = deviceId;
     this.message  = context.Message;
 }