示例#1
0
        public FizzRestClient(IFizzActionDispatcher dispatcher)
        {
            if (dispatcher == null)
            {
                throw ERROR_INVALID_DISPATCHER;
            }

            _dispatcher = dispatcher;
        }
        public FizzMQTTChannelMessageListener(IFizzActionDispatcher dispatcher)
        {
            if (dispatcher == null)
            {
                throw ERROR_INVALID_DISPATCHER;
            }

            _dispatcher = dispatcher;
        }
示例#3
0
        public FizzChatClient(string appId, IFizzActionDispatcher dispatcher)
        {
            if (dispatcher == null)
            {
                throw ERROR_INVALID_DISPATCHER;
            }

            _dispatcher = dispatcher;

            _messageListener = CreateListener(appId, _dispatcher);
        }
        public FizzChatClient(string appId, IFizzActionDispatcher dispatcher)
        {
            if (dispatcher == null)
            {
                throw ERROR_INVALID_DISPATCHER;
            }

            _dispatcher = dispatcher;

            _messageListener   = CreateListener(appId, _dispatcher);
            _groups            = new FizzGroups();
            _users             = new FizzUsers();
            _userNotifications = new FizzUserNotifications();
        }
示例#5
0
 public FizzTimer(int delayMS, IFizzActionDispatcher dispatcher, Action onTimeout)
 {
     dispatcher.Delay(delayMS, () =>
     {
         lock (_synclock)
         {
             if (!_aborted)
             {
                 _timeout = true;
                 onTimeout();
             }
         }
     });
 }
        public FizzMQTTChannelMessageListener(string appId,
                                              IFizzActionDispatcher dispatcher)
        {
            if (string.IsNullOrEmpty(appId))
            {
                throw ERROR_INVALID_APP_ID;
            }
            if (dispatcher == null)
            {
                throw ERROR_INVALID_DISPATCHER;
            }

            _dispatcher = dispatcher;
        }
        public FizzIngestionClient(IFizzEventLog eventLog, IFizzActionDispatcher dispatcher)
        {
            if (eventLog == null)
            {
                throw new FizzException(FizzError.ERROR_BAD_ARGUMENT, "invalid_event_log");
            }
            if (dispatcher == null)
            {
                throw new FizzException(FizzError.ERROR_BAD_ARGUMENT, "invalid_dispatcher");
            }

            _eventLog   = eventLog;
            _dispatcher = dispatcher;
            _interval   = new FizzInterval(_dispatcher, Flush, LOG_FLUSH_INTERVAL);
        }
示例#8
0
        public FizzMQTTConnection(string username,
                                  string password,
                                  string clientId,
                                  bool retry,
                                  bool cleanSession,
                                  IFizzActionDispatcher dispatcher)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                throw ERROR_INVALID_CLIENT_ID;
            }
            if (string.IsNullOrEmpty(username))
            {
                throw ERROR_INVALID_USERNAME;
            }
            if (string.IsNullOrEmpty(password))
            {
                throw ERROR_INVALID_PASSWORD;
            }
            if (dispatcher == null)
            {
                throw ERROR_INVALID_DISPATCHER;
            }

            _clientId     = clientId;
            _username     = username;
            _password     = password;
            _retry        = retry;
            _cleanSession = cleanSession;
            _dispatcher   = dispatcher;

            _client = new MqttClient(
                FizzConfig.MQTT_HOST_ENDPOINT,
                FizzConfig.MQTT_USE_TLS ? 8883 : 1883,
                FizzConfig.MQTT_USE_TLS,
                null, null,
                FizzConfig.MQTT_USE_TLS ? MqttSslProtocols.TLSv1_2 : MqttSslProtocols.None
                );

            _client.ConnectionClosed += (sender, args) =>
            {
                OnDisconnected(true, null);
            };

            _client.MqttMsgPublishReceived += OnMqttMessageReceived;
        }
