private void OnConnDisconnected(int connId, object sender, MqttClientDisconnectedEventArgs args) { if (_connection != null && _connection.Id != connId) { FizzLogger.W("Received disconnected event for old connection."); } FizzLogger.D("MQTT - OnDisconnected: " + args.ClientWasConnected.ToString()); if (OnDisconnected != null) { if (args.Exception == null) { OnDisconnected.Invoke(null); } else { if (args.Exception.GetType() == typeof(MQTTnet.Adapter.MqttConnectingFailedException)) { OnDisconnected.Invoke(ERROR_AUTH_FAILED); if (_sessionRepo != null) { _sessionRepo.FetchToken(null); } } else { OnDisconnected.Invoke(ERROR_CONNECTION_FAILED); } } } }
public void SubscribeChannel(FizzChannelMeta channelMeta) { if (Client.State == FizzClientState.Closed) { FizzLogger.W("FizzClient should be opened before subscribing channel."); return; } if (channelMeta == null) { FizzLogger.E("FizzClient unable to subscribe, channel meta is null."); return; } if (channelLookup.ContainsKey(channelMeta.Id)) { FizzLogger.W("FizzClient channel is already subscribed."); return; } FizzChannelModel channel = new FizzChannelModel(channelMeta); Channels.Add(channel); channelLookup.Add(channel.Id, channel); channel.SubscribeAndQueryLatest(); }
public bool SetChannel(string channelId) { if (!_initialized) { Initialize(); } FizzChannelModel channel = GetChannelById(channelId); if (channel == null) { return(false); } if (_channelsLookup.ContainsKey(channel.Id)) { HandleChannelSelected(channel); return(true); } else { FizzLogger.W("FizzChatView: Unable to set channel, add channel first"); return(false); } }
public void UnsubscribeUserNotifications(Action <FizzException> cb) { if (Client.State == FizzClientState.Closed) { FizzLogger.W("FizzClient should be opened before unsubscribing user."); return; } try { Client.Chat.UserNotifications.Unsubscribe(ex => { if (ex == null) { if (OnUserNotificationsUnsubscribed != null) { OnUserNotificationsUnsubscribed.Invoke(); } } FizzUtils.DoCallback(ex, cb); }); } catch (Exception e) { FizzLogger.E(e); } }
public void AddChannel(string channelId, bool select = false) { if (!_initialized) { Initialize(); } FizzChannelModel channel = GetChannelById(channelId); if (channel == null) { if (!_channelWatchList.Contains(channelId)) { _channelWatchList.Add(channelId); } FizzLogger.W("Channel not found, please add channel [" + channelId + "] to FizzService first."); return; } if (!_channelsLookup.ContainsKey(channel.Id)) { AddChannelInternal(channel); } if (_channelsLookup.ContainsKey(channel.Id) && select) { HandleChannelSelected(channel); } }
public void Open(string userId, long curServerTS, IFizzAuthRestClient client) { IfClosed(() => { if (_userId != null) { FizzLogger.W("Please close instance before re-opening"); return; } if (userId == null) { throw FizzException.ERROR_INVALID_USER_ID; } if (client == null) { throw ERROR_INVALID_CLIENT; } _client = client; _userId = userId; _timeOffset = FizzUtils.Now() - curServerTS; _startTime = FizzUtils.Now() + _timeOffset; _sessionId = Guid.NewGuid().ToString(); ClosePreviousSession(); SessionStarted(); _interval.Enable(); _onLogEmpty = () => { }; }); }
public void Unsubscribe(Action <FizzException> cb) { if (Client.State == FizzClientState.Closed) { FizzLogger.W("FizzClient should be opened before unsubscribing user."); return; } try { Client.Chat.Users.Unsubscribe(Id, ex => { if (ex == null) { IsSubscribed = false; } FizzUtils.DoCallback(ex, cb); }); } catch (Exception e) { FizzLogger.E(e); } }
public void UnsubscribeChannel(string channelId) { if (Client.State == FizzClientState.Closed) { FizzLogger.W("FizzClient should be opened before unsubscribing channel."); return; } if (string.IsNullOrEmpty(channelId)) { FizzLogger.E("FizzClient unable to unsubscribe, channelId is null or empty."); return; } if (!channelLookup.ContainsKey(channelId)) { FizzLogger.W("FizzService unable to remove, channel [" + channelId + "] does not exist. "); return; } FizzChannelModel channel = channelLookup[channelId]; channelLookup.Remove(channelId); Channels.Remove(channel); channel.Unsubscribe(null); }
public void SubscribeChannel(FizzChannelMeta meta) { if (!_isIntialized) { Initialize(); } if (Client.State == FizzClientState.Closed) { FizzLogger.W("FizzClient should be opened before subscribing channel."); return; } if (meta == null) { FizzLogger.E("FizzClient unable to subscribe, channel meta is null."); return; } if (channelLoopup.ContainsKey(meta.Id)) { FizzLogger.W("FizzClient channel is already subscribed."); return; } FizzChannel fizzChannel = AddChannelToList(meta); if (IsConnected && fizzChannel != null) { fizzChannel.SubscribeAndQuery(); } }
public void Put(FizzEvent item) { if (item == null) { FizzLogger.W("Empty item put in log"); return; } log.Add(item.Id, item); }
public void Post(Action action) { if (action == null) { FizzLogger.W("Empty action scheduled posted"); return; } Delay(0, action); }
private void IfClosed(Action callback) { if (_restClient == null) { FizzUtils.DoCallback(callback); } else { FizzLogger.W("Moderation client should be closed before opening."); } }
private void IfClosed(Action callback) { if (_client == null) { FizzUtils.DoCallback(callback); } else { FizzLogger.W("Client should have been closed."); } }
private void IfOpened(Action onInit) { if (string.IsNullOrEmpty(_userId)) { FizzLogger.W("Ingestion must be opened before use."); } else { onInit.Invoke(); } }
private void IfClosed(Action callback) { if (string.IsNullOrEmpty(_userId)) { FizzUtils.DoCallback(callback); } else { FizzLogger.W("Chat client should be closed before opening."); } }
private void IfOpened(Action callback) { if (_restClient != null) { FizzUtils.DoCallback(callback); } else { FizzLogger.W("Moderation client should be opened before usage."); } }
private void IfClosed(Action onClose) { if (string.IsNullOrEmpty(_userId)) { onClose.Invoke(); } else { FizzLogger.W("Ingestion is already opened"); } }
private void IfOpened(Action callback) { if (_restClient != null) { FizzUtils.DoCallback(callback); } else { FizzLogger.W("Client should have been opened."); } }
public void Delay(int delayMS, Action action) { if (action == null || delayMS < 0) { FizzLogger.W("Invalid timer scheduled"); return; } lock (synclock) { timers.Add(FizzUtils.Now() + delayMS, action); } }
FizzChannelModel GetChannelById(string channelId) { try { return(FizzService.Instance.GetChannel(channelId)); } catch (Exception) { FizzLogger.W("ChannelList unable to get channel with id " + channelId); } return(null); }
public void RemoveGroup(string groupId, Action <FizzException> cb) { if (Client.State == FizzClientState.Closed) { FizzLogger.W("FizzClient should be opened before removing group."); return; } Client.Chat.Users.RemoveGroup(UserId, groupId, ex => { FizzUtils.DoCallback(ex, cb); }); }
private void OnConnConnected(int connId, object sender, MqttClientConnectedEventArgs args) { if (_connection != null && _connection.Id != connId) { FizzLogger.W("Received conneced event for old connection."); } FizzLogger.D("MQTT - OnConnected: " + args.IsSessionPresent.ToString()); if (OnConnected != null) { OnConnected.Invoke(!args.IsSessionPresent); } }
private void OnConnConnected(object sender, bool sessionPresent) { if (_connection != null) { FizzLogger.W("Received connected event for old connection."); } FizzLogger.D("MQTT - OnConnected: " + sessionPresent); if (OnConnected != null) { OnConnected.Invoke(!sessionPresent); } }
public void Flush() { if (_flushInProgress) { FizzUtils.DoCallback(_onLogEmpty); return; } _flushInProgress = true; _eventLog.Read(128, items => { if (items.Count <= 0) { _flushInProgress = false; FizzUtils.DoCallback(_onLogEmpty); return; } PostEvents(items, (response, ex) => { bool rollLog = true; if (ex != null) { if (ex.Code == FizzError.ERROR_REQUEST_FAILED) { FizzLogger.W("Failed to submit events to service"); rollLog = false; } else if (ex.Code == FizzError.ERROR_INVALID_REQUEST) { FizzLogger.E("Submission of some events failed: " + ex.Message); } } if (rollLog) { _eventLog.RollTo(items[items.Count - 1]); } FizzUtils.DoCallback(_onLogEmpty); _flushInProgress = false; }); }); }
public void Subscribe(Action <FizzException> cb) { if (Client.State == FizzClientState.Closed) { FizzLogger.W("FizzClient should be opened before subscribing user."); return; } Client.Chat.Users.Subscribe(Id, ex => { if (ex == null) { IsSubscribed = true; } FizzUtils.DoCallback(ex, cb); }); }
public bool SetGroup(FizzGroupModel group) { if (!_initialized) { Initialize(); } if (_channelsLookup.ContainsKey(group.Channel.Id)) { HandleChannelSelected(group.Channel); return(true); } else { FizzLogger.W("FizzChatView: Unable to set group"); return(false); } }
public void UpdateGroup(string groupId, Action <FizzException> cb) { if (Client.State == FizzClientState.Closed) { FizzLogger.W("FizzClient should be opened before joining group."); return; } Client.Chat.Users.UpdateGroup(UserId, groupId, null, null, ex => { if (ex == null) { GroupInvites.Remove(groupId); groupLookup[groupId].Channel.SubscribeAndQueryLatest(); } FizzUtils.DoCallback(ex, cb); }); }
private void OnMessage(object sender, byte[] messagePayload) { try { string payload = Encoding.UTF8.GetString(messagePayload); FizzTopicMessage message = new FizzTopicMessage(payload); FizzLogger.D("OnMessage with id: " + message.Id); switch (message.Type) { case "CMSGP": if (OnMessagePublished != null) { OnMessagePublished.Invoke(AdaptTo(message)); } break; case "CMSGU": if (OnMessageUpdated != null) { OnMessageUpdated.Invoke(AdaptTo(message)); } break; case "CMSGD": if (OnMessageDeleted != null) { OnMessageDeleted.Invoke(AdaptTo(message)); } break; default: FizzLogger.W("unrecognized packet received: " + payload); break; } } catch { FizzLogger.W("received invalid message: " + messagePayload); } }
private void SubscribeNotificationsAndFetchGroups() { if (Client.State == FizzClientState.Closed) { FizzLogger.W("FizzClient should be opened before subscribing user."); return; } Client.Chat.UserNotifications.Subscribe(ex => { if (ex == null) { if (ex == null) { IFizzFetchUserGroupsQuery groupFetchQuery = Client.Chat.Users.BuildFetchUserGroupsQuery(UserId); FetchUserGroups(groupFetchQuery, new List <IFizzUserGroup>()); } } }); }
public void GetUser(string userId, Action <FizzUserModel, FizzException> cb) { if (Client.State == FizzClientState.Closed) { FizzLogger.W("FizzClient should be opened before fetching user."); return; } if (userId == null) { FizzLogger.E("FizzClient unable to fetch, userId is null."); return; } requestQueue.Enqueue(new GetUserRequest(userId, cb)); if (requestQueue.Count > 1) { return; } GetUser(requestQueue.Peek()); }