/// <summary> /// Executes the workflow associated with retrieving online channel by channel identifier. /// </summary> /// <param name="request">The request.</param> /// <returns>The response.</returns> protected override GetOnlineChannelResponse Process(GetOnlineChannelRequest request) { ThrowIf.Null(request, "request"); var getOnlineChannelByIdDataRequest = new GetOnlineChannelByIdDataRequest(request.ChannelId, new ColumnSet()); OnlineChannel channel = this.Context.Runtime.Execute <SingleEntityDataServiceResponse <OnlineChannel> >(getOnlineChannelByIdDataRequest, this.Context).Entity; if (channel == null) { string message = string.Format(CultureInfo.InvariantCulture, "Cannot load channel for ID '{0}'.", request.ChannelId); throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ValueOutOfRange, message); } var settings = QueryResultSettings.AllRecords; var getChannelProfileByChannelIdDataRequest = new GetChannelProfileByChannelIdDataRequest(request.ChannelId, QueryResultSettings.SingleRecord); channel.ChannelProfile = this.Context.Runtime.Execute <SingleEntityDataServiceResponse <ChannelProfile> >(getChannelProfileByChannelIdDataRequest, this.Context).Entity; var getChannelPropertiesByChannelIdDataRequest = new GetChannelPropertiesByChannelIdDataRequest(request.ChannelId, settings); channel.ChannelProperties = this.Context.Runtime.Execute <EntityDataServiceResponse <ChannelProperty> >(getChannelPropertiesByChannelIdDataRequest, this.Context).PagedEntityCollection.Results; var getChannelLanguagesByChannelIdDataRequest = new GetChannelLanguagesByChannelIdDataRequest(request.ChannelId, settings); channel.ChannelLanguages = this.Context.Runtime.Execute <EntityDataServiceResponse <ChannelLanguage> >(getChannelLanguagesByChannelIdDataRequest, this.Context).PagedEntityCollection.Results; var getOrgunitContactsDataRequest = new GetOrgUnitContactsDataRequest(new long[] { request.ChannelId }, settings); channel.Contacts = this.Context.Runtime.Execute <EntityDataServiceResponse <OrgUnitContact> >(getOrgunitContactsDataRequest, this.Context).PagedEntityCollection.Results; var response = new GetOnlineChannelResponse(channel); return(response); }
/// <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; }
/// <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> /// 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> /// Updates the channel publish status. /// </summary> /// <param name="request">The service request.</param> /// <returns>The service response.</returns> private static NullResponse UpdateChannelPublishStatus(UpdateChannelPublishStatusServiceRequest request) { var getOnlineChannelByIdDataRequest = new GetOnlineChannelByIdDataRequest(request.ChannelId, new ColumnSet()); OnlineChannel channel = request.RequestContext.Runtime.Execute <SingleEntityDataServiceResponse <OnlineChannel> >(getOnlineChannelByIdDataRequest, request.RequestContext).Entity; var updateOnlineChannelPublishStatusDataRequest = new UpdateOnlineChannelPublishStatusDataRequest(request.ChannelId, request.PublishStatus, request.PublishStatusMessage); request.RequestContext.Runtime.Execute <SingleEntityDataServiceResponse <bool> >(updateOnlineChannelPublishStatusDataRequest, request.RequestContext); try { var updateChannelPublishingStatusRequest = new UpdateChannelPublishingStatusRealtimeRequest(request.ChannelId, request.PublishStatus, request.PublishStatusMessage); request.RequestContext.Execute <NullResponse>(updateChannelPublishingStatusRequest); } catch (CommerceException) { // Revert the link status if it fails to update AX via transaction service. updateOnlineChannelPublishStatusDataRequest = new UpdateOnlineChannelPublishStatusDataRequest(request.ChannelId, channel.PublishStatus, channel.PublishStatusMessage); request.RequestContext.Runtime.Execute <SingleEntityDataServiceResponse <bool> >(updateOnlineChannelPublishStatusDataRequest, request.RequestContext); throw; } return(new NullResponse()); }