/// <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> /// Gets the commerce runtime configuration by using the currently executing application's config.. /// </summary> /// <returns>The commerce runtime configuration.</returns> private static CommerceRuntimeConfiguration GetCrtConfiguration() { var crtConnectionString = GetCrtConnectionString(); var commerceRuntimeSection = CommerceRuntimeConfigurationManager.GetConfigurationSection("commerceRuntime"); var crtConfiguration = new CommerceRuntimeConfiguration(commerceRuntimeSection, crtConnectionString, true); return(crtConfiguration); }
/// <summary> /// Gets the commerce runtime configuration by using the currently executing application's config.. /// </summary> /// <returns>The commerce runtime configuration.</returns> internal static CommerceRuntimeConfiguration GetCrtConfiguration() { string initialConnectionString = CommerceRuntimeConfigurationManager.GetInitialConnectionString(); CommerceRuntimeSection section = CommerceRuntimeConfigurationManager.GetConfigurationSection(CommerceRuntimeConfigurationManager.SectionName); Dictionary <string, string> connectionStrings = CommerceRuntimeConfigurationManager.GetStorageLookupConnectionStrings(); CommerceRuntimeConfiguration commerceRuntimeConfiguration = new CommerceRuntimeConfiguration(section, initialConnectionString, connectionStrings); return(commerceRuntimeConfiguration); }
/// <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; }
/// <summary> /// Gets the CommerceRuntime instance initialized by using the currently executing application's config. /// </summary> /// <returns>Commerce runtime instance.</returns> /// <remarks> /// Caches the commerce runtime configuration and default channel identifier. /// </remarks> private static CommerceRuntime GetCommerceRuntime() { if (_crtConfiguration == null) { _crtConfiguration = GetCrtConfiguration(); } var runtime = GetCommerceRuntime(_crtConfiguration); return(runtime); }
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; }
/// <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); }
private void RefreshActivationStorageInformation() { this.comboRetailServerUrl.Items.Clear(); foreach (DeviceActivationInformation x in this.appStorage.ActivationInformation) { this.comboRetailServerUrl.Items.Add(x); } if (this.currentDeviceActivationInfo != null) { this.comboRetailServerUrl.SelectedItem = this.currentDeviceActivationInfo; this.txtNewRetailServerUrl.Text = this.currentDeviceActivationInfo.RetailServerUrl; } else if (this.appStorage.ActivationInformation.Length > 0) { this.comboRetailServerUrl.SelectedIndex = 0; } if (this.appStorage.ActivationInformation.Length == 0) { this.btnSelectActivated.Enabled = false; } this.listViewActivationDetails.Items.Clear(); string retailServerUrl = null; string deviceToken = null; if (this.currentDeviceActivationInfo != null) { foreach (string line in this.currentDeviceActivationInfo.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) { this.listViewActivationDetails.Items.Add(line); } retailServerUrl = this.currentDeviceActivationInfo.RetailServerUrl; deviceToken = this.currentDeviceActivationInfo.DeviceToken; } else { retailServerUrl = this.txtNewRetailServerUrl.Text; } IContext context = null; if (this.ShouldUseOnlineMode) { if (!string.IsNullOrEmpty(retailServerUrl)) { context = Helpers.CreateNewRetailServerContext(retailServerUrl); this.currentManagerFactory = ManagerFactory.Create(context); if (!string.IsNullOrEmpty(deviceToken)) { this.currentManagerFactory.Context.SetDeviceToken(deviceToken); } } } else { string offlineConnectionString = ConfigurationManager.ConnectionStrings["OfflineDatabase"].ConnectionString; ICommerceRuntimeSection commerceRuntimeSection = (ICommerceRuntimeSection)ConfigurationManager.GetSection("commerceRuntime"); var commerceRuntimeConfiguration = new CommerceRuntimeConfiguration( commerceRuntimeSection, offlineConnectionString, storageLookupConnectionStrings: null, isOverride: true, isMasterDatabaseConnectionString: false); CommerceAuthenticationRuntimeProvider authenticationProvider = new CommerceAuthenticationRuntimeProvider(); context = new CommerceRuntimeContext(_ => commerceRuntimeConfiguration, authenticationProvider); this.currentManagerFactory = ManagerFactory.Create(context); context.SetDeviceToken(deviceToken); } }