String bundleTCM = "";
String bundleLocation = ConfigurationLoader.GetAppSetting("bundleLocation");
String bundleTypeSchema = ConfigurationLoader.GetAppSetting("bundleTypeSchema");
VirtualFolderData bundle = (VirtualFolderData)client.GetDefaultData(ItemType.VirtualFolder, bundleLocation, new ReadOptions());
bundle.Configuration = "<Bundle xmlns=\"http://www.sdltridion.com/ContentManager/Bundle\"><Items /></Bundle>";
bundle.TypeSchema = new LinkToSchemaData { IdRef = bundleTypeSchema };
bundle.Title = title + " [" + string.Format("{0:yyyy-MM-dd_hh-mm}", DateTime.Now) + "]";
TcmUri publicationId = new TcmUri(bundleLocation);
List<String> componentIDs = new List<string>();
XDocument doc = XDocument.Parse(bundle.Configuration);
XNamespace xmlns = "http://www.sdltridion.com/ContentManager/Bundle";
XNamespace xlink = "http://www.w3.org/1999/xlink";
XElement newItemNode = null;
foreach (PageData page in pages)
{
UsedItemsFilterData filter = new UsedItemsFilterData();
filter.ItemTypes = new ItemType[] { ItemType.Component };
IdentifiableObjectData[] pageComponents = client.GetList(page.Id, filter);
// Get all the components included in the page and add ithem in the bundle
foreach (IdentifiableObjectData obj in pageComponents)
{
ComponentData component = (ComponentData)client.Read(obj.Id.ToString(), new ReadOptions { LoadFlags = LoadFlags.Expanded });
if (!componentIDs.Contains(component.Id))
{
componentIDs.Add(component.Id);
TcmUri itemUri = new TcmUri(component.Id);
TcmUri inContext = new TcmUri(itemUri.ItemId, itemUri.ItemType, publicationId.PublicationId);
if (client.IsExistingObject(inContext.ToString()))
{
newItemNode = new XElement(xmlns + "Item",
new XAttribute(XNamespace.Xmlns + "xlink", xlink),
new XAttribute(xlink + "href", inContext.ToString()));
doc.Root.Element(xmlns + "Items").Add(newItemNode);
}
// Add Linked Components
// addLinkedComponents(doc, xmlns, xlink, newItemNode, component, componentIDs, publicationId.PublicationId, client);
}
}
}
bundle.Configuration = doc.ToString();
client.Save(bundle, null);
bundleTCM = bundle.Id;
Shiva
- 2.2k
- 11
- 19