Esempio n. 1
0
        static void Main(string[] args)
        {
            HostFactory.Run(x => x.Service<Server>(c =>
            {
                x.UseLog4Net("PaperCut.SmtpHost.exe.config");

                c.ConstructUsing(s =>
                    {
                        var address = IPAddress.Parse(ConfigurationManager.AppSettings["IP"]);
                        var port = int.Parse(ConfigurationManager.AppSettings["Port"]);
                        var mailFolder = ConfigurationManager.AppSettings["MailFolder"];
                        MessageFileService fileService = new MessageFileService(mailFolder);
                        return new Server(address, port, new Processor(fileService));
                    });
                c.WhenStarted(s => s.Start());
                c.WhenStopped(s => s.Stop());
            }));
        }
Esempio n. 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();
            }
        }
Esempio n. 3
0
 public Processor(MessageFileService messageFileService)
 {
     _messageFileService = messageFileService;
 }
Esempio n. 4
0
 public Processor(MessageFileService messageFileService)
 {
     _messageFileService = messageFileService;
 }