示例#1
0
        public DeviceSimulationService(IOptions <DeviceSettings> deviceSettings, ITelemetryMessageService telemetryMessagingService, IErrorMessageService errorMessagingService, ICommissioningMessageService commissioningMessagingService, ILoggerFactory loggerFactory)
        {
            if (deviceSettings == null)
            {
                throw new ArgumentNullException(nameof(deviceSettings));
            }

            if (deviceSettings.Value == null)
            {
                throw new ArgumentNullException("deviceSettings.Value", "No device configuration has been loaded.");
            }

            if (deviceSettings.Value.SimulationSettings == null)
            {
                throw new ArgumentNullException("deviceSettings.Value.SimulationSettings");
            }

            if (telemetryMessagingService == null)
            {
                throw new ArgumentNullException(nameof(telemetryMessagingService));
            }

            if (errorMessagingService == null)
            {
                throw new ArgumentNullException(nameof(errorMessagingService));
            }

            if (commissioningMessagingService == null)
            {
                throw new ArgumentNullException(nameof(commissioningMessagingService));
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory), "No logger factory has been provided.");
            }

            _deviceSettings     = deviceSettings.Value;
            _simulationSettings = deviceSettings.Value.SimulationSettings;

            _deviceId = _deviceSettings.DeviceId;
            _iotHub   = _deviceSettings.HostName;

            _telemetryInterval = _simulationSettings.TelemetryFrecuency;

            _logger = loggerFactory.CreateLogger <DeviceSimulationService>();

            _telemetryMessagingService     = telemetryMessagingService;
            _errorMessagingService         = errorMessagingService;
            _commissioningMessagingService = commissioningMessagingService;

            string logPrefix = "system".BuildLogPrefix();

            _logger.LogDebug($"{logPrefix}::{_deviceSettings.ArtifactId}::Logger created.");
            _logger.LogDebug($"{logPrefix}::{_deviceSettings.ArtifactId}::Device simulator created.");
        }
示例#2
0
        public ModuleSimulationService(ModuleSettings settings, SimulationSettingsModule simulationSettings, ITelemetryMessageService telemetryMessagingService, IErrorMessageService errorMessagingService, ICommissioningMessageService commissioningMessagingService, ILoggerFactory loggerFactory)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (simulationSettings == null)
            {
                throw new ArgumentNullException(nameof(simulationSettings));
            }

            if (telemetryMessagingService == null)
            {
                throw new ArgumentNullException(nameof(telemetryMessagingService));
            }

            if (errorMessagingService == null)
            {
                throw new ArgumentNullException(nameof(errorMessagingService));
            }

            if (commissioningMessagingService == null)
            {
                throw new ArgumentNullException(nameof(commissioningMessagingService));
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            string logPrefix = "system".BuildLogPrefix();

            ModuleSettings     = settings;
            SimulationSettings = simulationSettings;
            _logger            = loggerFactory.CreateLogger <ModuleSimulationService>();

            _telemetryMessagingService     = telemetryMessagingService;
            _errorMessagingService         = errorMessagingService;
            _commissioningMessagingService = commissioningMessagingService;

            _telemetryInterval = 10;
            _stopProcessing    = false;

            _moduleClient = ModuleClient.CreateFromConnectionString(ModuleSettings.ConnectionString, Microsoft.Azure.Devices.Client.TransportType.Mqtt);
            _logger.LogDebug($"{logPrefix}::{ModuleSettings.ArtifactId}::Logger created.");
            _logger.LogDebug($"{logPrefix}::{ModuleSettings.ArtifactId}::Module simulator created.");
        }
