public async Task SetUp()
        {
            this.log = this.CreateLogger();
            var args = new NameValueCollection();

            url = new Uri($"http://localhost:{TcpPort.NextFreePort()}");
            args.Add("selenium.baseUrl", url.ToString());

            browserConfig = WebDriver
                            .Configure(cfg => cfg.WithDefaultOptions().Providers(x => args[x]), log)
                            .Build();

            webHost = WebHost.Start(
                url.ToString(),
                router => router
                .MapGet(
                    "/page1",
                    (req, res, data) =>
            {
                res.ContentType = "text/html";
                return(res.WriteAsync("<body><a href='page2'>Page 2</a></body>"));
            })
                .MapGet(
                    "/page2",
                    (req, res, data) =>
            {
                res.ContentType = "text/html";
                return(res.WriteAsync("<body><label><input type='radio' />Foo</label></body>"));
            }));
            webDriver = WebDriverFactory.Create(browserConfig);
        }
Example #2
0
 public IPort Bind(int portNumber, IFormatter formatter)
 {
     TcpPort port = new TcpPort(portNumber, formatter);
     port.Open();
     ports.Add(port);
     return port;
 }
Example #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            IPort port = new TcpPort("" + this.tb_ip.Text.ToString().Trim() + ":" + this.tb_port.Text.ToString().Trim() + "");

            _serialize = new ProtoClass();
            TestDevice   _device  = new TestDevice(port, _serialize);
            eElementCode testenum = (eElementCode)Enum.Parse(typeof(eElementCode), cmb_in_type.SelectedValue.ToString(), false);

            //ushort content = ushort.Parse(this.tb_in_Content.ToString().Trim());
            while (true)
            {
                if ("0" == _device.Read(eElementCode.Y, uint.Parse("1")).ToString().Trim())
                {
                    Thread.Sleep(100);
                    _device.Write(eElementCode.Y, uint.Parse("1"), ushort.Parse("1"));
                }

                Thread.Sleep(100);
                if ("1" == _device.Read(eElementCode.M, uint.Parse("1")).ToString().Trim())
                {
                    _device.Write(eElementCode.Y, uint.Parse("1"), ushort.Parse("0"));
                    Thread.Sleep(100);
                }
            }
        }
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (TcpPort != null)
         {
             hashCode = hashCode * 59 + TcpPort.GetHashCode();
         }
         if (AllowRemoteAccess != null)
         {
             hashCode = hashCode * 59 + AllowRemoteAccess.GetHashCode();
         }
         if (MaxRenderRgnPixels != null)
         {
             hashCode = hashCode * 59 + MaxRenderRgnPixels.GetHashCode();
         }
         if (MaxMessageSize != null)
         {
             hashCode = hashCode * 59 + MaxMessageSize.GetHashCode();
         }
         if (RandomAccessUrlTimeout != null)
         {
             hashCode = hashCode * 59 + RandomAccessUrlTimeout.GetHashCode();
         }
         if (WorkerThreads != null)
         {
             hashCode = hashCode * 59 + WorkerThreads.GetHashCode();
         }
         return(hashCode);
     }
 }
Example #5
0
        /// <summary>
        /// 获取一次Tcp端口快照信息
        /// </summary>
        /// <returns></returns>
        public unsafe static List <TcpPort> Snapshot()
        {
            var portList = new List <TcpPort>();

            const int AF_INET = 2;
            const int TCP_TABLE_OWNER_PID_ALL = 5;

            var size = 0;

            TcpTable.GetExtendedTcpTable(null, &size, true, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0);
            byte *pTable = stackalloc byte[size];

            if (TcpTable.GetExtendedTcpTable(pTable, &size, true, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0) == 0)
            {
                var rowLength = *(int *)(pTable);
                var pRow      = pTable + Marshal.SizeOf(rowLength);

                for (int i = 0; i < rowLength; i++)
                {
                    var row     = *(MIB_TCPROW_OWNER_PID *)pRow;
                    var tcpPort = TcpPort.FromTcpRow(row);

                    if (portList.Contains(tcpPort) == false)
                    {
                        portList.Add(tcpPort);
                    }

                    pRow = pRow + Marshal.SizeOf(typeof(MIB_TCPROW_OWNER_PID));
                }
            }

            return(portList);
        }
