Пример #1
0
        /// <summary> Initializes a new instance of the <see cref="MainWindowViewModel"/> class. </summary>
        public MainWindowViewModel()
        {
            this.scoreboardControlViewModel = new ScoreboardControlPanelViewModel(this.Scoreboard);
            this.settingsPanelViewModel = new SettingsPanelViewModel(this.settings, this.scoreboardControlViewModel);
            display.SetViewModel(this.Scoreboard);
            this.IsMainSettingsVisible = true;

            if (Math.Abs(this.settings.Position.X - 0) > .001 || Math.Abs(this.settings.Position.Y - 0) > .001)
            {
                display.InitializePositionOnLoad = false;
                display.SetValue(Window.TopProperty, this.settings.Position.Y);
                display.SetValue(Window.LeftProperty, this.settings.Position.X);
            }
        }
Пример #2
0
        /// <summary> Initializes a new instance of the <see cref="MainWindowViewModel"/> class. </summary>
        public MainWindowViewModel()
        {
            this.scoreboardControlViewModel = new ScoreboardControlPanelViewModel(this.Scoreboard);
            this.settingsPanelViewModel     = new SettingsPanelViewModel(this.settings, this.scoreboardControlViewModel);
            display.SetViewModel(this.Scoreboard);
            this.IsMainSettingsVisible = true;

            if (Math.Abs(this.settings.Position.X - 0) > .001 || Math.Abs(this.settings.Position.Y - 0) > .001)
            {
                display.InitializePositionOnLoad = false;
                display.SetValue(Window.TopProperty, this.settings.Position.Y);
                display.SetValue(Window.LeftProperty, this.settings.Position.X);
            }
        }
        /// <summary> Initializes a new instance of the <see cref="MainWindowViewModel"/> class. </summary>
        public MainWindowViewModel()
        {
            this.scoreboardControlViewModel = new ScoreboardControlPanelViewModel(this.Scoreboard);
            this.settingsPanelViewModel = new SettingsPanelViewModel(this.settings, this.scoreboardControlViewModel);
            display.SetViewModel(this.Scoreboard);

            if (this.settings.Position.X != 0 || this.settings.Position.Y != 0)
            {
                display.InitializePositionOnLoad = false;
                display.SetValue(Window.TopProperty, this.settings.Position.Y);
                display.SetValue(Window.LeftProperty, this.settings.Position.X);
            }

            this.ActiveViewModel = this.scoreboardControlViewModel;
        }
        /// <summary> Initializes a new instance of the <see cref="MainWindowViewModel"/> class. </summary>
        public MainWindowViewModel()
        {
            this.scoreboardControlViewModel = new ScoreboardControlPanelViewModel(this.Scoreboard);
            this.settingsPanelViewModel     = new SettingsPanelViewModel(this.settings, this.scoreboardControlViewModel);
            display.SetViewModel(this.Scoreboard);

            if (this.settings.Position.X != 0 || this.settings.Position.Y != 0)
            {
                display.InitializePositionOnLoad = false;
                display.SetValue(Window.TopProperty, this.settings.Position.Y);
                display.SetValue(Window.LeftProperty, this.settings.Position.X);
            }

            this.ActiveViewModel = this.scoreboardControlViewModel;
        }
