本文整理汇总了C#中Database.SelectSingleItem方法的典型用法代码示例。如果您正苦于以下问题:C# Database.SelectSingleItem方法的具体用法?C# Database.SelectSingleItem怎么用?C# Database.SelectSingleItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database.SelectSingleItem方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Resolve
/// <summary>
/// Resolves a specific Item from whatever string-based Item reference one can provide, typically the Datasource
/// property of a Rendering. If datasource is empty, the Context Item is assumed to be the correct resolution.
/// </summary>
/// <param name="datasource">An absolute XPath, relative XPath, query statement, fast statement, or Guid string that resolves to a single Item.</param>
/// <param name="database">Database to use when resolving the datasource.</param>
/// <returns>The datasource Item, the Context Item (if datasource is empty) or null.</returns>
public static Item Resolve(string datasource, Database database)
{
// check for query/fast syntax
if (datasource.StartsWith("query:", StringComparison.OrdinalIgnoreCase) || datasource.StartsWith("fast:", StringComparison.OrdinalIgnoreCase))
{
return database.SelectSingleItem(EncodeQuery(datasource));
}
return database.GetItem(datasource);
}
示例2: AllowRedirectsOnFoundItem
private static bool AllowRedirectsOnFoundItem(Database db)
{
if (db == null)
return false;
var redirectRoot = Sitecore.Configuration.Settings.GetSetting(Constants.Settings.RedirectRootNode);
var redirectFolderRoot = db.SelectSingleItem(redirectRoot);
if (redirectFolderRoot == null)
return false;
var allowRedirectsOnItemIDs = redirectFolderRoot[Constants.Fields.ItemProcessRedirects];
return allowRedirectsOnItemIDs != null &&
allowRedirectsOnItemIDs.Contains(Sitecore.Context.Item.ID.ToString());
}
示例3: GetTargets
private static Database[] GetTargets(Database database)
{
Item itemNotNull = database.SelectSingleItem("/sitecore/system/publishing targets");
var list = new ArrayList();
foreach (Item item2 in itemNotNull.Children)
{
string name = item2["Target database"];
Database targetDatabase = Factory.GetDatabase(name, false);
if (targetDatabase != null)
{
list.Add(targetDatabase);
}
}
return Assert.ResultNotNull(list.ToArray(typeof(Database)) as Database[]);
}
示例4: GetRedirects
/// <summary>
/// This method return all of the possible matches for either the exact matches or the pattern matches
/// Note: Because Fast Query does not guarantee to return items in the current language context
/// (e.g. while in US/English, results may include other language items as well, even if the
/// US/EN language has no active versions), an additional LINQ query has to be run to filter for language.
/// Choose your query type appropriately.
/// </summary>
private static IEnumerable<Item> GetRedirects(Database db, string templateName, string versionedTemplateName, string queryType)
{
// Based off the config file, we can run different types of queries.
IEnumerable<Item> ret = null;
var redirectRoot = Sitecore.Configuration.Settings.GetSetting(Constants.Settings.RedirectRootNode);
switch (queryType)
{
case "fast": // fast query
{
//process shared template items
ret = db.SelectItems(String.Format("fast:{0}//*[@@templatename='{1}']", redirectRoot, templateName));
//because fast query requires to check for active versions in the current language
//run a separate query for versioned items to see if this is even necessary.
//if only shared templates exist in System/Modules, this step is extraneous and unnecessary.
IEnumerable<Item> versionedItems = db.SelectItems(String.Format("fast:{0}//*[@@templatename='{1}']", redirectRoot, versionedTemplateName));
//if active versions of items in the current context exist, union the two IEnumerable lists together.
ret = versionedItems.Any(i => i.Versions.Count > 0)
? ret.Union(versionedItems.Where(i => i.Versions.Count > 0))
: ret;
break;
}
case "query": // Sitecore query
{
ret = db.SelectItems(String.Format("{0}//*[@@templatename='{1}' or @@templatename='{2}']", redirectRoot, templateName, versionedTemplateName));
break;
}
default: // API LINQ
{
Item redirectFolderRoot = db.SelectSingleItem(redirectRoot);
if (redirectFolderRoot != null)
ret = redirectFolderRoot.Axes.GetDescendants().Where(i => i.TemplateName == templateName || i.TemplateName == versionedTemplateName);
break;
}
}
// make sure to return an empty list instead of null
return ret ?? new Item[0];
}
示例5: FetchFieldValue
//.........这里部分代码省略.........
{
str1 = String.Join(", ", ((MultilistField)field).Items.Select(i => currentDatabase.GetItem(i)[referenceFieldName]));
}
catch
{
}
else if (field.Type == "Checklist")
{
string str2 = field.Value;
char[] chArray = new char[1]
{
'|'
};
foreach (string path in str2.Split(chArray))
{
Sitecore.Data.Items.Item obj = currentDatabase.GetItem(path);
str1 = str1 + obj.Name + "\n";
}
}
else if (field.Type == "Rich Text")
{
string str2 = string.Empty;
try
{
str2 = RenderItemHelper.ReplaceSpecialCharacters(field.Value);
}
catch (Exception ex)
{
LogManager<ILogProvider>.Error("FetchFieldValue ERROR while trying to replace special characters ", ex, typeof(SitecoreHelper));
}
XmlNode xmlNode = (XmlNode)((XmlDocument)new XmlDocument()).CreateElement("temp");
xmlNode.InnerXml = str2;
str1 = xmlNode.InnerText.Trim();
}
else if (field.Type == "Single-Line Text")
{
if (field.Value.Contains("<ParagraphStyle"))
{
XmlElement element = ((XmlDocument)new XmlDocument()).CreateElement("temp");
element.InnerXml = Sitecore.PrintStudio.PublishingEngine.PatternBuilder.CdataParser(field.Value);
str1 = element.InnerText;
}
else
str1 = field.Value;
}
else if (field.Type == "Multi-Line Text")
{
if (field.Value.Contains("<ParagraphStyle"))
{
XmlElement element = ((XmlDocument)new XmlDocument()).CreateElement("temp");
element.InnerXml = Sitecore.PrintStudio.PublishingEngine.PatternBuilder.CdataParser(field.Value);
str1 = element.InnerText;
}
else
str1 = field.Value;
}
else if (field.Type == "Image")
{
MediaItem mediaItem = (MediaItem)((ImageField)field).MediaItem;
if (!Directory.Exists(WebConfigHandler.PrintStudioEngineSettings.ProjectsFolder + "Images\\"))
Directory.CreateDirectory(WebConfigHandler.PrintStudioEngineSettings.ProjectsFolder + "Images\\");
string destination = WebConfigHandler.PrintStudioEngineSettings.ProjectsFolder + (object)"Images\\" + (string)(object)mediaItem.ID.Guid + "." + mediaItem.Extension;
RenderItemHelper.CopyMediaToFile(mediaItem, destination, false);
str1 = destination;
}
else if (field.Type == "Print Text")
{
if (field.Value.Contains("<ParagraphStyle"))
{
str1 = field.Value;
}
else
{
string str2 = '"'.ToString();
str1 = "<ParagraphStyle Style=" + str2 + "Text" + str2 + "><![CDATA[" + field.Value + "]]></ParagraphStyle>";
}
}
else if (field.Type.ToLower() == "text")
str1 = field.Value;
else if (field.Type == "Integer" | field.Type == "Number")
str1 = field.Value;
else if (currentItem.Fields[fieldname].Value.Contains("{") | currentItem.Fields[fieldname].Value.Contains("/"))
{
try
{
Sitecore.Data.Items.Item obj = currentDatabase.SelectSingleItem(currentItem.Fields[fieldname].Value);
if (obj.Template.Name == "Pattern")
{
if (obj.Children[0].Template.Name == "Image" | obj.Children[0].Template.Name == "Barcode")
str1 = WebConfigHandler.PrintStudioEngineSettings.ProjectsFolder + "Images\\NoImage.jpg";
}
}
catch (Exception ex)
{
LogManager<ILogProvider>.Error("FetchFieldValue", ex, typeof(SitecoreHelper));
}
}
return str1;
}
示例6: AllowRedirectsOnFoundItem
private static bool AllowRedirectsOnFoundItem(Database db)
{
if (db == null)
return false;
var redirectRoot = Sitecore.Configuration.Settings.GetSetting("SharedSource.RedirectModule.RedirectRootNode");
var redirectFolderRoot = db.SelectSingleItem(redirectRoot);
if (redirectFolderRoot == null)
return false;
var allowRedirectsOnItemIDs = redirectFolderRoot["Items Which Always Process Redirects"];
return allowRedirectsOnItemIDs != null &&
allowRedirectsOnItemIDs.Contains(Context.Item.ID.ToString());
}
示例7: GetRedirects
/// <summary>
/// This method return all of the possible matches for either the exact matches or the pattern matches
/// </summary>
private static IEnumerable<Item> GetRedirects(Database db, string templateName, string queryType)
{
// Based off the config file, we can run different types of queries.
IEnumerable<Item> ret = null;
var redirectRoot = Sitecore.Configuration.Settings.GetSetting("SharedSource.RedirectModule.RedirectRootNode");
switch (queryType)
{
case "fast": // fast query
{
ret = db.SelectItems(String.Format("fast:{0}//*[@@templatename='{1}']", redirectRoot, templateName));
break;
}
case "query": // Sitecore query
{
ret = db.SelectItems(String.Format("{0}//*[@@templatename='{1}']", redirectRoot, templateName));
break;
}
default: // API LINQ
{
Item redirectFolderRoot = db.SelectSingleItem(redirectRoot);
if (redirectFolderRoot != null)
ret = redirectFolderRoot.Axes.GetDescendants().Where(i => i.TemplateName == templateName);
break;
}
}
// make sure to return an empty list instead of null
return ret ?? new Item[0];
}