Example #6
0
        /// <summary>
        /// 添加客户端Tcp端口
        /// </summary>
        /// <param name="port">tcp端口</param>
        /// <param name="flag">端口标志<1.控制 2.视频 3.图像 4.心跳></param>
        /// <param name="deviceDictonary">客户端字典</param>
        /// <returns></returns>
        public bool InstallClientPort(TcpPort port, int flag, ref Dictionary <string, ArmClient> deviceDictonary)
        {
            IPEndPoint remoteEndPoint = (IPEndPoint)port.PortSocket.RemoteEndPoint;
            IPAddress  ipaddress      = IPAddress.Parse(remoteEndPoint.Address.ToString());
            string     ip             = ipaddress.ToString();

            lock (syncLock)
            {
                ArmClient device = null;
                if (!deviceDictonary.TryGetValue(ip, out device))
                {
                    device = new ArmClient(ip);
                    deviceDictonary.Add(ip, device);
                }
                if (flag == 1)
                {
                    device.ControlPort = port;
                }
                else if (flag == 2)
                {
                    device.VideoPort = port;
                }
                else if (flag == 3)
                {
                    device.PhotoPort = port;
                }
                else
                {
                    device.HeartPort = port;
                }
            }
            return(true);
        }
Example #7
0
 // constructor
 public IgusDryve(string ip, int port)
 {
     _ip         = ip;
     _port       = port;
     _client     = new TcpPort(ip, port);
     _msgHandler = new DryveMessageHandler(_client);
 }
Example #8
0
        public IClient Create(ClientSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            // special consideration for obsolete ClientType values that may appear in hfmx configuration files
            if (!_clientFactories.TryGetValue(settings.ClientType, out var factory))
            {
                return(null);
            }

            if (!ClientSettings.ValidateName(settings.Name))
            {
                throw new ArgumentException($"Client name {settings.Name} is not valid.", nameof(settings));
            }
            if (String.IsNullOrWhiteSpace(settings.Server))
            {
                throw new ArgumentException("Client server (host) name is empty.", nameof(settings));
            }
            if (!TcpPort.Validate(settings.Port))
            {
                throw new ArgumentException($"Client server (host) port {settings.Port} is not valid.", nameof(settings));
            }

            IClient client = factory.Create();

            if (client != null)
            {
                client.Settings = settings;
            }
            return(client);
        }
Example #9
0
        public async Task SetUp()
        {
            this.log = this.CreateLogger();
            var args = new NameValueCollection();

            url = $"http://localhost:{TcpPort.NextFreePort()}";
            args.Add("selenium.baseUrl", url);

            var browserConfig = WebDriver
                                .Configure(cfg => cfg.WithDefaultOptions().Providers(x => args[x]), log)
                                .Build();

            webHost = WebHost.Start(
                url,
                router => router
                .MapGet(
                    "",
                    (req, res, data) =>
            {
                res.ContentType = "text/html; charset=utf-8";
                return(res.WriteAsync(
                           "<html><body><script type=\"text/javascript\">alert('Hello! I am an alert box!');</script></body></html>"));
            }));
            webDriver = WebDriverFactory.Create(browserConfig);
        }
Example #10
0
 /// <summary>
 /// Установить параметры канала связи в соответствии с настройками
 /// </summary>
 public void SetCommCnlParams(SortedList <string, string> commCnlParams)
 {
     commCnlParams["IpAddress"] = ConnMode == ConnectionModes.Shared ? IpAddress : "";
     commCnlParams["TcpPort"]   = TcpPort.ToString();
     commCnlParams["Behavior"]  = Behavior.ToString();
     commCnlParams["ConnMode"]  = ConnMode.ToString();
 }
Example #11
0
        /// <summary>
        /// Connects asynchronously to a remote TCP host using the specified host and port number.
        /// </summary>
        /// <param name="host">The name of the remote host.  The host can be an IP address or DNS name.</param>
        /// <param name="port">The port number of the remote host.</param>
        /// <param name="timeout">The time (in milliseconds) to wait while trying to establish a connection before terminating the attempt and generating an error.</param>
        /// <exception cref="ObjectDisposedException" />
        /// <exception cref="InvalidOperationException">The connection is already connected.</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="host" /> parameter is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">The <paramref name="port" /> parameter is not between zero and <see cref="Int16.MaxValue"/>.</exception>
        /// <exception cref="TimeoutException">A connection was not made before the timeout duration.</exception>
        public override async Task ConnectAsync(string host, int port, int timeout)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }
            if (Connected)
            {
                throw new InvalidOperationException("The connection is already connected.");
            }
            if (host is null)
            {
                throw new ArgumentNullException(nameof(host));
            }
            if (!TcpPort.Validate(port))
            {
                throw new ArgumentOutOfRangeException(nameof(port));
            }

            var connectTask = TcpClient.ConnectAsync(host, port);

            if (connectTask != await Task.WhenAny(connectTask, Task.Delay(timeout)).ConfigureAwait(false))
            {
                Close();
                throw new TimeoutException("Connection attempt has timed out.");
            }

            ThrowIfConnectTaskIsFaulted(connectTask);
        }