示例#9
0
        public FizzInterval(IFizzActionDispatcher dispatcher, Action callback, int intervalMS)
        {
            if (dispatcher == null)
            {
                throw new FizzException(FizzError.ERROR_BAD_ARGUMENT, "invalid_dispatcher");
            }
            if (callback == null)
            {
                throw new FizzException(FizzError.ERROR_BAD_ARGUMENT, "invalid_interval_callback");
            }
            if (intervalMS <= 0)
            {
                throw new FizzException(FizzError.ERROR_BAD_ARGUMENT, "invalid_interval");
            }

            _dispatcher = dispatcher;
            _callback   = callback;
            _intervalMS = intervalMS;
        }
        public FizzMQTTConnection(string username,
                                  string password,
                                  string clientId,
                                  bool retry,
                                  bool cleanSession,
                                  IFizzActionDispatcher dispatcher)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                throw ERROR_INVALID_CLIENT_ID;
            }
            if (string.IsNullOrEmpty(username))
            {
                throw ERROR_INVALID_USERNAME;
            }
            if (string.IsNullOrEmpty(password))
            {
                throw ERROR_INVALID_PASSWORD;
            }
            if (dispatcher == null)
            {
                throw ERROR_INVALID_DISPATCHER;
            }

            _clientId = clientId;
            _id       = Interlocked.Increment(ref nextId);

            MqttClientOptionsBuilder builder = new MqttClientOptionsBuilder()
                                               .WithClientId(_clientId)
                                               .WithCredentials(username, password)
                                               .WithTcpServer(FizzConfig.MQTT_HOST_ENDPOINT)
                                               .WithCleanSession(cleanSession);

            if (FizzConfig.MQTT_USE_TLS)
            {
                builder.WithTls();
            }

            _options    = builder.Build();
            _retry      = retry;
            _dispatcher = dispatcher;
        }
示例#11
0
 protected FizzMQTTChannelMessageListener CreateListener(string appId, IFizzActionDispatcher dispatcher)
 {
     return(new FizzMQTTChannelMessageListener(appId, dispatcher));
 }
示例#12
0
        public FizzMQTTConnection(string username,
                                  string password,
                                  string clientId,
                                  bool retry,
                                  bool cleanSession,
                                  IFizzActionDispatcher dispatcher)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                throw ERROR_INVALID_CLIENT_ID;
            }
            if (string.IsNullOrEmpty(username))
            {
                throw ERROR_INVALID_USERNAME;
            }
            if (string.IsNullOrEmpty(password))
            {
                throw ERROR_INVALID_PASSWORD;
            }
            if (dispatcher == null)
            {
                throw ERROR_INVALID_DISPATCHER;
            }

            _clientOptions = new MqttClientOptionsBuilder()
                             .WithClientId(clientId)
                             .WithTcpServer(FizzConfig.MQTT_HOST_ENDPOINT)
                             .WithCredentials(username, password)
                             .WithTls()
                             .WithCleanSession(cleanSession)
                             .WithKeepAlivePeriod(TimeSpan.FromSeconds(30))
                             .Build();

            _retry      = retry;
            _dispatcher = dispatcher;

            var clientFactory = new MqttFactory();

            _client = clientFactory.CreateMqttClient();


            _client.UseDisconnectedHandler(discArgs =>
            {
                if (discArgs.Exception is MqttConnectingFailedException failedException)
                {
                    if (failedException.ResultCode == MqttClientConnectResultCode.BadUserNameOrPassword ||
                        failedException.ResultCode == MqttClientConnectResultCode.NotAuthorized)
                    {
                        OnDisconnected(discArgs.ClientWasConnected, new FizzMqttAuthException());
                    }
                }
                else if (discArgs.Exception != null)
                {
                    OnDisconnected(discArgs.ClientWasConnected, discArgs.Exception);
                }
                else
                {
                    OnDisconnected(discArgs.ClientWasConnected, null);
                }
            });

            _client.UseConnectedHandler(conArgs => {
                if (_manualDisconnect)
                {
                    return;
                }

                if (Connected != null)
                {
                    _dispatcher.Post(() => Connected.Invoke(this, conArgs.AuthenticateResult.IsSessionPresent));
                }
            });

            _client.UseApplicationMessageReceivedHandler(OnMqttMessageReceived);
        }
示例#13
0
 protected FizzMQTTChannelMessageListener CreateListener(IFizzActionDispatcher dispatcher)
 {
     return(new FizzMQTTChannelMessageListener(dispatcher));
 }