예제 #1
0
        /// <summary>
        /// Saves user input to disk.
        /// </summary>
        /// <param name="persistor">Persistor object.</param>
        public static void Save(UserInputPersistor persistor)
        {
            try
            {
                var serializer = new XmlSer.XmlSerializer(typeof(UserInputPersistor));

                using (var writer = new System.IO.StreamWriter(GetFilepath()))
                {
                    serializer.Serialize(writer, persistor);
                }
            }
            catch { } // Silent failure, because persisting is not very important
        }
예제 #2
0
        private void Window_Loaded(object sender, RoutedEventArgs args)
        {
            // Initialising object only here, because the creation of AppLogic it takes long.
            // However, it is considered good that the window is visible while initialising.
            try
            {
                Title = string.Format("{0} v.{1}", Globals.ProductName, Globals.Version);

                // Using the "wait" cursor during startup
                var previousCursor = Cursor;
                Cursor = System.Windows.Input.Cursors.Wait;

                m_appLogic = new AppLogic(ConnectionEventCallback, MessageReceivedCallback);

                // Creating a persistor object - If anything has been saved in the disk, loading it
                UserInputPersistor persistor = UserInputPersistor.Load(); // Does not leak exceptions
                m_host               = persistor.Host;
                m_exchange           = persistor.Exchange;
                TopicTextBox.Text    = persistor.TopicPattern;
                UsernameTextBox.Text = persistor.Username;
                SecureConnectionCheckBox.IsChecked = persistor.IsSecureConnection;

                // Set up UI state
                ChangeUiState(canConnect: true, canTerminate: false);
                SetConnectionStatusText(text: "Not connected", isProblem: false);

                // Setting to the initial state, mostly applies to filters
                SetToInitialState();

                // Restoring the default cursor
                Cursor = previousCursor;

                args.Handled = true;
            }
            catch (Exception e)
            {
                MessageBox.Show(this, "Cannot start application: " + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);

                // Trying to add to log
                try
                {
                    HandleBug(e);
                }
                catch { }

                throw new Exception("Failed to start application", e);
            }
        }
예제 #3
0
        private void ConnectButton_Click(object sender, RoutedEventArgs args)
        {
            try
            {
                // Clear any previous connection error
                ClearConnectionStatusLabel();

                bool isSecure = SecureConnectionCheckBox.IsChecked.HasValue && SecureConnectionCheckBox.IsChecked.Value;

                // Saving user input to disk
                var persistor = new UserInputPersistor
                {
                    Host               = m_host,
                    Exchange           = m_exchange,
                    TopicPattern       = TopicTextBox.Text,
                    Username           = UsernameTextBox.Text,
                    IsSecureConnection = isSecure
                };
                UserInputPersistor.Save(persistor);

                // Updating UI state
                ChangeUiState(canConnect: false, canTerminate: true);

                try
                {
                    // Connecting
                    var connRequest = new ConnectionRequest(host: m_host, exc: m_exchange, secure: isSecure,
                                                            user: UsernameTextBox.Text, pwd: PasswordTextBox.Password, topic: TopicTextBox.Text);
                    m_appLogic.Connect(connRequest);
                }
                catch (InvalidOperationException e)
                {
                    // Showing the error in UI
                    SetConnectionStatusText(text: e.Message, isProblem: true);
                    return;
                }

                args.Handled = true;
            }
            catch (Exception e)
            {
                HandleBug(e);
            }
        }