Beispiel #1
0
        public async Task Send(TeleSharp.TL.TLMethod request)
        {
            // TODO: refactor
            if (needConfirmation.Any())
            {
                var ackRequest = new AckRequest(needConfirmation);
                using (var memory = new MemoryStream())
                    using (var writer = new BinaryWriter(memory))
                    {
                        ackRequest.SerializeBody(writer);
                        await Send(memory.ToArray(), ackRequest);

                        needConfirmation.Clear();
                    }
            }


            using (var memory = new MemoryStream())
                using (var writer = new BinaryWriter(memory))
                {
                    request.SerializeBody(writer);
                    await Send(memory.ToArray(), request);
                }

            _session.Save();
        }
Beispiel #2
0
        public async Task Send(TLMethod request, CancellationToken token = default)
        {
            token.ThrowIfCancellationRequested();

            // TODO: refactor
            if (needConfirmation.Any())
            {
                var ackRequest = new AckRequest(needConfirmation);
                using (var memory = new MemoryStream())
                    using (var writer = new BinaryWriter(memory))
                    {
                        ackRequest.SerializeBody(writer);
                        await Send(memory.ToArray(), ackRequest, token).ConfigureAwait(false);

                        needConfirmation.Clear();
                    }
            }


            using (var memory = new MemoryStream())
                using (var writer = new BinaryWriter(memory))
                {
                    request.SerializeBody(writer);
                    await Send(memory.ToArray(), request, token).ConfigureAwait(false);
                }

            session.Save();
        }
Beispiel #3
0
        public async Task Send(TLSchema.TLMethod request)
        {
            // TODO: refactor
            if (needConfirmation.Any())
            {
                var ackRequest = new AckRequest(needConfirmation);
                using (var memory = new MemoryStream())
                    using (var writer = new BinaryWriter(memory))
                    {
                        ackRequest.SerializeBody(writer);
                        await Send(memory.ToArray(), ackRequest);

                        needConfirmation.Clear();
                    }
            }


            using (var memory = new MemoryStream())
                using (var writer = new BinaryWriter(memory))
                {
                    request.SerializeBody(writer);
                    await Send(memory.ToArray(), request);
                }

            _client.RaiseSessionChanged();
        }
Beispiel #4
0
        public async Task Send(TeleSharp.TL.TLMethod request, CancellationToken token = default(CancellationToken))
        {
            token.ThrowIfCancellationRequested();

            // TODO: refactor
            if (this.needConfirmation.Any())
            {
                AckRequest ackRequest = new AckRequest(this.needConfirmation);
                using (MemoryStream memory = new MemoryStream())
                    using (BinaryWriter writer = new BinaryWriter(memory))
                    {
                        ackRequest.SerializeBody(writer);
                        await this.Send(memory.ToArray(), ackRequest, token).ConfigureAwait(false);

                        this.needConfirmation.Clear();
                    }
            }


            using (MemoryStream memory = new MemoryStream())
                using (BinaryWriter writer = new BinaryWriter(memory))
                {
                    request.SerializeBody(writer);
                    await this.Send(memory.ToArray(), request, token).ConfigureAwait(false);
                }

            this.session.Save();
        }
Beispiel #5
0
        private async Task Ack()
        {
            if (needConfirmation.Any())
            {
                var ackRequest = new AckRequest(needConfirmation);
                using (var memory = new MemoryStream())
                    using (var writer = new BinaryWriter(memory))
                    {
                        ackRequest.SerializeBody(writer);
                        await Send(memory.ToArray(), ackRequest);

                        needConfirmation.Clear();
                    }
            }
        }
Beispiel #6
0
        public async Task Send(TeleSharp.TL.TLMethod request)
        {
            // TODO: refactor
            if (needConfirmation.Any())
            {
                var ackRequest = new AckRequest(needConfirmation);
                using (var memory = new MemoryStream())
                    using (var writer = new BinaryWriter(memory))
                    {
                        ackRequest.SerializeBody(writer);
                        await Send(memory.ToArray(), ackRequest);

                        needConfirmation.Clear();
                    }
            }


            //using (var memory = new MemoryStream())
            //using (var writer = new BinaryWriter(memory))
            //{
            //    request.SerializeBody(writer);
            //    await Send(memory.ToArray(), request);
            //}



            TaskCompletionSource <bool> responseSource;

            using (var memory = new MemoryStream())
                using (var writer = new BinaryWriter(memory))
                {
                    //var messageId = _session.GetNewMessageId();
                    //request.MessageId = messageId;

                    //if (request.GetType() == typeof(TeleSharp.TL.TLRequestInvokeWithLayer))
                    //{
                    //    connectMessageID = messageId;
                    //}


                    request.SerializeBody(writer);
                    request.MessageId = _session.GetNewMessageId();

                    Debug.WriteLine($"Send request - {request.MessageId}");
                    responseSource = new TaskCompletionSource <bool>();
                    runningRequests.Add(request.MessageId, Tuple.Create(request, responseSource));

                    await Send(memory.ToArray(), request);

                    Debug.WriteLine("sended");
                }

            await responseSource.Task;

            Debug.WriteLine("complete");
            if (runningRequests.ContainsKey(request.MessageId))
            {
                runningRequests.Remove(request.MessageId);
            }
            Debug.WriteLine("request removed from queue");

            _session.Save();
            Debug.WriteLine("session saved");
        }