public void Should_return_configuration()
        {
            var configuration = new Configuration();

            configuration.Behaviors.Append <TestBehavior1>();
            configuration.Behaviors.Append <TestBehavior2>();
            var parameters = new TypeCache().GetTypeDescriptor(typeof(Handler)).Methods
                             .FirstOrDefault(x => x.Name == nameof(Handler.Get)).Parameters;
            var actionDescriptors = new List <ActionDescriptor>
            {
                new ActionDescriptor(
                    Type <Handler> .Expression(x => x.Get(null, 0, DateTime.MaxValue)).ToActionMethod(),
                    new RouteDescriptor("GET", "some/url",
                                        parameters.Where(x => x.Name == "urlParam").ToArray(), null,
                                        parameters.Where(x => x.Name == "queryParam").ToArray(),
                                        parameters.First(x => x.Name == "request"),
                                        new TypeCache().GetTypeDescriptor(typeof(OutputModel))),
                    new TypeDescriptor[] {})
            };
            var runtimeConfiguration = new RuntimeConfiguration(actionDescriptors);
            var handler = new DiagnosticsHandler(runtimeConfiguration, configuration,
                                                 new Metrics(), new Container(), new TypeCache());

            var result = handler.Get();

            result.ShouldContain(configuration.UnhandledExceptionStatusText);
            result.ShouldContain(configuration.HandlerNameFilterRegex);
            result.ShouldContain(configuration.HandlerNamespaceRegex);

            result.ShouldContain(typeof(GraphiteBootstrap).Assembly.GetFriendlyName());
            result.ShouldContain(typeof(GraphiteBootstrap).Assembly.GetName().Version.ToString());

            configuration.SupportedHttpMethods.ForEach(x => result.ShouldContain(x.Method));

            result.ShouldContain(configuration.Initializer.Type.GetFriendlyTypeName());
            result.ShouldContain(configuration.TypeCache.Type.GetFriendlyTypeName());
            result.ShouldContain(configuration.BehaviorChainInvoker.Type.GetFriendlyTypeName());
            result.ShouldContain(configuration.InvokerBehavior.Type.GetFriendlyTypeName());

            configuration.ActionMethodSources.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));
            configuration.ActionSources.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));
            configuration.RouteConventions.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));
            configuration.UrlConventions.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));
            configuration.RequestReaders.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));
            configuration.RequestBinders.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));
            configuration.ValueMappers.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));
            configuration.ResponseWriters.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));
            configuration.Behaviors.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));

            result.ShouldContain(typeof(TestBehavior1).GetFriendlyTypeName());
            result.ShouldContain(typeof(TestBehavior2).GetFriendlyTypeName());
            result.ShouldContain("some/url");
            result.ShouldContain("request");
            result.ShouldContain(typeof(InputModel).GetFriendlyTypeName());
            result.ShouldContain("queryParam");
            result.ShouldContain(typeof(int).GetFriendlyTypeName());
            result.ShouldContain("urlParam");
            result.ShouldContain(typeof(DateTime).GetFriendlyTypeName());
            result.ShouldContain(typeof(OutputModel).GetFriendlyTypeName());
        }
Ejemplo n.º 2
0
        public CpDeviceDiagnostics(CpDevice aDevice, DiagnosticsHandler aHandler)
        {
            try
            {
                iDevice = aDevice;
                aDevice.AddRef();

                iHandler = aHandler;

                iLock      = new object();
                iResponses = 0;

                iDiagnosticsService = new CpProxyLinnCoUkDiagnostics1(aDevice);
                iDiagnosticsService.BeginCrashDataStatus(HandleCrashDataStatus);
                iDiagnosticsService.BeginElfFingerprint(HandleElfFingerprint);
                // remove checking of RS232 connections
                //iDiagnosticsService.BeginDiagnosticTest("help", string.Empty, HandleHelp);

                iProductService = new CpProxyAvOpenhomeOrgProduct1(aDevice);
                iProductService.SetPropertyInitialEvent(InitialEvent);
                iProductService.SetPropertyProductRoomChanged(ProductRoomChanged);
                iProductService.SetPropertyProductNameChanged(ProductNameChanged);
                iProductService.SetPropertyProductImageUriChanged(ProductImageUriChanged);
                iProductService.SetPropertyModelNameChanged(ModelNameChanged);
                iProductService.Subscribe();
            }
            catch
            {
                aDevice.RemoveRef();
                throw;
            }
        }
