Inheritance: ILSFHandler, INotifyPropertyChanged
Beispiel #1
0
        public void AddBulb(MockLightingServiceHandler handler)
        {
            var bulb = new MockBulbDevice(handler);

            this.devices.Add(bulb);
            this.NotifyDeviceArrival(bulb);
        }
        // private AdapterInterface _interfaceRemoteControl;

        public MockBulbDevice(MockLightingServiceHandler handler) : base(handler.Name,
            "MockDevices Inc", "Mock Bulb", "1", handler.Id, "")
        {
            base.LightingServiceHandler = handler;
            Icon = new AdapterIcon(new System.Uri("ms-appx:///Icons/Light.png"));
            _interfaceOnOff = InterfaceCreators.CreateOnOffStatus(handler.LampState_OnOff);
            _interfaceOff = InterfaceCreators.CreateOffControl(()=> { handler.LampState_OnOff = false; });
            _interfaceOn = InterfaceCreators.CreateOnControl(() => { handler.LampState_OnOff = true; });
            _interfaceColor = InterfaceCreators.CreateColor(0d, 0d,
                (hue) => { handler.LampState_Hue = (UInt32)(hue / 360 * (UInt32.MaxValue - 1)); },
                (saturation) => { handler.LampState_Saturation = (UInt32)(saturation * (UInt32.MaxValue - 1)); });
            _interfaceBrightness = InterfaceCreators.CreateBrightness(0d, (brightness) => { handler.LampState_Brightness = (UInt32)(brightness * (UInt32.MaxValue - 1)); });
            AdapterBusObject abo = new AdapterBusObject("org/alljoyn/SmartSpaces/Operation");
            abo.Interfaces.Add(_interfaceOnOff);
            abo.Interfaces.Add(_interfaceOn);
            abo.Interfaces.Add(_interfaceOff);
            if (handler.LampDetails_Color)
                abo.Interfaces.Add(_interfaceColor);
            if (handler.LampDetails_Dimmable)
                abo.Interfaces.Add(_interfaceBrightness);
            base.CreateEmitSignalChangedSignal();
            this.BusObjects.Add(abo);
            handler.PropertyChanged += Handler_PropertyChanged;
            handler.LampStateChanged += Handler_LampStateChanged;
        }
        private void LoadBulbs()
        {
            var settings = ApplicationData.Current.LocalSettings;
            if (!settings.Containers.ContainsKey("Bulbs"))
            {
                // Create a set of initial bulbs
                var bulb = new MockLightingServiceHandler($"Mock Dimmable+Color+Temp Bulb", Guid.NewGuid().ToString(), true, true, true, this.Dispatcher);
                AllJoynDeviceManager.Current.AddBulb(bulb);
                bulb = new MockLightingServiceHandler($"Mock Dimmable+Temp Bulb", Guid.NewGuid().ToString(), true, false, true, this.Dispatcher);
                AllJoynDeviceManager.Current.AddBulb(bulb);
                bulb = new MockLightingServiceHandler($"Mock Dimmable Bulb", Guid.NewGuid().ToString(), true, false, false, this.Dispatcher);
                AllJoynDeviceManager.Current.AddBulb(bulb);
                bulb = new MockLightingServiceHandler($"Mock Bulb", Guid.NewGuid().ToString(), false, false, false, this.Dispatcher);
                AllJoynDeviceManager.Current.AddBulb(bulb);
            }
            else
            {
                var container = settings.Containers["Bulbs"];
                foreach(var item in container.Values)
                {
                    var bulb = MockLightingServiceHandler.FromJson((string)item.Value, Dispatcher);
                    AllJoynDeviceManager.Current.AddBulb(bulb);
                }
            }

            this.DataContext = AllJoynDeviceManager.Current;
        }
