Example #1
0
        private async void OnSend(byte[] data)
        {
            if (!ValidateSend())
            {
                return;
            }

            try
            {
                var msg = new Transmission(data, Transmission.EType.Sent);
                History.Append(msg);
                var res = await _udpClient.SendAsync(
                    msg, IPAddress.Parse(Send.MulticastGroup),
                    Send.Port.Value, ToEMulticastInterface(Send.SelectedInterface.Type),
                    Send.SelectedInterface.Address, Send.MulticastTtl);

                if (res != null)
                {
                    msg.Origin      = res.From;
                    msg.Destination = res.To;
                    Send.Message    = "";
                }
            }
            catch (Exception ex)
            {
                DialogUtils.ShowErrorDialog(ex.Message);
            }
        }
Example #2
0
        private bool ValidateJoin()
        {
            string error = null;

            if (HasError(nameof(MulticastGroup)))
            {
                error = GetError(nameof(MulticastGroup));
            }
            else if (HasError(nameof(MulticastSource)))
            {
                error = GetError(nameof(MulticastSource));
            }
            else if (HasError(nameof(MulticastPort)))
            {
                error = GetError(nameof(MulticastPort));
            }

            if (error != null)
            {
                DialogUtils.ShowErrorDialog(error);
                return(false);
            }

            return(true);
        }
Example #3
0
        private bool ValidateSend()
        {
            string error = null;

            if (Send.HasError(nameof(Send.MulticastGroup)))
            {
                error = Send.GetError(nameof(Send.MulticastGroup));
            }
            else if (Send.HasError(nameof(Send.Port)))
            {
                error = Send.GetError(nameof(Send.Port));
            }
            else if (Send.HasError(nameof(Send.MulticastTtl)))
            {
                error = Send.GetError(nameof(Send.MulticastTtl));
            }

            if (error != null)
            {
                DialogUtils.ShowErrorDialog(error);
                return(false);
            }

            return(true);
        }
Example #4
0
        private void Start()
        {
            if (!ValidateStart())
            {
                return;
            }

            try
            {
                _tcpServer.Start(SelectedInterface.Address, Port.Value);
            }
            catch (System.Net.Sockets.SocketException ex)
            {
                String message = ex.Message;
                if (ex.ErrorCode == 10013)
                {
                    message = "Port " + Port + " is already in use, unable to start server.";
                }

                DialogUtils.ShowErrorDialog(message);
            }
            catch (Exception ex)
            {
                DialogUtils.ShowErrorDialog(ex.Message);
            }
        }
Example #5
0
        private async void OnSend(byte[] data)
        {
            if (!ValidateSend())
            {
                return;
            }

            try
            {
                var msg = new Transmission(data, Transmission.EType.Sent);
                History.Append(msg);
                var res = await _udpClientServer.SendAsync(Send.IpAddress, Send.Port.Value, msg);

                if (res != null)
                {
                    msg.Origin      = res.From;
                    msg.Destination = res.To;
                    Send.Message    = "";
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.StackTrace);
                DialogUtils.ShowErrorDialog(ex.Message);
            }
        }
Example #6
0
        private void Start()
        {
            if (!ValidateStart())
            {
                return;
            }

            try
            {
                _udpClientServer.Start(SelectedInterface.Address, ListenPort.Value);
            }
            catch (Exception ex)
            {
                DialogUtils.ShowErrorDialog(ex.Message);
            }
        }
Example #7
0
        private async void Connect()
        {
            if (!ValidateConnect())
            {
                return;
            }

            try
            {
                await _tcpClient.ConnectAsync(IpAddress, Port.Value);
            }
            catch (Exception ex)
            {
                DialogUtils.ShowErrorDialog(ex.Message);
            }
        }
Example #8
0
        private bool ValidateStart()
        {
            string error = null;

            if (HasError(nameof(ListenPort)))
            {
                error = GetError(nameof(ListenPort));
            }

            if (error != null)
            {
                DialogUtils.ShowErrorDialog(error);
                return(false);
            }

            return(true);
        }
Example #9
0
        private void Join()
        {
            if (!ValidateJoin())
            {
                return;
            }

            try
            {
                _udpClient.JoinSSM(IPAddress.Parse(MulticastGroup), IPAddress.Parse(MulticastSource), MulticastPort.Value,
                                   ToEMulticastInterface(SelectedListenInterface.Type),
                                   SelectedListenInterface.Address);
            }
            catch (Exception ex)
            {
                DialogUtils.ShowErrorDialog(ex.Message);
            }
        }
Example #10
0
        private void Send()
        {
            if (FileSelected)
            {
                var filePath = Message;

                if (!File.Exists(filePath))
                {
                    DialogUtils.ShowErrorDialog("The file does not exist.");
                    return;
                }

                if (new FileInfo(filePath).Length > 4096)
                {
                    DialogUtils.ShowErrorDialog("The file is to large to send, maximum size is 16 KB.");
                    return;
                }

                try
                {
                    byte[] file = File.ReadAllBytes(filePath);
                    SendData?.Invoke(file);
                }
                catch (Exception ex)
                {
                    DialogUtils.ShowErrorDialog("Error while reading file. " + ex.Message);
                    return;
                }
            }
            else
            {
                byte[] data = new byte[0];
                try
                {
                    data = _parser.Parse(Message, SettingsUtils.GetEncoding());
                    SendData?.Invoke(data);
                }
                catch (FormatException ex)
                {
                    DialogUtils.ShowErrorDialog(ex.Message);
                    return;
                }
            }
        }
Example #11
0
        private async void OnSend(byte[] data)
        {
            try
            {
                Transmission msg = new Transmission(data, Transmission.EType.Sent);
                History.Append(msg);
                TransmissionResult res = await _tcpServer.SendAsync(msg);

                if (res != null)
                {
                    msg.Origin      = res.From;
                    msg.Destination = res.To;
                    Send.Message    = "";
                }
            }
            catch (Exception ex)
            {
                DialogUtils.ShowErrorDialog(ex.Message);
            }
        }
Example #12
0
        private void Save()
        {
            string data = GetSelectedItemsAsString();

            var dialog = new SaveFileDialog();

            dialog.Filter = "Text file (*.txt)|*.txt";

            if (dialog.ShowDialog().GetValueOrDefault())
            {
                try
                {
                    File.WriteAllText(dialog.FileName, data);
                }
                catch (Exception ex)
                {
                    DialogUtils.ShowErrorDialog("Failed to save file. " + ex.Message);
                }
            }
        }
Example #13
0
        private bool ValidateConnect()
        {
            string error = null;

            if (HasError(nameof(IpAddress)))
            {
                error = GetError(nameof(IpAddress));
            }
            else if (HasError(nameof(Port)))
            {
                error = GetError(nameof(Port));
            }

            if (error != null)
            {
                DialogUtils.ShowErrorDialog(error);
                return(false);
            }

            return(true);
        }