-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
80 lines (72 loc) · 2.56 KB
/
MainWindow.xaml.cs
File metadata and controls
80 lines (72 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
namespace Socket
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
var split = System.Reflection.Assembly.GetEntryAssembly().Location.Split('\\')
.TakeWhile(s => string.Compare(s, "bin") != 0).ToList()
.Union(new List<string>() { "7819996.xml" });
InitializeComponent();
File.Text = string.Join('\\', split);
LoadFile(File.Text);
}
void LoadFile(string file)
{
try
{
Data.Text = System.IO.File.ReadAllText(file);
}
catch (Exception e)
{
ButtonAutomationPeer peer = new ButtonAutomationPeer(Browse);
IInvokeProvider invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
invokeProv.Invoke();
}
}
private void Send_Click(object sender, RoutedEventArgs e)
{
try
{
var addr = IPAddress.Parse(IpAddress.Text);
byte[] bytes = new byte[1024];
using (var socket = new System.Net.Sockets.Socket(SocketType.Stream, ProtocolType.Tcp))
{
socket.Connect(new IPEndPoint(addr, 2202));
socket.Send(Encoding.ASCII.GetBytes(Data.Text));
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Exception");
}
}
private void Browse_Click(object sender, RoutedEventArgs e)
{
var fileContent = string.Empty;
var filePath = string.Empty;
var openFileDialog = new Microsoft.Win32.OpenFileDialog();
openFileDialog.InitialDirectory = string.Join('\\', System.Reflection.Assembly.GetEntryAssembly().Location.Split('\\')
.TakeWhile(s => string.Compare(s, "bin") != 0));
openFileDialog.Filter = "All files (*.*)|*.*|XML files (*.xml)|*.xml";
openFileDialog.FilterIndex = 2;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == true)
{
LoadFile(openFileDialog.FileName);
}
}
}
}