Beispiel #1
0
 private void UpdateState(ref ReceiverInternalState state, TdApi.Object obj)
 {
     if (obj is TdApi.Update.UpdateAuthorizationState authStateUpdate)
     {
         state.IsAuthenticationClosed = authStateUpdate.IsAuthorizationStateClosed();
     }
 }
Beispiel #2
0
 private void PerformQueuedActions(ref ReceiverInternalState state)
 {
     if (_actionQueue.IsEmpty)
     {
         return;
     }
     while (_actionQueue.TryDequeue(out var action))
     {
         action(ref state);
     }
 }
Beispiel #3
0
        private void ProcessEvents()
        {
            _cts = new CancellationTokenSource();

            var state = new ReceiverInternalState();
            var ct    = _cts.Token;

            while (!ct.IsCancellationRequested)
            {
                var data = _tdJsonClient.Receive(1);

                if (!string.IsNullOrEmpty(data))
                {
                    var structure = JsonConvert.DeserializeObject <TdApi.Object>(data, new Converter());
                    UpdateState(ref state, structure);
                    Received?.Invoke(this, structure);
                }

                PerformQueuedActions(ref state);
            }
        }