示例#1
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);
    }
示例#2
0
        /// <summary>
        /// Subscribes the matches.
        /// </summary>
        /// <returns>The matches.</returns>
        /// <param name="channel">Channel.</param>
        /// <param name="deviceId">Device identifier.</param>
        public IMatchMonitor SubscribeMatches(string deviceId, MatchChannel channel = MatchChannel.Polling)
        {
            if (!MainDeviceSet)
            {
                throw new MatchmoreException("Main nor optional device is not ready");
            }

            if (string.IsNullOrEmpty(deviceId))
            {
                throw new ArgumentException("Device Id null or empty");
            }

            var d = FindDevice(deviceId).device;

            if (d == null)
            {
                throw new InvalidOperationException("Device id unrecognized");
            }

            return(SubscribeMatches(channel, d));
        }
示例#3
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);
        }
示例#4
0
        /// <summary>
        /// Creates the device and start listening. This is useful when the device also manages pins
        /// </summary>
        /// <returns>The pin device and start listening.</returns>
        /// <param name="device">Device.</param>
        /// <param name="channel">Channel.</param>
        public async Task <(Device, IMatchMonitor)> CreateDeviceAndStartListening(Device device, MatchChannel channel)
        {
            if (!MainDeviceSet)
            {
                throw new MatchmoreException("Main nor optional device is not ready");
            }

            var createdDevice = await CreateDeviceAsync(device).ConfigureAwait(false);

            var monitor = SubscribeMatches(channel, createdDevice);

            return(createdDevice, monitor);
        }
示例#5
0
 public MatchReceivedEventArgs(Device device, MatchChannel channel, List <Match> matches)
 {
     Device  = device;
     Channel = channel;
     Matches = matches;
 }
示例#6
0
    /// <summary>
    /// Creates the pin device and start listening. This is useful when the device also manages pins
    /// </summary>
    /// <returns>The pin device and start listening.</returns>
    /// <param name="pinDevice">Pin device.</param>
    /// <param name="channel">Channel.</param>
    public MTuple <PinDevice, IMatchMonitor> CreatePinDeviceAndStartListening(PinDevice pinDevice, MatchChannel channel)
    {
        var createdDevice = CreatePinDevice(pinDevice);
        var monitor       = SubscribeMatches(channel, createdDevice);

        return(MTuple.New(createdDevice, monitor));
    }