コード例 #1
0
 /// <summary>
 /// Set ConfigIP for NetworkDevice
 /// </summary>
 /// <param name="nic">Network device.</param>
 ///  /// <param name="config">IP Config</param>
 private static void SetConfigIP(NetworkDevice nic, IPConfig config)
 {
     NetworkConfig.Add(nic, config);
     AddressMap.Add(config.IPAddress.Hash, nic);
     MACMap.Add(nic.MACAddress.Hash, nic);
     IPConfig.Add(config);
     nic.DataReceived = HandlePacket;
 }
コード例 #2
0
        public void ScanString(string str, ref int referenceAddress, IDictionary <byte, string> charLookup, bool scanCodesOnly,
                               out IList <string> references, out ISet <IControlCode> controlCodes)
        {
            references   = new List <string>();
            controlCodes = new HashSet <IControlCode>();

            for (int i = 0; i < str.Length;)
            {
                if (str[i] == '[')
                {
                    if (str.IndexOf(']', i + 1) == -1)
                    {
                        throw new Exception("Opening bracket has no matching closing bracket: position " + i);
                    }

                    string[] codeStrings = str.Substring(i + 1, str.IndexOf(']', i + 1) - i - 1)
                                           .Split(' ');

                    IControlCode code = ControlCodes.FirstOrDefault(c => c.IsMatch(codeStrings));
                    if (!controlCodes.Contains(code))
                    {
                        controlCodes.Add(code);
                    }

                    foreach (var codeString in codeStrings)
                    {
                        if (codeString[0] == '_')
                        {
                            if (codeString[codeString.Length - 1] != '_')
                            {
                                throw new Exception("Reference has no closing underscore: position " + i);
                            }

                            if (codeString.Length <= 2)
                            {
                                throw new Exception("Reference is empty: position " + i);
                            }

                            if (!scanCodesOnly)
                            {
                                referenceAddress += 4;
                            }

                            references.Add(codeString.Substring(1, codeString.Length - 2));
                        }
                        else if (IsHexByte(codeString))
                        {
                            if (!scanCodesOnly)
                            {
                                referenceAddress++;
                            }
                        }
                        else
                        {
                            throw new Exception(String.Format(
                                                    "Encountered invalid code string at position {0}: {1}", i, codeString));
                        }
                    }

                    i = str.IndexOf(']', i + 1) + 1;
                }
                else if (str[i] == ']')
                {
                    throw new Exception("Closing bracket has no matching opening bracket: position " + i);
                }
                else if (str[i] == '^')
                {
                    if (str.IndexOf('^', i + 1) == -1)
                    {
                        throw new Exception("Label has no matching closing caret: position " + i);
                    }

                    string label = str.Substring(i + 1, str.IndexOf('^', i + 1) - i - 1);

                    if (AddressMap.ContainsKey(label))
                    {
                        throw new Exception("Label already defined: position " + i);
                    }

                    if (!scanCodesOnly)
                    {
                        AddressMap.Add(label, referenceAddress);
                    }

                    i = str.IndexOf('^', i + 1) + 1;
                }
                else
                {
                    if (!(str[i] == '\r') && !(str[i] == '\n'))
                    {
                        if (!scanCodesOnly)
                        {
                            GetByte(str[i], charLookup); // just check if it's valid
                            referenceAddress++;
                        }
                    }
                    i++;
                }
            }
        }
コード例 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            AddressAndPort from = new AddressAndPort()
            {
                Address = textBox1.Text.Trim(), Port = (int)numericUpDown1.Value
            };

            if (!listBox1.Items.Contains(from))
            {
                AddressAndPort to = new AddressAndPort()
                {
                    Address = textBox2.Text.Trim(), Port = (int)numericUpDown2.Value
                };
                List <AddressAndPort> tos = new List <AddressAndPort>();
                tos.Add(to);
                int id = MapManager.AddMap(new KeyValuePair <AddressAndPort, List <AddressAndPort> >(from, tos), textBox3.Text.Trim());
                if (id > 0)
                {
                    AddressMap map = listBox1.Tag as AddressMap;
                    map.Add(id, from, to, textBox3.Text.Trim());
                    listBox1.Items.Add(from);
                    listBox2.Items.Add(to);
                    if (MessageBox.Show("添加映射成功!是否为双向映射?确定将自动为您添加一个反向映射。", "添加成功和双向提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    {
                        AddressAndPort from2 = new AddressAndPort()
                        {
                            Address = textBox2.Text.Trim(), Port = (int)numericUpDown2.Value
                        };
                        if (!listBox1.Items.Contains(from2))
                        {
                            AddressAndPort to2 = new AddressAndPort()
                            {
                                Address = textBox1.Text.Trim(), Port = (int)numericUpDown1.Value
                            };
                            List <AddressAndPort> tos2 = new List <AddressAndPort>();
                            tos2.Add(to2);
                            id = MapManager.AddMap(new KeyValuePair <AddressAndPort, List <AddressAndPort> >(from2, tos2), textBox3.Text.Trim() + "_反向");
                            if (id > 0)
                            {
                                map.Add(id, from2, to2, textBox3.Text.Trim() + "_反向");
                                listBox1.Items.Add(from2);
                                listBox2.Items.Add(to2);
                                MessageBox.Show("添加反向映射成功!");
                            }
                        }
                        else
                        {
                            MessageBox.Show("已存在该映射起点[" + from2 + "],请点击修改按钮!");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("添加映射失败!");
                }
                MapManager.Dispose();
            }
            else
            {
                MessageBox.Show("已存在该映射起点[" + from + "],请点击修改按钮!");
            }
        }