protected override void OnConnectedChanged(ConnectedChanged e) { if (!e.IsConnected) { UpdateUI(null); } }
protected override void OnConnectedChanged(ConnectedChanged e) { base.OnConnectedChanged(e); if (e.IsConnected && !string.IsNullOrEmpty(TargetId)) { m_isFollowingId = TargetIdType == AccountType.Artist ? SpotifyService.IsUserFollowingArtist(TargetId) : SpotifyService.IsUserFollowingUser(TargetId); // Gets information about the target id AccountInfo details = TargetIdType == AccountType.Artist ? (AccountInfo)SpotifyService.GetArtistDetails(TargetId) : SpotifyService.GetUserDetails(TargetId); if (details != null) { StartCoroutine(Spotify4Unity.Helpers.Utility.LoadImageFromUrl(details.ProfilePictureURL, Spotify4Unity.Enums.Resolution.x128, (sprite) => { m_userImg.sprite = sprite; })); if (m_name != null) { m_name.text = details.Name; } if (m_followers != null) { m_followers.text = "Followers: " + details.Followers.ToString(); } } m_followBtn.GetComponentInChildren <Text>().text = m_isFollowingId ? "Unfollow" : "Follow"; } }
/// <summary> /// Disconnect from any connected VM. /// </summary> public void Disconnect() { var conn = connection; connection = null; prepared = false; pid = -1; var oldMonitor = jdwpMonitor; jdwpMonitor = null; if (oldMonitor != null) { oldMonitor.Stop(); oldMonitor.Dispose(); } if (conn != null) { try { conn.Close(); } catch { // Ignore } } // Notify ConnectedChanged.Fire(this); }
private void OnConnected(bool connected) { if (connected != IsConnected) { IsConnected = connected; ConnectedChanged?.Invoke(connected); } }
public void Disconnect() { _connection.Stop(); _connection.Dispose(); _connection = null; IsConnected = false; ConnectedChanged.Invoke(this, new EventArgs <bool>(IsConnected)); }
public override void OnMouseClicked(Point position, MouseButtons button) { isConnected = !isConnected; BackColor = isConnected ? Color.DeepSkyBlue : Color.SkyBlue; ConnectedChanged?.Invoke(); }
protected override void OnConnectedChanged(ConnectedChanged e) { base.OnConnectedChanged(e); if (m_noDevicesUI != null) { m_noDevicesUI.SetActive(!e.IsConnected); } // Remove any UI if not connected if (!e.IsConnected) { UpdateUI(null); } }
protected override void OnConnectedChanged(ConnectedChanged e) { base.OnConnectedChanged(e); // Re-enable connect UI if not connected to Spotify if (m_connectCanvas != null) { m_connectCanvas.SetActive(!e.IsConnected); } // Always disable spinner if (m_connectingSpinner != null && m_connectingSpinner.activeInHierarchy) { m_connectingSpinner.SetActive(false); } }
public virtual void isNewSwitch(Object sender, IsNewSwitchEventArgs e) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); if (e.Device == Name) { ISwitchVector v = GetSwitchVector(e.Vector.Name); if (v == null) { AddSwitchVector(e.Vector); } if (e.Vector.Name == "CONNECTION" && e.Vector.Values[0].value != ConnectionState) { ConnectionState = e.Vector.Values[0].value; ConnectedChanged?.Invoke(this, e); } } }
public async Task Connect(string serverUri, string username) { if (_isConnecting || IsConnected) { return; } try { Username = username; ServerUri = serverUri; _isConnecting = true; _connection = new HubConnection(serverUri); _proxy = _connection.CreateHubProxy("ChatHub"); _proxy.On <MessageObject>(nameof(IServerHub.AddNewMessage), AddNewMessage); await _connection.Start(); var success = await _proxy.Invoke <bool>(nameof(IClientHub.ConnectUser), Username); if (!success) { MessageBox.Show("User already connected."); _isConnecting = false; Disconnect(); return; } IsConnected = true; _isConnecting = false; } catch (Exception) { IsConnected = false; _isConnecting = false; } ConnectedChanged.Invoke(this, new EventArgs <bool>(IsConnected)); }
/// <summary> /// Connect to the VM in the given process id on the given device. /// </summary> public void Connect(IDevice device, int pid, MapFile mapFile) { // Disconnect any pending connections Disconnect(); // Cleanup process = null; this.mapFile = mapFile; this.pid = pid; // Setup forward var port = GetFreePort(); var adb = new Adb(); adb.ForwardJdwp(device, port, pid); // Establish connection connection = new JdwpConnection(new IPEndPoint(IPAddress.Parse("127.0.0.1"), port), ChunkHandler, pid, PacketHandler); connection.Disconnect += OnConnectionDisconnect; // Notify ConnectedChanged.Fire(this); }
private void UpdateIsConnected() { bool succeeded = true; try { if (!IsConnected) { client = new OcularPlaneClient("localhost", 9999); } client.Ping(); } catch (Exception e) { Console.WriteLine("Could not connect because " + e.ToString()); succeeded = false; } if (this.IsConnected != succeeded) { this.IsConnected = succeeded; ConnectedChanged?.Invoke(this, null); } }
internal void RaiseConnectedChanged() { ConnectedChanged?.Invoke(this); }
public void Initialize(string userId, long lastActivity = 0) { try { // we can only initialize if the user is registered if (string.IsNullOrEmpty(userId)) { return; } _UserId = userId; PNConfiguration config = new PNConfiguration(); config.PublishKey = _PublishKey; config.SubscribeKey = _SubscribeKey; config.Uuid = _UserId; config.Secure = true; _Pubnub = new Pubnub(config); SubscribeCallbackExt listenerSubscribeCallack = new SubscribeCallbackExt((pubnubObj, message) => { try { // get the message base to determine type BaseMessage m = Serializer.Deserialize <BaseMessage>(message.Message.ToString()); // deserialize to actual type m = (BaseMessage)Serializer.Deserialize(GetType().Assembly.GetType(m.Type), message.Message.ToString()); // let listeners know MessageReceived?.Invoke(this, new MessageEventArgs <BaseMessage>(m)); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("*** ChatService.MessageReceived - Unable to deserialize message: {0}", message.Message.ToString())); } }, (pubnubObj, presence) => { // handle incoming presence data if (presence.Event.Equals("join")) { RaiseChannelJoined(presence.Channel, presence.Uuid); } else if (presence.Event.Equals("leave")) { RaiseChannelLeft(presence.Channel, presence.Uuid); } else if (presence.Event.Equals("state-change")) { // listen for status events - eg: typing, etc if ((presence.State == null) || (presence.State.Count == 0)) { return; } foreach (var key in presence.State.Keys) { var state = (ChatState)Enum.Parse(typeof(ChatState), presence.State[key].ToString()); RaiseChannelState(presence.Channel, presence.Uuid, state); } } else if (presence.Event.Equals("timeout")) { } else if (presence.Event.Equals("interval")) { // find the ids that have joined if ((presence.Join != null) && (presence.Join.Length > 0)) { foreach (var uuid in presence.Join) { RaiseChannelJoined(presence.Channel, uuid); } } if ((presence.Leave != null) && (presence.Leave.Length > 0)) { foreach (var uuid in presence.Leave) { RaiseChannelJoined(presence.Channel, uuid); } } } else if (presence.HereNowRefresh) { // TODO: request state for channels //GetState(); } }, (pubnubObj, status) => { if (status.Operation == PNOperationType.PNHeartbeatOperation) { Connected = !status.Error; ConnectedChanged?.Invoke(this, new EventArgs()); } else if ((status.Operation != PNOperationType.PNSubscribeOperation) && (status.Operation != PNOperationType.PNUnsubscribeOperation)) { return; } if (status.Category == PNStatusCategory.PNConnectedCategory) { // this is expected for a subscribe, this means there is no error or issue whatsoever } else if (status.Category == PNStatusCategory.PNReconnectedCategory) { // this usually occurs if subscribe temporarily fails but reconnects. This means // there was an error but there is no longer any issue } else if (status.Category == PNStatusCategory.PNDisconnectedCategory) { // this is the expected category for an unsubscribe. This means there // was no error in unsubscribing from everything } else if (status.Category == PNStatusCategory.PNUnexpectedDisconnectCategory) { // this is usually an issue with the internet connection, this is an error, handle appropriately } else if (status.Category == PNStatusCategory.PNAccessDeniedCategory) { // this means that PAM does allow this client to subscribe to this // channel and channel group configuration. This is another explicit error } }); _Pubnub.AddListener(listenerSubscribeCallack); // create and subscribe to the lobby channel _Pubnub .Subscribe <string>() .Channels(new string[] { _UserId }) .WithPresence() .Execute(); Initialized = true; InitializedChanged?.Invoke(this, new EventArgs()); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("*** ChatService.Initialize - Exception: {0}", ex)); } }
private void OnConnectedChanged(ConnectedChangedEventArgs e) { ConnectedChanged?.Invoke(this, e); }
protected void ConnChanged() { ConnectedChanged?.Invoke(null, null); }
} Initialized = true; InitializedChanged?.Invoke(Initialized); } public void Uninitialize() { // this can be called before Initialize if (_Pubnub == null) return; try { System.Diagnostics.Debug.WriteLine($"*** {GetType().Name}.Uninitialize - Uninitializing Chat for user {_UserId}"); _Pubnub.RemoveListener(_ListenerSubscribeCallack); _Pubnub.Unsubscribe<string>().Channels(new string[] { _UserId }).Execute(); // TODO: consider removing push channel association here Initialized = false; InitializedChanged?.Invoke(Initialized); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"{ GetType().Name}.Uninitialize - Exception: { ex}"); } } #endregion Init #region Callbacks private void OnMessageReceived(Pubnub pubnub, PNMessageResult<object> result) { try { MessageReceived?.Invoke(this, new MessageEventArgs(result.Message.ToString())); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"*** {GetType().Name}.MessageReceived - Unable to deserialize message: { result.Message}\r\n\tException: { ex}"); } } private void OnPresenceReceived(Pubnub pubnub, PNPresenceEventResult result) { System.Diagnostics.Debug.WriteLine($"*** { GetType().Name}.OnPresenceReceived\r\n -> Event: { result.Event}"); { // handle incoming presence data if (result.Event.Equals("join")) { RaiseChannelJoined(result.Channel, result.Uuid); } else if (result.Event.Equals("leave")) { RaiseChannelLeft(result.Channel, result.Uuid); } else if (result.Event.Equals("state-change")) { // listen for status events - eg: typing, etc if ((result.State == null) || (result.State.Count == 0)) return; foreach (var key in result.State.Keys) { var state = (ChatState)Enum.Parse(typeof(ChatState), result.State[key].ToString()); RaiseChannelState(result.Channel, result.Uuid, state); } } else if (result.Event.Equals("timeout")) { } else if (result.Event.Equals("interval")) { // find the ids that have joined if ((result.Join != null) && (result.Join.Length > 0)) { foreach (var uuid in result.Join) RaiseChannelJoined(result.Channel, uuid); } if ((result.Leave != null) && (result.Leave.Length > 0)) { foreach (var uuid in result.Leave) RaiseChannelJoined(result.Channel, uuid); } } else if (result.HereNowRefresh) { // TODO: request state for channels //GetState(); } } } private void OnStatusReceived(Pubnub pubnub, PNStatus status) { { System.Diagnostics.Debug.WriteLine($"*** {GetType().Name}.OnStatusReceived\r\n -> Operation: { status.Operation}\r\n -> Category: { status.Category}\r\n -> Error: { status.Error}\r\n -> Data: { status.ErrorData}\r\n -> Status Code: { status.StatusCode}"); if (status.Operation == PNOperationType.PNHeartbeatOperation) { Connected = !status.Error; ConnectedChanged?.Invoke(this, new EventArgs()); } if ((status.Operation == PNOperationType.PNSubscribeOperation) && (status.Category == PNStatusCategory.PNUnknownCategory) && (status.StatusCode == 404)) { try { _FailCount++; if (_FailCount > 3) { System.Diagnostics.Debug.WriteLine($" -> Not found error, max fails = {_FailCount}"); return; } System.Diagnostics.Debug.WriteLine(" -> Not found error, attempting to reinitialize"); // disconnect //System.Diagnostics.Debug.WriteLine(" -> -> uninitialize"); //Uninitialize(); // reconnect System.Diagnostics.Debug.WriteLine(" -> -> reinitialize"); Initialize(_UserId, _AuthKey, false, _PushData); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("*** ChatService.Initialize - Exception: {0}", ex)); } } if (status.Category == PNStatusCategory.PNConnectedCategory) { System.Diagnostics.Debug.WriteLine(" -> Connected"); // this is expected for a subscribe, this means there is no error or issue whatsoever // reset fail count _FailCount = 0; } else if (status.Category == PNStatusCategory.PNReconnectedCategory) { System.Diagnostics.Debug.WriteLine(" -> Reconnected"); // this usually occurs if subscribe temporarily fails but reconnects. This means // there was an error but there is no longer any issue } else if (status.Category == PNStatusCategory.PNDisconnectedCategory) { System.Diagnostics.Debug.WriteLine(" -> Disconnected"); // this is the expected category for an unsubscribe. This means there // was no error in unsubscribing from everything } else if (status.Category == PNStatusCategory.PNUnexpectedDisconnectCategory) { System.Diagnostics.Debug.WriteLine(" -> Unexpected disconnected"); // this is usually an issue with the internet connection, this is an error, handle appropriately } else if (status.Category == PNStatusCategory.PNAccessDeniedCategory) { System.Diagnostics.Debug.WriteLine(" -> Access Denied"); // this means that PAM does allow this client to subscribe to this // channel and channel group configuration. This is another explicit error } } } #endregion Callbacks #region Operations public void GetHistory(long timeStamp) { try { if (!Initialized || string.IsNullOrEmpty(_UserId)) return; _Pubnub.History() .Channel(_UserId) .Start(timeStamp) .Count(20) .Async(new PNHistoryResultExt((result, status) => { if ((result.Messages == null) || (result.Messages.Count == 0)) return; foreach (var message in result.Messages) { // let listeners know MessageReceived?.Invoke(this, new MessageEventArgs(message.Entry.ToString())); } })); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("*** ChatService.GetHistory - Exception: {0}", ex)); } } public void Publish(string to, string message, object state) { try { if (!Initialized || string.IsNullOrEmpty(_UserId)) throw new ArgumentException("Cannot publish before initialize."); // publish message _Pubnub.Publish() .Channel(to) .Message(message) .Async(new PNPublishResultExt((result, status) => { if (message == null) return; // get the message PublishComplete?.Invoke(this, new MessageEventArgs(message) { State = state, Success = !status.Error, Timestamp = new DateTime(result.Timetoken) }); })); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("*** ChatService.Publish - Exception: {0}", ex)); } } #endregion Operations #region Event Triggers private void RaiseChannelJoined(string channel, string uuid) { ChannelJoined?.Invoke(this, new PresenceEventArgs(channel, uuid)); } private void RaiseChannelLeft(string channel, string uuid) { ChannelLeft?.Invoke(this, new PresenceEventArgs(channel, uuid)); } private void RaiseChannelTimeout(string channel, string uuid) { ChannelTimeout?.Invoke(this, new PresenceEventArgs(channel, uuid)); } private void RaiseChannelState(string channel, string uuid, ChatState state) { ChannelState?.Invoke(this, new PresenceEventArgs(channel, uuid, state)); } #endregion Event Triggers #region Cleanup public void Dispose() { if (_Disposed) return; // TODO: check this - it looks dodgy SubscribeCallbackExt listenerSubscribeCallack = new SubscribeCallbackExt((pubnubObj, message) => { }, (pubnubObj, presence) => { }, (pubnubObj, status) => { }); _Pubnub.AddListener(listenerSubscribeCallack); // some time later _Pubnub.RemoveListener(listenerSubscribeCallack); _Pubnub.Destroy(); _Disposed = true; } #endregion Cleanup } }
/// <summary> /// Callback for when the service status of being connected to Spotify has changed /// </summary> /// <param name="e"></param> protected virtual void OnConnectedChanged(ConnectedChanged e) { }