本文整理汇总了C#中Sitecore类的典型用法代码示例。如果您正苦于以下问题:C# Sitecore类的具体用法?C# Sitecore怎么用?C# Sitecore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Sitecore类属于命名空间,在下文中一共展示了Sitecore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetItemDefinition
public override ItemDefinition GetItemDefinition(ID itemId, Sitecore.Data.DataProviders.CallContext context)
{
if (_cacheClearer == null)
{
lock (_lockObj)
{
if (_cacheClearer == null)
{
_cacheClearer = new MongoOplogCacheClearer(this.ConnectionString, this.MongoDatabase, this.Collection, this.MappingCollection);
new Thread(_cacheClearer.Start).Start();
}
}
}
if (!_initialized)
{
lock (_lockObj)
{
if (!_initialized)
{
_cacheClearer.AddDatabase(this.Database);
_initialized = true;
}
}
}
return null;
}
示例2: ComputeFieldValue
public object ComputeFieldValue(Sitecore.ContentSearch.IIndexable indexable)
{
var sitecoreIndexable = indexable as SitecoreIndexableItem;
if (sitecoreIndexable == null || !sitecoreIndexable.Item.TemplateName.Equals(TemplateKey,StringComparison.InvariantCultureIgnoreCase)) return null;
return sitecoreIndexable.Item.Axes.SelectSingleItem("./ancestor-or-self::*[@@templatekey='folder']").Name + " content";
}
示例3: Process
/// <summary>
/// Store source value to use to determine if an item is cloned as value is removed when items are published
/// http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2013/02/Identify-Cloned-Items-Sitecore-ASPNET-CMS-Publishing-Target-Databases.aspx
/// </summary>
/// <param name="context"></param>
public override void Process(Sitecore.Publishing.Pipelines.PublishItem.PublishItemContext context)
{
base.Process(context);
Item versionToPublish = context.VersionToPublish;
if (!context.Aborted
&& versionToPublish != null
&& versionToPublish.InheritsTemplate(BasePageNEWItem.TemplateId)
&& versionToPublish.Source != null
&& versionToPublish.IsClone)
{
BasePageNEWItem target = context.PublishOptions.TargetDatabase.GetItem(
versionToPublish.ID,
versionToPublish.Language);
if (target.InnerItem != null &&
target.SourceItem.Field.Value !=
versionToPublish.Source.ID.ToString())
{
using (new Sitecore.Data.Items.EditContext(target.InnerItem, updateStatistics: false, silent: true))
{
target.InnerItem[target.SourceItem.Field.InnerField.Name] = versionToPublish.ID.ToString();
}
}
}
}
示例4: DoProcessRequest
protected override bool DoProcessRequest(HttpContext context, MediaRequest request, Sitecore.Resources.Media.Media media)
{
Assert.ArgumentNotNull(context, "context");
Assert.ArgumentNotNull(request, "request");
Assert.ArgumentNotNull(media, "media");
if (this.Modified(context, media, request.Options) == Sitecore.Tristate.False)
{
Event.RaiseEvent("media:request", new object[] { request });
this.SendMediaHeaders(media, context);
context.Response.StatusCode = 0x130;
return true;
}
// Gets media stream for the requested media item thumbnail
MediaStream stream = ProcessThumbnail(request, media);
if (stream == null)
{
return false;
}
Event.RaiseEvent("media:request", new object[] { request });
this.SendMediaHeaders(media, context);
this.SendStreamHeaders(stream, context);
using (stream)
{
context.Response.AddHeader("Content-Length", stream.Stream.Length.ToString());
WebUtil.TransmitStream(stream.Stream, context.Response, Settings.Media.StreamBufferSize);
}
return true;
}
示例5: RenderContent
/// <summary>
/// Renders the content.
/// </summary>
/// <param name="printContext">The print context.</param>
/// <param name="output">The output.</param>
protected override void RenderContent(Sitecore.PrintStudio.PublishingEngine.PrintContext printContext, System.Xml.Linq.XElement output)
{
if (!string.IsNullOrEmpty(this.ChildDataKeyName))
{
printContext.Settings.Parameters[this.ChildDataKeyName] = this.DataSource;
}
if (!string.IsNullOrEmpty(this.DataSources))
{
foreach (var dataSource in this.DataSources.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
{
this.DataSource = dataSource;
if (!string.IsNullOrEmpty(this.ChildDataKeyName))
{
printContext.Settings.Parameters[this.ChildDataKeyName] = dataSource;
}
RenderChildren(printContext, output);
}
return;
}
this.RenderChildren(printContext, output);
}
示例6: GetMediaUrl
/// <summary>
/// If CDN is enabled for this request, replace the outgoing media url with the cdn version
/// </summary>
/// <param name="item"></param>
/// <param name="options"></param>
/// <returns></returns>
public override string GetMediaUrl(Sitecore.Data.Items.MediaItem item, MediaUrlOptions options)
{
string hostname = CDNManager.GetCDNHostName();
string url = base.GetMediaUrl(item, options);
bool shouldReplace = !string.IsNullOrEmpty(hostname) && // cdnHostname exists for site
Sitecore.Context.PageMode.IsNormal; // PageMode is normal
bool dontReplace = !CDNManager.IsMediaPubliclyAccessible(item) || // media is publicly accessible
CDNManager.IsMediaAnalyticsTracked(item); // media is analytics tracked
CDNUrlState contextState = CDNUrlSwitcher.CurrentValue;
if (contextState == CDNUrlState.Enabled)
{
shouldReplace = true;
}
else if (contextState == CDNUrlState.Disabled)
{
UrlString url2 = new UrlString(url);
url2[CDNManager.StopToken] = "1";
url = url2.ToString();
shouldReplace = false;
}
if (shouldReplace && !dontReplace) // media not DMS tracked
{
return CDNManager.ReplaceMediaUrl(url, hostname);
}
else
{
return url;
}
}
示例7: GetItemAccess
protected override AccessResult GetItemAccess(Sitecore.Data.Items.Item item, Account account, AccessRight accessRight, PropagationType propagationType)
{
//
//This method applies the specified AccessRight. Since the custom AccessRight
//has been extended to support additional properties (max comments and
//time range), these properties must be considered.
var result = base.GetItemAccess(item, account, accessRight, propagationType);
//
//
if (result == null || result.Permission != AccessPermission.Allow)
{
return result;
}
//
//
if (accessRight.Name != BucketRights.AddComments)
{
return result;
}
//
//
var right = accessRight as BucketAccessRight;
if (right != null)
{
result = GetItemAccess(item, account, right);
}
return result;
}
示例8: UpdateField
public void UpdateField(Sitecore.Data.Fields.Field field, string importValue, IImportOptions importOptions)
{
var selectionSource = field.Item.Database.SelectSingleItem(field.Source);
if (selectionSource != null)
{
var query = ID.IsID(importValue)
? ".//*[@@id='" + ID.Parse(importValue) + "']"
: "." +
Sitecore.StringUtil.EnsurePrefix('/',
importValue.Replace(importOptions.TreePathValuesImportSeparator, "/"));
var selectedItem = selectionSource.Axes.SelectSingleItem(query);
if (selectedItem != null)
{
field.Value = selectedItem.ID.ToString();
return;
}
}
if (importOptions.InvalidLinkHandling == InvalidLinkHandling.SetBroken)
{
field.Value = importValue;
}
else if (importOptions.InvalidLinkHandling == InvalidLinkHandling.SetEmpty)
{
field.Value = string.Empty;
}
}
示例9: Evaluate
protected override void Evaluate(Sitecore.Pipelines.InsertRenderings.InsertRenderingsArgs args, Sitecore.Data.Items.Item item)
{
RuleList<ConditionalRenderingsRuleContext> globalRules = this.GetGlobalRules(item);
foreach (RenderingReference reference in new List<RenderingReference>((IEnumerable<RenderingReference>)args.Renderings))
{
string conditions = reference.Settings.Conditions;
if (!string.IsNullOrEmpty(conditions))
{
List<Item> conditionItems = this.GetConditionItems(item.Database, conditions);
if (conditionItems.Count > 0)
{
RuleList<ConditionalRenderingsRuleContext> rules = RuleFactory.GetRules<ConditionalRenderingsRuleContext>((IEnumerable<Item>)conditionItems, "Rule");
ConditionalRenderingsRuleContext renderingsRuleContext = new ConditionalRenderingsRuleContext(args.Renderings, reference);
renderingsRuleContext.Item = item;
ConditionalRenderingsRuleContext ruleContext = renderingsRuleContext;
rules.Run(ruleContext);
}
}
if (globalRules != null)
{
ConditionalRenderingsRuleContext renderingsRuleContext = new ConditionalRenderingsRuleContext(args.Renderings, reference);
renderingsRuleContext.Item = item;
ConditionalRenderingsRuleContext ruleContext = renderingsRuleContext;
globalRules.Run(ruleContext);
}
GetCustomRules(args, item, reference);
}
}
示例10: AddTableCell
/// <summary>
/// This function will be used to add
/// table cell
/// </summary>
/// <param name="tableRow">Table Row</param>
/// <param name="aField">Field</param>
/// <param name="fieldType">Type of field</param>
/// <returns></returns>
private static TableCell AddTableCell(TableRow tableRow, Sitecore.Data.Fields.Field aField, FieldTypes fieldType)
{
TableCell tableCell1 = new TableCell();
string valueToPrint = "NA";
switch (fieldType)
{
case FieldTypes.DateTime:
if ((aField != null) && !string.IsNullOrEmpty(aField.Value))
{
string dateFormat = "r";
DateTime createdDate = DateTime.Now;
createdDate = Sitecore.DateUtil.IsoDateToDateTime(aField.Value);
valueToPrint = createdDate.ToString(dateFormat);
}
else
{
valueToPrint = "NA";
}
break;
case FieldTypes.Text:
valueToPrint = ((aField != null) && !string.IsNullOrEmpty(aField.Value)) ? aField.Value : "NA";
break;
default:
valueToPrint = ((aField != null) && !string.IsNullOrEmpty(aField.Value)) ? aField.Value : "NA";
break;
}
tableCell1.Text = valueToPrint;
tableRow.Cells.Add(tableCell1);
return tableCell1;
}
示例11: BeginRender
/// <summary>
/// Preliminary render action invoked before RenderContent <see cref="RenderContent"/>.
/// </summary>
/// <param name="printContext">The print context.</param>
protected override void BeginRender(Sitecore.PrintStudio.PublishingEngine.PrintContext printContext)
{
if (!string.IsNullOrEmpty(this.RenderingItem["Item Field"]))
{
var dataItem = this.GetDataItem(printContext);
var data = dataItem[this.RenderingItem["Item Field"]];
if (!string.IsNullOrEmpty(this.RenderingItem["Item Selector"]))
{
var xpath = this.RenderingItem["Item Selector"];
if (!string.IsNullOrEmpty(xpath))
{
var items = dataItem.Axes.SelectItems(xpath);
if (items != null)
{
//this.DataSources = string.Join("|", items.Select(t => t.ID.ToString()).ToArray());
foreach (Item lookup in items)
{
this.DataSources = lookup[this.RenderingItem["Item Field"]];
}
}
}
}
Logger.Info("found DataSources: " + this.DataSources);
Logger.Info("found DataSource: " + this.DataSource);
}
}
示例12: Process
/// <summary>
/// Processes the specified arguments.
/// </summary>
/// <param name="args">The arguments.</param>
public override void Process(Sitecore.Commerce.Pipelines.ServicePipelineArgs args)
{
Assert.ArgumentNotNull(args, "args");
Assert.ArgumentNotNull(args.Request, "args.request");
Assert.ArgumentNotNull(args.Result, "args.result");
RefSFArguments.TranslateEntityToOrderAddressRequest request = (RefSFArguments.TranslateEntityToOrderAddressRequest)args.Request;
Assert.ArgumentNotNull(request.SourceParty, "request.SourceParty");
Assert.ArgumentNotNull(request.DestinationAddress, "request.DestinationAddress");
if (request.SourceParty is ConnectOrderModels.CommerceParty)
{
this.TranslateCommerceParty(request.SourceParty as ConnectOrderModels.CommerceParty, request.DestinationAddress);
}
else if (request.SourceParty is EmailParty)
{
this.TranslateEmailParty(request.SourceParty as EmailParty, request.DestinationAddress);
}
else
{
this.TranslateCustomParty(request.SourceParty, request.DestinationAddress);
}
TranslateEntityToOrderAddressResult result = (TranslateEntityToOrderAddressResult)args.Result;
result.Address = request.DestinationAddress;
}
示例13: RunQuery
public override List<SkinnyItem> RunQuery(Sitecore.Search.QueryBase query, bool showAllVersions)
{
using (var scope = QueryTraceHelper.GetQueryTraceScope(query))
{
return base.RunQuery(query, showAllVersions);
}
}
示例14: GetField
/// <summary>
/// Gets the field.
/// </summary>
/// <param name="field">The field.</param>
/// <param name="config">The config.</param>
/// <param name="context">The context.</param>
/// <returns>System.Object.</returns>
public override object GetField(Sitecore.Data.Fields.Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
{
if (field == null)
return string.Empty;
if (config.Setting == SitecoreFieldSettings.RichTextRaw)
{
return field.Value;
}
Guid fieldGuid = field.ID.Guid;
// shortest route - we know whether or not its rich text
if (isRichTextDictionary.ContainsKey(fieldGuid))
{
return GetResult(field, isRichTextDictionary[fieldGuid]);
}
// we don't know - it might still be rich text
bool isRichText = field.TypeKey == _richTextKey;
isRichTextDictionary.TryAdd(fieldGuid, isRichText);
// now we know it isn't rich text - return the raw result.
return GetResult(field, isRichText);
}
示例15: InheritsFromTemplate
private bool InheritsFromTemplate(TemplateItem templateItem, Sitecore.Data.ID templateId)
{
return templateItem.ID == templateId
|| (templateItem.BaseTemplates != null
&& templateItem.BaseTemplates
.Where(baseTempl => InheritsFromTemplate(baseTempl, templateId)).Count() > 0);
}