Example #12
0
        public async Task ReturnsTrueForExpectedMatch()
        {
            var log  = this.CreateLogger();
            var args = new NameValueCollection();
            var url  = $"http://localhost:{TcpPort.NextFreePort()}";

            args.Add("selenium.baseUrl", url);

            var browserConfig = WebDriver
                                .Configure(cfg => cfg.WithDefaultOptions().Providers(x => args[x]), log)
                                .Build();

            using (WebHost.Start(
                       url,
                       router => router
                       .MapGet(
                           "",
                           (req, res, data) =>
            {
                res.ContentType = "text/html";
                return(res.WriteAsync("<body></body>"));
            })))
                using (var driver = WebDriverFactory.Create(browserConfig))
                {
                    driver.Navigate().GoToUrl(url);
                    driver.WaitForJavascriptResult("6 / 3", 2, log, TimeSpan.FromMilliseconds(100));
                }
        }
Example #13
0
 /// <summary>
 /// Установить параметры канала связи в соответствии с настройками
 /// </summary>
 public void SetCommCnlParams(SortedList <string, string> commCnlParams)
 {
     commCnlParams["TcpPort"]      = TcpPort.ToString();
     commCnlParams["InactiveTime"] = InactiveTime.ToString();
     commCnlParams["Behavior"]     = Behavior.ToString();
     commCnlParams["ConnMode"]     = ConnMode.ToString();
     commCnlParams["DevSelMode"]   = DevSelMode.ToString();
 }
Example #14
0
        public bool Equals(PeerSocketAddress other)
        {
            var t1 = InetAddress.Equals(other.InetAddress);
            var t2 = TcpPort.Equals(other.TcpPort);
            var t3 = UdpPort.Equals(other.UdpPort);

            return(t1 && t2 && t3);
        }
Example #15
0
 /// <summary>
 /// Установить параметры канала связи в соответствии с настройками
 /// </summary>
 public void SetCommCnlParams(SortedList <string, string> commCnlParams)
 {
     commCnlParams["Host"]           = ConnMode == ConnectionModes.Shared ? Host : "";
     commCnlParams["TcpPort"]        = TcpPort.ToString();
     commCnlParams["ReconnectAfter"] = ReconnectAfter.ToString();
     commCnlParams["StayConnected"]  = StayConnected.ToString();
     commCnlParams["Behavior"]       = Behavior.ToString();
     commCnlParams["ConnMode"]       = ConnMode.ToString();
 }
Example #16
0
 /// <summary>
 /// Adds the options to the list.
 /// </summary>
 public void AddToOptionList(OptionList options)
 {
     options.Clear();
     options["TcpPort"]        = TcpPort.ToString();
     options["ClientLifetime"] = ClientLifetime.ToString();
     options["Behavior"]       = Behavior.ToString();
     options["ConnectionMode"] = ConnectionMode.ToString();
     options["DeviceMapping"]  = DeviceMapping.ToString();
 }
Example #17
0
        /// <summary>
        /// 添加Socket
        /// </summary>
        /// <param name="socket">接收到的Socket</param>
        /// <param name="flag">该Socket类型</param>
        public void AddSocket(Socket socket, int flag)
        {
            lock (_sync)
            {
                ArmClient armClient = null;
                TcpPort   tempPort  = new TcpPort(socket);
                InstallClientPort(tempPort, flag, ref armClientDictionary);

                if (!(HasValDevice(out armClient)))
                {
                    return;
                }

                if (armClient != null)
                {
                    Console.WriteLine("ARM客户端开始接收数据");
                    TcpPort comPort  = armClient.ControlPort;
                    byte[]  location = new byte[200];
                    comPort.Receive(location);
                    armClient.Location = Encoding.ASCII.GetString(location);
                    Console.WriteLine("ARM客户端地址为:" + armClient.Location);


                    byte[] data = Encoding.ASCII.GetBytes("Welcome to server");
                    comPort.Send(data, Kind.message);
                    armClient.IsChecking     = false;
                    armClient.IsUsing        = false;
                    armClient.LastAccessTime = DateTime.Now;
                    armClient.IsLoseConnect  = false;
                }
            }

            //lock (_sync)
            //{
            //    if (controlListenning) //仍然在监听状态
            //    {
            //        lock (listSync) //套大锁,再套小锁
            //        {
            //            //检查该客户端之前是否已经登录过了。有的话,删除之前的,然后再添加

            //            int i;
            //            for (i = 0; i < clients.Count; ++i)
            //            {
            //                if (one_client.localtion.Equals(clients[i].localtion))
            //                {
            //                    clients.Remove(clients[i]);
            //                    break;
            //                }
            //            }

            //            clients.Add(one_client); //把连接好的客户端放到容器里面
            //            ShowClientsinGrid(one_client);
            //            lb_conn_num.Text = "" + clients.Count;
            //        }
            //    }
            //}
        }
