/// <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); }
/// <summary> /// Initializes a new instance of the <see cref="Publisher" /> class. /// </summary> /// <param name="appConfig">Application configuration which contains CRT initialization information.</param> /// <param name="publishingConfig">Publishing configuration.</param> public Publisher(Configuration appConfig, PublishingConfiguration publishingConfig) { this.runtime = CrtUtilities.GetCommerceRuntime(appConfig); this.channelManager = ChannelManager.Create(this.runtime); this.productManager = ProductManager.Create(this.runtime); this.onlineChannel = this.channelManager.GetOnlineChannel(this.channelManager.GetCurrentChannelId()); this.publishingConfig = publishingConfig; }
private static CommerceIdentity GetDefaultCommerceIdentity() { using (CommerceRuntime commerceRuntime = CommerceRuntime.Create(CommerceRuntimeManager.GetDefaultCommerceRuntimeConfiguration(), CommercePrincipal.AnonymousPrincipal)) { ChannelManager channelManager = ChannelManager.Create(commerceRuntime); var defaultChannelId = channelManager.GetDefaultChannelId(); return(new CommerceIdentity(defaultChannelId, SpecifiedRoles)); } }
private static CommerceIdentity GetDefaultCommerceIdentity() { using (CommerceRuntime commerceRuntime = CommerceRuntime.Create(Instance.Value.getCrtConfigurationByHostFunc(AdaptorCaller.HostName), CommercePrincipal.AnonymousPrincipal)) { ChannelManager channelManager = ChannelManager.Create(commerceRuntime); var defaultChannelId = channelManager.GetDefaultChannelId(); return(new CommerceIdentity(defaultChannelId, SpecifiedRoles)); } }
/// <summary> /// Gets the CommerceRuntime instance initialized by using the provided application configuration. /// </summary> /// <param name="appConfiguration">The application configuration.</param> /// <returns>Commerce runtime instance.</returns> /// <remarks>Caches the default channel identifier.</remarks> public static CommerceRuntime GetCommerceRuntime(Configuration appConfiguration) { string initialConnectionString = CommerceRuntimeConfigurationManager.GetInitialConnectionString(appConfiguration); CommerceRuntimeSection section = CommerceRuntimeConfigurationManager.GetConfigurationSection(appConfiguration, CommerceRuntimeConfigurationManager.SectionName); Dictionary <string, string> connectionStrings = CommerceRuntimeConfigurationManager.GetStorageLookupConnectionStrings(appConfiguration); CommerceRuntimeConfiguration commerceRuntimeConfiguration = new CommerceRuntimeConfiguration(section, initialConnectionString, connectionStrings); CommerceRuntime runtime = GetCommerceRuntime(commerceRuntimeConfiguration); return(runtime); }
/// <summary> /// Initializes a new instance of the <see cref="Publisher"/> class. /// </summary> /// <param name="publishingConfig">Publishing configuration.</param> /// <param name="channelId">The channel identifier.</param> public Publisher(PublishingConfiguration publishingConfig, long channelId) { CommerceRuntimeConfiguration configuration = CrtUtilities.GetCrtConfiguration(); this.runtime = CommerceRuntime.Create(configuration, new CommercePrincipal(new CommerceIdentity(channelId, new string[] { CommerceRoles.Storefront }))); this.channelManager = ChannelManager.Create(this.runtime); this.productManager = ProductManager.Create(this.runtime); this.onlineChannel = this.channelManager.GetOnlineChannel(channelId); this.publishingConfig = publishingConfig; }
public static CommerceRuntime GetCommerceRuntime() { if (crtConfiguration == null) { crtConfiguration = GetCrtConfiguration(); } CommerceRuntime runtime = GetCommerceRuntime(crtConfiguration); return(runtime); }
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> /// Initializes a new instance of the <see cref="Publisher"/> class. /// </summary> /// <param name="publishingConfig">Publishing configuration.</param> /// <param name="operatingUnitNumber">The channel's operating unit number.</param> public Publisher(PublishingConfiguration publishingConfig, string operatingUnitNumber) { CommerceRuntimeConfiguration configuration = CrtUtilities.GetCrtConfiguration(); // First creating a runtime without a channel association, this is needed to resolve the operating unit number. this.runtime = CommerceRuntime.Create(configuration, new CommercePrincipal(new CommerceIdentity(0, new string[] { CommerceRoles.Storefront }))); ChannelManager manager = ChannelManager.Create(this.runtime); long channelId = manager.ResolveOperatingUnitNumber(operatingUnitNumber); // Now creating a runtime with the resolved channel Id. this.runtime = CommerceRuntime.Create(configuration, new CommercePrincipal(new CommerceIdentity(channelId, new string[] { CommerceRoles.Storefront }))); this.channelManager = ChannelManager.Create(this.runtime); this.productManager = ProductManager.Create(this.runtime); this.onlineChannel = this.channelManager.GetOnlineChannel(channelId); this.publishingConfig = publishingConfig; }
private static void Main() { // This is a sample test host for the CommerceRuntime. Use it during development to get your extensions to work or troubleshoot. // In order to setup, you must // 1) configure the commerceRuntime.config for the correct assemblies and types (according to your environment/customization) // 2) configure the commerceRuntime.config for the default channel (i.e. <storage defaultOperatingUnitNumber="052" />) // 3) configure the app.config's connection string for Houston to point to a valid database CommerceRuntimeManager.SpecifiedRoles = new string[] { "Device" }; runtime = CommerceRuntimeManager.Runtime; // These should execute with default configuration of commerceruntime.config. Program.RunDefaultTests(); // These require additional commerceruntime.config changes. See comments inside method. Program.RunSdkSampleTests(); // You could use this to test your own CommerceRuntime extensions. Program.RunExtensionTests(); }
/// <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); }