using SunlightCentralizedControlManagement_SCCM_.View;
using SunlightCentralizedControlManagement_SCCM_.EX;
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.Shapes;
using System.Net.NetworkInformation;
using VncSharpWpf;
namespace SunlightCentralizedControlManagement_SCCM_.EX
{
///
/// UserMessage.xaml 的交互逻辑
///
public partial class VNC : Window
{
string host = "127.0.0.1"; // 替换为你的 VNC 服务器地址
int port = 5901; // 替换为你的 VNC 服务器端口
string password = "123456"; // 替换为你的 VNC 服务器密码
public VNC()
{
InitializeComponent();
// vnc.Cursor = Cursors;
// vnc.MouseMove += Vnc_MouseMove;
// vnc.MouseDown += Vnc_MouseDown ;
// vnc.MouseUp += Vnc_MouseUp;
// vnc.MouseLeave += Vnc_MouseLeave;
// vnc.MouseWheel += Vnc_MouseWheel;
// vnc.PreviewKeyDown += Vnc_PreviewKeyDown;
// rdp.ConnectComplete += new ConnectCompleteHandler(ConnectCompleteEventHandler);
// rdp.ConnectionLost += new EventHandler(ConnectionLostEventHandler);
// rdp.StoppedListen += new EventHandler(ConnectionLostEventHandler);
}
private void Save_Click(object sender, RoutedEventArgs e)
{
if (rdp.IsConnected) { rdp.Disconnect(); }//断开连接
this.Close();
}
public void Parameter(object IP, object PROT, object USER, object PASSWD)
{
host = IP.ToString();
port = Convert.ToInt16(PROT);
password = PASSWD.ToString();
}
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
if (await PingTest(host))
{
if (!rdp.IsConnected)
{
try
{
rdp.VncPort = port;
rdp.Passwd = password;
rdp.Connect(host, true, true);
}
catch (Exception ex)
{
}
}
}
}
private async Task PingTest(string ip)
{
bool result = false;
Ping pingSender = new Ping();
try
{
PingReply reply = await pingSender.SendPingAsync(ip, 3000);
if (reply.Status == IPStatus.Success)
{
result = true;
log.Text = ip + " Connected";
}
else
{
log.Text = ip + " Timeout";
}
}
catch (PingException e)
{
result = false;
log.Text = ip + " Not Connected";
}
return result;
}
}
}