Example #18
0
        public void Start()
        {
            if (Port == 0)
            {
                Port = TcpPort.FindNextAvailablePort(12345);
            }

            server = new Gate.Hosts.Firefly.ServerFactory().Create(App, Port);
        }
Example #19
0
 /// <summary>
 /// Adds the options to the list.
 /// </summary>
 public void AddToOptionList(OptionList options)
 {
     options.Clear();
     options["Host"]           = Host;
     options["TcpPort"]        = TcpPort.ToString();
     options["ReconnectAfter"] = ReconnectAfter.ToString();
     options["StayConnected"]  = StayConnected.ToLowerString();
     options["Behavior"]       = Behavior.ToString();
     options["ConnectionMode"] = ConnectionMode.ToString();
 }
        public override IEnumerable <KeyValuePair <string, string> > GetLoadedOptionsPairs()
        {
            foreach (var pair in base.GetLoadedOptionsPairs())
            {
                yield return(pair);
            }
            yield return(new KeyValuePair <string, string>("TCP PORT", TcpPort.ToString()));

            yield return(new KeyValuePair <string, string>("DB PATH", string.IsNullOrEmpty(DbPath) ? "<DEFAULT>" : DbPath));
        }
Example #21
0
        public JObject ToJson()
        {
            JObject json = new JObject();

            json["topPort"]   = TcpPort.ToString();
            json["wsPort"]    = WsPort.ToString();
            json["nonce"]     = Nonce.ToString();
            json["useragent"] = UserAgent;
            return(json);
        }
Example #22
0
 public void applyConfiguration()
 {
     config.AppSettings.Settings["nomeServer"].Value      = ServerName;
     config.AppSettings.Settings["password"].Value        = Password;
     config.AppSettings.Settings["indirizzo"].Value       = Address;
     config.AppSettings.Settings["portTCP"].Value         = TcpPort.ToString();
     config.AppSettings.Settings["portUDP"].Value         = UdpPort.ToString();
     config.AppSettings.Settings["enableUDP"].Value       = UdpEnabled.ToString();
     config.AppSettings.Settings["passwordEnabled"].Value = PasswordEnabled.ToString();
 }
Example #23
0
        private void bt_out_Click(object sender, EventArgs e)
        {
            IPort port = new TcpPort("" + this.tb_ip.Text.ToString().Trim() + ":" + this.tb_port.Text.ToString().Trim() + "");

            _serialize = new ProtoClass();
            TestDevice   _device  = new TestDevice(port, _serialize);
            eElementCode testenum = (eElementCode)Enum.Parse(typeof(eElementCode), cmb_in_type.SelectedValue.ToString(), false);

            //this.lb_out_content.Text =  _device.Read(testenum, uint.Parse(this.tb_out_Number.Text.ToString().Trim())).ToString().Trim();
            this.lb_out_content.Text = _device.Read(eElementCode.M, 10).ToString().Trim();
        }
        private bool ValidatePort()
        {
            switch (WebDeploymentType)
            {
            case WebDeploymentType.Ftp:
                return(TcpPort.Validate(Port));

            default:
                return(true);
            }
        }
Example #25
0
        private void button3_Click(object sender, EventArgs e)
        {
            IPort port = new TcpPort("" + this.tb_ip.Text.ToString().Trim() + ":" + this.tb_port.Text.ToString().Trim() + "");

            _serialize = new ProtoClass();
            WrapDevice _device = new WrapDevice(port, _serialize);

            //_device.Picking();
            Thread.Sleep(10000);
            // _device.Placing();
        }
