public MainWindow()
        {
            InitializeComponent();

            // Set up the notification icon
            notification = new NotifyIcon();
            notification.Icon = new Icon(Application.GetResourceStream(new Uri("/Papercut;component/App.ico", UriKind.Relative)).Stream);
            notification.Text = "Papercut";
            notification.Visible = true;
            notification.DoubleClick +=
                delegate
                {
                    Show();
                    WindowState = WindowState.Normal;
                    Topmost = true;
                    Focus();
                    Topmost = false;
                };
            notification.BalloonTipClicked +=
                delegate
                {
                    Show();
                    WindowState = WindowState.Normal;
                    messagesList.SelectedIndex = messagesList.Items.Count - 1;
                };
            notification.ContextMenu = new ContextMenu(
                new[]
                    {
                        new MenuItem("Show",
                                            delegate
                                                {
                                                    Show();
                                                    WindowState = WindowState.Normal;
                                                    Focus();
                                                }),
                        new MenuItem("Exit", delegate { Close(); })
                    }
                );

            // Set the version label
            versionLabel.Content = string.Format("Papercut v{0}", Assembly.GetExecutingAssembly().GetName().Version.ToString(3));

            // Load existing messages
            LoadMessages();
            messagesList.Items.SortDescriptions.Add(new SortDescription("ModifiedDate", ListSortDirection.Ascending));

            // Begin listening for new messages
            Processor.MessageReceived += new EventHandler<MessageEventArgs>(Processor_MessageReceived);

            // Start listening for connections
            server = new Server();
            try
            {
                server.Start();
            }
            catch
            {
                System.Windows.MessageBox.Show("Failed to bind to the address/port specified.  The port may already be in use by another process.  Please change the configuration in the Options dialog.", "Operation Failure");
            }

            // Minimize if set to
            if (Settings.Default.StartMinimized)
                Hide();
        }
Exemple #2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="MainWindow" /> class.
        ///     Initializes a new instance of the <see cref="MainWindow" /> class. Initializes a new instance of the
        ///     <see cref="MainWindow" /> class.
        /// </summary>
        public MainWindow()
        {
            this.InitializeComponent();
            this.messageFileService = new MessageFileService();
            // Set up the notification icon
            this.notification = new NotifyIcon
                                {
                                    Icon = new Icon(Application.GetResourceStream(new Uri("/Papercut;component/App.ico", UriKind.Relative)).Stream),
                                    Text = "Papercut",
                                    Visible = true
                                };

            this.notification.Click += delegate
            {
                this.Show();
                this.WindowState = WindowState.Normal;
                this.Topmost = true;
                this.Focus();
                this.Topmost = false;
            };

            this.notification.BalloonTipClicked += (sender, args) =>
            {
                this.Show();
                this.WindowState = WindowState.Normal;
                this.messagesList.SelectedIndex = this.messagesList.Items.Count - 1;
            };

            this.notification.ContextMenu = new ContextMenu(
                new[]
                {
                    new MenuItem(
                        "Show",
                        (sender, args) =>
                        {
                            this.Show();
                            this.WindowState = WindowState.Normal;
                            this.Focus();
                        }) { DefaultItem = true },
                    new MenuItem("Exit", (sender, args) => this.ExitApplication())
                });

            // Set the version label
            this.versionLabel.Content = string.Format("Papercut v{0}", Assembly.GetExecutingAssembly().GetName().Version.ToString(3));

            // Load existing messages
            this.LoadMessages();
            this.messagesList.Items.SortDescriptions.Add(new SortDescription("ModifiedDate", ListSortDirection.Ascending));

            // Begin listening for new messages
            Processor.MessageReceived += this.Processor_MessageReceived;

            // Load IP/Port settings
            IPAddress address;
            if (Settings.Default.IP == "Any")
            {
                address = IPAddress.Any;
            }
            else
            {
                address = IPAddress.Parse(Settings.Default.IP);
            }

            var port = Settings.Default.Port;

            // Start listening for connections

            this.server = new Server(address, port, new Processor(messageFileService));
            try
            {
                this.server.Start();
            }
            catch
            {
                MessageBox.Show(
                    "Failed to bind to the address/port specified.  The port may already be in use by another process.  Please change the configuration in the Options dialog.",
                    "Operation Failure");
            }

            this.SetTabs();

            this.UpdateSelectedMessage();

            // Minimize if set to
            if (Settings.Default.StartMinimized)
            {
                this.Hide();
            }
        }