Example #1
0
 public SecurityPageModel(IDeviceTwin deviceTwin, ISettings settings, IAzureIoTHub azureIoTHub, IUserDialogs dialogs)
 {
     DeviceTwin   = deviceTwin;
     Settings     = settings;
     _azureIoTHub = azureIoTHub;
     _dialogs     = dialogs;
 }
 private DeviceManagementClient(IDeviceTwin deviceTwin, IDeviceManagementRequestHandler requestHandler, ISystemConfiguratorProxy systemConfiguratorProxy)
 {
     this._deviceTwin              = deviceTwin;
     this._requestHandler          = requestHandler;
     this._systemConfiguratorProxy = systemConfiguratorProxy;
     this._externalStorage         = new ExternalStorage();
 }
 public AzureIoTHub(IDeviceTwin deviceTwin, ISettings settings)
 {
     _deviceTwin      = deviceTwin;
     _settings        = settings;
     _registryManager = RegistryManager.CreateFromConnectionString(ConnectionString);
     _serviceClient   = ServiceClient.CreateFromConnectionString(ConnectionString);
 }
        private DeviceManagementClient(IDeviceTwin deviceTwin, IDeviceManagementRequestHandler hostAppHandler, ISystemConfiguratorProxy systemConfiguratorProxy)
        {
            Logger.Log("Entering DeviceManagementClient constructor.", LoggingLevel.Verbose);

            this._lastDesiredPropertyVersion = -1;
            this._deviceTwin                   = deviceTwin;
            this._hostAppHandler               = hostAppHandler;
            this._systemConfiguratorProxy      = systemConfiguratorProxy;
            this._desiredPropertyMap           = new Dictionary <string, IClientPropertyHandler>();
            this._desiredPropertyDependencyMap = new Dictionary <string, List <IClientPropertyDependencyHandler> >();
        }
        public static async Task <DeviceManagementClient> CreateAsync(IDeviceTwin deviceTwin, IDeviceManagementRequestHandler requestHandler)
        {
            DeviceManagementClient deviceManagementClient = Create(deviceTwin, requestHandler, new SystemConfiguratorProxy());
            await deviceTwin.SetMethodHandlerAsync("microsoft.management.immediateReboot", deviceManagementClient.ImmediateRebootMethodHandlerAsync);

            await deviceTwin.SetMethodHandlerAsync("microsoft.management.appInstall", deviceManagementClient.AppInstallMethodHandlerAsync);

            await deviceTwin.SetMethodHandlerAsync("microsoft.management.reportAllDeviceProperties", deviceManagementClient.ReportAllDevicePropertiesMethodHandler);

            await deviceTwin.SetMethodHandlerAsync("microsoft.management.startAppSelfUpdate", deviceManagementClient.StartAppSelfUpdateMethodHandlerAsync);

            await deviceTwin.SetMethodHandlerAsync("microsoft.management.getCertificateDetails", deviceManagementClient.GetCertificateDetailsHandlerAsync);

            await deviceTwin.SetMethodHandlerAsync("microsoft.management.factoryReset", deviceManagementClient.FactoryResetHandlerAsync);

            return(deviceManagementClient);
        }
        //
        // 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 static async Task <DeviceManagementClient> CreateAsync(IDeviceTwin deviceTwin, IDeviceManagementRequestHandler hostAppHandler)
        {
            Logger.Log("Creating Device Management objects.", LoggingLevel.Verbose);

            var systemConfiguratorProxy = new SystemConfiguratorProxy();
            DeviceManagementClient deviceManagementClient = Create(deviceTwin, hostAppHandler, systemConfiguratorProxy);
            IClientHandlerCallBack clientCallback         = deviceManagementClient;

            // Attach methods...
            await deviceTwin.SetMethodHandlerAsync(CommonDataContract.ReportAllAsync, deviceManagementClient.ReportAllDevicePropertiesMethodHandler);

            // Create/Attach handlers...
            deviceManagementClient._externalStorageHandler = new ExternalStorageHandler(clientCallback, systemConfiguratorProxy);
            deviceManagementClient.AddPropertyHandler(deviceManagementClient._externalStorageHandler);

            var deviceHealthAttestationHandler = new DeviceHealthAttestationHandler(clientCallback, systemConfiguratorProxy);

            deviceManagementClient.AddPropertyHandler(deviceHealthAttestationHandler);
            await deviceManagementClient.AddDirectMethodHandlerAsync(deviceHealthAttestationHandler);

            deviceManagementClient._factoryResetHandler = new FactoryResetHandler(clientCallback, systemConfiguratorProxy);
            await deviceManagementClient.AddDirectMethodHandlerAsync(deviceManagementClient._factoryResetHandler);

            deviceManagementClient._windowsUpdatePolicyHandler = new WindowsUpdatePolicyHandler(clientCallback, systemConfiguratorProxy);
            deviceManagementClient.AddPropertyHandler(deviceManagementClient._windowsUpdatePolicyHandler);

            var windowsUpdatesHandler = new WindowsUpdatesHandler(clientCallback, systemConfiguratorProxy);

            deviceManagementClient.AddPropertyHandler(windowsUpdatesHandler);

            var wifiHandler = new WifiHandler(clientCallback, systemConfiguratorProxy);

            deviceManagementClient.AddPropertyHandler(wifiHandler);
            await deviceManagementClient.AddDirectMethodHandlerAsync(wifiHandler);

            var appxHandler = new AppxManagement(clientCallback, systemConfiguratorProxy, deviceManagementClient._desiredCache);

            deviceManagementClient.AddPropertyHandler(appxHandler);

            var appxLifeCycleHandler = new AppxLifeCycleHandler(clientCallback, systemConfiguratorProxy);
            await deviceManagementClient.AddDirectMethodHandlerAsync(appxLifeCycleHandler);

            var eventTracingHandler = new EventTracingHandler(clientCallback, systemConfiguratorProxy, deviceManagementClient._desiredCache);

            deviceManagementClient.AddPropertyHandler(eventTracingHandler);

            var storageHandler = new StorageHandler(clientCallback, systemConfiguratorProxy);
            await deviceManagementClient.AddDirectMethodHandlerAsync(storageHandler);

            var timeSettingsHandler = new TimeSettingsHandler(clientCallback, systemConfiguratorProxy);

            deviceManagementClient.AddPropertyHandler(timeSettingsHandler);

            deviceManagementClient._timeServiceHandler = new TimeServiceHandler(clientCallback, systemConfiguratorProxy);
            deviceManagementClient.AddPropertyHandler(deviceManagementClient._timeServiceHandler);

            deviceManagementClient._rebootCmdHandler = new RebootCmdHandler(
                clientCallback,
                systemConfiguratorProxy,
                deviceManagementClient._hostAppHandler,
                deviceManagementClient._windowsUpdatePolicyHandler);
            await deviceManagementClient.AddDirectMethodHandlerAsync(deviceManagementClient._rebootCmdHandler);

            var rebootInfoHandler = new RebootInfoHandler(clientCallback, systemConfiguratorProxy, deviceManagementClient._desiredCache);

            deviceManagementClient.AddPropertyHandler(rebootInfoHandler);

            deviceManagementClient._windowsTelemetryHandler = new WindowsTelemetryHandler(clientCallback, systemConfiguratorProxy);
            deviceManagementClient.AddPropertyHandler(deviceManagementClient._windowsTelemetryHandler);

            var deviceInfoHandler = new DeviceInfoHandler(clientCallback, systemConfiguratorProxy);

            deviceManagementClient.AddPropertyHandler(deviceInfoHandler);

            var dmAppStoreUpdate = new DmAppStoreUpdateHandler(clientCallback, systemConfiguratorProxy);
            await deviceManagementClient.AddDirectMethodHandlerAsync(dmAppStoreUpdate);

            deviceManagementClient._certificateHandler = new CertificateHandler(clientCallback, systemConfiguratorProxy);
            deviceManagementClient.AddPropertyHandler(deviceManagementClient._certificateHandler);
            await deviceTwin.SetMethodHandlerAsync(MethodGetCertificateDetails, deviceManagementClient._certificateHandler.GetCertificateDetailsHandlerAsync);

            var clearReportedPropertiesHandler = new ClearReportedPropertiesHandler(clientCallback);
            await deviceManagementClient.AddDirectMethodHandlerAsync(clearReportedPropertiesHandler);

            return(deviceManagementClient);
        }
 internal static DeviceManagementClient Create(IDeviceTwin deviceTwin, IDeviceManagementRequestHandler requestHandler, ISystemConfiguratorProxy systemConfiguratorProxy)
 {
     return(new DeviceManagementClient(deviceTwin, requestHandler, systemConfiguratorProxy));
 }
 public LightsPageModel(IDeviceTwin deviceTwin, IAzureIoTHub azureIoTHub, IUserDialogs dialogs)
 {
     DeviceTwin   = deviceTwin;
     _azureIoTHub = azureIoTHub;
     _dialogs     = dialogs;
 }