示例#3
0
        public DeviceSimulationService(
            IOptionsMonitor <DeviceSettings> deviceSettingsDelegate,
            IOptions <DPSSettings> dpsSettings,
            ITelemetryMessageService telemetryMessagingService,
            IErrorMessageService errorMessagingService,
            ICommissioningMessageService commissioningMessagingService,
            IProvisioningService provisioningService,
            ILoggerFactory loggerFactory)
        {
            if (deviceSettingsDelegate == null)
            {
                throw new ArgumentNullException(nameof(deviceSettingsDelegate));
            }

            if (deviceSettingsDelegate.CurrentValue == null)
            {
                throw new ArgumentNullException("deviceSettingsDelegate.CurrentValue");
            }

            if (deviceSettingsDelegate.CurrentValue.SimulationSettings == null)
            {
                throw new ArgumentNullException("deviceSettingsDelegate.CurrentValue.SimulationSettings");
            }

            if (dpsSettings == null)
            {
                throw new ArgumentNullException(nameof(dpsSettings));
            }

            if (dpsSettings.Value == null)
            {
                throw new ArgumentNullException("dpsSettings.Value");
            }

            if (telemetryMessagingService == null)
            {
                throw new ArgumentNullException(nameof(telemetryMessagingService));
            }

            if (errorMessagingService == null)
            {
                throw new ArgumentNullException(nameof(errorMessagingService));
            }

            if (commissioningMessagingService == null)
            {
                throw new ArgumentNullException(nameof(commissioningMessagingService));
            }

            if (provisioningService == null)
            {
                throw new ArgumentNullException(nameof(provisioningService));
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory), "No logger factory has been provided.");
            }

            _deviceSettingsDelegate = deviceSettingsDelegate;
            _simulationSettings     = _deviceSettingsDelegate.CurrentValue.SimulationSettings;
            _dpsSettings            = dpsSettings.Value;

            //_deviceId = _deviceSettingsDelegate.CurrentValue.DeviceId;
            _iotHub = _deviceSettingsDelegate.CurrentValue.HostName;

            _telemetryInterval = _simulationSettings.TelemetryFrecuency;

            _logger = loggerFactory.CreateLogger <DeviceSimulationService>();

            _telemetryMessagingService     = telemetryMessagingService;
            _errorMessagingService         = errorMessagingService;
            _commissioningMessagingService = commissioningMessagingService;
            _provisioningService           = provisioningService;

            _environmentName = Environment.GetEnvironmentVariable("ENVIRONMENT");

            string logPrefix = "system".BuildLogPrefix();

            _logger.LogDebug($"{logPrefix}::{_deviceSettingsDelegate.CurrentValue.ArtifactId}::Logger created.");
            _logger.LogDebug($"{logPrefix}::{_deviceSettingsDelegate.CurrentValue.ArtifactId}::Device simulator created.");
            _logger.LogDebug($"{logPrefix}::{_deviceSettingsDelegate.CurrentValue.ArtifactId}::Enrollment type:{_dpsSettings.EnrollmentType.ToString()}.");
            _logger.LogDebug($"{logPrefix}::{_deviceSettingsDelegate.CurrentValue.ArtifactId}::Security type:{_dpsSettings.GroupEnrollment?.SecurityType.ToString()}.");
        }
        public ModuleSimulationService(
            ModuleSettings settings,
            ITelemetryMessageService telemetryMessagingService,
            IErrorMessageService errorMessagingService,
            ICommissioningMessageService commissioningMessagingService,
            IProvisioningService provisioningService,
            ILoggerFactory loggerFactory)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (settings.SimulationSettings == null)
            {
                throw new ArgumentNullException("settings.SimulationSettings");
            }

            if (telemetryMessagingService == null)
            {
                throw new ArgumentNullException(nameof(telemetryMessagingService));
            }

            if (errorMessagingService == null)
            {
                throw new ArgumentNullException(nameof(errorMessagingService));
            }

            if (commissioningMessagingService == null)
            {
                throw new ArgumentNullException(nameof(commissioningMessagingService));
            }

            if (provisioningService == null)
            {
                throw new ArgumentNullException(nameof(provisioningService));
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            string logPrefix = "system".BuildLogPrefix();

            ModuleSettings     = settings;
            SimulationSettings = settings.SimulationSettings;
            _logger            = loggerFactory.CreateLogger <ModuleSimulationService>();

            _telemetryMessagingService     = telemetryMessagingService;
            _errorMessagingService         = errorMessagingService;
            _commissioningMessagingService = commissioningMessagingService;

            _provisioningService = provisioningService;

            _telemetryInterval = 10;
            _stopProcessing    = false;

            _environmentName = Environment.GetEnvironmentVariable("ENVIRONMENT");

            _logger.LogDebug($"{logPrefix}::{ModuleSettings.ArtifactId}::Logger created.");
            _logger.LogDebug($"{logPrefix}::{ModuleSettings.ArtifactId}::Module simulator created.");
        }