예제 #1
0
        public void LoadVirtualBridge()
        {
            System.Windows.Forms.OpenFileDialog fd = new System.Windows.Forms.OpenFileDialog
            {
                Filter = @"Text files (*.txt)|*.txt"
            };
            if (fd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            string    file    = File.ReadAllText(fd.FileName);
            DataStore ds      = JsonConvert.DeserializeObject <DataStore>(file);
            Bridge    vbridge = new Bridge()
            {
                Virtual = true, Name = "Virtual Bridge", RequiredUpdate = false
            };

            ListBridges.Add(vbridge);
            SelectedBridge = vbridge;
            CurrentBridgeHueObjectsList = new ObservableCollection <IHueObject>(ds.ToList());
            CreateExpanders();
        }
예제 #2
0
        public void LoadBridges()
        {
            while (true)
            {
                log.Info("Loading bridge(s)...");

                log.Info($"Checking if any bridge already present in settings... found {WinHueSettings.bridges.BridgeInfo.Count}");

                if (WinHueSettings.bridges.BridgeInfo.Count == 0 || WinHueSettings.bridges.DefaultBridge == string.Empty || !WinHueSettings.bridges.BridgeInfo.ContainsKey(WinHueSettings.bridges.DefaultBridge))
                {   // No bridge found in the list of bridge.
                    log.Info("Either no bridge found in settings or no default bridge. Pairing needed.");
                    if (DoBridgePairing())
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }

                foreach (KeyValuePair <string, BridgeSaveSettings> b in WinHueSettings.bridges.BridgeInfo)
                {
                    log.Info($"Bridge OK. Checking if bridge already in the bridge list...");
                    if (ListBridges.All(x => x.Mac != b.Key))
                    {
                        Bridge bridge = new Bridge()
                        {
                            ApiKey    = b.Value.apikey,
                            IpAddress = IPAddress.Parse(b.Value.ip),
                            Name      = b.Value.name,
                            IsDefault = b.Key == WinHueSettings.bridges.DefaultBridge,
                            Mac       = b.Key
                        };
                        if (b.Value.apikey == string.Empty)
                        {
                            continue;
                        }

                        bridge.LastCommandMessages.OnMessageAdded += LastCommandMessages_OnMessageAdded;
                        bridge.RequiredUpdate = WinHueSettings.settings.CheckForBridgeUpdate && UpdateManager.CheckBridgeNeedUpdate(bridge.ApiVersion);

                        log.Info("Bridge not in the list adding it...");
                        ListBridges.Add(bridge);
                    }
                    else
                    {
                        log.Info("Bridge already in the list skipping...");
                    }
                }

                foreach (Bridge br in ListBridges)
                {
                    log.Info($"Checking bridge {br}");
                    if (!CheckBridge(br))
                    {
                        log.Info("Bridge IP has changed... Pairing needed.");
                        Form_BridgeFinder fbf = new Form_BridgeFinder(br)
                        {
                            Owner = Application.Current.MainWindow
                        };
                        fbf.ShowDialog();

                        if (fbf.IpFound())
                        {
                            br.BridgeNotResponding += Br_BridgeNotResponding;
                            br.IpAddress            = fbf.newip;
                            if (!br.IsDefault)
                            {
                                continue;
                            }
                            SelectedBridge = br;
                        }
                        else
                        {
                            DoBridgePairing();
                            break;
                        }
                    }
                    else
                    {
                        if (!br.IsDefault)
                        {
                            continue;
                        }
                        SelectedBridge = br;
                    }
                }


                break;
            }
        }
예제 #3
0
 public void AddBridge(Bridge bridge)
 {
     ListBridges.Add(bridge);
     OnBridgeAdded?.Invoke(bridge);
 }