Exemplo n.º 1
0
        private void UpsertMonitor(Device deviceToSubscribe, IMatchMonitor monitor)
        {
            if (_monitors.ContainsKey(deviceToSubscribe.Id))
            {
                _monitors[deviceToSubscribe.Id].Stop();
                _monitors.Remove(deviceToSubscribe.Id);
            }

            foreach (var handler in _eventHandlers)
            {
                monitor.MatchReceived += handler;
            }

            _monitors.Add(deviceToSubscribe.Id, monitor);
        }
Exemplo n.º 2
0
    public void StopEverything()
    {
        var keys = new List <string>(_monitors.Keys);

        foreach (var key in keys)
        {
            IMatchMonitor monitor = null;
            if (_monitors.TryGetValue(key, out monitor))
            {
                monitor.Stop();
            }
        }

        _monitors.Clear();
        if (_locationService != null)
        {
            _locationService.Stop();
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Subscribes the matches.
    /// </summary>
    /// <returns>The matches.</returns>
    /// <param name="channel">Channel.</param>
    /// <param name="device">Device, if null will default to main device</param>
    public IMatchMonitor SubscribeMatches(MatchChannel channel, Device device = null)
    {
        var           deviceToSubscribe = device == null ? _state.Device : device;
        IMatchMonitor monitor           = null;

        switch (channel)
        {
        case MatchChannel.polling:
            monitor = CreatePollingMonitor(deviceToSubscribe);
            break;

        case MatchChannel.websocket:
            monitor = CreateWebsocketMonitor(deviceToSubscribe);
            break;

        case MatchChannel.threadedPolling:
            monitor = CreateThreadedPollingMonitor(deviceToSubscribe);
            break;

        default:
            break;
        }

        if (monitor == null)
        {
            throw new ArgumentException(String.Format("{0} is an unrecognized channel", channel));
        }

        if (_monitors.ContainsKey(deviceToSubscribe.Id))
        {
            _monitors[deviceToSubscribe.Id].Stop();
            _monitors.Remove(deviceToSubscribe.Id);
        }

        foreach (var handler in _eventHandlers)
        {
            monitor.MatchReceived += handler;
        }

        _monitors.Add(deviceToSubscribe.Id, monitor);

        return(monitor);
    }
Exemplo n.º 4
0
        /// <summary>
        /// Subscribes the matches.
        /// </summary>
        /// <returns>The matches.</returns>
        /// <param name="device">Device, if null will default to main device</param>
        /// <param name="channel">Channel.</param>
        public IMatchMonitor SubscribeMatches(MatchChannel channel = MatchChannel.Polling | MatchChannel.Websocket, Device device = null)
        {
            if (!MainDeviceSet)
            {
                throw new MatchmoreException("Main nor optional device is not ready");
            }

            var deviceToSubscribe = device ?? _state.MainDevice;

            var monitors = new List <IMatchMonitor>();

            if (channel.HasFlag(MatchChannel.Polling))
            {
                monitors.Add(new PollingMatchMonitor(this, deviceToSubscribe));
            }

            if (channel.HasFlag(MatchChannel.Websocket))
            {
                monitors.Add(new WebsocketMatchMonitor(this, deviceToSubscribe, _worldId));
            }

            if (!monitors.Any())
            {
                throw new MatchmoreException("Invalid match monitors");
            }

            IMatchMonitor monitor = null;

            if (monitors.Count == 1)
            {
                monitor = monitors.Single();
            }
            else
            {
                monitor = new MultiChannelMatchMonitor(monitors.ToArray());
            }
            UpsertMonitor(deviceToSubscribe, monitor);
            monitor.Start();
            return(monitor);
        }