private async Task <List <string> > BootstrapDefaultDevices()
        {
            List <string> sampleIds = SampleDeviceFactory.GetDefaultDeviceNames();

            foreach (string id in sampleIds)
            {
                dynamic      device       = DeviceSchemaHelper.BuildDeviceStructure(id, true);
                SecurityKeys securityKeys = _securityKeyGenerator.CreateRandomKeys();
                try
                {
                    await _iotHubRepository.AddDeviceAsync(device, securityKeys);

                    await _virtualDeviceStorage.AddOrUpdateDeviceAsync(new InitialDeviceConfig()
                    {
                        DeviceId = DeviceSchemaHelper.GetDeviceID(device),
                        HostName = _configProvider.GetConfigurationSettingValue("iotHub.HostName"),
                        Key      = securityKeys.PrimaryKey
                    });
                }
                catch (Exception ex)
                {
                    //if we fail adding to table storage for the device simulator just continue
                    Trace.TraceError("Failed to add simulated device : {0}", ex.Message);
                }
            }
            return(sampleIds);
        }
        protected virtual void InitDeviceInfo(InitialDeviceConfig config)
        {
            dynamic initialDevice = SampleDeviceFactory.GetSampleSimulatedDevice(config.DeviceId, config.Key);

            DeviceProperties = DeviceSchemaHelper.GetDeviceProperties(initialDevice);
            Commands         = CommandSchemaHelper.GetSupportedCommands(initialDevice);
            HostName         = config.HostName;
            PrimaryAuthKey   = config.Key;
        }
Exemplo n.º 3
0
        protected virtual void InitDeviceInfo(InitialDeviceConfig config)
        {
            DeviceModel initialDevice = SampleDeviceFactory.GetSampleSimulatedDevice(config.DeviceId, config.Key);

            DeviceProperties = initialDevice.DeviceProperties;
            Commands         = initialDevice.Commands ?? new List <Command>();
            Telemetry        = initialDevice.Telemetry ?? new List <Common.Models.Telemetry>();
            HostName         = config.HostName;
            PrimaryAuthKey   = config.Key;
        }
        /// <summary>
        /// Generates N devices with random data and properties for testing
        /// NOTE: Adds the devices to both the device registry and device identity repository
        /// </summary>
        /// <param name="deviceCount">Number of devices to generate</param>
        /// <returns></returns>
        /// <remarks>TEMPORARY DEVICE GENERATION CODE FOR TESTING PURPOSES!</remarks>
        public async Task GenerateNDevices(int deviceCount)
        {
            Random randomNumber = new Random();

            for (int i = 0; i < deviceCount; i++)
            {
                SecurityKeys generatedSecurityKeys = _securityKeyGenerator.CreateRandomKeys();
                DeviceModel  device = SampleDeviceFactory.GetSampleDevice(randomNumber, generatedSecurityKeys);
                await this.AddDeviceToRepositoriesAsync(device, generatedSecurityKeys);
            }
        }
Exemplo n.º 5
0
        public void TestGetSampleDevice()
        {
            var randomnumber = new Random();
            ISecurityKeyGenerator securityKeyGenerator = new SecurityKeyGenerator();
            var keys = securityKeyGenerator.CreateRandomKeys();
            var d    = SampleDeviceFactory.GetSampleDevice(randomnumber, keys);

            Assert.NotNull(d);
            Assert.NotNull(d.DeviceProperties);
            Assert.NotNull(d.DeviceProperties.DeviceID);
        }
        public async Task <List <string> > BootstrapDefaultDevices()
        {
            List <string> sampleIds = SampleDeviceFactory.GetDefaultDeviceNames();

            foreach (string id in sampleIds)
            {
                DeviceModel  device = DeviceCreatorHelper.BuildDeviceStructure(id, true, null);
                SecurityKeys generatedSecurityKeys = _securityKeyGenerator.CreateRandomKeys();
                await this.AddDeviceToRepositoriesAsync(device, generatedSecurityKeys);
            }
            return(sampleIds);
        }
        private async Task <DeviceWithKeys> AddDeviceAsync(UnregisteredDeviceModel unregisteredDeviceModel)
        {
            Debug.Assert(
                unregisteredDeviceModel != null,
                "unregisteredDeviceModel is a null reference.");

            Debug.Assert(
                unregisteredDeviceModel.DeviceType != null,
                "unregisteredDeviceModel.DeviceType is a null reference.");

            DeviceModel device = DeviceCreatorHelper.BuildDeviceStructure(
                unregisteredDeviceModel.DeviceId,
                unregisteredDeviceModel.DeviceType.IsSimulatedDevice,
                unregisteredDeviceModel.Iccid);

            SampleDeviceFactory.AssignDefaultTags(device);
            SampleDeviceFactory.AssignDefaultDesiredProperties(device);

            DeviceWithKeys addedDevice = await this._deviceLogic.AddDeviceAsync(device);

            return(addedDevice);
        }
Exemplo n.º 8
0
        public void TestGetDefaultDeviceNames()
        {
            var s = SampleDeviceFactory.GetDefaultDeviceNames();

            Assert.NotEmpty(s);
        }