/// <summary> /// Activates the device. /// </summary> /// <param name="request">The device activation request.</param> /// <returns>The device activation response.</returns> private static ActivateDeviceRealtimeResponse ActivateDevice(ActivateDeviceRealtimeRequest request) { var getDeviceRequest = new GetDeviceDataRequest(request.DeviceNumber, isActivatedOnly: false); Device device = request.RequestContext.Runtime.Execute <SingleEntityDataServiceResponse <Device> >(getDeviceRequest, request.RequestContext).Entity; device.ActivatedDateTime = device.ActivatedDateTime ?? DateTimeOffset.UtcNow; device.DeactivateComments = device.DeactivateComments ?? string.Empty; device.DeactivatedDateTime = device.DeactivatedDateTime ?? DateTimeOffset.MinValue; device.TokenIssueTime = device.TokenIssueTime ?? DateTimeOffset.UtcNow; var result = new DeviceActivationResult(); 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.DeviceNumber); throw new ConfigurationException(ConfigurationErrors.Microsoft_Dynamics_Commerce_Runtime_DeviceConfigurationNotFound, message); } else if (string.IsNullOrWhiteSpace(device.TerminalId)) { // If device is found but the terminal associated with the device is not found, try to find the terminal using input terminal id. var columnSet = new ColumnSet(Terminal.RecordIdColumn, Terminal.TerminalIdColumn, Terminal.ChannelIdColumn); var settings = new QueryResultSettings(columnSet, PagingInfo.AllRecords); var getTerminalRequest = new GetTerminalDataRequest(request.TerminalId, settings); Terminal terminal = request.RequestContext.Runtime.Execute <SingleEntityDataServiceResponse <Terminal> >(getTerminalRequest, request.RequestContext).Entity; if (terminal == null) { string message = string.Format("The input device number '{0}' and terminal identifier '{1}' do not exist in demo database.", request.DeviceNumber, request.TerminalId); throw new ConfigurationException(ConfigurationErrors.Microsoft_Dynamics_Commerce_Runtime_DeviceConfigurationNotFound, message); } result.Device = new Device { DeviceId = request.DeviceId, DeviceNumber = request.DeviceNumber, TerminalRecordId = terminal.RecordId, TerminalId = terminal.TerminalId, ChannelId = terminal.ChannelId, DeviceTypeRecordId = device.DeviceTypeRecordId, ActivatedDateTime = device.ActivatedDateTime, TokenIssueTime = device.TokenIssueTime, DeactivatedDateTime = device.DeactivatedDateTime, DeactivateComments = device.DeactivateComments, TokenData = device.TokenData, TokenSalt = device.TokenSalt }; } else { // Both the device and associated terminal are found. device.DeviceNumber = request.DeviceNumber; device.DeviceId = request.DeviceId; result.Device = device; } var response = new ActivateDeviceRealtimeResponse(result); return(response); }
/// <summary> /// Activates the device. /// </summary> /// <param name="request">The device activation request.</param> /// <returns>The device activation response.</returns> private static ActivateDeviceRealtimeResponse ActivateDevice(ActivateDeviceRealtimeRequest request) { var transactionService = new TransactionService.TransactionServiceClient(request.RequestContext); // Call transaction service to activate the device. var activationResult = transactionService.ActivateDevice(request.DeviceNumber, request.TerminalId, request.StaffId, request.DeviceId, request.ForceActivation, request.DeviceType); var response = new ActivateDeviceRealtimeResponse(activationResult); return(response); }
/// <summary> /// Activates the device and updates the activated device in the channel database. /// </summary> /// <param name="request">The device activation request.</param> /// <returns>The device activation response.</returns> private static ActivateDeviceServiceResponse ActivateDevice(ActivateDeviceServiceRequest request) { ActivateDeviceRealtimeRequest realtimeRequest = new ActivateDeviceRealtimeRequest(request.DeviceNumber, request.TerminalId, request.StaffId, request.DeviceId, request.ForceActivation, request.DeviceType); ActivateDeviceRealtimeResponse realtimeResponse = request.RequestContext.Execute <ActivateDeviceRealtimeResponse>(realtimeRequest); if (realtimeResponse.DeviceActivationResult.Device != null) { realtimeResponse.DeviceActivationResult.Device.Token = GenerateDeviceToken(realtimeResponse.DeviceActivationResult.Device); } // Creating or updating the activated device in the channel db. CreateOrUpdateDeviceDataRequest createOrUpdateDeviceDataRequest = new CreateOrUpdateDeviceDataRequest(realtimeResponse.DeviceActivationResult.Device); request.RequestContext.Execute <NullResponse>(createOrUpdateDeviceDataRequest); return(new ActivateDeviceServiceResponse(realtimeResponse.DeviceActivationResult)); }