Ejemplo n.º 3
0
 public override void Save()
 {
     if (_yes)
     {
         DiagnosticsHandler.SetLogLevel(LogLevel.Debug);
         DiagnosticsHandler.FocusStealingInstance.SubscribeToMessages();
     }
     else
     {
         DiagnosticsHandler.SetLogLevel(LogLevel.Information);
         DiagnosticsHandler.FocusStealingInstance.UnsubscribeFromMessages();
     }
 }
Ejemplo n.º 4
0
        public ClientPipelineBuilder(
            CosmosClient client,
            ConsistencyLevel?requestedClientConsistencyLevel,
            IReadOnlyCollection <RequestHandler> customHandlers)
        {
            this.client = client ?? throw new ArgumentNullException(nameof(client));
            this.requestedClientConsistencyLevel = requestedClientConsistencyLevel;
            this.transportHandler = new TransportHandler(client);
            Debug.Assert(this.transportHandler.InnerHandler == null, nameof(this.transportHandler));

            this.invalidPartitionExceptionRetryHandler = new NamedCacheRetryHandler();
            Debug.Assert(this.invalidPartitionExceptionRetryHandler.InnerHandler == null, "The invalidPartitionExceptionRetryHandler.InnerHandler must be null to allow other handlers to be linked.");

            this.PartitionKeyRangeHandler = new PartitionKeyRangeHandler(client);
            Debug.Assert(this.PartitionKeyRangeHandler.InnerHandler == null, "The PartitionKeyRangeHandler.InnerHandler must be null to allow other handlers to be linked.");

            this.diagnosticsHandler = new DiagnosticsHandler();
            Debug.Assert(this.diagnosticsHandler.InnerHandler == null, nameof(this.diagnosticsHandler));

            this.UseRetryPolicy();
            this.AddCustomHandlers(customHandlers);
        }
