Exemplo n.º 1
0
        public static void Default_1_GetPortStatus()
        {
            var unusedPort = LocalPortManager.GetRandomUnusedPort();

            Assert.True(unusedPort > 0);
            var portStatus = LocalPortManager.GetPortStatus(unusedPort);

            Assert.Equal(LocalPortManager.PortStatus.Available, portStatus);
        }
Exemplo n.º 2
0
        public static void Default_1_GetPortStatus_WithUsedPort()
        {
            var listener = new TcpListener(IPAddress.Loopback, 0);

            try
            {
                listener.Start();
                var usedPort = ((IPEndPoint)listener.LocalEndpoint).Port;
                Assert.True(usedPort > 0);
                var portStatus = LocalPortManager.GetPortStatus(usedPort);
                Assert.Equal(LocalPortManager.PortStatus.InUse, portStatus);
            }
            finally
            {
                listener.Stop();
            }
        }
Exemplo n.º 3
0
        private static void Main()
        {
            Console.WriteLine($"SecurityProtocolManager.GetAvailableProtocol(): {SecurityProtocolManager.GetAvailableProtocol()}");
            Console.ReadKey();

            Console.WriteLine("NetworkInterface.IsNetworkAvailable(): " + NetworkInterface.IsNetworkAvailable());
            Console.WriteLine("NetworkInterface.IsInternetAvailable(): " + NetworkInterface.IsInternetAvailable());
            Console.ReadKey();

            Console.WriteLine("Platform.DetectProcessArch(): " + Platform.DetectProcessArch());
            Console.ReadKey();

            using (var usbWatcher = UsbWatcherFactory.GetInstance().CreateUsbWatcher())
            {
                usbWatcher.OnDeviceConnected    += OnUsbDeviceConnected;
                usbWatcher.OnDeviceDisconnected += OnUsbDeviceDisconnected;
                var isRunning = usbWatcher.IsRunning();
                if (isRunning)
                {
                    Console.WriteLine("usbWatcher is running");
                }
                else
                {
                    Console.WriteLine("usbWatcher.Start(): " + usbWatcher.Start());
                }
                Console.ReadKey();

                Console.WriteLine("usbWatcher.Stop(): " + usbWatcher.Stop());
                Console.ReadKey();
            }

            var deviceInfos = UsbManager.GetHidDevices();
            var index       = 0;

            foreach (var deviceInfo in deviceInfos)
            {
                Console.WriteLine($"deviceInfo[{index}].Path: \"{deviceInfo.Path}\"");
                Console.WriteLine($"deviceInfo[{index}].VendorId: \"{deviceInfo.VendorId}\"");
                Console.WriteLine($"deviceInfo[{index}].ProductId: \"{deviceInfo.ProductId}\"");
                Console.WriteLine($"deviceInfo[{index}].Description: \"{deviceInfo.Description}\"");
                Console.WriteLine($"deviceInfo[{index}].Manufacturer: \"{deviceInfo.Manufacturer}\"");
                Console.WriteLine($"deviceInfo[{index}].SerialNumber: \"{deviceInfo.SerialNumber}\"");
                var featureReport = UsbManager.GetHidFeatureReport(deviceInfo.Path, 0);
                if (featureReport == null)
                {
                    Console.WriteLine($"deviceInfo[{index}].featureReport is null");
                }
                else
                {
                    Console.WriteLine($"deviceInfo[{index}].featureReport is {Util.Convert.ToHexString(featureReport)}");
                }
                index++;
            }
            Console.ReadKey();

            deviceInfos = UsbManager.GetUsbDevices();
            index       = 0;
            foreach (var deviceInfo in deviceInfos)
            {
                Console.WriteLine($"deviceInfo[{index}].Path: \"{deviceInfo.Path}\"");
                Console.WriteLine($"deviceInfo[{index}].VendorId: \"{deviceInfo.VendorId}\"");
                Console.WriteLine($"deviceInfo[{index}].ProductId: \"{deviceInfo.ProductId}\"");
                Console.WriteLine($"deviceInfo[{index}].Description: \"{deviceInfo.Description}\"");
                Console.WriteLine($"deviceInfo[{index}].Manufacturer: \"{deviceInfo.Manufacturer}\"");
                Console.WriteLine($"deviceInfo[{index}].SerialNumber: \"{deviceInfo.SerialNumber}\"");
                index++;
            }
            Console.ReadKey();

            var randomUnusedPort             = LocalPortManager.GetRandomUnusedPort();
            var specificPort                 = 35447;
            var randomUnusedPortStatus       = LocalPortManager.GetPortStatus(randomUnusedPort);
            var specificPortStatus           = LocalPortManager.GetPortStatus(specificPort);
            var randomUnusedPortVerifyStatus = LocalPortManager.VerifyPortStatus(randomUnusedPort);
            var specificPortVerifyStatus     = LocalPortManager.VerifyPortStatus(specificPort);

            Console.WriteLine("Random unused port [" + randomUnusedPort + "] status: " + randomUnusedPortStatus + ", verify: " + randomUnusedPortVerifyStatus);
            Console.WriteLine("Specific port [" + specificPort + "] status: " + specificPortStatus + ", verify: " + specificPortVerifyStatus);

            var processWatcherFactory = ProcessWatcherFactory.GetInstance();
            var notepadProcessWatcher = processWatcherFactory.CreateProcessWatcher("notepad.exe");

            notepadProcessWatcher.ProcessCreated += OnProcessCreated;
            notepadProcessWatcher.ProcessDeleted += OnProcessDeleted;
            notepadProcessWatcher.Start();
            Console.ReadKey();

            notepadProcessWatcher.Stop();
            Console.ReadKey();

            var allProcessWatcher = processWatcherFactory.CreateProcessWatcher();

            allProcessWatcher.ProcessCreated += OnProcessCreated;
            allProcessWatcher.ProcessDeleted += OnProcessDeleted;
            allProcessWatcher.Start();
            Console.ReadKey();

            allProcessWatcher.Stop();
            Console.ReadKey();

            var serviceName = "Winmgmt";

            Console.WriteLine("service[" + serviceName + "].CurrentState: " + ServiceManager.QueryStartType(serviceName).CurrentState);
            Console.ReadKey();

            Console.WriteLine("WARNING!! This program will reboot system");
            Console.ReadKey();

            Platform.Exit(Platform.ExitType.Reboot);
            Console.ReadKey();
        }