Exemplo n.º 1
0
        private void Initialize()
        {
            var port = PortUtility.GetFreeTcpPort();

            // TODO : Need to move Execute logic to J2NET
            var classPaths = string.Join(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ";" : ":", jarPath, DriverPath);

            _process = JavaRuntime.Execute($"-XX:G1PeriodicGCInterval=5000 -cp \"{classPaths}\" com.chequer.jdbcnet.bridge.Main -p {port}");
            PortUtility.WaitForOpen(port);

            _channel = new Channel($"{host}:{port}", ChannelCredentials.Insecure);

            Driver    = new DriverService.DriverServiceClient(_channel);
            Reader    = new ReaderService.ReaderServiceClient(_channel);
            Statement = new StatementService.StatementServiceClient(_channel);
            Database  = new DatabaseService.DatabaseServiceClient(_channel);

            var loadDriverResponse = Driver.loadDriver(new LoadDriverRequest
            {
                ClassName = DriverClass
            });

            DriverMajorVersion = loadDriverResponse.MajorVersion;
            DriverMinorVersion = loadDriverResponse.MinorVersion;
        }
Exemplo n.º 2
0
 /// <summary>
 /// 控件单击事件。
 /// </summary>
 /// <param name="sender">触发事件的对象。</param>
 /// <param name="e">事件参数。</param>
 /// comment by peter 2012-2-27
 private void GetWeightCtrl_Click(object sender, EventArgs e)
 {
     try
     {
         //获取称重值。
         PortUtility portUtil = new PortUtility();
         portUtil.Start();
         portUtil.ParserValue();
         this.Text = portUtil.WeighValue;
     }
     catch (Exception ex)
     {
         MessageService.ShowError(ex.Message);
     }
 }
        private static int ConfigurePort()
        {
            string portPath = Path.Combine(ROOT_DIRECTORY, "Port");

            if (!File.Exists(portPath))
            {
                File.WriteAllText(portPath, "19962");
            }

            if (!int.TryParse(File.ReadAllText(portPath), out int port) || port < 5000)
            {
                port = 19962;
                File.WriteAllText(portPath, port.ToString());
            }

            if (!PortUtility.IsPortAvailable(port))
            {
                port = PortUtility.GetFirstAvailablePort(5000);
            }

            return(port);
        }