public Task ListenAsync(CancellationToken ct) { return NetworkConnection.ListenAsync(_port, async connection => { var lineNeedsToBeReset = false; var cts = new CancellationTokenSource(); using (var timer = new Timer(state => { Util.Log("Idle Timeout"); cts.Cancel(); }, null, _idleTimeout, Timeout.InfiniteTimeSpan)) { while (connection.Connected && !cts.Token.IsCancellationRequested) { var receiver = new Receiver(connection.Stream); var message = await receiver.ReceiveMessageAsync(cts.Token); if (message == null) return; // Stop the idle timeout timer, since we have data timer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan); // Ignore any backlog of messages if (!message.LastInBuffer) { lineNeedsToBeReset = true; continue; } // Make sure a good message came through if (message.Response == null) continue; using (var client = new SynelClient(connection, message.Response.TerminalId)) { // Reset the line if we detected a backlog earlier if (lineNeedsToBeReset) { client.Terminal.ResetLine(); lineNeedsToBeReset = false; } var notification = new PushNotification(client, message.Response); // Only push valid notifications if (Enum.IsDefined(typeof (NotificationType), notification.Type)) { Util.Log(string.Format("Listener Received: {0}", message.RawResponse), connection.RemoteEndPoint.Address); if (AsyncMessageReceivedHandler != null) { await AsyncMessageReceivedHandler(notification); } } } } } }, ct); }
internal ProgrammingOperations(SynelClient client) { _fingerprintOperations = new Lazy<FingerprintOperations>(() => new FingerprintOperations(client)); _client = client; try { _client.Terminal.Halt(); } catch { _client.Terminal.Run(); throw; } }
internal ProgrammingOperations(SynelClient client) { _fingerprintOperations = new Lazy <FingerprintOperations>(() => new FingerprintOperations(client)); _client = client; try { _client.Terminal.Halt(); } catch { _client.Terminal.Run(); throw; } }
internal PushNotification(SynelClient client, Response message) { _client = client; _message = message; }
internal TerminalOperations(SynelClient client) { _client = client; }
internal FingerprintOperations(SynelClient client) { _client = client; }
public Task ListenAsync(CancellationToken ct) { return(NetworkConnection.ListenAsync(_port, async connection => { var lineNeedsToBeReset = false; var cts = new CancellationTokenSource(); using (var timer = new Timer(state => { Util.Log("Idle Timeout"); cts.Cancel(); }, null, _idleTimeout, Timeout.InfiniteTimeSpan)) { while (connection.Connected && !cts.Token.IsCancellationRequested) { var receiver = new Receiver(connection.Stream); var message = await receiver.ReceiveMessageAsync(cts.Token); if (message == null) { return; } // Stop the idle timeout timer, since we have data timer.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan); // Ignore any backlog of messages if (!message.LastInBuffer) { lineNeedsToBeReset = true; continue; } // Make sure a good message came through if (message.Response == null) { continue; } using (var client = new SynelClient(connection, message.Response.TerminalId)) { // Reset the line if we detected a backlog earlier if (lineNeedsToBeReset) { client.Terminal.ResetLine(); lineNeedsToBeReset = false; } var notification = new PushNotification(client, message.Response); // Only push valid notifications if (Enum.IsDefined(typeof(NotificationType), notification.Type)) { Util.Log(string.Format("Listener Received: {0}", message.RawResponse), connection.RemoteEndPoint.Address); if (AsyncMessageReceivedHandler != null) { await AsyncMessageReceivedHandler(notification); } } } } } }, ct)); }