/// <summary> /// Authenticates the device. /// </summary> /// <param name="request">The device authentication request.</param> /// <returns>The response.</returns> private static AuthenticateDeviceRealtimeResponse AuthenticateDevice(AuthenticateDeviceRealtimeRequest request) { ThrowIf.Null(request.Device, "request.Device"); var transactionService = new TransactionService.TransactionServiceClient(request.RequestContext); Device device = transactionService.AuthenticateDevice(request.Device.DeviceNumber, request.Device.TokenData); return(new AuthenticateDeviceRealtimeResponse(device)); }
/// <summary> /// Authenticates the device. /// </summary> /// <param name="request">The device authentication request.</param> /// <returns>The response.</returns> private static AuthenticateDeviceRealtimeResponse AuthenticateDevice(AuthenticateDeviceRealtimeRequest request) { var getDeviceRequest = new GetDeviceDataRequest(request.Device.DeviceNumber, isActivatedOnly: false); Device device = request.RequestContext.Runtime.Execute <SingleEntityDataServiceResponse <Device> >(getDeviceRequest, request.RequestContext).Entity; if (device == null) { // Device is not found, throws exception. string message = string.Format("The input device number '{0}' does not exist in demo database.", request.Device.DeviceNumber); throw new ConfigurationException(ConfigurationErrors.Microsoft_Dynamics_Commerce_Runtime_DeviceConfigurationNotFound, message); } device.ActivatedDateTime = device.ActivatedDateTime ?? DateTimeOffset.UtcNow; device.DeactivateComments = device.DeactivateComments ?? string.Empty; device.DeactivatedDateTime = device.DeactivatedDateTime ?? DateTimeOffset.MinValue; device.TokenIssueTime = device.TokenIssueTime ?? DateTimeOffset.UtcNow; return(new AuthenticateDeviceRealtimeResponse(device)); }
/// <summary> /// Authenticates the device. /// </summary> /// <param name="request">The device authentication request.</param> /// <returns>The response.</returns> private static AuthenticateDeviceServiceResponse AuthenticateDevice(AuthenticateDeviceServiceRequest request) { Device device = new Device(); if (string.IsNullOrWhiteSpace(request.Token)) { throw new ArgumentException("request.Token is not set", "request"); } device = ConstructDeviceFromToken(request.Token); try { // Try to validate the device token using the channel database device = ValidateDeviceTokenLocally(device.DeviceNumber, device.TokenData, request.Token, request.RequestContext); } catch (DeviceAuthenticationException deviceAuthenticationException) { RetailLogger.Log.CrtServicesDeviceManagementServiceDeviceAuthenticationInChannelDbFailure(device.ToString(), deviceAuthenticationException); try { // If local authentication failed then try to contact AX for activation and refresh local data. AuthenticateDeviceRealtimeRequest realtimeRequest = new AuthenticateDeviceRealtimeRequest(device); device = request.RequestContext.Execute <AuthenticateDeviceRealtimeResponse>(realtimeRequest).Device; } catch (HeadquarterTransactionServiceException ex) { RetailLogger.Log.CrtServicesDeviceManagementServiceDeviceAuthenticationInAxFailure(device.ToString(), ex); throw new DeviceAuthenticationException(SecurityErrors.Microsoft_Dynamics_Commerce_Runtime_HeadquarterTransactionServiceMethodCallFailure, ex, ex.Message) { LocalizedMessage = ex.LocalizedMessage }; } // Creating or updating the authenticated device in the channel db. CreateOrUpdateDeviceDataRequest createOrUpdateDeviceDataRequest = new CreateOrUpdateDeviceDataRequest(device); request.RequestContext.Execute <NullResponse>(createOrUpdateDeviceDataRequest); } return(new AuthenticateDeviceServiceResponse(device)); }