public void SetRoomStatus(IRoomConfig roomConfig) { if (roomConfig == null) { this.AppController.TrackAppEvent("Error: trying set room status for null room reference"); return; } else if (roomConfig.FloorMapVarName == null) { this.AppController.TrackAppEvent(String.Format("Error: no FloorMapVarName specified in config file for room location {0}", roomConfig.Location)); return; } if (statusCache[roomConfig.FloorMapVarName] == null) { statusCache[roomConfig.FloorMapVarName] = (int)roomConfig.RoomStatus; } else if ((int)statusCache[roomConfig.FloorMapVarName] == (int)roomConfig.RoomStatus) { // status stays the same - ignore return; } else { // update current status statusCache[roomConfig.FloorMapVarName] = (int)roomConfig.RoomStatus; } Task.Run(() => { SetVariable(roomConfig.FloorMapVarName, (int)roomConfig.RoomStatus); }); }
/// <summary> /// 新房间 /// </summary> /// <param name="roomManager_">房主</param> /// <param name="config_">房间配置</param> public Room(IPlayerJoinRoom roomManager_, IRoomConfig config_) : this() { Id = Id + roomManager_.Id; Name = config_.Name; IsFull = config_.IsFull; Timelimit = config_.Timelimit; IsOpening = config_.IsOpening; SecretKey = config_.SecretKey; TicketPrice = config_.TicketPrice; InningGame = config_.InningGame; InningGame.IRoom = this; if (InningGame.IGameProject.PlayerCountLeast <= config_.PlayerCountTopLimit && config_.PlayerCountTopLimit <= InningGame.IGameProject.PlayerCountLimit) { PlayerCountTopLimit = config_.PlayerCountTopLimit; } else { PlayerCountTopLimit = InningGame.IGameProject.PlayerCountLimit; } if (PlayerCountTopLimit == 1) { IsFull = true; } RoomManager = roomManager_; Affiche = config_.Affiche; IsRandom = config_.IsRandom; Players.Add(roomManager_); InningGame.PlaySitDown(roomManager_); }
/// <summary> /// Calculate IRoomConfig.RoomStatus property based on last events /// </summary> /// <param name="roomConfig"></param> /// <param name="sensor"></param> private void UpdateRoomStatus(IRoomConfig roomConfig, IRoomSensor sensor) { if (roomConfig == null) { return; // Nothing to do; } // If this is PiR a sensor telemetry IRoomSensor piRSensor = null; if (sensor != null && NotificationEventSchema.PirSensorValueLabel.Equals(sensor.Telemetry)) { piRSensor = sensor; } else if (roomConfig.RoomSensors != null) { // If Not - extract sensor from Room Config piRSensor = roomConfig.RoomSensors.FirstOrDefault <IRoomSensor>(s => NotificationEventSchema.PirSensorValueLabel.Equals(s.Telemetry)); } DateTime leeWayEndTime = DateTime.Now.AddSeconds(roomConfig.EventLeewaySeconds); // Remove outdated appointments // TODO? Perform this check for all rooms ? if (roomConfig.CurrentAppointment != null && leeWayEndTime >= DateTime.Parse(roomConfig.CurrentAppointment.EndTime)) { // Check if room appointment expired roomConfig.CurrentAppointment = null; } double PiR = -1.0; if (piRSensor != null && piRSensor.LastMeasurement != null)// PiR sensor changed { Double.TryParse(piRSensor.LastMeasurement.Value, out PiR); } if (PiR > 0.0) //Presense detected { if (roomConfig.CurrentAppointment != null) { roomConfig.RoomStatus = RoomStatus.RoomScheduledAndOccupied; } else { roomConfig.RoomStatus = RoomStatus.RoomOccupied; } } else // No presence in the room { if (roomConfig.CurrentAppointment != null) { roomConfig.RoomStatus = RoomStatus.RoomScheduled; } else { roomConfig.RoomStatus = RoomStatus.RoomFree; } } }
internal void roomsScheduleView_ItemTapped(object sender, ItemTappedEventArgs e) { RoomViewModel rv = e.Item as RoomViewModel; if (rv == null) { return; } IRoomConfig config = CurrentLevel.GetRoomConfig(rv.Location); ShowRoomDetailPopup(config); }
/// <summary> /// Check if we have any engagements /// </summary> /// <param name="roomCfg"></param> /// <param name="e"></param> /// <returns></returns> internal static RoomStatus CalculateRoomStatus(IRoomConfig roomCfg, OnScheduleUpdateEventArgs e) { if (e.Schedule == null || roomCfg == null || e.Schedule.Length == 0) { return(RoomStatus.Unknown); } Appointment currentAppointment = e.Schedule.SingleOrDefault <Appointment>(a => DateTime.Parse(a.StartTime) >= DateTime.Now && DateTime.Parse(a.EndTime) <= DateTime.Now); if (currentAppointment != null) { roomCfg.CurrentAppointment = currentAppointment; } }
public RoomDetailPopupPage(IRoomConfig roomViewModel) { InitializeComponent(); this.CurrentRoom = roomViewModel; this.CurrentDate = "Расписание на " + DateTime.Now.ToString("dd/MM/yyyy ddd"); BindingContext = this; Appointment[] scheduleData = this.RoomSchedule; if (scheduleData != null && scheduleData.Length > 0) { this.roomScheduleListView.ItemsSource = scheduleData; this.roomScheduleListView.IsVisible = true; } }
private void Transport_OnNotification(object sender, OnNotificationEventArgs e) { try { #if !__ANDROID__ updateMutex.WaitOne(5 * 1000); #endif // Log this event this.AppController.TrackAppEvent(e); IRoomConfig roomConfig = this.levelConfig.GetRoomConfigForSensorDeviceId(e.DeviceId); if (roomConfig != null) { var sensor = roomConfig.RoomSensors.FirstOrDefault <IRoomSensor>(s => s.DeviceId.Equals(e.DeviceId) && s.Telemetry.Equals(e.ValueLabel)); bool IsChanged = false; if (sensor != null) { // Check if value was changed IsChanged = sensor.LastMeasurement == null || (!string.IsNullOrEmpty(sensor.LastMeasurement.Value) && !sensor.LastMeasurement.Value.Equals(e.Value)); sensor.LastMeasurement = e; if (IsChanged && this.OnRoomSensorChanged != null) { UpdateRoomStatus(roomConfig, sensor); this.AppController.BeginInvokeOnMainThread(() => { this.OnRoomSensorChanged.Invoke(roomConfig, sensor); }); } } } else { this.AppController.TrackAppEvent("Error: no config found for " + e.DeviceId); } }catch (Exception ex) { this.AppController.TrackAppEvent("Transport_OnNotification Error"); this.AppController.TrackAppException(ex); } finally { #if !__ANDROID__ updateMutex.ReleaseMutex(); #endif } }
internal static RoomStatus CalculateRoomStatus(IRoomConfig roomCfg, string PiRSensorValue) { //TODO: Add implementation return(RoomStatus.RoomFree); /* * if (PiRSensorValue.StartsWith("1")) * { // PiR is ON * if () * roomStatus = RoomStatus.RoomFree; * } * else * { * * }*/ }
private void Transport_OnScheduleUpdate(object sender, OnScheduleUpdateEventArgs e) { IRoomConfig roomConfig = this.levelConfig.GetRoomConfig(e.RoomId); if (roomConfig == null) { return; } Appointment currentAppointment = null; if (e.Schedule != null && e.Schedule.Length > 0) { //Assume event started early to add leeway DateTime leeWayStartTime = DateTime.Now.AddSeconds(roomConfig.EventLeewaySeconds); currentAppointment = e.Schedule.SingleOrDefault <Appointment>(a => leeWayStartTime >= DateTime.Parse(a.StartTime)); } bool IsChanged = false; if (roomConfig.CurrentAppointment != null) { IsChanged = !new AppointmentComparer().Equals(roomConfig.CurrentAppointment, currentAppointment); } else { IsChanged = roomConfig.CurrentAppointment != currentAppointment; } if (currentAppointment != null) { roomConfig.CurrentAppointment = currentAppointment; } else { roomConfig.CurrentAppointment = null; } if (IsChanged && this.OnRoomScheduleStatusChanged != null) { UpdateRoomStatus(roomConfig, null); this.OnRoomScheduleStatusChanged(roomConfig, currentAppointment); } }
internal void UpdateRoomConfig(IRoomConfig currentRoomConfig) { try { #if !__ANDROID__ updateMutex.WaitOne(5 * 1000); #endif RoomTypeGroup existingGroup = this.FindRoomTypeGroupForRoom(currentRoomConfig); if (existingGroup != null) { RoomViewModel existingViewModel = existingGroup.FirstOrDefault <RoomViewModel>(r => r.Location.Equals(currentRoomConfig.Location)); // Handle update as remove and add bool isSuccess = existingGroup.Remove(existingViewModel); if (isSuccess && existingGroup.Count == 0) { // If this is the last room in a group - remove whole group this.Remove(existingGroup); } } existingGroup = FindRoomTypeGroupForStatus(currentRoomConfig); if (existingGroup == null) { existingGroup = new RoomTypeGroup(currentRoomConfig.RoomStatus); this.Insert(0, existingGroup); } existingGroup.AddSorted(new RoomViewModel(currentRoomConfig)); }catch (Exception ex) { // TODO Add logging throw ex; } finally { #if !__ANDROID__ updateMutex.ReleaseMutex(); #endif } }
private void Transport_OnNotification(object sender, OnNotificationEventArgs e) { IRoomConfig roomConfig = this.levelConfig.GetRoomConfigForSensorDeviceId(e.DeviceId); if (roomConfig != null) { var sensor = roomConfig.RoomSensors.FirstOrDefault <IRoomSensor>(s => s.DeviceId.Equals(e.DeviceId) && s.Telemetry.Equals(e.ValueLabel)); bool IsChanged = false; if (sensor != null) { // Check if value was changed IsChanged = sensor.LastMeasurement == null || (!string.IsNullOrEmpty(sensor.LastMeasurement.Value) && !sensor.LastMeasurement.Value.Equals(e.Value)); sensor.LastMeasurement = e; if (IsChanged && this.OnRoomSensorChanged != null) { UpdateRoomStatus(roomConfig, sensor); this.OnRoomSensorChanged.Invoke(roomConfig, sensor); } } } }
public RoomViewModel(IRoomConfig roomConfig) { this.roomConfig = roomConfig; }
private void Transport_OnScheduleUpdate(object sender, OnScheduleUpdateEventArgs e) { try { #if !__ANDROID__ updateMutex.WaitOne(5 * 1000); #endif // Log this event this.AppController.TrackAppEvent(e); IRoomConfig roomConfig = this.levelConfig.GetRoomConfig(e.RoomId); if (roomConfig == null) { // Log this event this.AppController.TrackAppEvent("Error: no config for RoomId:" + e.RoomId); return; } Appointment currentAppointment = null; if (e.Schedule != null && e.Schedule.Length > 0) { //Assume event started early to add leeway DateTime leeWayStartTime = DateTime.Now.AddSeconds(roomConfig.EventLeewaySeconds); currentAppointment = e.Schedule.FirstOrDefault <Appointment>(a => leeWayStartTime >= a.StartDateTime); } // save Schedule information for the room if (this.LevelSchedule.ContainsKey(e.RoomId)) { this.LevelSchedule[e.RoomId] = e.Schedule; } else { this.LevelSchedule.Add(e.RoomId, e.Schedule); } bool IsChanged = false; if (roomConfig.CurrentAppointment != null) { IsChanged = !new AppointmentComparer().Equals(roomConfig.CurrentAppointment, currentAppointment); } else { IsChanged = roomConfig.CurrentAppointment != currentAppointment; } if (currentAppointment != null) { roomConfig.CurrentAppointment = currentAppointment; } else { roomConfig.CurrentAppointment = null; } if (IsChanged && this.OnRoomScheduleStatusChanged != null) { UpdateRoomStatus(roomConfig, null); this.AppController.BeginInvokeOnMainThread(() => { this.OnRoomScheduleStatusChanged(roomConfig, currentAppointment); }); } } catch (Exception ex) { this.AppController.TrackAppEvent("Transport_OnScheduleUpdate Error"); this.AppController.TrackAppException(ex); } finally { #if !__ANDROID__ updateMutex.ReleaseMutex(); #endif } }
/// <summary> /// Find first existing room group for this room (match Location) /// </summary> /// <param name="config"></param> /// <returns></returns> private RoomTypeGroup FindRoomTypeGroupForRoom(IRoomConfig room) { return(this.FirstOrDefault <RoomTypeGroup>(t => t.FirstOrDefault <RoomViewModel>(r => r.Location.Equals(room.Location)) != null)); }
/// <summary> /// Find first existing room group for this room status /// </summary> /// <param name="config"></param> /// <returns></returns> private RoomTypeGroup FindRoomTypeGroupForStatus(IRoomConfig status) { RoomGroupType type = RoomTypeGroup.MapRoomStatusToGroup(status.RoomStatus); return(this.FirstOrDefault <RoomTypeGroup>(t => t.GroupType == type)); }
public void SetRoomStatus(IRoomConfig roomConfig) { SetVariable(roomConfig.FloorMapVarName, (int)roomConfig.RoomStatus); }
private async void ShowRoomDetailPopup(IRoomConfig config) { this.roomDetailPopup = new RoomDetailPopupPage(config); await this.mainPage.Navigation.PushPopupAsync(this.roomDetailPopup); }
public void Connect(IRoomConfig SettingsProvider) { throw new NotImplementedException(); }
private static RoomStatus(IRoomConfig roomCfg)