private void MasterStatusUpdate(MasterStatus a_fwStat, int alertingNode) { if (_masterStatus != a_fwStat) { _masterStatus = a_fwStat; _log.Debug("Master Status changed: " + _masterStatus); switch (a_fwStat) { case MasterStatus.MasterWelcomeScreen: case MasterStatus.MasterBootloaderMode: case MasterStatus.MasterHiddenMenu: case MasterStatus.MasterNotSupportedHardware: case MasterStatus.MasterInfoScreen: case MasterStatus.MasterAdvancedMenu: case MasterStatus.MasterNonArmed: viewEZMacNetwork1.setStatus(alertingNode, ViewEZMacNetwork.Status.Unarmed); viewAlarmPanel1.setStatus(AlarmStatus.UnArmed); viewHouse.setAlarmState(false); return; case MasterStatus.MasterArming: viewEZMacNetwork1.setStatus(alertingNode, ViewEZMacNetwork.Status.Armed); viewAlarmPanel1.setStatus(AlarmStatus.Arming); viewHouse.setAlarmState(false); return; case MasterStatus.MasterArmed: viewEZMacNetwork1.setStatus(alertingNode, ViewEZMacNetwork.Status.Armed); viewAlarmPanel1.setStatus(AlarmStatus.Armed); viewHouse.setAlarmState(false); return; case MasterStatus.MasterAlert: viewEZMacNetwork1.setStatus(alertingNode, ViewEZMacNetwork.Status.Alarm); viewAlarmPanel1.setStatus(AlarmStatus.Alarm); viewHouse.setAlarmState(true); return; } } }
private void SendRestoreLookup() { if (Library.User.Data == null) { return; } // NOTE: One would assume that we should be able to create a broadcast after we successfully restore // our previous state and performing a master promotion. m_SocketClient.SendMessage( new RestoreLookupRequest(Library.User.Data.ArtistID != 0 ? Library.User.Data.ArtistID : Library.User.Data.UserID), p_Message => { if (p_Message == null) { Trace.WriteLine("Restore command failed."); return; } var s_Message = p_Message.As <ReturnResponse>(); if (s_Message == null || s_Message.Return == null || s_Message.Return.Value <JArray>("values") == null) { Library.DispatchEvent(ClientEvent.Authenticated, null); return; } var s_Values = s_Message.Return.Value <JArray>("values"); if (s_Values.Count == 0) { PromoteSelfToMaster("restore_not_found", OnRestoreFinished); return; } var s_RestoreValue = s_Values[0].ToObject <Dictionary <String, JToken> >(); if (s_RestoreValue == null) { PromoteSelfToMaster("restore_not_found", OnRestoreFinished); return; } var s_LocalTime = DateTime.UtcNow.ToUnixTimestampMillis() + Library.TimeDifference; var s_RestoreTime = s_RestoreValue.ContainsKey("time") ? s_RestoreValue["time"].Value <Int64>() : s_LocalTime; if ((!s_RestoreValue.ContainsKey("bcastOwner") || s_RestoreValue["bcastOwner"].Value <int>() == 0) && ((!s_RestoreValue.ContainsKey("status") || s_RestoreValue["status"].Value <int>() == 0) || (!s_RestoreValue.ContainsKey("songEx") || s_RestoreValue["songEx"].ToObject <Dictionary <String, JToken> >() == null) || s_LocalTime - s_RestoreTime > c_MaxOnlineIdleTime)) { PromoteSelfToMaster("last_master_idle_lower", OnRestoreFinished); return; } var s_LastUUID = LoggedInMaster != null ? LoggedInMaster.UUID : null; LoggedInMaster = new MasterStatus() { UUID = null, LastMouseMove = s_RestoreTime, LastUpdate = s_RestoreTime, CurrentBroadcast = s_RestoreValue.ContainsKey("bcast") ? s_RestoreValue["bcast"].Value <String>() : null, IsBroadcasting = s_RestoreValue["bcastOwner"].Value <int>(), CurrentlyPlayingSong = s_RestoreValue.ContainsKey("songEx") && s_RestoreValue["songEx"].ToObject <Dictionary <String, JToken> >() != null ? 1 : 0, }; if (s_LocalTime - s_RestoreTime > 5 * 60 * 1000 || s_LocalTime - s_RestoreTime > 10 * 1000 && (!s_RestoreValue.ContainsKey("remora") || Double.Parse(s_RestoreValue["remora"].Value <String>()) == 0.0)) { PingMaster(OnRestoreFinished); } else if (LastMasterUUID != null) { PromoteSelfToMaster("were_last_master", OnRestoreFinished); } else { Library.DispatchEvent(ClientEvent.Authenticated, null); } }); }
private void UpdateLoggedInMaster(Dictionary <String, JToken> p_Attributes) { if (p_Attributes == null) { return; } LoggedInMaster = new MasterStatus(); JToken s_UUID; if (p_Attributes.TryGetValue("uuid", out s_UUID)) { LoggedInMaster.UUID = s_UUID.Value <String>(); } JToken s_LastMouseMove; if (p_Attributes.TryGetValue("lastMouseMove", out s_LastMouseMove)) { LoggedInMaster.LastMouseMove = s_LastMouseMove.Value <Int64>(); } JToken s_CurrentBroadcast; if (p_Attributes.TryGetValue("currentBroadcast", out s_CurrentBroadcast)) { LoggedInMaster.CurrentBroadcast = s_CurrentBroadcast.Value <String>(); } JToken s_Broadcasting; if (p_Attributes.TryGetValue("isBroadcasting", out s_Broadcasting)) { LoggedInMaster.IsBroadcasting = s_Broadcasting.Value <int>(); } JToken s_CurrentlyPlayingSong; if (p_Attributes.TryGetValue("currentlyPlayingSong", out s_CurrentlyPlayingSong)) { LoggedInMaster.CurrentlyPlayingSong = s_CurrentlyPlayingSong.Value <int>(); } JToken s_Reason; if (p_Attributes.TryGetValue("reason", out s_Reason)) { LoggedInMaster.Reason = s_Reason.Value <String>(); } LoggedInMaster.LastUpdate = DateTime.UtcNow.ToUnixTimestampMillis(); if (String.IsNullOrWhiteSpace(LoggedInMaster.CurrentBroadcast) || LoggedInMaster.CurrentBroadcast == Library.Broadcast.ActiveBroadcastID) { return; } Library.Broadcast.ActiveBroadcastID = LoggedInMaster.CurrentBroadcast; SubscribeToBroadcast(); }