public DefaultConsole(ConsoleStream stream)
        {
            _constructionForeground = Console.ForegroundColor;
            _constructionBackground = Console.BackgroundColor;

            _currentForeground = _constructionForeground;
            _currentBackground = _constructionBackground;

            _stream = stream == ConsoleStream.Out ? Console.Out : Console.Error;
        }
        public RedirectedConsole(ConsoleStream stream)
        {
            try
            {
                //this will throw if there is no real console.
                _width = Console.BufferWidth;
                Encoding = Console.OutputEncoding;
            }
            catch (Exception)
            {
                _width = DefaultWidth;
                Encoding = Encoding.Default;
            }

            _stream = stream == ConsoleStream.Out ? Console.Out : Console.Error;
        }
        public MainWindow()
        {
            InitializeComponent();

            for (var i = 512; i <= 4096; i += 512)
            {
                MemoryComboBox.Items.Add(i + "M");
            }

            memboxGal.SelectedItem = Config.Default["MaxHeap"];

            try
            {
                Noticon = new NotifyIcon {Icon = Properties.Resources.bukkit, Visible = true};
                Noticon.DoubleClick += delegate
                                           {
                                               if (Visibility != Visibility.Visible)
                                                   Show();
                                           };

                var notimenu = new ContextMenuStrip();

                var startMi = new ToolStripMenuItem("Start") {Image = Properties.Resources.start};
                startMi.Click += Commands.StartServer.Execute;

                var stopMi = new ToolStripMenuItem("Stop") {Image = Properties.Resources.stop};
                stopMi.Click += Commands.StopServer.Execute;

                var restartMi = new ToolStripMenuItem("Restart") {Image = Properties.Resources.restart};
                restartMi.Click += Commands.RestartServer.Execute;

                notimenu.Items.Add(startMi);

                Noticon.ContextMenuStrip = notimenu;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }

            s_stats_update = new Timer(delegate
                          {
                              Dispatcher.BeginInvoke(
                                  new Action(delegate
                                                 {
                                                     MemStats.Text = "Memory: " +
                                                                     ProcessHandler
                                                                         .Instance.
                                                                         WorkingSet/
                                                                     1048576 + " MB";
                                                     Uptime.Text = "Uptime: " +
                                                                   UptimeString();
                                                 }));
                          }, null, 100, 1000);

            Ribbon_Status.Text = "Server is\nStopped";
            ProcessHandler.Output +=
                (sender, data) =>
                    {
                        if (String.IsNullOrEmpty(data)) return;

                        if (ReferenceEquals(sender, ProcessHandler.ConsoleError))
                            Dispatcher.BeginInvoke(new Action(
                                                       () =>
                                                           {
                                                               var para = new Paragraph();

                                                               switch (data[10])
                                                               {
                                                                   case 'W':
                                                                       para.Foreground =
                                                                           new SolidColorBrush(Colors.DarkOrange);
                                                                       para.Inlines.Add(data);
                                                                       break;
                                                                   case 'S':
                                                                       para.Foreground =
                                                                           new SolidColorBrush(Colors.Red);
                                                                       para.Inlines.Add(data);
                                                                       break;
                                                                   case 'I':
                                                                       para = (Paragraph) ParseAnsiColor(data);
                                                                       break;
                                                                   default:
                                                                       para.Foreground =
                                                                           new SolidColorBrush(Colors.Black);
                                                                       para.Inlines.Add(data);
                                                                       break;
                                                               }

                                                               para.LineHeight = 0.1;

                                                               outputBox.Document.Blocks.Add(para);
                                                           }));
                        else if (ReferenceEquals(sender, ProcessHandler.ConsoleOutput))
                            Dispatcher.BeginInvoke(new Action(
                                                       () =>
                                                       {
                                                           var para = new Paragraph
                                                                          {
                                                                              Foreground =
                                                                                  new SolidColorBrush(
                                                                                  Colors.Black),
                                                                              LineHeight = 0.1
                                                                          };
                                                           para.Inlines.Add(data);
                                                           outputBox.Document.Blocks.Add(para);
                                                       }));
                        else
                            Dispatcher.BeginInvoke(new Action(
                                                       () =>
                                                       {
                                                           var para = new Paragraph
                                                                          {
                                                                              Foreground =
                                                                                  new SolidColorBrush(
                                                                                  Color.FromRgb(0, 127, 0)),
                                                                              LineHeight = 0.1
                                                                          };
                                                           para.Inlines.Add(data);
                                                           outputBox.Document.Blocks.Add(para);
                                                       }));

                        Dispatcher.BeginInvoke(new Action(() => outputBox.ScrollToEnd()));
                    };
            ProcessHandler.Instance.StateChanged +=
                delegate(bool newstate)
                    {
                        if (newstate)
                        {
                            Dispatcher.BeginInvoke(
                                new Action(
                                    delegate
                                        {
                                            StartRB.IsEnabled = false;
                                            StopRB.IsEnabled = true;
                                            RestartRB.IsEnabled = true;

                                            StartStopQAB.SmallImageSource = new BitmapImage
                                                (new Uri
                                                     ("/Images/stop.png",
                                                      UriKind.Relative));
                                            StartStopQAB.Command = Commands.StopServer;

                                            Ribbon_Status.Text = "Server is\nRunning";

                                            StartThumb.IsEnabled = false;
                                            StopThumb.IsEnabled = true;
                                            RestartThumb.IsEnabled = true;
                                        }));
                        }
                        else
                        {
                            Dispatcher.BeginInvoke(
                                new Action(
                                    delegate
                                        {
                                            StartRB.IsEnabled = true;
                                            StopRB.IsEnabled = false;
                                            RestartRB.IsEnabled = false;

                                            StartStopQAB.SmallImageSource = new BitmapImage
                                                (new Uri("/Images/start.png",
                                                         UriKind.Relative));
                                            StartStopQAB.Command = Commands.StartServer;

                                            Ribbon_Status.Text = "Server is\nStopped";

                                            StartThumb.IsEnabled = true;
                                            StopThumb.IsEnabled = false;
                                            RestartThumb.IsEnabled = false;
                                        }));
                        }
                    };

            if (Config.NetConf["enabled"] == "true")
            {
                int port;
                if (!int.TryParse(Config.NetConf["port"], out port))
                    port = 3000;

                //Net.Listener.StartListening(port);
                NetworkToggle.IsChecked = true;
            }

            Instance = this;

            memcb.IsEditable = true;
            memcb.Text = Config.Default["maxheap"];

            _consoleStream = new ConsoleStream(this);

            non_startup = true;
        }
Beispiel #4
0
 public Console()
 {
     InitializeComponent();
     StreamInstance = new ConsoleStream();
     StreamInstance.Console = this;
 }