예제 #1
0
        public void TestGetSampleSimulatedDevice()
        {
            var d = DeviceCreatorHelper.BuildDeviceStructure("test", true, null);

            Assert.NotNull(d);
            Assert.Equal("test", d.DeviceProperties.DeviceID);
            Assert.Equal("normal", d.DeviceProperties.DeviceState);
            Assert.Equal(null, d.DeviceProperties.HubEnabledState);
        }
        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);
        }
예제 #3
0
        public static DeviceModel GetSampleSimulatedDevice(string deviceId, string key)
        {
            DeviceModel device = DeviceCreatorHelper.BuildDeviceStructure(deviceId, true, null);

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

            AssignTelemetry(device);
            AssignCommands(device);

            return(device);
        }
예제 #4
0
        public static DeviceModel GetSampleSimulatedDevice(string deviceId, string key)
        {
            var device = DeviceCreatorHelper.BuildDeviceStructure(deviceId, true, null);

            AssignDeviceProperties(device);
            device.ObjectType        = ObjectTypeDeviceInfo;
            device.Version           = Version10;
            device.IsSimulatedDevice = IsSimulatedDevice;

            AssignTelemetry(device);
            AssignCommands(device);

            return(device);
        }
예제 #5
0
        /// <summary>
        /// Generates a DeviceInfo packet for a simulated device to send over the wire
        /// </summary>
        /// <returns></returns>
        public virtual DeviceModel GetDeviceInfo()
        {
            DeviceModel device = DeviceCreatorHelper.BuildDeviceStructure(DeviceID, true, null);

            device.DeviceProperties = this.DeviceProperties;
            device.Commands         = this.Commands?.Where(c => c.DeliveryType == DeliveryType.Message).ToList() ?? new List <Command>();
            device.Telemetry        = this.Telemetry ?? new List <Common.Models.Telemetry>();
            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.
            device.SystemProperties = null;

            return(device);
        }
예제 #6
0
        /// <summary>
        /// Generates a DeviceInfo packet for a simulated device to send over the wire
        /// </summary>
        /// <returns></returns>
        public virtual DeviceModel GetDeviceInfo()
        {
            DeviceModel device = DeviceCreatorHelper.BuildDeviceStructure(DeviceID, true, null);

            device.DeviceProperties = this.DeviceProperties;
            device.Commands         = this.Commands ?? new List <Command>();
            device.Telemetry        = this.Telemetry ?? new List <WebApi.Common.Models.Telemetry>();
            device.Version          = SampleDeviceFactory.Version10;
            device.ObjectType       = SampleDeviceFactory.ObjectTypeDeviceInfo;

            // Remove the system properties from a device, to better emulate the behavior of real devices when sending device info messages.
            device.SystemProperties = null;

            return(device);
        }
예제 #7
0
        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);

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

            return(addedDevice);
        }
예제 #8
0
        private static DeviceModel GetDefaultTestDevice()
        {
            var device = DeviceCreatorHelper.BuildDeviceStructure("DeviceID-Test", true, null);

            device.DeviceProperties.CreatedTime     = new DateTime(2000, 01, 01);
            device.DeviceProperties.DeviceState     = "DeviceState-Test";
            device.DeviceProperties.HubEnabledState = true;
            device.DeviceProperties.FirmwareVersion = "FirmwareVersion-Test";
            device.DeviceProperties.InstalledRAM    = "InstalledRAM-Test";
            device.DeviceProperties.Manufacturer    = "Manufacturer-Test";
            device.DeviceProperties.ModelNumber     = "ModelNumber-Test";
            device.DeviceProperties.Platform        = "Platform-Test";
            device.DeviceProperties.Processor       = "Processor-Test";
            device.DeviceProperties.SerialNumber    = "SerialNumber-Test";
            device.DeviceProperties.UpdatedTime     = new DateTime(2000, 01, 01);

            return(device);
        }
예제 #9
0
        public static DeviceModel GetSampleDevice(Random randomNumber, SecurityKeys keys)
        {
            var deviceId = string.Format(
                CultureInfo.InvariantCulture,
                "00000-DEV-{0}C-{1}LK-{2}D-{3}",
                MAX_COMMANDS_SUPPORTED,
                randomNumber.Next(99999),
                randomNumber.Next(99999),
                randomNumber.Next(99999));

            var device = DeviceCreatorHelper.BuildDeviceStructure(deviceId, false, null);

            device.ObjectName = "IoT Device Description";

            AssignDeviceProperties(device);
            AssignTelemetry(device);
            AssignCommands(device);

            return(device);
        }
예제 #10
0
        private void TestNullDeviceProperties(ClauseType filterType)
        {
            var device = DeviceCreatorHelper.BuildDeviceStructure(Guid.NewGuid().ToString(), true, null);

            device.DeviceProperties = null;

            var list = new List <DeviceModel> {
                device
            };

            var filters = new List <Clause>
            {
                new Clause
                {
                    ColumnName  = "DeviceID",
                    ClauseType  = filterType,
                    ClauseValue = "x"
                }
            };

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

            Assert.Equal(0, filtered.Count());
        }