I have a requirement to publish all the dynamic components associated with the page.Also, the dynamic components should be published only if they are not yet published to the current target. My code is publishing the page and its associated dynamic components properly first time, and If I try to publish the page again the dynamic components are not getting published. But if I unpublish the dynamic components and if I publish the page again, the dynamic components are not getting published. Help me in understanding what went wrong and how to achieve the same.
private void publishComponents(Component component, TridionCollections.ISet<ResolvedItem> resolvedItems, ComponentTemplate BHTemplate, ComponentTemplate FNTemplate,PublishContext context)
{
if (component.Path.Contains("Balloon Help"))
{
var resolvedItem = new ResolvedItem(component, BHTemplate);
if (!PublishEngine.IsPublished(component, context.PublicationTarget)) resolvedItems.Add(resolvedItem);
}
if (component.Path.Contains("Footnote"))
{
var resolvedItem = new ResolvedItem(component, FNTemplate);
if (!PublishEngine.IsPublished(component, context.PublicationTarget)) resolvedItems.Add(resolvedItem); ;
}
}