public bool Connect() { if (!_provider.CheckAndGenerateAuth()) { throw new TlException(new Exception("Auth key not created")); } try { bool authorized = _provider .InitConnection(ApiId, ConfigDevice, ConfigSystem, ConfigApplication, LangCode, ApiLayer); if (!authorized) { Combinator result = RpcCall("auth.sendCode", _phoneNumber, 0, ApiId, ApiHash, LangCode); _smsHash = result.Get <string>("phone_code_hash"); _phoneRegistered = (result.Get <Combinator>("phone_registered")).Name == "boolTrue"; } return(authorized); } catch (Exception e) { Trace.TraceError(e.ToString()); throw new TlException(e); } }
protected Combinator(Combinator combinator) { _descriptor = combinator._descriptor; _arguments = new KeyValuePair <string, object> [combinator._arguments.Length]; Array.Copy(combinator._arguments, _arguments, combinator._arguments.Length); }
// ReSharper restore MemberCanBePrivate.Global // ReSharper restore UnusedMember.Global private Combinator RpcCall(string name, params object[] parameters) { RpcAnswer answer; try { var combinator = new Combinator(name, parameters); answer = _provider.PerformRpcCall(combinator); } catch (Exception e) { e = e is AggregateException ? e.InnerException : e; throw new TlException(e); } if (!answer.Success) { throw new TlException(new Exception(answer.Error.ToString())); } return(answer.Combinator); }
public void SendMessage(string phone, string message) { Combinator result = RpcCall("auth.checkPhone", phone); if (result.Get <Combinator>("phone_registered").Name == "boolFalse") { throw new TlException(new Exception("Phone not registered: " + phone)); } if (result.Get <Combinator>("phone_invited").Name == "boolFalse") { do { result = RpcCall("auth.sendInvites" , new Combinator("vector", "string", phone) , "Invite"); } while (result.Name == "boolFalse"); RpcCall("contacts.importContacts" , new Combinator("vector", "InputContact" , new Combinator("inputPhoneContact", new Random().Next(), phone, "c_" + phone, "c_" + phone)) , new Combinator("boolTrue")); } result = RpcCall("contacts.getContacts", new Random().Next(int.MaxValue).ToString(CultureInfo.InvariantCulture)); var users = result.Get <Combinator>("users"); if (users.Count(val => ((Combinator)val).Get <string>("phone") == phone) > 0) { var userId = ((Combinator)users.First(val => ((Combinator)val).Get <string>("phone") == phone)).Get <int>("id"); RpcCall("messages.sendMessage", new Combinator("inputPeerContact", userId), message, new Random().Next(int.MaxValue)); } else { throw new TlException(new Exception("Contact not exists: " + phone)); } }
private void OnDifference(Combinator obj) { _differences.Add(obj); }
private void OnUpdate(Combinator obj) { _updates.Add(obj); }