示例#1
0
        private void TestNullDeviceProperties(FilterType filterType)
        {
            var device = DeviceSchemaHelper.BuildDeviceStructure(Guid.NewGuid().ToString(), true, null);

            device.DeviceProperties = null;

            var list = new List <dynamic>()
            {
                device
            };

            var filters = new List <FilterInfo>()
            {
                new FilterInfo()
                {
                    ColumnName  = "DeviceID",
                    FilterType  = filterType,
                    FilterValue = "x"
                }
            };

            var filtered = FilterHelper.FilterDeviceList(list.AsQueryable(), filters);

            Assert.AreEqual(0, filtered.Count());
        }
        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);
        }
        private async Task SendStartupEventMessage(string deviceId, DeviceClient deviceClient)
        {
            var deviceSchema = DeviceSchemaHelper.BuildDeviceStructure(deviceId);
            var message      = JsonConvert.SerializeObject(deviceSchema);

            await SendMessageAsync(message, deviceClient);
        }
        /// <summary>
        /// Generates a DeviceInfo packet for a simulated device to send over the wire
        /// </summary>
        /// <returns></returns>
        public virtual dynamic GetDeviceInfo()
        {
            dynamic device = DeviceSchemaHelper.BuildDeviceStructure(DeviceID, true);

            device.DeviceProperties = DeviceSchemaHelper.GetDeviceProperties(this);
            device.Commands         = CommandSchemaHelper.GetSupportedCommands(this);
            device.Version          = SampleDeviceFactory.VERSION_1_0;
            device.ObjectType       = SampleDeviceFactory.OBJECT_TYPE_DEVICE_INFO;

            return(device);
        }
        public async Task <List <string> > BootstrapDefaultDevices()
        {
            List <string> sampleIds = SampleDeviceFactory.GetDefaultDeviceNames();

            foreach (string id in sampleIds)
            {
                dynamic      device = DeviceSchemaHelper.BuildDeviceStructure(id, true, null);
                SecurityKeys generatedSecurityKeys = _securityKeyGenerator.CreateRandomKeys();
                await AddDeviceToRepositoriesAsync(device, generatedSecurityKeys);
            }
            return(sampleIds);
        }
        public static dynamic GetSampleSimulatedDevice(string deviceId, string key)
        {
            dynamic device = DeviceSchemaHelper.BuildDeviceStructure(deviceId, true);

            AssignDeviceProperties(deviceId, device);
            device.ObjectType        = OBJECT_TYPE_DEVICE_INFO;
            device.Version           = VERSION_1_0;
            device.IsSimulatedDevice = IS_SIMULATED_DEVICE;

            AssignCommands(device);

            return(device);
        }
示例#7
0
        public static dynamic GetSampleDevice(Random randomNumber, SecurityKeys keys)
        {
            string deviceId = string.Format("00000-DEV-{0}C-{1}LK-{2}D-{3}",
                                            MAX_COMMANDS_SUPPORTED, randomNumber.Next(99999));
            dynamic device = DeviceSchemaHelper.BuildDeviceStructure(deviceId, false);

            device.ObjectName = "IoT Device Description";

            AssignDeviceProperties(deviceId, device);
            AssignCommands(device);

            return(device);
        }
示例#8
0
        /// <summary>
        /// Generates a DeviceInfo packet for a simulated device to send over the wire
        /// </summary>
        /// <returns></returns>
        public virtual dynamic GetDeviceInfo()
        {
            dynamic device = DeviceSchemaHelper.BuildDeviceStructure(DeviceID, true, null);

            device.DeviceProperties = DeviceSchemaHelper.GetDeviceProperties(this);
            device.Commands         = CommandSchemaHelper.GetSupportedCommands(this);
            device.Version          = SampleDeviceFactory.VERSION_1_0;
            device.ObjectType       = SampleDeviceFactory.OBJECT_TYPE_DEVICE_INFO;

            // Remove the system properties from a device, to better emulate the behavior of real devices when sending device info messages.
            DeviceSchemaHelper.RemoveSystemPropertiesForSimulatedDeviceInfo(device);

            return(device);
        }
示例#9
0
        private async Task <dynamic> AddDeviceAsync(UnregisteredDeviceModel unregisteredDeviceModel)
        {
            dynamic device;

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

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

            device = DeviceSchemaHelper.BuildDeviceStructure(unregisteredDeviceModel.DeviceId, unregisteredDeviceModel.DeviceType.IsSimulatedDevice);

            return(await this._deviceLogic.AddDeviceAsync(device));
        }
        private async Task <dynamic> AddDeviceAsync(
            UnregisteredDeviceModel unregisteredDeviceModel,
            string userName)
        {
            dynamic device;

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

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

            Debug.Assert(
                !string.IsNullOrEmpty(userName),
                "userName is a null reference or empty string.");

            device = DeviceSchemaHelper.BuildDeviceStructure(unregisteredDeviceModel.DeviceId, unregisteredDeviceModel.DeviceType.IsSimulatedDevice);

            return(await this._deviceLogic.AddDeviceAsync(device, userName));
        }
示例#11
0
        private static dynamic GetDefaultTestDevice()
        {
            dynamic device = DeviceSchemaHelper.BuildDeviceStructure("DeviceID-Test", true, null);
            dynamic props  = DeviceSchemaHelper.GetDeviceProperties(device);

            props.AvailablePowerSources = 123;
            props.BatteryLevel          = 12;
            props.CreatedTime           = new DateTime(2000, 01, 01);
            props.DeviceState           = "DeviceState-Test";
            props.HubEnabledState       = true;
            props.FirmwareVersion       = "FirmwareVersion-Test";
            props.InstalledRAM          = "InstalledRAM-Test";
            props.Manufacturer          = "Manufacturer-Test";
            props.MemoryFree            = 123;
            props.ModelNumber           = "ModelNumber-Test";
            props.Platform           = "Platform-Test";
            props.PowerSourceVoltage = 1234;
            props.Processor          = "Processor-Test";
            props.SerialNumber       = "SerialNumber-Test";
            props.UpdatedTime        = new DateTime(2000, 01, 01);

            return(device);
        }