コード例 #1
0
        public void Create_Includes_Property_Values_As_JSON()
        {
            var device  = Device.Create <Dummy>();
            var payload = DevicePayloadFactory.Create(device);

            var properties = JObject.Parse(payload.Properties).Properties().ToArray();
            var names      = properties.Select((p) => p.Name).ToArray();

            Assert.That(names, Has.Member("type"));
            Assert.That(names, Has.Member("state"));
            Assert.That(names, Has.Member("streamingValue"));

            var type = properties
                       .Where((p) => p.Name == "type").First();

            var state = properties
                        .Where((p) => p.Name == "state").First();

            var streamingValue = properties
                                 .Where((p) => p.Name == "streamingValue").First();

            Assert.That((string)type, Is.EqualTo("dummy"));
            Assert.That((string)state, Is.EqualTo("off"));
            Assert.That((int)streamingValue.Value, Is.EqualTo(3));
        }
コード例 #2
0
        public void Create_Includes_Monitor_Properties()
        {
            var device  = Device.Create <Dummy>();
            var payload = DevicePayloadFactory.Create(device);

            Assert.That(payload.Monitors.ToArray(), Has.Length.EqualTo(1));
            Assert.That(payload.Monitors.First(), Is.EqualTo("streamingValue"));
        }
コード例 #3
0
        public void Create_Includes_Transitions_Dictionary()
        {
            var device  = Device.Create <Dummy>();
            var payload = DevicePayloadFactory.Create(device);

            Assert.That(payload.Transitions.Keys, Has.Member("turn-on"));
            Assert.That(payload.Transitions.Keys, Has.Member("turn-off"));
            Assert.That(payload.Transitions["turn-on"], Is.Not.Null);
            Assert.That(payload.Transitions["turn-off"], Is.Not.Null);
        }
コード例 #4
0
        public void Create_Includes_Allowed_Dictionary()
        {
            var device  = Device.Create <Dummy>();
            var payload = DevicePayloadFactory.Create(device);

            Assert.That(payload.Allowed.Keys, Has.Member("on"));
            Assert.That(payload.Allowed.Keys, Has.Member("off"));
            Assert.That(payload.Allowed["on"], Has.Member("turn-off"));
            Assert.That(payload.Allowed["off"], Has.Member("turn-on"));
        }
コード例 #5
0
        private Func <object, Task <object> > WrapHandler(Func <Task> function)
        {
            Func <object, Task <object> > wrappedHandler = async(input) => {
                await function();

                return(DevicePayloadFactory.Create(this));
            };

            return(wrappedHandler);
        }
コード例 #6
0
        private Func <object, Task <object> > WrapHandler <T1, T2, T3>(Func <T1, T2, T3, Task> function)
        {
            Func <object, Task <object> > wrappedHandler = async(input) => {
                var parameters = (object[])input;

                await function((T1)parameters[0], (T2)parameters[1], (T3)parameters[2]);

                return(DevicePayloadFactory.Create(this));
            };

            return(wrappedHandler);
        }
コード例 #7
0
        public async Task Provision <T>(T device) where T : Device
        {
            device.Server = Server;
            EnsureType(device);

            await _provision(DevicePayloadFactory.Create(device));

            if (device is IInitializableAsync)
            {
                await((IInitializableAsync)device).Initialize();
            }
            else if (device is IInitializable)
            {
                ((IInitializable)device).Initialize();
            }
        }
コード例 #8
0
        public async Task Discover <T>(T device) where T : Device
        {
            device.Server = Server;
            EnsureType(device);

            MemoryRegistry.Instance.Save(device);

            await _discover(DevicePayloadFactory.Create(device));

            if (device is IInitializableAsync)
            {
                await((IInitializableAsync)device).Initialize();
            }
            else if (device is IInitializable)
            {
                ((IInitializable)device).Initialize();
            }
        }
コード例 #9
0
 public async Task Prepare <T>(T device) where T : Device
 {
     await _prepare.Invoke(DevicePayloadFactory.Create(device));
 }