TOM.NET
In TOM.NET (e.g. from an Event System), you can publish an item using the code below:
Core Service
In an earlier post, I presented my CoreServiceSession. A utility method in it, is the Publish method:
PublishInstructionData publishInstructionData = new PublishInstructionData();
publishInstructionData.StartAt
= publishDateTime;
In TOM.NET (e.g. from an Event System), you can publish an item using the code below:
private void Publish(IdentifiableObject item, PublicationTarget
publicationTarget,
bool rollBackOnFailure, bool includeComponentLinks)
{
IEnumerable<IdentifiableObject>
items = new List<IdentifiableObject>() { item };
IEnumerable<PublicationTarget>
targets =
new List<PublicationTarget>() { publicationTarget };
PublishInstruction instruction = new PublishInstruction(item.Session)
{
DeployAt = DateTime.Now,
RenderInstruction = new RenderInstruction(item.Session)
{
RenderMode = RenderMode.Publish
},
ResolveInstruction = new ResolveInstruction(item.Session)
{
IncludeComponentLinks = includeComponentLinks
},
RollbackOnFailure = rollBackOnFailure,
StartAt
= DateTime.MinValue
};
PublishEngine.Publish(items, instruction,
targets);
}
Core Service
In an earlier post, I presented my CoreServiceSession. A utility method in it, is the Publish method:
public void Publish(string[] itemUris, PublishInstructionData
publishInstructionData,
string[]
destinationTargetUris, PublishPriority
publishPriority, ReadOptions readOptions) {
_coreServiceClient.Publish(itemUris,
publishInstructionData, destinationTargetUris, publishPriority, readOptions);
}
This is a helper method that calls the CoreServiceSession.Publish():
public void Publish(string itemUri, string destinationTargetUri,
string publishAtTime, bool includeChildPublications) {
try {
DateTime publishDateTime = DateTime.Parse(publishAtTime);
PublishInstructionData publishInstructionData = new PublishInstructionData();
ResolveInstructionData resolveInstructionData
= new ResolveInstructionData();
resolveInstructionData.IncludeChildPublications
= true;
resolveInstructionData.IncludeWorkflow
= false;
resolveInstructionData.IncludeComponentLinks
= true;
publishInstructionData.ResolveInstruction
= resolveInstructionData;
RenderInstructionData renderInstructionData = new RenderInstructionData();
publishInstructionData.RenderInstruction
= renderInstructionData;
string[] itemUris = new string[] { itemUri };
string[] destinationTargetUris = new string[] {
destinationTargetUri };
ReadOptions readOptions = new ReadOptions();
using (CoreServiceSession coreServiceSession
= new CoreServiceSession())
{
coreServiceSession.Publish(itemUris,
publishInstructionData, destinationTargetUris, PublishPriority, readOptions);
Logger.Debug("Item
{0} was added to the Publishing Queue successfully", itemUri);
}
} catch (Exception ex) {
Logger.Error("Publish:
Exception occurred " + ex.ToString());
}
}
Comments