/// <summary> /// Initializes a new marketplace group, and sets the MWS endpoint of this group to the MWS endpoint of the Marketplace provided as parameter. /// </summary> public MwsMarketplaceGroup(MwsMarketplace marketplace) { MwsEndpoint = marketplace.MwsEndpoint ?? throw new InvalidOperationException( $"Cannot initialize marketplace group because the MWS access endpoint is not set on for the provided marketplace"); _mwsMarketplaces = new List <MwsMarketplace> { marketplace }; }
/// <summary> /// Tries to add a marketplace to the current group. <para /> /// When attempting to add a marketplace to a group, please note that a group can only contain marketplaces with the same MWS endpoint as the one setup for the group at initialization.<para /> /// Failure in following this convention will result in an InvalidOperationException.<para /> /// Example: A group initialized with an European marketplace cannot also contain a North-American or Asian marketplace.<para/> /// If a report has to be requested for marketplaces belonging to different MWS endpoints, then a request object has to be generated for each different MWS endpoint. /// </summary> /// <param name="marketplace"></param> public void TryAddMarketplace(MwsMarketplace marketplace) { if (marketplace.MwsEndpoint != MwsEndpoint) { throw new InvalidOperationException( $@"Cannot add marketplace:'{marketplace.Name}' to group with MwsEndpoint:'{MwsEndpoint}', Because it belongs to a different MwsEndpoint:'{marketplace.MwsEndpoint}'. In order to request reports for marketplaces belonging to different MwsEndpoints you must perform a separate request for each different MwsEndpoint"); } if (GetMarketplacesIdList.Contains(marketplace.Id)) { throw new InvalidOperationException( $@"Cannot add marketplace:'{marketplace.Name}' to group with MwsEndpoint:'{MwsEndpoint}', Because it the group already contains this marketplace. A marketplace cannot be added twice to the same group"); } _mwsMarketplaces.Add(marketplace); }
/// <summary> /// Tries to add a marketplace to the current group. <para /> /// When attempting to add a marketplace to a group, please note that a group can only contain marketplaces with the same MWS endpoint as the one setup for the group at initialization.<para /> /// Failure in following this convention will result in an InvalidOperationException.<para /> /// Example: A group initialized with an European marketplace cannot also contain a North-American or Asian marketplace.<para/> /// If a report has to be requested for marketplaces belonging to different MWS endpoints, then a request object has to be generated for each different MWS endpoint. /// </summary> /// <returns>The same ReportRequestedMarketplacesGroup object, also containing the newly added marketplace.</returns> public static MwsMarketplaceGroup AddMarketplace(this MwsMarketplaceGroup group, MwsMarketplace marketplace) { group.TryAddMarketplace(marketplace); return(group); }