private async Task ReconnectImpl() { await CloseProto(); Debug.WriteLine("Creating new transport.."); if (session.authKey == null) { var result = await Authenticator.Authenticate(session.serverAddress, session.port); session.authKey = result.authKey; session.timeOffset = result.timeOffset; session.salt = result.serverSalt; } protoSender = new MtProtoSender(session); Subscribe(); protoSender.Start(); var request = new InitConnectionAndGetConfigRequest(apiLayer, apiId, deviceInfo); await SendRpcRequest(request); configuration = request.config; dcOptions = new DcOptionsCollection(request.config.dcOptions); OnConnectionStateChanged(ConnectionStateEventArgs.Connected()); }
public override TCObject Execute(TCObject item, TCAddOnTaskContext taskContext) { var config = ((OwnedItem)item).GetJiraConfig(); string[] props = new string[] { }; if (item.GetType() == typeof(RequirementSet)) { props = ToscaHelpers.GetPropertyNames("requirement"); } if (item.GetType() == typeof(TCFolder)) { var folder = item as TCFolder; props = ToscaHelpers.GetPropertyNames(folder.PossibleContent); } var properties = props; var configConstructor = new ConfigConstructor { currentConfig = config, availableAttributes = properties }; ParameterizedThreadStart pts = new ParameterizedThreadStart(ThreadStart); Thread t = new Thread(ThreadStart); t.SetApartmentState(ApartmentState.STA); t.Start(configConstructor); t.Join(); ((OwnedItem)item).SaveConfig(config); return(item); }
public override void OnResponse(BinaryReader reader) { var code = new Combinator(reader.ReadUInt32()); //if (constructor != typeof (ConfigConstructor) ) if (code.ToType == typeof(Messages_messagesSliceConstructor)) { var gzipStream = reader.BaseStream as GZipStream; var memoryStream = reader.BaseStream as MemoryStream; if (gzipStream == null && memoryStream == null) { Debugger.Break(); } // ReSharper disable once PossibleNullReferenceException var count = gzipStream?.BufferSize ?? memoryStream.Length; var readBytes = reader.ReadBytes((int)count); throw new Exception("Error obtaining configuration."); //while(true) reader } ConfigConstructor config = new ConfigConstructor(); config.Read(reader); ConfigConstructor = config; }
private async Task ReconnectImpl() { await CloseProto(); Debug.WriteLine("Creating new transport.."); if (ClientSettings.Session.AuthKey == null) { Step3_Response result = await Authenticator.Authenticate(ClientSettings.Session.ServerAddress, ClientSettings.Session.Port); ClientSettings.Session.AuthKey = result.authKey; ClientSettings.Session.TimeOffset = result.timeOffset; ClientSettings.Session.Salt = result.serverSalt; } _protoSender = new MtProtoSender(ClientSettings.Session); Subscribe(); _protoSender.Start(); var request = new InitConnectionAndGetConfigRequest(s_apiLayer, ClientSettings.AppId, _deviceInfo); await SendRpcRequest(request); _configuration = request.config; _dcOptions = new DcOptionsCollection(request.config.dcOptions); OnConnectionStateChanged(ConnectionStateEventArgs.Connected()); }
public override void OnResponse(BinaryReader reader) { uint code = reader.ReadUInt32(); ConfigConstructor config = new ConfigConstructor(); config.Read(reader); ConfigConstructor = config; }
public override void OnResponse(BinaryReader reader) { uint code = reader.ReadUInt32(); ConfigConstructor config = new ConfigConstructor(); config.Read(reader); responseCompletionSource.SetResult(config); }
public override void OnResponse(BinaryReader reader) { uint code = reader.ReadUInt32(); ConfigConstructor config = new ConfigConstructor(); config.Read(reader); ConfigConstructor = config; }
public async Task <TLApi> GetFileSession(int dc) { logger.debug("Getting file session for dc {0}", dc); await Established; ConfigConstructor config = (ConfigConstructor)gateway.Config; TelegramDC targetDc; if (dcs.ContainsKey(dc)) { targetDc = dcs[dc]; } else { targetDc = new TelegramDC(); foreach (var dcOption in config.dc_options) { DcOptionConstructor optionConstructor = (DcOptionConstructor)dcOption; if (optionConstructor.id == dc) { TelegramEndpoint endpoint = new TelegramEndpoint(optionConstructor.ip_address, optionConstructor.port); targetDc.Endpoints.Add(endpoint); } } dcs[dc] = targetDc; } MTProtoGateway fileGateway = await targetDc.GetFileGateway(gateway.Salt); TLApi fileGatewayApi = new TLApi(fileGateway); if (targetDc.FileAuthorized || dc == mainDcId) { return(fileGatewayApi); } Task <auth_ExportedAuthorization> exportAuthTask = Api.auth_exportAuthorization(dc); Auth_exportedAuthorizationConstructor exportedAuth = (Auth_exportedAuthorizationConstructor)await exportAuthTask; auth_Authorization authorization = await fileGatewayApi.auth_importAuthorization(exportedAuth.id, exportedAuth.bytes); targetDc.SaveFileAuthorization(authorization); return(fileGatewayApi); }
public async Task Migrate(int dc) { if (gateway == null) { logger.error("gateway not found, migration impossible"); return; } if (gateway.Config == null) { logger.error("config in gateway not found, migration impossible"); return; } ConfigConstructor config = (ConfigConstructor)gateway.Config; if (config.this_dc == dc) { logger.warning("migration to same dc: {0}", dc); return; } TelegramDC newDc = new TelegramDC(); foreach (var dcOption in config.dc_options) { DcOptionConstructor optionConstructor = (DcOptionConstructor)dcOption; if (optionConstructor.id == dc) { TelegramEndpoint endpoint = new TelegramEndpoint(optionConstructor.ip_address, optionConstructor.port); newDc.Endpoints.Add(endpoint); } } dcs[dc] = newDc; mainDcId = dc; gateway.Dispose(); gateway = null; establishedTask = new TaskCompletionSource <object>(); ConnectAsync(); await Established; }
public override void OnResponse(BinaryReader reader) { uint code = reader.ReadUInt32(); System.Diagnostics.Debug.WriteLine("code: " + code.ToString("x")); ; if (code == 0x4e32b894) // config constructor { ConfigConstructor config = new ConfigConstructor(); config.Read(reader); ConfigConstructor = config; } else if (code == 0xff036af1) // auth.authorization :/ { Auth_authorizationConstructor auth = new Auth_authorizationConstructor(); auth.Read(reader); UserConstructor = (UserConstructor)auth.user; } else // TODO something didn't go right... { if (code == 0xb446ae3) // messages slice still? { var result = TL.Parse(reader, code); ; } else { try { while (true) { reader.ReadUInt32(); // flush reader, it's the best we can do! } } catch (EndOfStreamException) { } } } }