private DeviceManagementClient(IDeviceTwin deviceTwin, IDeviceManagementRequestHandler requestHandler, ISystemConfiguratorProxy systemConfiguratorProxy)
 {
     this._deviceTwin              = deviceTwin;
     this._requestHandler          = requestHandler;
     this._systemConfiguratorProxy = systemConfiguratorProxy;
     this._externalStorage         = new ExternalStorage();
 }
 public RebootCmdHandler(IClientHandlerCallBack callback,
                         ISystemConfiguratorProxy systemConfiguratorProxy,
                         IDeviceManagementRequestHandler hostAppHandler,
                         WindowsUpdatePolicyHandler windowsUpdatePolicyHandler)
 {
     _systemConfiguratorProxy    = systemConfiguratorProxy;
     _deviceManagementClient     = callback;
     _hostAppHandler             = hostAppHandler;
     _windowsUpdatePolicyHandler = windowsUpdatePolicyHandler;
 }
        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 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 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);
        }