private void ScannerManager_RemoteScannerConnected(object sender, ScannerEventArgs e)
 {
     lock (s_remoteScannerSync)
     {
         if (IsRemoteScannerConnected)
         {
             Logger.LogVerbose(Message.SyncIgnoreRemoteScannerConnectedEvent);
             return;
         }
         _remoteScannerInfo = new ScannerInfo(e.SerialNumber, e.IpAddress);
     }
     if (_localScannerInfo == null)
     {
         return;
     }
     try
     {
         Logger.LogVerbose(Message.SyncTryOpenConnection);
         var uri       = GetUriForRemoteInteraction(e.IpAddress);
         var connector = GetRemoteScannerConnector(uri);
         var allowed   = connector.IsRemoteConnectionAllow(
             _localScannerInfo.SerialNumber, _localScannerInfo.IpAddress);
         if (!allowed)
         {
             Logger.LogVerbose(Message.SyncRemoteConnectionNotAllow);
             return;
         }
         _remoteScannerInterface.SetInteractionChannel(connector, _remoteScannerInfo);
         Logger.LogInfo(Message.SyncRemoteConnectionSuccess, e.SerialNumber, e.IpAddress);
         _remoteScannerDisconnected.Reset();
         _remoteScannerConnected.Set();
         RemoteScannerConnected.RaiseEvent(this);
     }
     catch (ThreadAbortException)
     {
         throw;
     }
     catch (Exception ex)
     {
         if (ex is RemotingException || ex is SocketException)
         {
             Logger.LogInfo(Message.SyncCannotConnectToRemoteScanner, ex.Message);
         }
         else
         {
             Logger.LogError(Message.SyncConnectRemoteScannerError, ex);
         }
     }
 }
Exemple #2
0
        private void HandleRemoteScannerEvent(RemoteScannerEventType eventType)
        {
            lock (s_remoteScannerEventSync)
            {
                _lastRemoteScannerEvent = eventType;
            }
            if (!Monitor.TryEnter(s_handleRemoteScannerEventSync, 100))
            {
                return;
            }
            try
            {
                _scannerManager.StopScanning();
                lock (s_remoteScannerEventSync)
                {
                    switch (_lastRemoteScannerEvent)
                    {
                    case RemoteScannerEventType.Connected:
                        _logger.LogVerbose(Message.SyncRemoteScannerConnectedEventRaise);
                        RemoteScannerConnected.RaiseEvent(this);
                        break;

                    case RemoteScannerEventType.Disconnected:
                        _logger.LogVerbose(Message.SyncRemoteScannerDisconnectedEventRaise);
                        RemoteScannerDisconnected.RaiseEvent(this);
                        break;

                    case RemoteScannerEventType.WaitForInitialization:
                        _logger.LogVerbose(Message.SyncRemoteScannerWaitForInitializationEventRaise);
                        RemoteScannerWaitForInitialization.RaiseEvent(this);
                        break;

                    case RemoteScannerEventType.ExitFromMenu:
                        _logger.LogVerbose(Message.SyncRemoteScannerExitFromMenuEventRaise);
                        RemoteScannerExitFromMenu.RaiseEvent(this);
                        break;
                    }
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
            }
            finally
            {
                Monitor.Exit(s_handleRemoteScannerEventSync);
            }
        }