Beispiel #1
0
        public void Default_0_GetAvailableProtocol()
        {
            var availableProtocol = SecurityProtocolManager.GetAvailableProtocol();

            Assert.NotEqual(0, (int)availableProtocol);
            _output.WriteLine($@"availableProtocol: {availableProtocol}");
        }
Beispiel #2
0
        public void Configuration(IAppBuilder app)
        {
            var configuration = new HttpConfiguration();

            // enable logging
            configuration.Filters.Add(new DiagnosticsFilterAttribute());

            // Web API configuration and services
            // CORS Attribute
            configuration.EnableCors(CorsManager.CorsAttribute());

            // Ensure HTTPS over TLS 1.2 for External and Prod
            SecurityProtocolManager.SetSecurityProtocol();

            // Set application specific Json Serialization settings
            SerializerManager.ApplyCustomSettings(configuration.Formatters);

            // Web API routes and application routes
            RoutesManager.AddRoutes(configuration);

            // Owin level exception handling
            app.Use <GlobalExceptionMiddleware>();

            // IoC and DI configuration
            configuration.DependencyResolver = ConfigureIocResolver();

            // Middleware for properties stored on the LogicalThreadContext for log4net and other purposes
            app.Use <RequestMetadataMiddleware>();

            var authMiddleware = (AuthMiddleware)configuration.DependencyResolver.GetService(typeof(IAuthMiddleware));

            app.Use(async(context, next) =>
            {
                await authMiddleware.Invoke(context, next);
            });

            // Global exception handler for AC errors
            configuration.Filters.Add(new MgiExceptionFilter());
            // Filter to add custom headers to the response
            configuration.Filters.Add(new HeaderFilter());
            AwMapper.Configure();

            // Web API documentation configuration
            // Web API documentation for environments that have ApiDocumentation app key set to true
            var keyName         = "ApiDocumentation";
            var apiDocKeyExists = ConfigurationManager.AppSettings.AllKeys.Contains(keyName);

            if (apiDocKeyExists && bool.Parse(ConfigurationManager.AppSettings[keyName]))
            {
                ApiDocumentationManager.Configure(configuration);
            }

            app.UseWebApi(configuration);
        }
        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();
        }