Example #26
0
        public void SetUp()
        {
            var log  = this.CreateLogger();
            var args = new NameValueCollection();

            fakeWebDriver = Substitute.For <IWebDriver>();
            args.Add("selenium.baseUrl", $"http://localhost:{TcpPort.NextFreePort()}");
            args.Add("webdriver.browser.type", "fake-webdriver");
            fakeConfig = WebDriver.Configure(cfg => cfg.WithDefaultOptions().Providers(x => args[x]), log).Build();
            WebDriverFactory.AddDriverBuilder("fake-webdriver", c => fakeWebDriver);
        }
Example #27
0
        public void TcpHandler()
        {
            var request = new TcpPort
            {
                Host = "www.microsoft.com",
                Port = 80
            };

            new TcpMonitor().Handle(request);

            Assert.AreSame(State.Ok, request.State);
        }
Example #28
0
 public static void SaveSetting()
 {
     reader.SetNodeText("PingTimeout", PingTimeout.ToString());
     reader.SetNodeText("RequestTimeout", RequestTimeout.ToString());
     reader.SetNodeText("TcpPort", TcpPort.ToString());
     reader.SetNodeText("UdpPort", UdpPort.ToString());
     reader.SetNodeText("ClientPort", ClientPort.ToString());
     reader.SetNodeText("Adapter", Adapter);
     reader.SetNodeText("PlayerID", PlayerID);
     reader.SetNodeText("DataMode", dataMode);
     reader.SetNodeText("SyncMode", syncMode);
     reader.Save("setting.xml");
 }
        public async Task ImportsCookiesForDomain()
        {
            string actualCookieValue = null;

            var expectedCookieValue = "Bar";
            var url             = $"http://localhost:{TcpPort.NextFreePort()}";
            var cookieContainer = new CookieContainer();
            var log             = this.CreateLogger();

            var args = new NameValueCollection();

            args.Add("selenium.baseUrl", url);
            var browserConfig = WebDriver
                                .Configure(cfg => cfg.WithDefaultOptions().Providers(x => args[x]), log)
                                .Build();

            using (WebHost.Start(
                       url,
                       router => router
                       .MapGet(
                           "",
                           (req, res, data) =>
            {
                res.Cookies.Append("Foo", expectedCookieValue);
                res.ContentType = "text/html";
                return(res.WriteAsync(""));
            })
                       .MapGet(
                           "checkcookie",
                           (req, res, data) =>
            {
                actualCookieValue = req.Cookies["Foo"];
                return(res.WriteAsync(""));
            })))
                using (var cookieHandler = new HttpClientHandler {
                    CookieContainer = cookieContainer,
                    UseCookies = true,
                    AllowAutoRedirect = false
                })
                    using (var httpClient = new HttpClient(cookieHandler)
                    {
                        BaseAddress = new Uri(url)
                    })
                        using (var driver = WebDriverFactory.Create(browserConfig))
                        {
                            driver.Navigate().GoToUrl(url);
                            driver.ImportCookies(cookieContainer, new Uri(url));
                            driver.Navigate().GoToUrl(url + "/checkcookie");
                            actualCookieValue.Should().Be(expectedCookieValue);
                        }
        }
Example #30
0
        private void bt_in_Click(object sender, EventArgs e)
        {
            IPort port = new TcpPort("" + this.tb_ip.Text.ToString().Trim() + ":" + this.tb_port.Text.ToString().Trim() + "");

            _serialize = new ProtoClass();
            TestDevice   _device  = new TestDevice(port, _serialize);
            eElementCode testenum = (eElementCode)Enum.Parse(typeof(eElementCode), cmb_in_type.SelectedValue.ToString(), false);

            //ushort content = ushort.Parse(this.tb_in_Content.ToString().Trim());
            // _device.Write( eElementCode.D,uint.Parse("204"),ushort.Parse("100"));
            // _device.Write(eElementCode.M, uint.Parse("0"), ushort.Parse("0"));
            //_device.Write(eElementCode.M, uint.Parse("8"), ushort.Parse("1"));
            _device.Write(eElementCode.Y, uint.Parse("20"), ushort.Parse("1"));
        }
        public async Task CreatesAChromeDriver()
        {
            var args = new NameValueCollection();

            args.Add("selenium.baseUrl", $"http://localhost:{TcpPort.NextFreePort()}");
            var browserConfig = WebDriver
                                .Configure(cfg => cfg.WithDefaultOptions().Providers(x => args[x]), log)
                                .Build();

            using (var driver = WebDriverFactory.Create(browserConfig))
            {
                driver.Should().BeOfType <ChromeDriver>();
            }
        }