private void LightGroupOn_Click(object sender, RoutedEventArgs e) { Button lightGroupButton = sender as Button; LightGroup lightGroup = lightGroupButton.DataContext as LightGroup; myHome.setStatus(lightGroup, 1); }
public async Task LoadConfig() { string path = Path.Combine(Package.Current.InstalledLocation.Path, configPath); StorageFile configFile = await StorageFile.GetFileFromPathAsync(path); string config = await FileIO.ReadTextAsync(configFile); JsonObject jsonConfig = JsonObject.Parse(config); foreach (JsonValue jsonLight in jsonConfig.GetNamedArray("lights")) { int id = (int)jsonLight.GetObject().GetNamedNumber("id"); string name = jsonLight.GetObject().GetNamedString("name"); bool dimmable = jsonLight.GetObject().GetNamedBoolean("dimmable"); Light light = new Light(id, name, dimmable); lights.Add(light); components[light.id] = light; } foreach (JsonValue jsonShutter in jsonConfig.GetNamedArray("shutters")) { int id = (int)jsonShutter.GetObject().GetNamedNumber("id"); string name = jsonShutter.GetObject().GetNamedString("name"); Shutter shutter = new Shutter(id, name); shutters.Add(shutter); components[shutter.id] = shutter; } foreach (JsonValue jsonLightGroup in jsonConfig.GetNamedArray("lightGroups")) { string name = jsonLightGroup.GetObject().GetNamedString("name"); JsonArray jsonLightsArray = jsonLightGroup.GetObject().GetNamedArray("lights"); LightGroup lightGroup = new LightGroup(name); foreach (JsonValue jsonLight in jsonLightsArray) { lightGroup.Add(components[(int)jsonLight.GetNumber()] as Light); } lightGroups.Add(lightGroup); } foreach (JsonValue jsonShutterGroup in jsonConfig.GetNamedArray("shutterGroups")) { string name = jsonShutterGroup.GetObject().GetNamedString("name"); JsonArray jsonShuttersArray = jsonShutterGroup.GetObject().GetNamedArray("shutters"); ShutterGroup shutterGroup = new ShutterGroup(name); foreach (JsonValue jsonShutter in jsonShuttersArray) { shutterGroup.Add(components[(int)jsonShutter.GetNumber()] as Shutter); } shutterGroups.Add(shutterGroup); } }