/// <summary>
            /// Gets the device configuration and sets it on the context.
            /// </summary>
            /// <param name="context">The context.</param>
            private static void PopulateContextWithDeviceConfiguration(RequestContext context)
            {
                GetDeviceConfigurationDataRequest dataRequest = new GetDeviceConfigurationDataRequest(includeImages: false);
                DeviceConfiguration deviceConfiguration       = context.Runtime.Execute <SingleEntityDataServiceResponse <DeviceConfiguration> >(dataRequest, context, skipRequestTriggers: true).Entity;

                context.SetDeviceConfiguration(deviceConfiguration);
            }
            /// <summary>
            /// Gets the device configuration.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>The response.</returns>
            /// <exception cref="Microsoft.Dynamics.Commerce.Runtime.ConfigurationException">Required Service missing.</exception>
            protected override GetDeviceConfigurationResponse Process(GetDeviceConfigurationRequest request)
            {
                ThrowIf.Null(request, "request");

                GetDeviceConfigurationDataRequest dataServiceRequest = new GetDeviceConfigurationDataRequest(includeImages: true);
                var response = request.RequestContext.Runtime.Execute <SingleEntityDataServiceResponse <DeviceConfiguration> >(dataServiceRequest, this.Context);

                if (response.Entity == null)
                {
                    throw new ConfigurationException(
                              ConfigurationErrors.Microsoft_Dynamics_Commerce_Runtime_DeviceConfigurationNotFound,
                              string.Format("There is no device configuration for the current channel '{0}' and terminal {1}", this.Context.GetPrincipal().ChannelId, this.Context.GetTerminal().TerminalId));
                }

                return(new GetDeviceConfigurationResponse(response.Entity));
            }
Esempio n. 3
0
            /// <summary>
            /// The data service method to execute the data manager to get the device configuration.
            /// </summary>
            /// <param name="request">The data service request.</param>
            /// <returns>The data service response.</returns>
            private SingleEntityDataServiceResponse <DeviceConfiguration> GetDeviceConfiguration(GetDeviceConfigurationDataRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.RequestContext, "request.RequestContext");
                ThrowIf.Null(request.QueryResultSettings, "request.QueryResultSettings");

                ICommercePrincipal principal = request.RequestContext.GetPrincipal();

                if (principal.IsChannelAgnostic || principal.IsTerminalAgnostic || string.IsNullOrWhiteSpace(principal.DeviceNumber))
                {
                    throw new InvalidOperationException("Current request context is not associated to a device.");
                }

                Terminal terminal = request.RequestContext.GetTerminal();

                ParameterSet parameters = new ParameterSet();
                Tuple <PagedResult <DeviceConfiguration>,
                       ReadOnlyCollection <HardwareConfiguration>,
                       ReadOnlyCollection <HardwareConfiguration>,
                       ReadOnlyCollection <HardwareConfiguration> > dataSets = null;

                parameters[DatabaseAccessor.ChannelIdVariableName] = terminal.ChannelId;
                parameters[TerminalIdVariableName]    = terminal.TerminalId;
                parameters[IncludeImagesVariableName] = request.IncludeImages;

                using (SqlServerDatabaseContext databaseContext = new SqlServerDatabaseContext(request.RequestContext, request.QueryResultSettings))
                {
                    dataSets = databaseContext.ExecuteStoredProcedure <DeviceConfiguration, HardwareConfiguration, HardwareConfiguration, HardwareConfiguration>(GetDeviceConfigurationSprocName, parameters);
                }

                DeviceConfiguration deviceConfiguration             = dataSets.Item1.SingleOrDefault();
                ReadOnlyCollection <HardwareConfiguration> drawers  = dataSets.Item2;
                ReadOnlyCollection <HardwareConfiguration> printers = dataSets.Item3;
                ReadOnlyCollection <HardwareConfiguration> pinpads  = dataSets.Item4;

                if (deviceConfiguration != null)
                {
                    deviceConfiguration.HardwareConfigurations = new HardwareConfigurations();
                    deviceConfiguration.HardwareConfigurations.CashDrawerConfigurations.AddRange(drawers);
                    deviceConfiguration.HardwareConfigurations.PrinterConfigurations.AddRange(printers);
                    deviceConfiguration.HardwareConfigurations.PinPadConfiguration = pinpads.SingleOrDefault();
                }

                GetDeviceDataRequest getDeviceRequest = new GetDeviceDataRequest(principal.DeviceNumber);
                Device device = request.RequestContext.Execute <SingleEntityDataServiceResponse <Device> >(getDeviceRequest).Entity;

                if (deviceConfiguration != null && device != null)
                {
                    deviceConfiguration.UseInMemoryDeviceDataStorage = device.UseInMemoryDeviceDataStorage;
                }

                return(new SingleEntityDataServiceResponse <DeviceConfiguration>(deviceConfiguration));
            }