本文整理汇总了C#中Keyword.GetListUsingItems方法的典型用法代码示例。如果您正苦于以下问题:C# Keyword.GetListUsingItems方法的具体用法?C# Keyword.GetListUsingItems怎么用?C# Keyword.GetListUsingItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Keyword
的用法示例。
在下文中一共展示了Keyword.GetListUsingItems方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindComponent
private Component FindComponent(Keyword kw)
{
XmlElement usingItems = kw.GetListUsingItems(new UsingItemsFilter(Engine.GetSession()) { ItemTypes = new List<ItemType>() { ItemType.Component }, IncludedVersions = VersionCondition.OnlyLatestVersions });
Component component = null;
List<Component> matchingComponents = new List<Component>();
List<Component> otherComponents = new List<Component>();
if (kw.Title.Contains("Web Content Management"))
Logger.Debug(string.Format("looking for component for keyword {0}", kw.Title));
foreach (XmlElement item in usingItems.SelectNodes("/*/*"))
{
Component c = (Component)Engine.GetObject(item.GetAttribute("ID"));
if (kw.Title.Contains("Web Content Management"))
Logger.Debug(string.Format("round 1: component {0}, schema title {2}", c.Title, c.Id, c.Schema.Title));
//The component which is based on the header schema related to the current taxonomy takes precedence
if (c.Schema.Title.ToLower().Contains(kw.OrganizationalItem.Title.ToLower())) // e.g. if the keyword is in the category 'Product', a component with schema 'Header For Product' matches!
matchingComponents.Add(c);
else
//The first one that is returned by the system takes precedence
otherComponents.Add(c);
}
if (matchingComponents.Count == 0 && otherComponents.Count == 0)
{
if (kw.Title.Contains("Web Content Management"))
Logger.Debug("no components found, returning null");
return null;
}
if (TryFindComponentWithinMatchingComponents(matchingComponents, kw, out component))
return component;
matchingComponents.Clear();
foreach (Component c in otherComponents)
{
if (kw.Title.Contains("Web Content Management"))
Logger.Debug(string.Format("round 2: component {0}, schema {1}", c.Title, c.Schema.Title));
//The component which is based on any other header schema takes precedence
if (c.Schema.Title.StartsWith("Header")) // TODO: make configurable
matchingComponents.Add(c);
}
if (TryFindComponentWithinMatchingComponents(matchingComponents, kw, out component))
return component;
if (kw.Title.Contains("Web Content Management"))
Logger.Debug(string.Format("no rules matched, returning first component in list ({0})", otherComponents[0].Title));
if (TryFindComponentWithinMatchingComponents(otherComponents, kw, out component))
return component;
return null;
}