private void LoadMessages(object sender, RoutedEventArgs e)
        {
            var folderBrowser = new FolderBrowserDialog();

            _nameWrapper = new UsernameWrapper();
            var enterNameWindow = new EnterNameWindow(_nameWrapper);

            enterNameWindow.ShowDialog();

            if (_nameWrapper.UserName == null)
            {
                MessageBox.Show("Name can not be null");
                LoadingLabel.Visibility = Visibility.Hidden;
                return;
            }

            if (folderBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                LoadingLabel.Visibility = Visibility.Visible;
                var dbLoader = new DbManager(folderBrowser.SelectedPath, _nameWrapper.UserName);

                try
                {
                    new Thread(() =>
                    {
                        Thread.CurrentThread.IsBackground = true;
                        var messageCount = dbLoader.Run();
                        MessageBox.Show($"Loaded {messageCount} messages.");
                        Dispatcher.Invoke(() => { LoadingLabel.Visibility = Visibility.Hidden; });
                    }).Start();
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Loading error {ex}");
                }
            }
        }
示例#2
0
 public EnterNameWindow(UsernameWrapper wrapper)
 {
     _nameWrapper = wrapper;
     InitializeComponent();
 }