Beispiel #4
0
        public void RemoveBulb(MockLightingServiceHandler handler)
        {
            var bulb = this.devices.Where(d => d.LightingServiceHandler == handler).FirstOrDefault();

            if (bulb != null)
            {
                this.devices.Remove(bulb);
                this.NotifyDeviceRemoval(bulb);
            }
        }
        public static MockLightingServiceHandler FromJson(string json, Windows.UI.Core.CoreDispatcher dispatcher)
        {
            DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(SerializerClass));

            using (MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(json)))
            {
                var sc   = (SerializerClass)s.ReadObject(ms);
                var mlsh = new MockLightingServiceHandler(sc.Name, sc.Id, sc.IsDimmable, sc.SupportsColor, sc.SupportsTemperature, dispatcher);
                mlsh.LampState_Hue        = sc.Hue;
                mlsh.LampState_Brightness = sc.Brightness;
                mlsh.LampState_Saturation = sc.Saturation;
                mlsh.LampState_ColorTemp  = sc.ColorTemp;
                mlsh.LampState_OnOff      = sc.IsOn;
                return(mlsh);
            }
        }
        private void LoadDevices()
        {
            var settings = ApplicationData.Current.LocalSettings;
            if (!settings.Containers.ContainsKey("Devices"))
            {
                // Create a set of initial bulbs
                var bulb = new MockLightingServiceHandler($"Mock Advanced Bulb", Guid.NewGuid().ToString(), true, true, true, this.Dispatcher);
                AllJoynDsbServiceManager.Current.AddDevice(new MockBulbDevice(bulb));
                bulb = new MockLightingServiceHandler($"Mock Simple Bulb", Guid.NewGuid().ToString(), true, false, false, this.Dispatcher);
                AllJoynDsbServiceManager.Current.AddDevice(new MockBulbDevice(bulb));
                AllJoynDsbServiceManager.Current.AddDevice(new MockCurrentHumidityDevice("Mock Humidity Sensor", Guid.NewGuid().ToString(), 50));
                AllJoynDsbServiceManager.Current.AddDevice(new MockCurrentTemperatureDevice("Mock Temperature Sensor", Guid.NewGuid().ToString(), 25));
                AllJoynDsbServiceManager.Current.AddDevice(new MockOnOffSwitchDevice("Mock Switch", Guid.NewGuid().ToString(), false, Dispatcher));
            }
            else
            {
                var container = settings.Containers["Devices"];
                foreach(var item in container.Values)
                {
                    var data = ((string)item.Value).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    var type = data[0].Trim();
                    if (type == "Lamp")
                    {
                        var bulb = MockLightingServiceHandler.FromJson(data[1], Dispatcher);
                        AllJoynDsbServiceManager.Current.AddDevice(new MockBulbDevice(bulb));
                    }
                    else if(type == "CurrentTemperature")
                    {
                        var d = new MockCurrentTemperatureDevice(
                            data[2], data[1], double.Parse(data[3], CultureInfo.InvariantCulture));
                        AllJoynDsbServiceManager.Current.AddDevice(d);
                    }
                    else if (type == "CurrentHumidity")
                    {
                        var d = new MockCurrentHumidityDevice(
                            data[2], data[1], double.Parse(data[3], CultureInfo.InvariantCulture));
                        AllJoynDsbServiceManager.Current.AddDevice(d);
                    }
                    else if (type == "OnOffSwitch")
                    {
                        var d = new MockOnOffSwitchDevice(data[2], data[1], data[3] == "true", Dispatcher);
                        AllJoynDsbServiceManager.Current.AddDevice(d);
                    }
                }
            }

            this.DataContext = AllJoynDsbServiceManager.Current;
        }
 private void Button_Click_OK(object sender, RoutedEventArgs e)
 {
     var bulb = new MockLightingServiceHandler(bulbName.Text, Guid.NewGuid().ToString(),
         switchDimming.IsOn, switchColor.IsOn, switchTemperature.IsOn, this.Dispatcher);
     bulb.LampState_Hue = (UInt32)(new Random().NextDouble() * (uint.MaxValue - 1));
     bulb.LampState_Brightness = UInt32.MaxValue - 1;            
     bulb.LampState_Saturation = UInt32.MaxValue - 1;
     bulb.LampState_OnOff = true;
     AllJoynDsbServiceManager.Current.AddDevice(new MockBulbDevice(bulb));
     SaveDevices();
     Button_Click_Cancel(sender, e);
 }
 public static MockLightingServiceHandler FromJson(string json, Windows.UI.Core.CoreDispatcher dispatcher)
 {
     DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(SerializerClass));
     using (MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(json)))
     {
         var sc = (SerializerClass)s.ReadObject(ms);
         var mlsh = new MockLightingServiceHandler(sc.Name, sc.Id, sc.IsDimmable, sc.SupportsColor, sc.SupportsTemperature, dispatcher);
         mlsh.LampState_Hue = sc.Hue;
         mlsh.LampState_Brightness = sc.Brightness;
         mlsh.LampState_Saturation = sc.Saturation;
         mlsh.LampState_ColorTemp= sc.ColorTemp;
         mlsh.LampState_OnOff = sc.IsOn;
         return mlsh;
     }
 }
 public void RemoveBulb(MockLightingServiceHandler bulb)
 {
     _Bulbs.Remove(bulb);
     adapter.RemoveBulb(bulb);
 }
 public void AddBulb(MockLightingServiceHandler bulb)
 {
     _Bulbs.Add(bulb);
     adapter.AddBulb(bulb);
 }
 public void RemoveBulb(MockLightingServiceHandler handler)
 {
     var bulb = this.devices.Where(d => d.LightingServiceHandler == handler).FirstOrDefault();
     if(bulb != null)
     {
         this.devices.Remove(bulb);
         this.NotifyDeviceRemoval(bulb);
     }
 }
 public void AddBulb(MockLightingServiceHandler handler)
 {
     var bulb = new MockBulbDevice(handler);
     this.devices.Add(bulb);
     this.NotifyDeviceArrival(bulb);
 }