private static async Task InitializeAppliance() { // Initialize Config Config.Initialize(_serviceProvider.GetService <IArmedState>()); // Initialize Azure IoT Hub _azureIoTHub = _serviceProvider.GetService <IAzureIoTHub>(); await _azureIoTHub.Initialize(); // Initialize Sensors var sensorController = _serviceProvider.GetService <ISensorBoard>(); await sensorController.Initialize(); // Initialize Temperature sensor var networkCabinetTempService = _serviceProvider.GetService <ITempHumidityService>(); networkCabinetTempService.Start(); // Start Timer var timer = _serviceProvider.GetService <ITimerService>(); timer.Start(); // Update sunrise/sunset times for garden lights //await _mediator.Publish(new UpdateSunriseSunsetCommand()); // Uncomment if you require OpenWeather data, and add App ID in Config.cs Log.Information("Initialization complete"); }
public SecurityPageModel(IDeviceTwin deviceTwin, ISettings settings, IAzureIoTHub azureIoTHub, IUserDialogs dialogs) { DeviceTwin = deviceTwin; Settings = settings; _azureIoTHub = azureIoTHub; _dialogs = dialogs; }
public override async Task <ConnectedServiceInstance> CreateServiceInstanceAsync(CancellationToken ct) { ConnectedServiceInstance result = null; IAzureIoTHub createdAccount = await this.Authenticator.CreateIoTHub(this.iotHubAccountManager, ct).ConfigureAwait(false); if (createdAccount != null) { result = AzureIoTHubAccountProviderGrid.CreateServiceInstance(createdAccount); } return(result); }
private static ConnectedServiceInstance CreateServiceInstance(IAzureIoTHub iotHubAccount) { ConnectedServiceInstance instance = new ConnectedServiceInstance(); instance.InstanceId = iotHubAccount.Id; instance.Name = iotHubAccount.Properties["IoTHubName"]; foreach (var property in iotHubAccount.Properties) { instance.Metadata.Add(property.Key, property.Value); } instance.Metadata.Add("IoTHubAccount", iotHubAccount); instance.Metadata.Add("Cancel", false); instance.Metadata.Add("TPM", false); return(instance); }
private static ConnectedServiceInstance CreateServiceInstance(IAzureIoTHub iotHubAccount) { ConnectedServiceInstance instance = new ConnectedServiceInstance(); instance.InstanceId = iotHubAccount.Id; instance.Name = iotHubAccount.Properties["IoTHubName"]; foreach (var property in iotHubAccount.Properties) { instance.Metadata.Add(property.Key, property.Value); } instance.Metadata.Add("IoTHubAccount", iotHubAccount); instance.Metadata.Add("Cancel", false); instance.Metadata.Add("TPM", false); return instance; }
// // This method is invoked when the application has loaded and is ready to run. In this // method you should instantiate the window, load the UI into it and then make the window // visible. // // You have 17 seconds to return from this method, or iOS will terminate your application. // public override bool FinishedLaunching(UIApplication app, NSDictionary options) { AppCenter.Start("app-center-secret", typeof(Analytics), typeof(Crashes)); _settings = FreshIOC.Container.Resolve <ISettings>(); _deviceTwin = FreshIOC.Container.Resolve <IDeviceTwin>(); _azureIoTHub = FreshIOC.Container.Resolve <IAzureIoTHub>(); global::Xamarin.Forms.Forms.Init(); InitializeCachedImageService(); Estimote.Config.SetupAppId("estimote-app-id", "estimote-app-token"); _secureBeaconManager = new SecureBeaconManager(); _monitoringV2ManagerImmediate = new MonitoringV2Manager(ImmediateMeanTriggerDistance, this); LoadApplication(new App(_azureIoTHub)); _settings.PropertyChanged += async(sender, args) => { await OccupantStateUpdated(); }; _secureBeaconManager.RequestAlwaysAuthorization(); _monitoringV2ManagerImmediate.RequestAlwaysAuthorization(); UNUserNotificationCenter.Current.RequestAuthorization( UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound, (approved, err) => { // Handle approval }); UIApplication.SharedApplication.RegisterForRemoteNotifications(); UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate(_azureIoTHub); MonitorHomeGeolocation(); MonitorSecureBeacons(); MonitorProximityBeacons(); return(base.FinishedLaunching(app, options)); }
public App(IAzureIoTHub azureIoTHub) { InitializeComponent(); _azureIoTHub = azureIoTHub; var seucrityPage = FreshPageModelResolver.ResolvePageModel <SecurityPageModel>(); var lightsPage = FreshPageModelResolver.ResolvePageModel <LightsPageModel>(); var otherPage = FreshPageModelResolver.ResolvePageModel <OtherPageModel>(); var tabbedPage = new TabbedPage(); tabbedPage.Children.Add(seucrityPage); tabbedPage.Children.Add(lightsPage); tabbedPage.Children.Add(otherPage); if (Config.DebugMode) { var deviceTwinPage = FreshPageModelResolver.ResolvePageModel <DeviceTwinPageModel>(); tabbedPage.Children.Add(deviceTwinPage); } MainPage = tabbedPage; }
public UpdateReportedPropertiesHandler(IAzureIoTHub azureIoTHub) { _azureIoTHub = azureIoTHub; }
public UserNotificationCenterDelegate(IAzureIoTHub azureIoTHub) { _azureIoTHub = azureIoTHub; }
public DeviceTwinPageModel(IAzureIoTHub azureIoTHub) { _azureIoTHub = azureIoTHub; _stopwatch = new Stopwatch(); }
public LightsPageModel(IDeviceTwin deviceTwin, IAzureIoTHub azureIoTHub, IUserDialogs dialogs) { DeviceTwin = deviceTwin; _azureIoTHub = azureIoTHub; _dialogs = dialogs; }
public override async Task <AddServiceInstanceResult> AddServiceInstanceAsync(ConnectedServiceHandlerContext context, CancellationToken ct) { var cancel = context.ServiceInstance.Metadata["Cancel"]; if (cancel != null) { if ((bool)cancel) { // Cancellation throw new OperationCanceledException(); } } // Once C++ is officially supported, we can switch this to context.HandlerHelper, removing AzureIoTHubConnectedServiceHandlerHelper var handlerHelper = GetConnectedServiceHandlerHelper(context); bool bUseTPM = (bool)context.ServiceInstance.Metadata["TPM"]; if (bUseTPM) { handlerHelper.TokenReplacementValues.Add("TPMSlot", "0"); } else { IAzureIoTHub iotHubAccount = context.ServiceInstance.Metadata["IoTHubAccount"] as IAzureIoTHub; var primaryKeys = await iotHubAccount.GetPrimaryKeysAsync(ct); var ioTHubUri = context.ServiceInstance.Metadata["iotHubUri"] as string; handlerHelper.TokenReplacementValues.Add("iotHubUri", ioTHubUri); var device = GetSelectedDevice(context, ioTHubUri, primaryKeys.IoTHubOwner); if (device == null) { throw new OperationCanceledException(); } else { handlerHelper.TokenReplacementValues.Add("deviceId", device.Id); handlerHelper.TokenReplacementValues.Add("deviceKey", device.Key); handlerHelper.TokenReplacementValues.Add("iotHubOwnerPrimaryKey", primaryKeys.IoTHubOwner); handlerHelper.TokenReplacementValues.Add("servicePrimaryKey", primaryKeys.Service); } } HandlerManifest configuration = this.BuildHandlerManifest(bUseTPM); await this.AddSdkReferenceAsync(context, configuration, ct); foreach (var fileToAdd in configuration.Files) { var file = this.CopyResourceToTemporaryPath(fileToAdd.Path, handlerHelper); string targetPath = Path.GetFileName(fileToAdd.Path); // Use the same name string addedFile = await handlerHelper.AddFileAsync(file, targetPath); } AddServiceInstanceResult result = this.CreateAddServiceInstanceResult(context); await context.Logger.WriteMessageAsync(LoggerMessageCategory.Information, "New service instance {0} created", context.ServiceInstance.Name); return(result); }