NetTunnelWindows/NetTunnelApp/ServerMenuItems.cs

89 lines
2.1 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace NetTunnelApp;
public class ServerMenuItems
{
private static string _selItems = "";
private List<ToolStripMenuItem> _menuItems = new List<ToolStripMenuItem>();
private static List<VirtualMathineConfig> _menuDataItems = new List<VirtualMathineConfig>();
public ServerMenuItems(List<VirtualMathineConfig> vmList)
{
if (_menuItems.Count > 0)
{
_menuItems.Clear();
}
_menuDataItems.Clear();
_menuDataItems.AddRange(vmList);
foreach (var cfg in vmList)
{
ToolStripMenuItem item = new ToolStripMenuItem();
item.Text = cfg.vmName;
item.Name = "svrMenu_" + cfg.vmId.ToString() + "_" + cfg.vmName;
item.Click += delegate(object sender, EventArgs e)
{
var control = (ToolStripMenuItem)sender;
_selItems = control.Name;
foreach (var v in _menuItems)
{
v.Checked = (_selItems == v.Name);
}
};
_menuItems.Add(item);
}
}
public List<ToolStripMenuItem> GetMenuItems()
{
return _menuItems;
}
public static VirtualMathineConfig? GetSelectItemData()
{
foreach (var k in _menuDataItems)
{
if (_selItems == "svrMenu_" + k.vmId.ToString() + "_" + k.vmName)
{
return k;
}
}
return null;
}
}
public class UserClientCfg
{
///< 用户接入网关控制 ID
public int scgCtrlAppId;
///< 用户接入网关隧道 ID
public int scgTunnelAppId;
///< 用户客户端公钥
public string cliPublicKey;
///< 用户客户端私钥
public string cliPrivateKey;
///< 用户客户端隧道IP地址
public string cliAddress;
///< 用户虚拟机配置列表
public List<VirtualMathineConfig> vmList;
public UserClientCfg()
{
vmList = new List<VirtualMathineConfig>();
}
}