/// <summary> /// asynchronously run a tdapi.Function /// </summary> /// <param name="func">function you want to run asynchronously</param> /// <param name="expectedtype">the type which you expect your function response receives</param> /// <returns>A Responseobject contains your task information</returns> public async Task <Responseobject> ExecuteCommandAsync(tdapi.Function func, tdapi.BaseObject expectedtype = null) { Responseobject res = new Responseobject(); Dictionary <string, Action <tdapi.BaseObject, Reshandler> > customcommands = new Dictionary <string, Action <tdapi.BaseObject, Reshandler> >(); customcommands.Add("Custom", (a, b) => { b.responseobject = a; if (expectedtype is null) { b.response = enums.Response.Success; } else { if (a.GetType() == expectedtype.GetType()) { b.response = enums.Response.Success; } else { b.response = enums.Response.Failed; } } }); Reshandler handler = new Reshandler(this) { command = "Custom", }; ReadCommands(handler, customcommands); client.Send(func, handler); res = await handler.getresponse(); return(res); }
public void initializeclient() { string lgfilename = $"{phonenumber}-log.txt"; switch (hpcore.debuglevel) { case enums.DebugLevel.Full: if (System.IO.File.Exists(lgfilename)) { System.IO.File.Delete(lgfilename); } tdlib.Log.SetFilePath(lgfilename); break; default: tdlib.Log.SetVerbosityLevel(0); break; } mainhandler = new Reshandler(this); ReadCommands(mainhandler); client = tdlib.Client.Create(mainhandler); Task.Factory.StartNew(() => { client.Run(); }); hpcore.addlog($"{phonenumber} client initialization successed"); }