Exemple #1
0
        private async void FrmMain_Load(object sender, EventArgs e)
        {
            try
            {
                string sessionPath = Path.Combine(Application.StartupPath, @"session.dat");
                Store.Load(sessionPath);
                client = new TelegramClient(35699, "c5faabe85e286bbb3eac32df78b34517", Store, sessionPath);

                bool connectResult = await client.ConnectAsync();

                if (connectResult == false)
                {
                    this.Text = this.Text + "  Failed to login";
                }

                else
                {
                    this.Text = this.Text + "  Login success";

                    try
                    {
                        var client = NewClient();

                        await client.ConnectAsync();

                        var result = await client.GetContactsAsync();

                        //find recipient in contacts
                        var user = result.users.lists.ToList()
                                   .Where(x => x.GetType() == typeof(TLUser))
                                   .Cast <TLUser>()
                                   .FirstOrDefault(x => x.self);

                        var photo         = ((TLUserProfilePhoto)user.photo);
                        var photoLocation = (TLFileLocation)photo.photo_small;
                        var resFile       = await client.GetFile(new TLInputFileLocation()
                        {
                            local_id  = photoLocation.local_id,
                            secret    = photoLocation.secret,
                            volume_id = photoLocation.volume_id
                        }, 100000, 0);


                        Bitmap image;
                        using (MemoryStream stream = new MemoryStream(resFile.bytes))
                        {
                            image = new Bitmap(stream);
                        }
                        pbSelfPicture.Image = image;
                    }
                    catch (Exception)
                    {
                    }



                    // pictureBox1.Image = ByteToImage( resFile.bytes);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }