本文整理汇总了C#中Package.GetByType方法的典型用法代码示例。如果您正苦于以下问题:C# Package.GetByType方法的具体用法?C# Package.GetByType怎么用?C# Package.GetByType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Package
的用法示例。
在下文中一共展示了Package.GetByType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: using
void ITemplate.Transform(Engine engine, Package package)
{
TemplatingLogger logger = TemplatingLogger.GetLogger(this.GetType());
Item item = package.GetByType(ContentType.Component);
if (item.Properties.ContainsKey(Item.ItemPropertyTcmUri))
{
Component component = (Component)engine.GetObject(item.Properties[Item.ItemPropertyTcmUri].ToString());
if (component.ComponentType == ComponentType.Multimedia)
{
if (string.Compare(component.BinaryContent.MultimediaType.MimeType, "text/css", true) == 0)
{
StructureGroup structureGroup = (StructureGroup)engine.GetObject(STRUCTURE_GROUP_FOR_CSS);
string[] filenameParts = component.BinaryContent.Filename.Split(new char[]{'\\'});
string filename = filenameParts[filenameParts.GetUpperBound(0)];
string unMinifiedString = Encoding.Default.GetString(component.BinaryContent.GetByteArray());
string minifiedString = CssCompressor.Compress(unMinifiedString, 0, CssCompressionType.Hybrid);
using (MemoryStream memoryStream = new MemoryStream(Encoding.Default.GetBytes(minifiedString)))
{
engine.PublishingContext.RenderedItem.AddBinary(
memoryStream,
filename,
structureGroup,
"mmbyname",
component,
component.BinaryContent.MultimediaType.MimeType
);
}
}
}
}
}
示例2: GetComponent
private static Component GetComponent(Engine engine, Package package)
{
Item component = package.GetByType(ContentType.Component);
return (Component)engine.GetObject(component.GetAsSource().GetValue("ID"));
}
示例3: GetPage
private static Page GetPage(Engine engine, Package package)
{
Item pageItem = package.GetByType(ContentType.Page);
if (pageItem != null)
{
return engine.GetObject(pageItem.GetAsSource().GetValue("ID")) as Page;
}
Page page = engine.PublishingContext.RenderContext.ContextItem as Page;
return page;
}
示例4: GetPublication
//private Engine _engine;
private static Publication GetPublication(Engine engine, Package package)
{
RepositoryLocalObject pubItem = null;
Repository repository = null;
if (package.GetByType(ContentType.Page) != null)
pubItem = GetPage(engine, package);
else
pubItem = GetComponent(engine, package);
if (pubItem != null) repository = pubItem.ContextRepository;
return repository as Publication;
}