本文整理汇总了C#中Package.GetByName方法的典型用法代码示例。如果您正苦于以下问题:C# Package.GetByName方法的具体用法?C# Package.GetByName怎么用?C# Package.GetByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Package
的用法示例。
在下文中一共展示了Package.GetByName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transform
public void Transform(Engine engine, Package package)
{
if (package.GetByName(Package.PageName) == null) return;
comm.Page page = (comm.Page)engine.GetObject(package.GetByName(Package.PageName));
Dictionary<string, List<ComponentPresentation>> lists = new Dictionary<string, List<ComponentPresentation>>();
string matchTokens = package.GetValue("ComponentTemplateTitleMatchTokens");
if (!String.IsNullOrEmpty(matchTokens))
{
foreach (string token in matchTokens.Split(','))
{
_matchTokens.Add(token.Trim());
}
}
foreach (comm.ComponentPresentation cp in page.ComponentPresentations)
{
string ct = GetPresentationType(cp.ComponentTemplate.Title);
if (!lists.ContainsKey(ct))
lists.Add(ct, new List<ComponentPresentation>());
lists[ct].Add(new ComponentPresentation(cp.Component.Id, cp.ComponentTemplate.Id));
}
foreach (string token in lists.Keys)
{
Item item = package.CreateStringItem(ContentType.ComponentArray, ComponentPresentationList.ToXml(lists[token]));
package.PushItem(token + "Components", item);
}
}
示例2: Transform
public void Transform(Engine engine, Package package)
{
TemplatingLogger log = TemplatingLogger.GetLogger(GetType());
if (package.GetByName(Package.OutputName) == null)
{
log.Error("Could not find \"Output\" item in Package. This template building block should be the last TBB in your template.");
return;
}
Item output = package.GetByName(Package.OutputName);
string outputText = output.GetAsString();
bool outputchanged = false;
foreach (Match m in TcmUriRegEx.Matches(outputText))
{
log.Debug("Found " + m.Value);
TcmUri uri = new TcmUri(m.Value);
if(uri.GetVersionlessUri().ToString().Equals(m.Value)) continue;
log.Debug("Found version information on uri " + m.Value + ". Removing.");
outputText = outputText.Replace(m.Value, uri.GetVersionlessUri().ToString());
outputchanged = true;
}
if (outputchanged)
{
output.SetAsString(outputText);
package.Remove(output);
package.PushItem(Package.OutputName, output);
}
}
示例3: Transform
public void Transform(Engine engine, Package package)
{
TemplatingLogger log = TemplatingLogger.GetLogger(GetType());
if (package.GetByName(Package.ComponentName) == null)
{
log.Info("This template should only be used with Component Templates. Could not find component in package, exiting");
return;
}
var c = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
var container = (Folder)c.OrganizationalItem;
var filter = new OrganizationalItemItemsFilter(engine.GetSession()) { ItemTypes = new[] { ItemType.Component } };
// Always faster to use GetListItems if we only need limited elements
foreach (XmlNode node in container.GetListItems(filter))
{
string componentId = node.Attributes["ID"].Value;
string componentTitle = node.Attributes["Title"].Value;
}
// If we need more info, use GetItems instead
foreach (Component component in container.GetItems(filter))
{
// If your filter is messed up, GetItems will return objects that may
// not be a Component, in which case the code will blow up with an
// InvalidCastException. Be careful with filter.ItemTypes[]
Schema componentSchema = component.Schema;
SchemaPurpose purpose = componentSchema.Purpose;
XmlElement content = component.Content;
}
}
示例4: Transform
public void Transform(Engine engine, Package package)
{
if (package.GetByName(Package.PageName) == null) return;
Page page = (Page)engine.GetObject(package.GetByName(Package.PageName));
bool hasHeader = false;
bool hasFooter = false;
foreach (CP cp in page.ComponentPresentations)
{
if (cp.ComponentTemplate.Title.ToLower().Contains("header")) hasHeader = true;
if (cp.ComponentTemplate.Title.ToLower().Contains("footer")) hasFooter = true;
}
if (!hasHeader)
{
ComponentTemplate headerCt = (ComponentTemplate)engine.GetObject(page.ContextRepository.RootFolder.WebDavUrl + HeaderComponentTemplateUrl);
Component header = (Component)engine.GetObject(page.ContextRepository.RootFolder.WebDavUrl + HeaderComponentUrl);
package.PushItem("headerCP", package.CreateStringItem(ContentType.Html, string.Format("<tcdl:ComponentPresentation type=\"Dynamic\" componentURI=\"{0}\" templateURI=\"{1}\" />", header.Id, headerCt.Id)));
}
if (!hasFooter)
{
ComponentTemplate footerCt = (ComponentTemplate)engine.GetObject(page.ContextRepository.RootFolder.WebDavUrl + FooterComponentTemplateUrl);
Component footer = (Component)engine.GetObject(page.ContextRepository.RootFolder.WebDavUrl + FooterComponentUrl);
package.PushItem("footerCP", package.CreateStringItem(ContentType.Html, string.Format("<tcdl:ComponentPresentation type=\"Dynamic\" componentURI=\"{0}\" templateURI=\"{1}\" />", footer.Id, footerCt.Id)));
}
}
示例5: Transform
public void Transform(Engine engine, Package package)
{
TemplatingLogger log = TemplatingLogger.GetLogger(GetType());
if (package.GetByName(Package.PageName) == null)
{
log.Info("Do not use this template building block in Component Templates");
return;
}
Page page = (Page)engine.GetObject(package.GetByName(Package.PageName));
string output;
if (page.Title.ToLower().Contains("index"))
output = StripNumbersFromTitle(page.OrganizationalItem.Title);
else
{
output = GetLinkToSgIndexPage((StructureGroup)page.OrganizationalItem, engine.GetSession()) + Separator + StripNumbersFromTitle(page.Title);
}
foreach (OrganizationalItem parent in page.OrganizationalItem.GetAncestors())
{
output = GetLinkToSgIndexPage((StructureGroup)parent, engine.GetSession()) + Separator + output;
}
package.PushItem("breadcrumb", package.CreateStringItem(ContentType.Html, output));
}
示例6: Transform
public void Transform(Engine engine, Package package)
{
RepositoryLocalObject context;
if (package.GetByName(Package.ComponentName) != null)
{
context = (RepositoryLocalObject)engine.GetObject(package.GetByName(Package.ComponentName));
}
else if (package.GetByName(Package.PageName) != null)
{
context = (RepositoryLocalObject)engine.GetObject(package.GetByName(Package.PageName));
}
else
{
throw new Exception("Could not determine context from package. Did not find page or component in package");
}
Repository contextPublication = context.ContextRepository;
if (contextPublication.Metadata == null) return;
ItemFields metadata = new ItemFields(contextPublication.Metadata, contextPublication.MetadataSchema);
ComponentLinkField configuration = (ComponentLinkField)metadata["SiteConfiguration"];
foreach (Component c in configuration.Values)
{
ItemFields content = new ItemFields(c.Content, c.Schema);
foreach (ItemField field in content)
{
var textField = field as TextField;
if (textField != null)
{
package.PushItem(textField.Name, package.CreateStringItem(ContentType.Text, textField.Value));
}
}
}
}
示例7: Transform
public void Transform(Engine engine, Package package)
{
TemplatingLogger log = TemplatingLogger.GetLogger(GetType());
RepositoryLocalObject context;
if (package.GetByName(Package.PageName) != null)
{
context = (RepositoryLocalObject)engine.GetObject(package.GetByName(Package.PageName));
log.Debug("Setting context to page with ID " + context.Id);
}
else
{
log.Info("This template building block should only run on a page. Exiting.");
return;
}
if (!(context is Page)) return;
Page page = (Page)context;
package.PushItem(SiteEditPageContext, package.CreateStringItem(ContentType.Text, page.OwningRepository.Id));
package.PushItem(SiteEditPublishContext, package.CreateStringItem(ContentType.Text, page.ContextRepository.Id));
if (page.ComponentPresentations.Count <= 0) return;
Component component = page.ComponentPresentations[0].Component;
package.PushItem(SiteEditComponentContext, package.CreateStringItem(ContentType.Text, component.OwningRepository.Id));
}
示例8: Transform
public void Transform(Engine engine, Package package)
{
const string componentTemplateWebdavUrl = "/System/Component%20Templates/Promo%20Content.tctcmp";
if (package.GetByName(Package.PageName) == null) return;
Page page = (Page)engine.GetObject(package.GetByName(Package.PageName));
ComponentTemplate promoCt = (ComponentTemplate)engine.GetObject(page.ContextRepository.RootFolder.WebDavUrl + componentTemplateWebdavUrl);
package.PushItem("promoCtId", package.CreateStringItem(ContentType.Text, promoCt.Id));
}
示例9: 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);
}
}
示例10: Transform
public override void Transform(Engine engine, Package package)
{
this.Initialize(engine, package);
string searchData = m_Package.GetValue(Constants.PACKAGE_ITEM_SEARCHDATA);
Logger.Debug("Found Search Index Data in package: " + searchData);
if (!String.IsNullOrEmpty(searchData))
{
XmlDocument outputXml = this.GetXmlDocumentFromPackage("Output");
if (outputXml != null)
{
XmlComment data = outputXml.CreateComment(String.Format(Constants.DELIMITER_PATTERN_SEARCHDATA, searchData));
outputXml.DocumentElement.InsertBefore(data, outputXml.DocumentElement.FirstChild);
this.PushXmlDocumentToPackage("Output", outputXml);
}
else
{
String output = package.GetByName("Output").GetAsString();
output = String.Format("<!--{0}-->{1}", String.Format(Constants.DELIMITER_PATTERN_SEARCHDATA, searchData),output);
this.PushStringToPackage("Output", output);
}
}
else
{
Logger.Debug(String.Format("No Search Index Data (package item : {0}) found - nothing to do", Constants.PACKAGE_ITEM_SEARCHDATA));
}
}
示例11: Transform
public void Transform(Engine engine, Package package)
{
Component component = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
ItemFields fields = new ItemFields(component.Content, component.Schema);
TextField code = (TextField)fields["Code"];
package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Html, code.Value));
}
示例12: Transform
public void Transform(Engine engine, Package package)
{
// do NOT execute this logic when we are actually publishing! (similair for fast track publishing)
if (engine.RenderMode == RenderMode.Publish || (engine.PublishingContext.PublicationTarget != null && !Tcm.TcmUri.IsNullOrUriNull(engine.PublishingContext.PublicationTarget.Id)))
{
return;
}
Item outputItem = package.GetByName("Output");
String inputValue = package.GetValue("Output");
if (string.IsNullOrEmpty(inputValue))
{
log.Warning("Could not find 'Output' in the package, nothing to preview");
return;
}
// read staging url from configuration
string stagingUrl = TridionConfigurationManager.GetInstance(engine, package).AppSettings["StagingUrl"];
string outputValue = HttpPost(stagingUrl, inputValue);
if (string.IsNullOrEmpty(outputValue))
{
outputValue = "<h2>There was an error while generating the preview.</h2>";
}
// replace the Output item in the package
package.Remove(outputItem);
package.PushItem("Output", package.CreateStringItem(ContentType.Html, outputValue));
}
示例13: Transform
public void Transform(Engine engine, Package package)
{
_log = TemplatingLogger.GetLogger(GetType());
RepositoryLocalObject context =
engine.GetObject(package.GetByName(Package.PageName)) as RepositoryLocalObject;
if (context == null)
{
_log.Error("Could not retrieve page from package. Exiting.");
return;
}
string categoryUrl = context.ContextRepository.WebDavUrl + NavigationCategoryWebDavUrl;
Category navigation = (Category)engine.GetObject(categoryUrl);
using (MemoryStream ms = new MemoryStream())
{
XmlTextWriter w = new XmlTextWriter(ms, new UTF8Encoding(false))
{
Indentation = 4,
Formatting = Formatting.Indented
};
w.WriteStartDocument();
w.WriteStartElement(Navigation.RootNodeName);
KeywordsFilter filter = new KeywordsFilter(engine.GetSession()) { IsRoot = true };
foreach (XmlNode rootChildren in navigation.GetListKeywords(filter))
{
Keyword rootKeyword = (Keyword)engine.GetObject(rootChildren.Attributes["ID"].Value);
w.WriteStartElement(Navigation.NodeName);
NavigationNode n = new NavigationNode(rootKeyword);
}
}
}
示例14: Transform
public void Transform(Engine engine, Package package)
{
this.package = package;
this.engine = engine;
if (engine.PublishingContext.RenderContext != null && engine.PublishingContext.RenderContext.ContextVariables.Contains(BasePageTemplate.VariableNameCalledFromDynamicDelivery))
{
if (engine.PublishingContext.RenderContext.ContextVariables[BasePageTemplate.VariableNameCalledFromDynamicDelivery].Equals(BasePageTemplate.VariableValueCalledFromDynamicDelivery))
{
log.Debug("template is rendered by a DynamicDelivery page template, will not convert from XML to java");
return;
}
}
Item outputItem = package.GetByName("Output");
String inputValue = package.GetValue("Output");
if (inputValue == null || inputValue.Length == 0)
{
log.Warning("Could not find 'Output' in the package, nothing to transform");
return;
}
// Combine the 'to lower' and 'to java' functions, since there is no reason to have one without the other.
// Note: it is still possible (for backwards compatibility) to have a separate ToLower TBB in your templates.
// In that case, the first letter of each element will be converted into lower case twice, which doesn't do any harm.
string outputValue = LowerCaseConverter.Convert(inputValue);
outputValue = XmlToJavaConverter.Convert(outputValue);
// outputValue = XmlMinimizer.Convert(outputValue);
// replace the Output item in the package
package.Remove(outputItem);
outputItem.SetAsString(outputValue);
package.PushItem("Output", outputItem);
}
示例15: Transform
public void Transform(Engine engine, Package package)
{
this.package = package;
this.engine = engine;
if (engine.PublishingContext.RenderContext != null && engine.PublishingContext.RenderContext.ContextVariables.Contains(BasePageTemplate.VariableNameCalledFromDynamicDelivery))
{
if (engine.PublishingContext.RenderContext.ContextVariables[BasePageTemplate.VariableNameCalledFromDynamicDelivery].Equals(BasePageTemplate.VariableValueCalledFromDynamicDelivery))
{
log.Debug("template is rendered by a DynamicDelivery page template, will not convert from XML to java");
return;
}
}
Item outputItem = package.GetByName("Output");
String inputValue = package.GetValue("Output");
if (inputValue == null || inputValue.Length == 0)
{
log.Warning("Could not find 'Output' in the package, nothing to transform");
return;
}
String minimizeSettings = package.GetValue("MinimizeSettings");
string outputValue = XmlMinimizer.Convert(inputValue, minimizeSettings);
// replace the Output item in the package
package.Remove(outputItem);
outputItem.SetAsString(outputValue);
package.PushItem("Output", outputItem);
}