当前位置: 首页>>代码示例>>C#>>正文


C# Service.DebugPrint方法代码示例

本文整理汇总了C#中Service.DebugPrint方法的典型用法代码示例。如果您正苦于以下问题:C# Service.DebugPrint方法的具体用法?C# Service.DebugPrint怎么用?C# Service.DebugPrint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Service的用法示例。


在下文中一共展示了Service.DebugPrint方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateAuthentication

 public static TelegramSettings GenerateAuthentication(Service service)
 {
     try
     {
         service.DebugPrint("Fetching nearest DC...");
         var settings = new TelegramSettings();
         var authInfo = TelegramUtils.RunSynchronously(FetchNewAuthentication(DefaultTransportConfig));
         using (var client = new TelegramClient(DefaultTransportConfig, 
             new ConnectionConfig(authInfo.AuthKey, authInfo.Salt), AppInfo))
         {
             TelegramUtils.RunSynchronously(client.Connect());
             var nearestDcId = (NearestDc)TelegramUtils.RunSynchronously(client.Methods.HelpGetNearestDcAsync(new HelpGetNearestDcArgs{}));
             var config = (Config)TelegramUtils.RunSynchronously(client.Methods.HelpGetConfigAsync(new HelpGetConfigArgs{ }));
             var dcOption = config.DcOptions.OfType<DcOption>().FirstOrDefault(x => x.Id == nearestDcId.NearestDcProperty);
             settings.NearestDcId = nearestDcId.NearestDcProperty;
             settings.NearestDcIp = dcOption.IpAddress;
             settings.NearestDcPort = (int)dcOption.Port;
         }
         service.DebugPrint("Generating authentication on nearest DC...");
         var authInfo2 = TelegramUtils.RunSynchronously(FetchNewAuthentication(
             new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort)));
         settings.AuthKey = authInfo2.AuthKey;
         settings.Salt = authInfo2.Salt;
         service.DebugPrint("Great! Ready for the service to start.");
         return settings;
     }
     catch (Exception ex)
     {
         service.DebugPrint("Error in GenerateAuthentication: " + ex);
     }
     return null;
 }
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:32,代码来源:Authentication.cs

示例2: RegisterCode

        public static CodeRegister RegisterCode(Service service, TelegramSettings settings, string number, string codeHash, string code, string firstName, string lastName, bool signIn)
        {
            try
            {
                service.DebugPrint("Registering code...");
                var transportConfig = 
                    new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort);
                using (var client = new TelegramClient(transportConfig,
                    new ConnectionConfig(settings.AuthKey, settings.Salt), AppInfo))
                {
                    TelegramUtils.RunSynchronously(client.Connect());

                    try
                    {
                        IAuthAuthorization iresult = null;
                        if (signIn)
                        {
                            iresult = TelegramUtils.RunSynchronously(client.Methods.AuthSignInAsync(new AuthSignInArgs
                                {
                                    PhoneNumber = number,
                                    PhoneCodeHash = codeHash,
                                    PhoneCode = code,
                                }));
                        }
                        else
                        {
                            iresult = TelegramUtils.RunSynchronously(client.Methods.AuthSignUpAsync(new AuthSignUpArgs
                                {
                                    PhoneNumber = number,
                                    PhoneCodeHash = codeHash,
                                    PhoneCode = code,
                                    FirstName = firstName,
                                    LastName = lastName,
                                }));
                        }
                        var result = (AuthAuthorization)iresult;
                        return new CodeRegister
                        {
                            AccountId = (result.User as UserSelf).Id,
                            Expires = result.Expires,
                            Response = CodeRegister.Type.Success,
                        };
                    }
                    catch (RpcErrorException ex)
                    {
                        var error = (RpcError)ex.Error;
                        var cr = new CodeRegister();
                        var response = CodeRegister.Type.Failure;
                        switch (error.ErrorMessage)
                        {
                            case "PHONE_NUMBER_INVALID":
                                cr.Response = CodeRegister.Type.NumberInvalid;
                                break;
                            case "PHONE_CODE_EMPTY":
                                cr.Response = CodeRegister.Type.CodeEmpty;
                                break;
                            case "PHONE_CODE_EXPIRED":
                                cr.Response = CodeRegister.Type.CodeExpired;
                                break;
                            case "PHONE_CODE_INVALID":
                                cr.Response = CodeRegister.Type.CodeInvalid;
                                break;
                            case "FIRSTNAME_INVALID":
                                cr.Response = CodeRegister.Type.FirstNameInvalid;
                                break;
                            case "LASTNAME_INVALID":
                                cr.Response = CodeRegister.Type.LastNameInvalid;
                                break;
                            default:
                                cr.Response = CodeRegister.Type.Failure;
                                break;
                        }
                        return cr;
                    }
                }
            }
            catch (Exception ex)
            {
                service.DebugPrint("Error in CodeRequest: " + ex);
            }
            return null;
        }
开发者ID:akonsand,项目名称:DisaOpenSource,代码行数:82,代码来源:Telegram.cs

示例3: RequestCode

        public static CodeRequest RequestCode(Service service, string number, string codeHash, TelegramSettings settings, bool call)
        {
            try
            {
                service.DebugPrint("Requesting code...");
                var transportConfig = 
                    new TcpClientTransportConfig(settings.NearestDcIp, settings.NearestDcPort);
                using (var client = new TelegramClient(transportConfig,
                    new ConnectionConfig(settings.AuthKey, settings.Salt), AppInfo))
                {
                    TelegramUtils.RunSynchronously(client.Connect());

                    if (!call)
                    {
                        try
                        {
                            var result = TelegramUtils.RunSynchronously(client.Methods.AuthSendCodeAsync(new AuthSendCodeArgs
                            {
                                PhoneNumber = number,
                                SmsType = 0,
                                ApiId = AppInfo.ApiId,
                                ApiHash = "f8f2562579817ddcec76a8aae4cd86f6",
                                LangCode = PhoneBook.Language
                            })) as AuthSentCode;
                            return new CodeRequest
                            {
                                Registered = result.PhoneRegistered,
                                CodeHash = result.PhoneCodeHash,
                            };
                        }
                        catch (RpcErrorException ex)
                        {
                            var error = (RpcError)ex.Error;
                            var cr = new CodeRequest();
                            var response = CodeRequest.Type.Failure;
                            switch (error.ErrorCode)
                            {
                                case 400:
                                    cr.Response = CodeRequest.Type.NumberInvalid;
                                    break;
                                default:
                                    cr.Response = CodeRequest.Type.Failure;
                                    break;
                            }
                            return cr;
                        }
                    }
                    var result2 = (bool)TelegramUtils.RunSynchronously(client.Methods.AuthSendCallAsync(new AuthSendCallArgs
                    {
                        PhoneNumber = number,
                        PhoneCodeHash = codeHash,
                    }));
                    return new CodeRequest
                    {
                        Response = result2 ? CodeRequest.Type.Success : CodeRequest.Type.Failure
                    };
                }
            }
            catch (Exception ex)
            {
                service.DebugPrint("Error in CodeRequest: " + ex);
            }
            return null;
        }
开发者ID:akonsand,项目名称:DisaOpenSource,代码行数:64,代码来源:Telegram.cs


注:本文中的Service.DebugPrint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。