Esempio n. 1
0
            /// <summary>
            /// Provides the channel's parameters which can be used to publish a channel to the target.
            /// </summary>
            /// <param name="parameters">Available channel's parameters.</param>
            /// <param name="isPublishingRequested">True if channel's publishing was requested from AX. False otherwise.</param>
            /// <remarks>The implementer can use this method to, for instance, instantiate a navigational hierarchy in the target channel.</remarks>
            public void OnChannelInformationAvailable(PublishingParameters parameters, bool isPublishingRequested)
            {
                if (parameters == null)
                {
                    throw new ArgumentNullException("parameters");
                }

                Trace.TraceInformation(
                    "Channel publishing information is available. Publishing requested={0}, DefaultCulture={1}, Number of Categories={2}, Number of Attributes={3}",
                    isPublishingRequested,
                    parameters.ChannelDefaultCulture,
                    parameters.Categories.Count(),
                    parameters.CategoriesAttributes.Count);

                StringBuilder builder = new StringBuilder();

                Trace.TraceInformation("The following categories are available:");
                foreach (Category category in parameters.Categories)
                {
                    builder.AppendFormat("Name={0}; ID={1}; Parent={2}\r\n", category.Name, category.ParentCategory, category.RecordId);
                }

                Trace.TraceInformation(builder.ToString());
            }
Esempio n. 2
0
            /// <summary>
            /// Initiates a channel publishing process.
            /// </summary>
            /// <param name="channelPublisher">Instance of the object which implements IChannelPublisher.</param>
            /// <returns>Return publishing parameters.</returns>
            /// <remarks>Retrieves the channel info from the CRT, then executes callbacks for the supplied IChannelPublisher and finally updates the channel publishing status in CRT/AX.</remarks>
            public PublishingParameters PublishChannel(IChannelPublisher channelPublisher)
            {
                if (channelPublisher == null)
                {
                    throw new ArgumentNullException(nameof(channelPublisher));
                }

                if (this.onlineChannel.PublishStatus != OnlineChannelPublishStatusType.Published &&
                    this.onlineChannel.PublishStatus != OnlineChannelPublishStatusType.InProgress)
                {
                    throw new ChannelNotPublishedException(Resources.ErrorChannelNotInPublishedState, this.onlineChannel.PublishStatus, this.onlineChannel.PublishStatusMessage);
                }

                IEnumerable <Category> categories;
                Dictionary <long, IEnumerable <AttributeCategory> > categoriesAttributes;

                // always load the categories but process them only if the channel is not published yet.
                try
                {
                    this.LoadCategories(out categories, out categoriesAttributes);
                    int categoriesCount = categories.Count();
                    NetTracer.Information(Resources.NumberOfReadCategoriesAndTheirAttributes, categoriesCount, categoriesAttributes.Count());
                    if (categoriesCount == 0)
                    {
                        throw new InvalidDataException(string.Format(
                                                           "Navigation categories count returned is '{0}'. Error details {1}",
                                                           categoriesCount,
                                                           Resources.ErrorNoNavigationCategories));
                    }

                    // Loading product attributes schema from CRT
                    IEnumerable <AttributeProduct> productAttributes = this.LoadProductAttributes();
                    channelPublisher.OnValidateProductAttributes(productAttributes);

                    int listingAttributesCount = productAttributes.Count();
                    NetTracer.Information(Resources.NumberOfReadAttributes, listingAttributesCount);
                    if (listingAttributesCount == 0)
                    {
                        throw new InvalidDataException(string.Format(
                                                           "Listing Attributes Count returned is '{0}'. Error details '{1}'",
                                                           listingAttributesCount,
                                                           Resources.ErrorNoSchemaAttributes));
                    }

                    ChannelLanguage language = this.onlineChannel.ChannelLanguages.Single(l => l.IsDefault);
                    CultureInfo     culture  = new CultureInfo(language.LanguageId);

                    PublishingParameters parameters = new PublishingParameters
                    {
                        Categories            = categories,
                        CategoriesAttributes  = categoriesAttributes,
                        ProductsAttributes    = productAttributes,
                        ChannelDefaultCulture = culture,
                        GiftCartItemId        = this.channelManager.GetChannelConfiguration().GiftCardItemId
                    };

                    if (this.onlineChannel.PublishStatus == OnlineChannelPublishStatusType.InProgress)
                    {
                        channelPublisher.OnChannelInformationAvailable(parameters, true);
                        this.channelManager.UpdateOnlineChannelPublishStatus(OnlineChannelPublishStatusType.Published, null);
                    }
                    else
                    {
                        channelPublisher.OnChannelInformationAvailable(parameters, false);
                    }

                    return(parameters);
                }
                catch (Exception ex)
                {
                    RetailLogger.Log.EcommercePlatformChannelPublishFailure(ex);
                    string error = string.Format(CultureInfo.InvariantCulture, Resources.ErrorChannelPublishingFailed, ex.Message, DateTime.Now);
                    this.channelManager.UpdateOnlineChannelPublishStatus(OnlineChannelPublishStatusType.Failed, error);
                    throw;
                }
            }