/// <summary>
            /// Retrieves the security verification configuration.
            /// </summary>
            /// <returns>The security verification configuration.</returns>
            public LogOnConfiguration GetSecurityVerificationConfiguration()
            {
                LogOnConfiguration verificationConfiguration;

                if (this.CanUseLocalDatabase)
                {
                    GetChannelConfigurationDataRequest getChannelConfiguration = new GetChannelConfigurationDataRequest(this.ChannelId.Value);
                    ChannelConfiguration channelConfiguration = this.context.Execute <SingleEntityDataServiceResponse <ChannelConfiguration> >(getChannelConfiguration).Entity;

                    // make sure channel configuration is valid
                    if (channelConfiguration == null)
                    {
                        string errorMessage = string.Format(
                            CultureInfo.InvariantCulture,
                            "The channel {0} does not exist.",
                            this.ChannelId.Value);
                        throw new SecurityException(SecurityErrors.Microsoft_Dynamics_Commerce_Runtime_InvalidChannel, errorMessage);
                    }

                    verificationConfiguration = channelConfiguration.TransactionServiceProfile.StaffLogOnConfiguration;
                }
                else
                {
                    // no channel, we can only use headquarters
                    verificationConfiguration = LogOnConfiguration.RealTimeService;
                }

                return(verificationConfiguration);
            }
            /// <summary>
            /// Populates the request context.
            /// </summary>
            /// <param name="context">The request context.</param>
            /// <returns>The populated request context.</returns>
            public static RequestContext PopulateRequestContext(RequestContext context)
            {
                ThrowIf.Null(context, "context");
                ICommercePrincipal principal = context.GetPrincipal();

                if (principal != null && !principal.IsChannelAgnostic)
                {
                    var getChannelConfigurationDataServiceRequest = new GetChannelConfigurationDataRequest(context.GetPrincipal().ChannelId);
                    ChannelConfiguration channelConfiguration     = context.Runtime.Execute <SingleEntityDataServiceResponse <ChannelConfiguration> >(getChannelConfigurationDataServiceRequest, context, skipRequestTriggers: true).Entity;

                    context.SetChannelConfiguration(channelConfiguration);

                    if (context.GetChannelConfiguration().ChannelType == RetailChannelType.RetailStore)
                    {
                        PopulateContextWithOrgUnit(context);
                    }

                    if (!principal.IsTerminalAgnostic)
                    {
                        PopulateContextWithTerminal(context);

                        if (!string.IsNullOrWhiteSpace(principal.DeviceNumber))
                        {
                            PopulateContextWithDeviceConfiguration(context);
                        }
                    }

                    // Use the channel's default language if no language was set on the request.
                    if (string.IsNullOrWhiteSpace(context.LanguageId))
                    {
                        if (!string.IsNullOrWhiteSpace(context.Runtime.Locale))
                        {
                            context.LanguageId = context.Runtime.Locale;
                        }
                        else
                        {
                            context.LanguageId = context.GetChannelConfiguration().DefaultLanguageId;
                        }
                    }

                    if (context.GetTerminal() != null && !string.IsNullOrWhiteSpace(principal.UserId) && principal.ShiftId == 0)
                    {
                        PopulateContextWithShiftInformation(context);
                    }
                }

                return(context);
            }