protected override void EstablishContext()
        {
            A.CallTo(() => _contextFactory.Establish(SCardScope.System))
            .Returns(_context);

            A.CallTo(() => _context.IsValid())
            .Returns(true);

            A.CallTo(() => _context.Infinite)
            .Returns(SCardContext.INFINITE);

            // first call -> only one attached reader
            A.CallTo(() => _context.GetReaders())
            .Returns(new[] { READER_A });

            A.CallTo(() => _context.GetStatusChange(SCardContext.INFINITE, A <SCardReaderState[]> .That.Matches(
                                                        states => MatchFirstCall(states))))
            .ReturnsLazily(call => {
                // second call -> two attached readers
                A.CallTo(() => _context.GetReaders())
                .Returns(new[] { READER_A, READER_B });

                _getStatusChangeCall.Set();

                return(SCardError.Success);
            });

            A.CallTo(() => _context.GetStatusChange(SCardContext.INFINITE, A <SCardReaderState[]> .That.Matches(
                                                        states => MatchSecondCall(states))))
            .Returns(SCardError.Cancelled);

            _sut           = new DeviceMonitor(_contextFactory, SCardScope.System);
            _monitorEvents = _sut.MonitorEvents();
        }
Exemplo n.º 2
0
        public bool TryGetMonitor(object eventSource, out IEventMonitor eventMonitor)
        {
            IEventMonitor result = null;

            ForEach(eventSource, pair => result = pair.Value);
            eventMonitor = result;
            return(eventMonitor != null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method finds an instance of a monitored event, in the monitors collection.
        /// If it is found, a message is broadcast to all clients.
        /// </summary>
        /// <param name="monitor"></param>
        /// <param name="monitoredEventId"></param>
        public static void PushMessage(IEventMonitor monitor, Guid monitoredEventId)
        {
            var monitoredEvent = monitor.MonitoredEvents.SingleOrDefault(x => x.Id == monitoredEventId);

            if (monitoredEvent != null)
            {
                _Hub.Clients.All.broadcastMessage(monitoredEvent.Title, JsonConvert.SerializeObject(monitoredEvent));
            }
        }
Exemplo n.º 4
0
        public IEventMonitor this[object eventSource]
        {
            get
            {
                IEventMonitor result = null;
                TryGetMonitor(eventSource, out result);

                if (result == null)
                {
                    throw new InvalidOperationException(string.Format(
                                                            "Object <{0}> is not being monitored for events or has already been garbage collected. " +
                                                            "Use the MonitorEvents() extension method to start monitoring events.", eventSource));
                }

                return(result);
            }
        }
Exemplo n.º 5
0
        public void Add(object eventSource, IEventMonitor recorder)
        {
            ForEach(eventSource, keyValuePair => map.Remove(keyValuePair.Key));

            map.Add(new WeakReference(eventSource), recorder);
        }