Exemplo n.º 1
0
        private async Task <string> loginProcess()
        {
            while (true)
            {
                await Task.Run(() => waitingLoginTokenSource.Token.WaitHandle.WaitOne());

                UsernameInput.IsReadOnly       = true;
                PasswordInput.Focusable        = false;
                PasswordInput.IsHitTestVisible = false;
                string login = null;
                try
                {
                    login = await ProgressTrackerAPI.LoginAsync(UsernameInput.Text, PasswordInput.Password.ToString());
                }
                catch (TaskCanceledException) { }
                catch (HttpRequestException) { }

                if (login != null)
                {
                    return(login);
                }
                else
                {
                    MessageBox.Show("Login failed. Please try again.", "Login failed", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                UsernameInput.Clear();
                PasswordInput.Clear();
                UsernameInput.IsReadOnly       = false;
                PasswordInput.Focusable        = true;
                PasswordInput.IsHitTestVisible = true;
                waitingLoginTokenSource        = new CancellationTokenSource();
            }
        }
Exemplo n.º 2
0
        private async void onSendButtonClicked(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            NewTaskStoryboardReverse.Begin();
            await ProgressTrackerAPI.SendNewMessage(TitleTextBox.Text, ContentsTextBox.Text, 0);

            TitleTextBox.Text    = string.Empty;
            ContentsTextBox.Text = string.Empty;
        }
 private async void onDeleteButtonClicked(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     if (await ProgressTrackerAPI.DeleteMessage(ID))
     {
         this.Visibility = System.Windows.Visibility.Collapsed;
     }
     else
     {
         Console.WriteLine("AN ERROR HAS OCCURED. Cannot Delete!");
     }
 }
Exemplo n.º 4
0
        public async Task ReloadUI()
        {
            MessageHolder.Children.Clear();
            MessageControls.Clear();
            var messages = await ProgressTrackerAPI.GetMessages(newestTimestamp);

            foreach (var msg in messages)
            {
                var mc = new MessageControl(msg);
                MessageHolder.Children.Add(mc);
                MessageControls.Add(msg.ID, mc);
            }
        }
Exemplo n.º 5
0
        private async void MainWindowLoaded(object sender, RoutedEventArgs e)
        {
            string hash = null;

            if (File.Exists(HASH_FILE))
            {
                var file = File.ReadAllText(HASH_FILE);
                if (await ProgressTrackerAPI.IsHashValid(file))
                {
                    hash = file;
                }
                else
                {
                    File.Delete(HASH_FILE);
                }
            }
            if (hash == null)
            {
                hash = await loginProcess();

                var sw = File.CreateText(HASH_FILE);
                await sw.WriteAsync(hash);

                sw.Close();
            }

            ProgressTrackerAPI.hash = hash;
            loggedInAuthor          = await ProgressTrackerAPI.GetAuthorInfo();

            LoginPanel.Visibility = Visibility.Collapsed;
            MainPanel.Visibility  = Visibility.Visible;

            ws = new GenericWebSocket(new Uri(WS_ADDRESS + "/" + hash));
            ws.OnWebSocketConnected += onWSConnected;
            await ws.Connect();

            new WebSocketHandler(ws, this);
        }
Exemplo n.º 6
0
 private async void onProgressBarUpdated(object sender, EventArgs e)
 {
     var pb = (RoundedProgressBar)sender;
     await ProgressTrackerAPI.UpdateMessage(ID, null, null, (int)pb.Progress);
 }