Ejemplo n.º 1
0
        /// <summary>
        /// Change recipient
        /// </summary>
        /// <param name="sender"></param>
        private void ButtonChangeRecepientClick_OnClick(object sender)
        {
            //Call the dialog box for entering the recipient's nickname
            WindowInputDialog windowInputDialogChangeRecepient =
                new WindowInputDialog("Input new recepient name", "Change");

            windowInputDialogChangeRecepient.ShowDialog();

            if (!string.IsNullOrEmpty(windowInputDialogChangeRecepient.InputModel.TextEdit))
            {
                //If the data was entered we change the value of the recipient field to the values from the dialog
                Rrecpient = windowInputDialogChangeRecepient.InputModel.TextEdit;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialization method, starts the process of connecting to the service telegram
        /// </summary>
        /// <returns></returns>
        public async static Task Initial()
        {
            /*Telegram methods do not always behave predictably.
             * Most of them simply block the flow if you set a await on it.*/

            _client = new TelegramClient(DevConstants.API_ID, DevConstants.API_HASH);

            _client.ConnectAsync();

            if (!_client.IsUserAuthorized())
            {
                //Creating a dialogue to enter the user's phone
                WindowInputDialog inputDialogPhone = new WindowInputDialog("Please input your phone number", "Send autorize message");

                inputDialogPhone.ShowDialog();

                string phone = inputDialogPhone.InputModel.TextEdit;


                if (string.IsNullOrEmpty(phone))
                {
                    throw new Exception("Wrong phone");
                }

                string hash = string.Empty;

                /*Due to the fact that all methods are asynchronous,
                 * cannot be await and have no synchronous counterparts,
                 * you have to use similar hacks to get data from them*/
                _client.SendCodeRequestAsync(phone).ContinueWith(hashAsync => { hash = hashAsync.Result; });


                WindowInputDialog inputDialogAuthMsg =
                    new WindowInputDialog("Please input telegram authorize message", "OK");

                //Creating a dialogue to enter a temporary password (comes in active telegram clients or SMS)
                inputDialogAuthMsg.ShowDialog();

                string authMsg = inputDialogAuthMsg.InputModel.TextEdit;

                if (string.IsNullOrEmpty(authMsg))
                {
                    throw new Exception("Wrong authorize message");
                }

                //Authorization confirmation method again using hacks
                _client.MakeAuthAsync(phone, hash, authMsg).ContinueWith(user => { _user = user.Result; });
            }
        }