/// <summary> /// Gets the commerce runtime based on the passed in commerce runtime configuration. /// </summary> /// <param name="commerceRuntimeConfiguration">The commerce runtime configuration.</param> /// <returns>An instance of commerce runtime.</returns> /// <exception cref="Microsoft.Dynamics.Commerce.Runtime.ConfigurationException"> /// The default channel identifier cannot be zero /// </exception> private static CommerceRuntime GetCommerceRuntime(CommerceRuntimeConfiguration commerceRuntimeConfiguration) { if (_defaultChannelIdentifer == InvalidDefaultChannelId) { if (!long.TryParse(ConfigurationManager.AppSettings["channelId"], out _defaultChannelIdentifer)) { using (var commerceRuntime = CommerceRuntime.Create(commerceRuntimeConfiguration, CommercePrincipal.AnonymousPrincipal)) { var channelManager = ChannelManager.Create(commerceRuntime); _defaultChannelIdentifer = channelManager.GetCurrentChannelId(); } if (_defaultChannelIdentifer == InvalidDefaultChannelId) { var message = string.Format( CultureInfo.InvariantCulture, "The default channel identifier {0} was returned from CRT. Please ensure that a default operating unit number has been specified as part of the <commerceRuntime> configuration section.", _defaultChannelIdentifer); throw new ConfigurationException(ConfigurationErrors.InvalidChannelConfiguration, message); } } } var principal = new CommercePrincipal(new CommerceIdentity(_defaultChannelIdentifer, new[] { CommerceRoles.Storefront })); var runtime = CommerceRuntime.Create(commerceRuntimeConfiguration, principal); return(runtime); }
private static RequestContext CreateRequestContext(string staffId, Device device, ICommerceRuntime runtime) { CommerceIdentity identity; if (string.IsNullOrWhiteSpace(staffId)) { identity = new CommerceIdentity(device); identity.Roles.Add(CommerceRoles.Anonymous); } else { var employee = new Employee() { StaffId = staffId }; identity = new CommerceIdentity(employee, device); } CommercePrincipal principal = new CommercePrincipal(identity); RequestContext context = new RequestContext(runtime); context.SetPrincipal(principal); return(context); }
private ProductManager GetProductManager() { var connectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]; var configurationSection = CommerceRuntimeConfigurationManager.GetConfigurationSection(CommerceRuntimeConfigurationManager.SectionName); var configuration = new CommerceRuntimeConfiguration(configurationSection, connectionString); var principal = new CommercePrincipal(this.CommerceIdentity); var runtime = CommerceRuntime.Create(configuration, principal); var pm = ProductManager.Create(runtime); return(pm); }
/// <summary> /// Gets the commerce runtime based on the passed in commerce runtime configuration. /// </summary> /// <param name="commerceRuntimeConfiguration">The commerce runtime configuration.</param> /// <returns>An instance of commerce runtime.</returns> /// <exception cref="Microsoft.Dynamics.Commerce.Runtime.ConfigurationException">The default channel identifier cannot be zero.</exception> private static CommerceRuntime GetCommerceRuntime(CommerceRuntimeConfiguration commerceRuntimeConfiguration) { if (defaultChannelIdentifer == InvalidDefaultChannelId) { using (CommerceRuntime commerceRuntime = CommerceRuntime.Create(commerceRuntimeConfiguration, CommercePrincipal.AnonymousPrincipal)) { ChannelManager channelManager = ChannelManager.Create(commerceRuntime); defaultChannelIdentifer = channelManager.GetDefaultChannelId(); } if (defaultChannelIdentifer == InvalidDefaultChannelId) { string message = string.Format(CultureInfo.InvariantCulture, "The default channel identifier {0} was returned from CRT. Please ensure that a default operating unit number has been specified as part of the <commerceRuntime> configuration section.", defaultChannelIdentifer); throw new Microsoft.Dynamics.Commerce.Runtime.ConfigurationException(ConfigurationErrors.Microsoft_Dynamics_Commerce_Runtime_InvalidChannelConfiguration, message); } } CommercePrincipal principal = new CommercePrincipal(new CommerceIdentity(defaultChannelIdentifer, new string[] { CommerceRoles.Storefront })); CommerceRuntime runtime = CommerceRuntime.Create(commerceRuntimeConfiguration, principal); return(runtime); }