Ejemplo n.º 5
0
        public ClientPipelineBuilder(
            CosmosClient client,
            ConsistencyLevel?requestedClientConsistencyLevel,
            IReadOnlyCollection <RequestHandler> customHandlers,
            ClientTelemetry telemetry)
        {
            this.client = client ?? throw new ArgumentNullException(nameof(client));
            this.requestedClientConsistencyLevel = requestedClientConsistencyLevel;
            this.transportHandler = new TransportHandler(client);
            Debug.Assert(this.transportHandler.InnerHandler == null, nameof(this.transportHandler));

            this.invalidPartitionExceptionRetryHandler = new NamedCacheRetryHandler();
            Debug.Assert(this.invalidPartitionExceptionRetryHandler.InnerHandler == null, "The invalidPartitionExceptionRetryHandler.InnerHandler must be null to allow other handlers to be linked.");

            this.PartitionKeyRangeHandler = new PartitionKeyRangeHandler(client);
            Debug.Assert(this.PartitionKeyRangeHandler.InnerHandler == null, "The PartitionKeyRangeHandler.InnerHandler must be null to allow other handlers to be linked.");

            // Disable system usage for internal builds. Cosmos DB owns the VMs and already logs
            // the system information so no need to track it.
#if !INTERNAL
            this.diagnosticsHandler = new DiagnosticsHandler();
            Debug.Assert(this.diagnosticsHandler.InnerHandler == null, nameof(this.diagnosticsHandler));

            if (telemetry != null)
            {
                this.telemetryHandler = new TelemetryHandler(telemetry);
                Debug.Assert(this.telemetryHandler.InnerHandler == null, nameof(this.telemetryHandler));
            }
#else
            this.diagnosticsHandler = null;
            this.telemetryHandler   = null;
#endif

            this.UseRetryPolicy();
            this.AddCustomHandlers(customHandlers);
        }
        public override void Save()
        {
            LogLevel desired = _yes ? LogLevel.All : LogLevel.Information;

            DiagnosticsHandler.SetLogLevel(desired);
        }
        public override void Load()
        {
            LogLevel activeLevel = DiagnosticsHandler.GetLogLevel();

            _yes = activeLevel == LogLevel.All;
        }
        public void Should_return_configuration()
        {
            var configuration = new Configuration();

            configuration.Behaviors.Configure(c => c
                                              .Append <TestBehavior1>()
                                              .Append <TestBehavior2>());
            var parameters = new TypeCache().GetTypeDescriptor(typeof(Handler)).Methods
                             .FirstOrDefault(x => x.Name == nameof(Handler.Get))?.Parameters;
            var actionMethod    = ActionMethod.From <Handler>(x => x.Get(null, 0, DateTime.MaxValue));
            var routeDescriptor = new RouteDescriptor("GET", "some/url",
                                                      parameters.Where(x => x.Name == "urlParam")
                                                      .Select(x => new UrlParameter(actionMethod, x, false)).ToArray(),
                                                      parameters.Where(x => x.Name == "queryParam")
                                                      .Select(x => new ActionParameter(actionMethod, x)).ToArray(),
                                                      parameters.First(x => x.Name == "request"),
                                                      new TypeCache().GetTypeDescriptor(typeof(OutputModel)));
            var actionDescriptors = new List <ActionDescriptor>
            {
                new ActionDescriptorFactory(configuration, null, new TypeCache())
                .CreateDescriptor(actionMethod, routeDescriptor)
            };
            var runtimeConfiguration = new RuntimeConfiguration(actionDescriptors);
            var handler = new DiagnosticsHandler(configuration, runtimeConfiguration,
                                                 new Metrics(), new Container(), new TypeCache());

            var result = handler.Get();

            //result.ShouldContain(DefaultActionMethodSource.DefaultHandlerNameConventionRegex);
            //result.ShouldContain(DefaultRouteConvention.DefaultHandlerNamespaceConventionRegex);

            result.ShouldContain(typeof(GraphiteApplication).Assembly.GetFriendlyName());
            result.ShouldContain(typeof(GraphiteApplication).Assembly.GetName().Version.ToString());

            configuration.SupportedHttpMethods.ForEach(x => result.ShouldContain(x.Method));

            result.ShouldContain(configuration.Initializer.Type.GetFriendlyTypeName());
            result.ShouldContain(configuration.TypeCache.Type.GetFriendlyTypeName());
            result.ShouldContain(configuration.BehaviorChainInvoker.Type.GetFriendlyTypeName());
            result.ShouldContain(configuration.DefaultBehavior.GetFriendlyTypeName());

            configuration.ActionMethodSources.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));
            configuration.ActionSources.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));
            configuration.RouteConventions.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));
            configuration.UrlConventions.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));
            configuration.RequestReaders.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));
            configuration.RequestBinders.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));
            configuration.ValueMappers.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));
            configuration.ResponseWriters.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));
            configuration.Behaviors.ForEach(x => result.ShouldContain(x.Type.GetFriendlyTypeName()));

            result.ShouldContain(typeof(TestBehavior1).GetFriendlyTypeName());
            result.ShouldContain(typeof(TestBehavior2).GetFriendlyTypeName());
            result.ShouldContain("some/url");
            result.ShouldContain("request");
            result.ShouldContain(typeof(InputModel).GetFriendlyTypeName());
            result.ShouldContain("queryParam");
            result.ShouldContain(typeof(int).GetFriendlyTypeName());
            result.ShouldContain("urlParam");
            result.ShouldContain(typeof(DateTime).GetFriendlyTypeName());
            result.ShouldContain(typeof(OutputModel).GetFriendlyTypeName());
        }
