/// <summary> /// Associate a station, if its config exists, or open the config procedure /// </summary> public Station tryAddStation(String NameMAC, StationHandler _handler, bool AllowAsynchronous) //Replace Object with the relevant type { //check if not attempting reconnection locker.EnterReadLock(); //lock to avoid removal if reconnecting Station s = getStation(NameMAC); if (s != null) // s is reconnecting after losing contact { s.handler.socket.Close(); s.handler = _handler; //updating handler s.hearbeat(); locker.ExitReadLock(); return(s); } locker.ExitReadLock(); s = loadStation(NameMAC, _handler); //search Station in DB if (s == null && AllowAsynchronous) //this is already the check if a configuration for the station exists or not { int?wId = FindWindowByMAC(_handler.macAddress); if (wId != null) { int id = wId ?? 0; Application.Current.Windows[id].Close(); } StationAdder sa1 = new StationAdder(this, _handler); sa1.Show(); return(null); } return(s); }
internal StationAdder(Context _ctx, StationHandler _handler) { InitializeComponent(); this.Title += " (" + _handler.macAddress + ")"; this.Tag = _handler.macAddress; FrameNewStation.Content = new AddingStationPages.SelectRoom(_ctx, _handler); ctx = _ctx; handler = _handler; }
/// <summary> /// Create a new station object for a room /// </summary> public Station createStation(Room room, String NameMAC, double X, double Y, StationHandler handler) { Station s = new Station(); s.lastHearthbeat = DateTime.Now; s.NameMAC = NameMAC; s.location = new PositionTools.Position(X, Y, room); s.handler = handler; locker.EnterWriteLock(); room.addStation(s); stations[s.NameMAC] = s; locker.ExitWriteLock(); foreach (Publisher pb in publishers) { if (pb.supportsOperation(Publisher.DisplayableType.StationUpdate)) { pb.publishStationUpdate(room, s, Publisher.EventType.Appear); } } return(s); }
/// <summary> /// Try to load the configs of a station from persistent storage /// </summary> public Station loadStation(String NameMAC, StationHandler handler) { DatabaseInterface.StationInfo?si = databaseInt.loadStationInfo(NameMAC); if (si == null) { return(null); } Station s = new Station(); s.hearbeat(); s.NameMAC = NameMAC; s.handler = handler; String roomName = si.Value.RoomName; double x = si.Value.X; double y = si.Value.Y; Room room = getRoom(roomName); if (room == null) // The room to which it was attached does not exist anymore. Reconfig { deleteStation(NameMAC); return(null); } s.location = new PositionTools.Position(x, y, room); locker.EnterWriteLock(); room.addStation(s); stations[s.NameMAC] = s; locker.ExitWriteLock(); foreach (Publisher pb in publishers) { if (pb.supportsOperation(Publisher.DisplayableType.StationUpdate)) { pb.publishStationUpdate(room, s, Publisher.EventType.Appear); } } return(s); }