-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMainForm.cs
146 lines (137 loc) · 5.74 KB
/
MainForm.cs
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
Copyright (C) <2007-2019> <Kay Diefenthal>
SatIp is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SatIp is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SatIp. If not, see <http://www.gnu.org/licenses/>.
*/
using System.Windows.Forms;
using SatIp.Properties;
using SatIp.Usercontrols;
namespace SatIp
{
public partial class MainForm : Form
{
private SSDPClient ssdp = null;
public MainForm()
{
InitializeComponent();
Logger.SetLogFilePath("SatIp Scan Sample.log", Settings.Default.LogLevel);
ssdp = new SSDPClient();
ssdp.DeviceFound += new SSDPClient.DeviceFoundHandler(DeviceFound);
ssdp.DeviceLost += new SSDPClient.DeviceLostHandler(DeviceLost);
ssdp.FindByType("urn:ses-com:device:SatIPServer:1");
}
private void DeviceFound(object sender, SatIpDeviceFoundArgs args)
{
if (InvokeRequired)
{
this.BeginInvoke((MethodInvoker)delegate
{
DeviceFound(sender, args);
});
return;
}
var servernode = treeView1.Nodes[0].Nodes.Add(args.Device.UniqueDeviceName, args.Device.FriendlyName);
servernode.ToolTipText = args.Device.DeviceDescription;
servernode.Tag = args.Device;
foreach (var tuner in args.Device.Tuners)
{
switch (tuner.Type)
{
case TunerType.Cable:
var dvbcnode = new TreeNode("DVBC Tuner");
dvbcnode.Tag = "Cable";
servernode.Nodes.Add(dvbcnode);
break;
case TunerType.Satellite:
var dvbsnode = new TreeNode("DVBS Tuner");
dvbsnode.Tag = "Satellite";
servernode.Nodes.Add(dvbsnode);
break;
case TunerType.Terrestrial:
var dvbtnode = new TreeNode("DVBT Tuner");
dvbtnode.Tag = "Terrestrial";
servernode.Nodes.Add(dvbtnode);
break;
}
}
if (treeView1.Nodes[0].IsExpanded != true)
treeView1.Nodes[0].Expand();
}
private void DeviceLost(object sender, SatIpDeviceLostArgs args)
{
if (InvokeRequired)
{
this.BeginInvoke((MethodInvoker)delegate
{
DeviceLost(sender, args);
});
return;
}
Logger.Info("Device with UUID :{0} restarts,and will removed from the Devices Tree", args.Uuid);
if (treeView1.Nodes[0].Nodes.ContainsKey(args.Uuid))
{
var tn = treeView1.Nodes[0].Nodes[args.Uuid];
treeView1.Nodes[0].Nodes.Remove(tn);
treeView1.Update();
}
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
panel1.Controls.Clear();
if(e.Node.Tag != null && e.Node.Tag is "Root")
{
var projectinfo = new ProjectInformation();
panel1.Controls.Add(projectinfo);
label1.Text = "Sat>Ip Project";
}
else if (e.Node.Tag != null && e.Node.Tag is SatIpDevice)
{
var device = ssdp.FindByUDN(e.Node.Name);
if (device != null)
{
var deviceinfo = new DeviceInformation(device);
label1.Text = e.Node.Text;
panel1.Controls.Add(deviceinfo);
//TransponderScan frm = new TransponderScan(device);
//frm.ShowDialog();
}
}
else if (e.Node.Tag != null && e.Node.Tag is "Cable")
{
var device = ssdp.FindByUDN(e.Node.Parent.Name);
var cabinfo = new CableInformation(device);
panel1.Controls.Add(cabinfo);
label1.Text = string.Format("{0} - {1}", device.FriendlyName, e.Node.Text);
}
else if (e.Node.Tag != null && e.Node.Tag is "Satellite")
{
var device = ssdp.FindByUDN(e.Node.Parent.Name);
var satinfo = new SatelliteInformation(device);
panel1.Controls.Add(satinfo);
label1.Text = string.Format("{0} - {1}", device.FriendlyName, e.Node.Text);
}
else if (e.Node.Tag != null && e.Node.Tag is "Terrestrial")
{
var device = ssdp.FindByUDN(e.Node.Parent.Name);
var terinfo = new TerrestrialInformation(device);
panel1.Controls.Add(terinfo);
label1.Text = string.Format("{0} - {1}", device.FriendlyName, e.Node.Text);
}
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
ssdp.Dispose();
ssdp.DeviceFound -= new SSDPClient.DeviceFoundHandler(DeviceFound);
ssdp.DeviceLost -= new SSDPClient.DeviceLostHandler(DeviceLost);
ssdp = null;
}
}
}