Ejemplo n.º 9
0
        public async void OnBLEAdvertismentReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs eventArgs)
        {
            // The local name of the advertising device contained within the payload, if any
            string localName             = eventArgs.Advertisement.LocalName.TrimEnd('\0');
            UInt16 extractedAppearanceID = 0;

            //Debug.WriteLine("## BLE SCAN ENTRY " + localName);
            try
            {
                // The BLE scan response contains the service IDs
                if (eventArgs.AdvertisementType == BluetoothLEAdvertisementType.ScanResponse)
                {
                    ScannedDevice scannedDevice = null;

                    // See if the Advertisement has been received for this device
                    if (_scannedDevices.TryGetValue(eventArgs.BluetoothAddress, out scannedDevice))
                    {
                        if (scannedDevice.ScanResponsePending)
                        {
                            // Look for the UART service
                            Guid guid = eventArgs.Advertisement.ServiceUuids.FirstOrDefault(i => i == GattServiceUuids.UART);
                            if (guid != null)
                            {
                                // Device is now registered
                                _scannedDevices[eventArgs.BluetoothAddress].ScanResponsePending = false;

                                BLE_Device bleConntectibleDevice = new BLE_Device(scannedDevice.Name, scannedDevice.BLEAddress);
#if WINDOWS_UWP
                                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
#else
                                Application.Current.Dispatcher.Invoke(() =>
#endif
                                {
                                    _discoveredDevices.Add(bleConntectibleDevice);
                                });
                            }
                        }
                        else
                        {
                            // Debug.WriteLine(eventArgs.Advertisement.ManufacturerData.Count);
                            if (eventArgs.Advertisement.ManufacturerData.Count > 0)
                            {
                                // Only print the first one of the list
                                var manufacturerData = eventArgs.Advertisement.ManufacturerData[0];
                                var data             = new byte[manufacturerData.Data.Length];
                                using (var reader = DataReader.FromBuffer(manufacturerData.Data))
                                {
                                    reader.ReadBytes(data);
                                    if (scannedDevice.LastManufacturerData == null || !data.SequenceEqual(scannedDevice.LastManufacturerData))
                                    {
                                        scannedDevice.LastManufacturerData = data;
                                    }
                                }
                            }
                        }
                    }
                }

                // Extract the Appearance ID from the advertisement
                BluetoothLEAdvertisementDataSection dataItem = eventArgs.Advertisement.DataSections.FirstOrDefault(i => i.DataType == GAP_ADTYPE_APPEARANCE);
                if (dataItem != null && dataItem.Data.Capacity == sizeof(UInt16))
                {
                    var data = new byte[dataItem.Data.Length];
                    using (var reader = DataReader.FromBuffer(dataItem.Data))
                        reader.ReadBytes(data);
                    extractedAppearanceID = BitConverter.ToUInt16(data, 0);

                    if (extractedAppearanceID == GAP_APPEARANCE_ID)
                    {
                        ScannedDevice scannedDevice = null;

                        // Debug.WriteLine("FOUND CANDIDATE DEVICE " + localName);
                        if (_scannedDevices.TryGetValue(eventArgs.BluetoothAddress, out scannedDevice))
                        {
                            // Update the scan time
                            scannedDevice.ScanTime = DateTime.Now;

                            // See if the device's name has changed
                            if (scannedDevice.Name.CompareTo(localName) != 0)
                            {
                                scannedDevice.Name = localName;
#if WINDOWS_UWP
                                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
#else
                                Application.Current.Dispatcher.Invoke(() =>
#endif
                                {
                                    var discoveredItem = _discoveredDevices.FirstOrDefault(i => i.DeviceID == scannedDevice.BLEAddress.ToString());
                                    if (discoveredItem != null)
                                    {
                                        discoveredItem.DeviceName = localName;
                                    }
                                });
                            }
                        }
                        else
                        {
                            scannedDevice = new ScannedDevice();
                            scannedDevice.Name = localName;
                            scannedDevice.BLEAddress = eventArgs.BluetoothAddress;
                            scannedDevice.ScanTime = DateTime.Now;
                            scannedDevice.ScanResponsePending = true;
                            _scannedDevices.Add(eventArgs.BluetoothAddress, scannedDevice);
                        }
                    }
                }

                ulong address = eventArgs.BluetoothAddress;
                short rssi = eventArgs.RawSignalStrengthInDBm;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("## BLE SCAN EXIT EXCEPTION " + localName + " " + ex.ToString());
                DiagnosticsHandler?.Invoke(this, "## BLE SCAN EXIT EXCEPTION " + localName + " " + ex.ToString());
            }
        }
Ejemplo n.º 10
0
 private void OnBLEAdvertismentStopped(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementWatcherStoppedEventArgs args)
 {
     Debug.WriteLine("#### OnBLEAdvertismentStopped ####");
     DiagnosticsHandler?.Invoke(this, "#### OnBLEAdvertismentStopped ####");
 }