Beispiel #1
0
        protected override Task OnInitializeAsync(IActivatedEventArgs args)
        {
            // ***
            // *** The temperature data will come from the emote IoT device,
            // *** so use a NULL device.
            // ***
            this.Container.RegisterType <ITemperatureRepository, NullTemperatureRepository>(new ContainerControlledLifetimeManager());

            // ***
            // *** Set the hub configuration values
            // ***
            IIotHubConfiguration iotHubConfiguration = new IotHubConfiguration()
            {
                ConnectionString = "{YOUR CONNECTION STRING HERE}",
                DeviceId         = "{YOUR DEVICE ID HERE}"
            };

            this.Container.RegisterInstance <IIotHubConfiguration>(iotHubConfiguration, new ContainerControlledLifetimeManager());

            // ***
            // *** All device commands will pass through an IoT Hub. This version of the application is
            // *** loaded to the IoT device and will only be SENDING commands.
            // ***
            this.Container.RegisterType <IRelayProviderSender <DeviceCommandEventArgs>, IotHubRelayProviderSender <DeviceCommandEventArgs> >(new ContainerControlledLifetimeManager());
            this.Container.RegisterType <IRelayProviderReceiver <DeviceCommandEventArgs>, NullRelayProviderReceiver <DeviceCommandEventArgs> >(new ContainerControlledLifetimeManager());

            // ***
            // *** Initialize the container with registrations used by both versions of the application.
            // ***
            UnityConfiguration.InitializeContainer(this.Container, this.NavigationService);

            return(base.OnInitializeAsync(args));
        }
Beispiel #2
0
        protected override Task OnInitializeAsync(IActivatedEventArgs args)
        {
            // ***
            // *** Set the hub configuration values. The connection string used here is
            // *** non-device-specific.
            // ***
            IIotHubConfiguration iotHubConfiguration = new IotHubConfiguration()
            {
                ConnectionString = "{YOUR CONNECTION STRING HERE}",
                DeviceId         = "{YOUR DEVICE ID HERE}"
            };

            this.Container.RegisterInstance <IIotHubConfiguration>(iotHubConfiguration, new ContainerControlledLifetimeManager());

            // ***
            // *** Configure the pins
            // ***
            IGpioPinConfiguration gpioPinConfiguration = new GpioPinConfiguration()
            {
                BluePinNumber       = 18,                       // *** Blue LED
                GreenLedPinNumber   = 23,                       // *** Green LED
                RedLedPinNumber     = 12,                       // *** Red LED
                YellowPinNumber     = 16,                       // *** Blue LED
                PushButtonPinNumber = 5,                        // *** Push Button Pin
                AlertPinNumber      = 6,                        // *** Alert Pin
            };

            this.Container.RegisterInstance <IGpioPinConfiguration>(gpioPinConfiguration, new ContainerControlledLifetimeManager());

            // ***
            // *** Temperature Device
            // ***
            this.Container.RegisterType <ITemperatureRepository, Mcp9808TemperatureRepository>(new ContainerControlledLifetimeManager());

            // ***
            // *** These services are only necessary on the IoT device.
            // ***
            this.Container.RegisterType <IBackgroundService, TelemetryService>(MagicValue.BackgroundService.Telemetry, new ContainerControlledLifetimeManager());
            this.Container.RegisterType <IBackgroundService, LedService>(MagicValue.BackgroundService.Led, new ContainerControlledLifetimeManager());
            this.Container.RegisterType <IBackgroundService, PushButtonMonitoringService>(MagicValue.BackgroundService.PushButtonMonitor, new ContainerControlledLifetimeManager());
            this.Container.RegisterType <IBackgroundService, AlertPinMonitoringService>(MagicValue.BackgroundService.AlertPinMonitor, new ContainerControlledLifetimeManager());

            // ***
            // *** All device commands will pass through an IoT Hub. This version of the application is
            // *** loaded to the IoT device and will only be RECIEVING commands.
            // ***
            this.Container.RegisterType <IRelayProviderSender <DeviceCommandEventArgs>, NullRelayProviderSender <DeviceCommandEventArgs> >(new ContainerControlledLifetimeManager());
            this.Container.RegisterType <IRelayProviderReceiver <DeviceCommandEventArgs>, IotHubRelayProviderReceiver <DeviceCommandEventArgs> >(new ContainerControlledLifetimeManager());

            // ***
            // *** Initialize the container with registrations used by both versions of the application.
            // ***
            UnityConfiguration.InitializeContainer(this.Container, this.NavigationService);

            return(base.OnInitializeAsync(args));
        }