/// <summary> /// /// </summary> /// <returns></returns> private bool CreateSocketCommuniType(out SocketCommuniType ct) { DiscriminateMode dm = (DiscriminateMode)this.cmbDiscriminateMode.SelectedValue; ct = null; switch (dm) { case DiscriminateMode.ByIPAddress: bool b = CheckIPAddress(); if (!b) { return(false); } IPAddress ip = GetIPAddress(); ct = new SocketCommuniType(ip); break; case DiscriminateMode.ByLocalPort: int lp = GetLocalPort(); ct = new SocketCommuniType(dm, lp); break; case DiscriminateMode.ByRemotePort: int rp = GetRemotePort(); ct = new SocketCommuniType(dm, rp); break; default: throw new NotImplementedException("DiscriminateMode: " + dm); } return(true);; }
/// <summary> /// /// </summary> /// <param name="dm"></param> private void VisiblePanel(DiscriminateMode dm) { panelByIPAddress.Visible = dm == DiscriminateMode.ByIPAddress; panelByLocalPort.Visible = dm == DiscriminateMode.ByLocalPort; panelBylRemotePort.Visible = dm == DiscriminateMode.ByRemotePort; panelByRemoteIPAndPort.Visible = dm == DiscriminateMode.ByRemoteIPAddressAndPort; }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmbDiscriminateMode_SelectedIndexChanged(object sender, EventArgs e) { object obj = this.cmbDiscriminateMode.SelectedItem; StationDiscriminateMode.Item item = obj as StationDiscriminateMode.Item; DiscriminateMode dm = item.DiscriminateMode; VisiblePanel(dm); }
/// <summary> /// /// </summary> /// <param name="xmlNode"></param> /// <returns></returns> static private CommuniType BuildSocketCommuniType(XmlNode socketNode) { if (socketNode == null) { throw new ArgumentNullException("socketNode"); } XmlNode node = null; XmlNode discriminateModeNode = socketNode.SelectSingleNode(HardwareNodeNames.DiscriminateMode); string modestr = discriminateModeNode.InnerText; //CS.wl(modestr); DiscriminateMode mode = (DiscriminateMode)Enum.Parse(typeof(DiscriminateMode), modestr, true); if (mode == DiscriminateMode.ByIPAddress) { node = socketNode.SelectSingleNode(HardwareNodeNames.IPAddress); IPAddress ipaddress = IPAddress.Parse(node.InnerText); return(new SocketCommuniType(ipaddress)); } else if (mode == DiscriminateMode.ByLocalPort) { node = socketNode.SelectSingleNode(HardwareNodeNames.LocalPort); int localport = int.Parse(node.InnerText); return(new SocketCommuniType(DiscriminateMode.ByLocalPort, localport)); } else if (mode == DiscriminateMode.ByRemotePort) { node = socketNode.SelectSingleNode(HardwareNodeNames.RemotePort); int remotePort = int.Parse(node.InnerText); return(new SocketCommuniType(DiscriminateMode.ByRemotePort, remotePort)); } //else if (mode == DiscriminateMode.ByIPAddressPort) //{ // node = socketNode.SelectSingleNode(HardwareNodeNames.IPAddress); // IPAddress ipaddress = IPAddress.Parse(node.InnerText); // node = socketNode.SelectSingleNode(HardwareNodeNames.Port); // int port = int.Parse(node.InnerText); // return new SocketCommuniType(ipaddress, port); //} // TODO: by phonenumber // throw new ArgumentException("unknown discriminate mode: " + modestr); }
//#region SocketCommuniType ///// <summary> ///// ///// </summary> ///// <param name="ip"></param> ///// <param name="port"></param> //public SocketCommuniType(IPAddress ip, int port) // : this(DiscriminateMode.ByIPAddressPort, ip, port, "") //{ //} //#endregion //SocketCommuniType #region SocketCommuniType /// <summary> /// by local or remote port /// </summary> /// <param name="port"></param> public SocketCommuniType(DiscriminateMode dm, int port) //: this(DiscriminateMode.ByLocalPort, IPAddress.None, port, "") { if (dm == DiscriminateMode.ByLocalPort) { this.LocalPort = port; } else if (dm == DiscriminateMode.ByRemotePort) { this.RemotePort = port; } else { throw new ArgumentException("dm must be ByLocalPort or ByRemotePort"); } this.DiscriminateMode = dm; }
public bool Verify() { DiscriminateMode dm = (DiscriminateMode)this.cmbDiscriminateMode.SelectedValue; if (dm == DiscriminateMode.ByIPAddress) { IPAddress ip; bool r = IPAddress.TryParse(this.txtStationIP.Text, out ip); if (!r) { NUnit.UiKit.UserMessage.DisplayFailure(strings.InvalidIPAddress); } return(r); } else { return(true); } }
/// <summary> /// /// </summary> /// <param name="dm"></param> private void VisiblePanel(DiscriminateMode dm) { panelByIPAddress.Visible = dm == DiscriminateMode.ByIPAddress; panelByLocalPort.Visible = dm == DiscriminateMode.ByLocalPort; panelBylRemotePort.Visible = dm == DiscriminateMode.ByRemotePort; }
/// <summary> /// /// </summary> /// <param name="dm"></param> /// <param name="text"></param> public Item(DiscriminateMode dm, string text) { this._discriminateMode = dm; this._text = text; }
/// <summary> /// /// </summary> /// <param name="dm"></param> /// <param name="text"></param> public Item(DiscriminateMode dm, string text, Type type) { this._discriminateMode = dm; this._text = text; this._type = type; }