Пример #5
0
        public void Listen(SettingsPanelViewModel sb)
        {
            if (this.listenThread != null)
            {
                if (this.listenThread.IsAlive)
                {
                    this.StopListen = true;

                    while (this.listenThread.IsAlive)
                    {
                        Thread.Sleep(20);
                    }
                }
            }

            this.StopListen = false;

            IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
            IPEndPoint endPoint = null;

            foreach (var entry in hostEntry.AddressList)
            {
                if (entry.AddressFamily == AddressFamily.InterNetwork)
                {
                    endPoint = new IPEndPoint(entry, this.PortNumber);
                }
            }

            if (endPoint == null)
            {
                MessageBox.Show("This application does not support IPv6 yet.");
                return;
            }

            var socket = new Socket(endPoint.Address.AddressFamily, SocketType.Dgram, ProtocolType.Udp) { ReceiveTimeout = 2000 };
            socket.Bind(endPoint);

            // This ReceiveTimeout was causing issues with the Android app... we may need to change this?
            // A value of 0 worked with the app, but then the application couldn't abort the thread while waiting.
            socket.ReceiveTimeout = 5000;

            this.listenThread = new Thread(
                new ThreadStart(
                    delegate
                    {
                        while (this.StopListen == false)
                        {
                            var inBuffer = new byte[1000];
                            EndPoint senderRemote = new IPEndPoint(IPAddress.Any, 0);

                            try
                            {
                                socket.ReceiveFrom(inBuffer, ref senderRemote);
                            }
                            catch (SocketException ex)
                            {
                                int errorCode = ex.ErrorCode;
                                continue;
                            }

                            var packet = ScoreboardPacket.Parse(inBuffer);

                            foreach (var cmd in packet.Commands)
                            {
                                if (cmd.Command == CommandType.Ping)
                                {
                                    var pongCmd = new EmptyPacketCommand { Command = CommandType.Pong };
                                    var pongPacket = new ScoreboardPacket() { Commands = new[] { pongCmd } };

                                    socket.SendTo(pongPacket.ToBytes(), senderRemote);
                                }
                            }

                            this.dispatcher.BeginInvoke((Action)(() => sb.HandleRemoteCommands(packet, socket, senderRemote)));
                        }

                        socket.Close();
                        socket.Dispose();
                    }));

            this.listenThread.Start();
            this.IsListening = true;
        }
Пример #6
0
        public void Listen(SettingsPanelViewModel sb)
        {
            if (this.listenThread != null)
            {
                if (this.listenThread.IsAlive)
                {
                    this.StopListen = true;

                    while (this.listenThread.IsAlive)
                    {
                        Thread.Sleep(20);
                    }
                }
            }

            this.StopListen = false;

            IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
            var endPoints = new List<IPEndPoint>();

            foreach (var entry in hostEntry.AddressList)
            {
                if (entry.AddressFamily == AddressFamily.InterNetwork)
                {
                    endPoints.Add(new IPEndPoint(entry, this.PortNumber));
                    break;
                }
            }

            if (endPoints.Count == 0)
            {
                MessageBox.Show("No valid networks were found to connect to.");
                return;
            }

            var socket = new Socket(endPoints[0].Address.AddressFamily, SocketType.Dgram, ProtocolType.Udp) { ReceiveTimeout = 5000 };
            foreach (var e in endPoints)
            {
                socket.Bind(e);
            }

            this.listenThread = new Thread(
                new ThreadStart(
                    delegate
                    {
                        while (this.StopListen == false)
                        {
                            var inBuffer = new byte[1000];
                            EndPoint senderRemote = new IPEndPoint(IPAddress.Any, 0);

                            try
                            {
                                socket.ReceiveFrom(inBuffer, ref senderRemote);
                            }
                            catch (SocketException ex)
                            {
                                int errorCode = ex.ErrorCode;
                                continue;
                            }

                            var packet = ScoreboardPacket.Parse(inBuffer);

                            foreach (var cmd in packet.Commands)
                            {
                                if (cmd.Command == CommandType.Ping)
                                {
                                    var pongCmd = new EmptyPacketCommand { Command = CommandType.Pong };
                                    var pongPacket = new ScoreboardPacket() { Commands = new[] { pongCmd } };

                                    socket.SendTo(pongPacket.ToBytes(), senderRemote);
                                }
                            }

                            this.dispatcher.BeginInvoke((Action)(() => sb.HandleRemoteCommands(packet, socket, senderRemote)));
                        }

                        socket.Close();
                        socket.Dispose();
                    }));

            this.listenThread.Start();
            this.IsListening = true;
        }