/// <inheritdoc /> public virtual void OnConnected(IPlugin plugin) { Plugin = plugin; Status = PluginStatus.Connected; ConnectedEvent.Set(); }
public override void OnReceive(Android.Content.Context context, Android.Content.Intent intent) { try { string action = intent.Action; switch (action) { case BluetoothDevice.ActionAclConnected: case BluetoothDevice.ActionAclDisconnected: { BluetoothDevice device = (BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice); if (device != null) { if (!string.IsNullOrEmpty(_connectDeviceAddress) && string.Compare(device.Address, _connectDeviceAddress, StringComparison.OrdinalIgnoreCase) == 0) { _deviceConnected = action == BluetoothDevice.ActionAclConnected; ConnectedEvent.Set(); } } break; } } } catch (Exception) { // ignored } }
protected virtual void OnConnected() { if (!IsConnected) { IsConnected = true; ConnectedEvent.Set(); Connected?.Invoke(this, null); } }
/// <param name="crashed"></param> /// <inheritdoc /> public virtual void OnStopped(bool crashed) { Process = null; Plugin = default; Guid = default; Status = PluginStatus.Stopped; ConnectedEvent.Set(); }
public void OnStopped() { ConnectedEvent.Set(); Status = PluginStatus.Stopped; Process = null; Plugin = null; Guid = default; }
private async Task HandleConnection(CancellationTokenSource connectionCts) { Interlocked.Exchange(ref _hbLastAction, 0); using (_client = new ClientWebSocket()) { try { _ = Task.Run(() => HeartbeatWatcher(_client, connectionCts)); await _client.ConnectAsync(new Uri(_url), connectionCts.Token); ConnectedTime = DateTime.UtcNow; ConnectedEvent.Set(); ConnectedEvent.Reset(); Interlocked.Exchange(ref _hbLastAction, 0); var currentHello = HelloMessage; var helloAs = new ArraySegment <byte>(JsonSerializer.Serialize(currentHello)); await _client.SendAsync(helloAs, WebSocketMessageType.Text, true, connectionCts.Token); Interlocked.Exchange(ref _hbLastAction, 0); var bufferArray = new byte[ReceiveBufferSize]; while (_client.State == WebSocketState.Open && !connectionCts.IsCancellationRequested) { if (currentHello != HelloMessage) { currentHello = HelloMessage; helloAs = new ArraySegment <byte>(JsonSerializer.Serialize(currentHello)); await _client.SendAsync(helloAs, WebSocketMessageType.Text, true, connectionCts.Token); Interlocked.Exchange(ref _hbLastAction, 0); } var messageData = await WSUtils.ReceiveMessage(_client, connectionCts.Token, bufferArray); Interlocked.Exchange(ref _hbLastAction, 0); if (messageData.MessageType == WebSocketMessageType.Close) { return; } _queueThread.Enqueue(messageData); } } catch (TaskCanceledException) { await _client.CloseAsync(WebSocketCloseStatus.NormalClosure, "Normal", CancellationToken.None); } catch (Exception ex) { OnError(ex); } } }
public void OnConnected(ISMAPlugin plugin) { Status = PluginStatus.Connected; Plugin = plugin; if (Metadata.IsDevelopment) { Metadata.DisplayName = plugin.Name; } ConnectedEvent.Set(); }
private async Task HandleConnection(CancellationTokenSource connectionCts) { _hbLastAction = DateTime.UtcNow; using (_client = new ClientWebSocket()) { try { _ = Task.Run(() => HeartbeatWatcher(_client, connectionCts)); await _client.ConnectAsync(new Uri(_url), connectionCts.Token); ConnectedEvent.Set(); ConnectedEvent.Reset(); _hbLastAction = DateTime.UtcNow; var currentHello = HelloMessage; var helloAs = new ArraySegment <byte>(JsonSerializer.Serialize(currentHello)); await _client.SendAsync(helloAs, WebSocketMessageType.Text, true, connectionCts.Token); _hbLastAction = DateTime.UtcNow; while (_client.State == WebSocketState.Open && !connectionCts.IsCancellationRequested) { if (currentHello != HelloMessage) { currentHello = HelloMessage; helloAs = new ArraySegment <byte>(JsonSerializer.Serialize(currentHello)); await _client.SendAsync(helloAs, WebSocketMessageType.Text, true, connectionCts.Token); _hbLastAction = DateTime.UtcNow; } var messageData = await WSUtils.ReceiveMessage(_client, connectionCts.Token); _hbLastAction = DateTime.UtcNow; if (messageData.MessageType == WebSocketMessageType.Close) { return; } _queueThread.Enqueue(messageData); } } catch (TaskCanceledException) { } catch (Exception ex) { OnError(ex); } } }
protected void ConnectMethod() { try { CloseActiveConnection(); _client = new TcpClient(); while (!Terminated && !ConnectToTCPServer()) { Thread.Sleep(ReconnectInterval); } if (!Terminated) { _netStream = _client.GetStream(); _netStream.ReadTimeout = _readTimeOut; _netStream.WriteTimeout = _writeTimeOut; if (_receivedDataAsync != null) { // subscribe for receiving messages _netStream.BeginRead(_readBuffer, 0, _readBuffer.Length, EndRead, _readBuffer); } WorkWithSync(() => { ConnectionStatus = ConnectionStatusEnum.ConnectedNotInicialized; }); if (_inicializationMethod() == true) { WorkWithSync(() => { ConnectionStatus = ConnectionStatusEnum.ConnectedInicialized; ConnectedEvent.Set(); }); } } } catch (Exception) { throw; } }