本文整理汇总了C#中Package.CreateMultimediaItem方法的典型用法代码示例。如果您正苦于以下问题:C# Package.CreateMultimediaItem方法的具体用法?C# Package.CreateMultimediaItem怎么用?C# Package.CreateMultimediaItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Package
的用法示例。
在下文中一共展示了Package.CreateMultimediaItem方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transform
public void Transform(Engine engine, Package package)
{
Component component = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
package.PushItem(package.CreateMultimediaItem(component.Id));
if (package.GetByName(Package.OutputName) == null)
{
Item output = package.CreateStringItem(ContentType.Text, string.Empty);
package.PushItem(Package.OutputName, output);
}
}
示例2: Transform
public void Transform(Engine engine, Package package)
{
_engine = engine;
_package = package;
_log = TemplatingLogger.GetLogger(GetType());
TemplateType templateType;
if (package.GetByName(Package.ComponentName) != null)
templateType = TemplateType.Component;
else
templateType = TemplateType.Page;
Item output = null;
if (templateType == TemplateType.Page)
{
Page page = (Page)engine.GetObject(package.GetByName(Package.PageName));
page.Load(LoadFlags.KeywordXlinks);
output = package.CreateXmlDocumentItem(ContentType.Xml, page.ToXml(XmlFormat.R6Native, XmlSections.All).OwnerDocument);
foreach (ComponentPresentation cp in page.ComponentPresentations)
{
engine.RenderComponentPresentation(cp.Component.Id, cp.ComponentTemplate.Id);
}
}
if (templateType == TemplateType.Component)
{
Component component = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
component.Load(LoadFlags.KeywordXlinks);
output = package.CreateXmlDocumentItem(ContentType.Xml, component.ToXml(XmlFormat.R6Native, XmlSections.All).OwnerDocument);
if(component.BinaryContent != null)
{
package.PushItem(package.CreateMultimediaItem(component));
}
}
if (output != null)
package.PushItem(Package.OutputName, output);
}
示例3: ExtractBinaries
/// <summary>
/// Extracts binaries from the template and adds them to the package for processing.
/// </summary>
/// <param name="output"></param>
/// <param name="engine"></param>
/// <param name="package"></param>
/// <returns></returns>
private string ExtractBinaries(string output, Engine engine, Package package)
{
IExtractBinariesContentWrapper contentWrapper = new ExtractBinariesFromText(output);
foreach (LinkReferenceWrapper linkAttribute in contentWrapper.GetLinkAttributes())
{
string pathAttributeValue = contentWrapper.GetAttributeValue(linkAttribute);
// _logger.Debug("Path: " + pathAttributeValue);
TcmUri targetItemUri = null;
if (TcmUri.IsValid(pathAttributeValue))
{
// Attribute value is TCM URI, now localize to currect context publication.
targetItemUri = engine.LocalizeUri(new TcmUri(pathAttributeValue));
}
if (targetItemUri != null || pathAttributeValue.StartsWith("/webdav/"))
{
Component targetItem = engine.GetObject(targetItemUri ?? pathAttributeValue) as Component;
if (targetItemUri == null && targetItem != null)
{
targetItemUri = engine.LocalizeUri(targetItem.Id);
}
if ((targetItem != null) && (targetItem.ComponentType == ComponentType.Multimedia))
{
Item binaryItem = package.CreateMultimediaItem(targetItemUri);
string itemName;
binaryItem.Properties.TryGetValue(Item.ItemPropertyFileName, out itemName);
Item existingItem = package.GetByName(itemName);
if (
existingItem == null ||
!existingItem.Properties[Item.ItemPropertyTcmUri].Equals(targetItemUri) ||
!existingItem.Equals(binaryItem) // Ensure that a transformed item is not considered the same
)
{
// _logger.Debug(string.Format("Image {0} ({1}) unique, adding to package", itemName, targetItemUri));
package.PushItem(itemName, binaryItem);
}
else
{
// _logger.Debug(string.Format("Image {0} ({1}) already present in package, not adding again", itemName, targetItemUri));
}
contentWrapper.ProcessLinkChange(linkAttribute, targetItemUri);
}
}
}
return contentWrapper.Content.ToString();
}