コード例 #1
0
ファイル: SynelServer.cs プロジェクト: synel/syndll2
        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);
        }
コード例 #2
0
 internal ProgrammingOperations(SynelClient client)
 {
     _fingerprintOperations = new Lazy<FingerprintOperations>(() => new FingerprintOperations(client));
     _client = client;
     try
     {
         _client.Terminal.Halt();
     }
     catch
     {
         _client.Terminal.Run();
         throw;
     }
 }
コード例 #3
0
 internal ProgrammingOperations(SynelClient client)
 {
     _fingerprintOperations = new Lazy <FingerprintOperations>(() => new FingerprintOperations(client));
     _client = client;
     try
     {
         _client.Terminal.Halt();
     }
     catch
     {
         _client.Terminal.Run();
         throw;
     }
 }
コード例 #4
0
ファイル: PushNotification.cs プロジェクト: synel/syndll2
 internal PushNotification(SynelClient client, Response message)
 {
     _client = client;
     _message = message;
 }
コード例 #5
0
ファイル: TerminalOperations.cs プロジェクト: synel/syndll2
 internal TerminalOperations(SynelClient client)
 {
     _client = client;
 }
コード例 #6
0
ファイル: TerminalOperations.cs プロジェクト: synel/syndll2
 internal TerminalOperations(SynelClient client)
 {
     _client = client;
 }
コード例 #7
0
 internal FingerprintOperations(SynelClient client)
 {
     _client = client;
 }
コード例 #8
0
        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));
        }
コード例 #9
0
 internal FingerprintOperations(SynelClient client)
 {
     _client = client;
 }
コード例 #10
0
ファイル: PushNotification.cs プロジェクト: synel/syndll2
 internal PushNotification(SynelClient client, Response message)
 {
     _client  = client;
     _message = message;
 }