public void RequestInvokeWithLayer_Serialize() { var request = new RequestInvokeWithLayer { Layer = SchemaInfo.SchemaVersion, Query = new RequestInitConnection { ApiId = 123123123, AppVersion = "1.0.0", DeviceModel = "PC", LangCode = "en", LangPack = "en", SystemLangCode = "en", Query = new RequestGetConfig(), SystemVersion = "Win 10.0" } }; var data = Serializer.SerializeObject(request).ToArray(); var legacy = (RequestInvokeWithLayer)LegacyDeserialize(data); var obj = (RequestInvokeWithLayer)Serializer.DeserializeObject(data); Assert.Equal(request.Layer, obj.Layer); Assert.Equal(request.Query, obj.Query); }
private async Task ConnectAsync(bool forceAuth) { if (ClientSettings.Session.AuthKey == null || ClientSettings.Session.AuthKey.Data.Length == 0 || forceAuth) { var result = await DoAuthentication().ConfigureAwait(false); ClientSettings.Session.AuthKey = result.AuthKey; ClientSettings.Session.TimeOffset = result.TimeOffset; await SessionStore.Save().ConfigureAwait(false); } ProtoRecieveService.StartReceiving(); //set-up layer var request = new RequestInvokeWithLayer { Layer = SchemaInfo.SchemaVersion, Query = new RequestInitConnection { ApiId = ClientSettings.AppId, AppVersion = "1.0.0", DeviceModel = "PC", LangCode = "en", LangPack = "tdesktop", SystemLangCode = "en", Query = new RequestGetConfig(), SystemVersion = "Win 10.0" } }; var response = (TConfig)await SendService.SendRequestAsync(request).ConfigureAwait(false); _dcOptions = response.DcOptions.Items.Cast <TDcOption>().ToArray(); }
public void RequestInvokeWithLayer_Serialize() { var request = new RequestInvokeWithLayer { Layer = SchemaInfo.SchemaVersion, Query = new RequestInitConnection { ApiId = 123123123, AppVersion = "1.0.0", DeviceModel = "PC", LangCode = "en", LangPack = "en", SystemLangCode = "en", Query = new RequestGetConfig(), SystemVersion = "Win 10.0" } }; var buffer = Serializer.Serialize(request); var data = new byte[buffer.ReadableBytes]; buffer.ReadBytes(data); buffer.ResetReaderIndex(); var obj = (RequestInvokeWithLayer)Serializer.Deserialize(buffer); Assert.Equal(request.Layer, obj.Layer); Assert.NotNull(request.Query); Assert.IsType <RequestInitConnection>(request.Query); }
private async Task SendInitConnectionRequest() { Log.Debug($"#{ClientSettings.ClientSession.SessionId}: Send init connection request"); try { Guard.That(ClientSettings.AppId).IsNotDefault(); Guard.That(ClientSettings.ApplicationProperties.AppVersion).IsNotNullOrWhiteSpace(); Guard.That(ClientSettings.ApplicationProperties.DeviceModel).IsNotNullOrWhiteSpace(); Guard.That(ClientSettings.ApplicationProperties.LangCode).IsNotNullOrWhiteSpace(); Guard.That(ClientSettings.ApplicationProperties.LangPack).IsNotNullOrWhiteSpace(); Guard.That(ClientSettings.ApplicationProperties.SystemLangCode).IsNotNullOrWhiteSpace(); Guard.That(ClientSettings.ApplicationProperties.SystemVersion).IsNotNullOrWhiteSpace(); var request = new RequestInvokeWithLayer { Layer = SchemaInfo.SchemaVersion, Query = new RequestInitConnection { ApiId = ClientSettings.AppId, AppVersion = ClientSettings.ApplicationProperties.AppVersion, DeviceModel = ClientSettings.ApplicationProperties.DeviceModel, LangCode = ClientSettings.ApplicationProperties.LangCode, LangPack = ClientSettings.ApplicationProperties.LangPack, SystemLangCode = ClientSettings.ApplicationProperties.SystemLangCode, Query = new RequestGetConfig(), SystemVersion = ClientSettings.ApplicationProperties.SystemVersion } }; var resultTask = RequestService.RegisterRequest(request, CancellationToken.None); await Context.WriteAndFlushAsync(request).ConfigureAwait(false); ClientSettings.Config = (IConfig)await resultTask.ConfigureAwait(false); if (!ClientSettings.UseIPv6) { var filtredDc = ClientSettings.Config.DcOptions.Where(dc => !dc.Ipv6).ToArray(); ClientSettings.Config.DcOptions = new TVector <IDcOption>(filtredDc); } foreach (var replyRequest in RequestService.GetAllRequestToReply()) { #pragma warning disable 4014 Context.WriteAsync(replyRequest); #pragma warning restore 4014 } Context.Flush(); } catch (Exception e) { RequestService.ReturnException(e); } }
private async Task StartRecievingTask(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { try { var recieveData = await TcpTransport.Receieve().ConfigureAwait(false); var decodedData = DecodeMessage(recieveData); Log.Debug($"Receive message with remote id: {decodedData.Item2}"); ProcessReceivedMessage(decodedData.Item1); ConfirmationSendService.AddForSend(decodedData.Item2); } catch (Exception e) { Log.Error("Receive message failed. Reconnecting", e); var request = new RequestInvokeWithLayer { Layer = SchemaInfo.SchemaVersion, Query = new RequestInitConnection { ApiId = ClientSettings.AppId, AppVersion = "1.0.0", DeviceModel = "PC", LangCode = "en", LangPack = "tdesktop", Query = new RequestGetConfig(), SystemLangCode = "en", SystemVersion = "Win 10.0" } }; try { await TcpTransport.Disconnect().ConfigureAwait(false); var sendTask = await Sender.SendWithConfim(request).ConfigureAwait(false); ResponseResultGetter.Receive(sendTask.Item2).ContinueWith( async task => { await sendTask.Item1.ConfigureAwait(false); }); } catch { Log.Error("Failed to reconnect", e); } } } }