本文整理汇总了C#中SitecoreContext.GetCurrentItem方法的典型用法代码示例。如果您正苦于以下问题:C# SitecoreContext.GetCurrentItem方法的具体用法?C# SitecoreContext.GetCurrentItem怎么用?C# SitecoreContext.GetCurrentItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SitecoreContext
的用法示例。
在下文中一共展示了SitecoreContext.GetCurrentItem方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public override void Process(GetModelArgs args)
{
if (args.Result == null)
{
try
{
Type type = GetFromField(args.Rendering, args);
if (Context.StaticContext.Classes.ContainsKey(type))
{
ISitecoreContext context = new SitecoreContext();
var result = context.GetCurrentItem(type);
args.Result = result;
}
}
catch (MapperException ex)
{
//do nothing
}
catch (System.TypeLoadException ex)
{
//do nothing
}
}
}
示例2: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
ISitecoreContext context = new SitecoreContext();
var home = context.GetCurrentItem<Home>();
Title.Text = home.Title;
Text.Text = home.Text;
CreateBy.Text = home.CreatedBy;
CreatedOn.Text = home.Created.ToShortDateString();
Path.Text = home.Path;
}
示例3: DropSave
public void DropSave()
{
ISitecoreContext context = new SitecoreContext();
DemoItem current = context.GetCurrentItem<DemoItem>();
OtherItem other = context.GetItem<OtherItem>("/sitecore/content/home/someOtherItem");
current.Drop = other;
context.Save(current);
}
示例4: DropRead
public void DropRead()
{
ISitecoreContext context = new SitecoreContext();
DemoItem current = context.GetCurrentItem<DemoItem>();
if (current.Drop != null)
{
string otherName = current.Drop.Name;
}
}
示例5: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
ISitecoreContext context = new SitecoreContext();
Home item = context.GetCurrentItem<Home>();
title.Text = item.Title;
body.Text = item.Body;
date.Text = item.Date.ToString("dd MMM yyyy");
}
示例6: DoWork
public void DoWork()
{
var context = new SitecoreContext();
using (new VersionCountDisabler())
{
var current = context.GetCurrentItem<MyModel>();
//you will need to evaluate the query before you exit the VersionCountDisabler scope
var results = current.Query.ToList();
}
}
示例7: Page_Load
/// <summary>
/// Handles the Load event of the Page control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void Page_Load(object sender, EventArgs e)
{
ISitecoreContext context = new SitecoreContext();
BasePageModel = context.GetCurrentItem<BasePageModel>();
HomeModel = context.GetHomeItem<HomeModel>();
LoadMetaData();
RegisterGoogleAnalyticsScript();
if (BasePageModel.Id == HomeModel.Id)
{
body.Attributes.Add("class", "homepage");
}
}
示例8: MultiTreeRead
public void MultiTreeRead()
{
ISitecoreContext context = new SitecoreContext();
DemoItem current = context.GetCurrentItem<DemoItem>();
foreach (OtherItem other in current.Multi)
{
string title = other.Title;
}
foreach (OtherItem other in current.Tree)
{
string title = other.Title;
}
}
示例9: GetCurrentItem_NoParameters
public void GetCurrentItem_NoParameters()
{
//Assign
var db = Sitecore.Configuration.Factory.GetDatabase("master");
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));
var path = "/sitecore/content/Tests/SitecoreContext/GetCurrentItem/Target";
var scContext = new SitecoreContext();
Sitecore.Context.Item = db.GetItem(path);
//Act
var result = scContext.GetCurrentItem<StubClass>();
//Assert
Assert.AreEqual(Sitecore.Context.Item.ID, result.Id);
}
示例10: CreateChildControls
/// <summary>
/// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
/// </summary>
protected override void CreateChildControls()
{
Type type = Type.GetType(TypeName);
Type razorControlType = typeof(AbstractRazorControl<>);
Type finalControlType = razorControlType.MakeGenericType(type);
WebControl finalControl =Activator.CreateInstance(finalControlType) as WebControl;
ISitecoreContext _context = new SitecoreContext(Context);
var model = _context.GetCurrentItem(type);
TypeDescriptor.GetProperties(finalControlType).Find("Model", false).SetValue(finalControl, model);
this.Controls.Add(finalControl);
base.CreateChildControls();
}
示例11: GetCurrentItem_NoParameters
public void GetCurrentItem_NoParameters()
{
//Assign
using (Db database = new Db
{
new Sitecore.FakeDb.DbItem("Target")
})
{
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass)));
var path = "/sitecore/content/Target";
var scContext = new SitecoreContext();
Sitecore.Context.Item = database.GetItem(path);
//Act
var result = scContext.GetCurrentItem<StubClass>();
//Assert
Assert.AreEqual(Sitecore.Context.Item.ID, result.Id);
}
}
示例12: GetObject
/// <summary>
/// Gets the object.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="db">The db.</param>
/// <returns></returns>
/// <exception cref="Glass.Mapper.MapperException">Failed to find context {0}.Formatted(ContextName)</exception>
public object GetObject(string model, Database db, Rendering renderingItem)
{
if (model.IsNullOrEmpty())
return null;
//must be a path to a Model item
if (model.StartsWith("/sitecore"))
{
var target = db.GetItem(model);
if (target == null)
return null;
string newModel = target[ModelTypeField];
return GetObject(newModel, db, renderingItem);
}
//if guid must be that to Model item
Guid targetId;
if (Guid.TryParse(model, out targetId))
{
var target = db.GetItem(new ID(targetId));
if (target == null)
return null;
string newModel = target[ModelTypeField];
return GetObject(newModel, db, renderingItem);
}
var type = Type.GetType(model, false);
if (type == null)
return null;
var context = Context.Contexts.ContainsKey(ContextName) ? Context.Contexts[ContextName] : null;
if (context == null) throw new MapperException("Failed to find context {0}".Formatted(ContextName));
//this is really aggressive
if (!context.TypeConfigurations.ContainsKey(type))
{
//if the config is null then it is probably an ondemand mapping so we have to load the ondemand part
IConfigurationLoader loader =
new OnDemandLoader<SitecoreTypeConfiguration>(type);
context.Load(loader);
}
ISitecoreContext scContext = new SitecoreContext(context);
if (renderingItem.DataSource.IsNotNullOrEmpty())
{
var item = scContext.Database.GetItem(renderingItem.DataSource);
return scContext.CreateType(type, item, false, false, null);
}
return scContext.GetCurrentItem(type);
}
示例13: GetCurrentItem_FourParameters
public void GetCurrentItem_FourParameters()
{
//Assign
using (Db database = new Db
{
new Sitecore.FakeDb.DbItem("Target")
})
{
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass)));
string param1 = "1para";
string param2 = "2para";
string param3 = "3para";
string param4 = "4para";
var path = "/sitecore/content/Target";
var scContext = new SitecoreContext();
Sitecore.Context.Item = database.GetItem(path);
//Act
var result = scContext.GetCurrentItem<StubClass, string, string, string, string>(param1, param2, param3,
param4);
//Assert
Assert.AreEqual(Sitecore.Context.Item.ID, result.Id);
Assert.AreEqual(param1, result.Param1);
Assert.AreEqual(param2, result.Param2);
Assert.AreEqual(param3, result.Param3);
Assert.AreEqual(param4, result.Param4);
}
}
示例14: GetObject
public object GetObject(string model)
{
if (model.IsNullOrEmpty())
return null;
var type = Type.GetType(model, true);
if (type == null)
return null;
var context = Context.Contexts[ContextName];
if (context == null) throw new MapperException("Failed to find context {0}".Formatted(ContextName));
if (context.TypeConfigurations.ContainsKey(type))
{
ISitecoreContext scContext = new SitecoreContext(context);
var result = scContext.GetCurrentItem(type);
return result;
}
return null;
}