telnet comm
This commit is contained in:
70
PacticeSolution/TelnetCommunicator/MainWindow.xaml.cs
Normal file
70
PacticeSolution/TelnetCommunicator/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
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;
|
||||
}
|
||||
|
||||
private async void btnStatus_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string response = await _tap.SendMessage("STA");
|
||||
tbMessage.AppendText(GetInfo(response) + Environment.NewLine);
|
||||
tbMessage.ScrollToEnd();
|
||||
}
|
||||
|
||||
private void On_Received(object sender, Exception e)
|
||||
{
|
||||
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
||||
{
|
||||
tbMessage.AppendText(e.Message + Environment.NewLine);
|
||||
tbMessage.ScrollToEnd();
|
||||
}));
|
||||
}
|
||||
|
||||
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 "";
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user