You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.5 KiB
89 lines
2.5 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
using System.Windows.Threading;
|
|
using TelnetCommunicator.Telnet;
|
|
|
|
namespace TelnetCommunicator
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
private TAP _tap;
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
InitInstance();
|
|
}
|
|
|
|
private void InitInstance()
|
|
{
|
|
_tap = new TAP("200.200.200.123", 23);
|
|
_tap.ErrorHandler -= On_Received;
|
|
_tap.ErrorHandler += On_Received;
|
|
}
|
|
|
|
private async void btnStatus_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
string response = await _tap.SendMessage("STA");
|
|
//tbMessage.AppendText(GetInfo(response) + Environment.NewLine);
|
|
tbMessage.AppendText(response + Environment.NewLine);
|
|
tbMessage.ScrollToEnd();
|
|
|
|
if (CheckConnectionError(response))
|
|
{
|
|
InitInstance();
|
|
}
|
|
}
|
|
|
|
private void On_Received(object sender, Exception e)
|
|
{
|
|
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
|
{
|
|
tbMessage.AppendText(e.Message + Environment.NewLine);
|
|
tbMessage.ScrollToEnd();
|
|
}));
|
|
}
|
|
|
|
private bool CheckConnectionError(string message)
|
|
{
|
|
string[] lines = message.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
|
|
foreach (string line in lines)
|
|
{
|
|
if (line.IndexOf("trouble") > 0)
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private string GetInfo(string message)
|
|
{
|
|
string[] lines = message.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
|
|
foreach (string line in lines)
|
|
{
|
|
if (line.IndexOf("Serial Num:") < 0)
|
|
continue;
|
|
|
|
string tmp = line.ToLower().Replace(" ", "");
|
|
return tmp.Substring(tmp.IndexOf(":") + 1);
|
|
}
|
|
|
|
return "";
|
|
}
|
|
}
|
|
}
|
|
|