本文整理汇总了C#中SitecoreContext类的典型用法代码示例。如果您正苦于以下问题:C# SitecoreContext类的具体用法?C# SitecoreContext怎么用?C# SitecoreContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SitecoreContext类属于命名空间,在下文中一共展示了SitecoreContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FieldWithSpacesReturningNullIssue
public void FieldWithSpacesReturningNullIssue()
{
/*
* This test is in response to issue 53 raised on the Glass.Sitecore.Mapper
* project. When two interfaces have similar names are created as proxies
* the method GetTypeConfiguration returns the wrong config.
*/
//Assign
string path = "/sitecore/content/Tests/Misc/FieldWithSpace";
string expected = "Hello space";
string imageValue =
"<image mediaid=\"{C2CE5623-1E36-4535-9A01-669E1541DDAF}\" mediapath=\"/Tests/Dayonta\" src=\"~/media/C2CE56231E3645359A01669E1541DDAF.ashx\" />";
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));
var db = Sitecore.Configuration.Factory.GetDatabase("master");
var item = db.GetItem(path);
using (new ItemEditing(item, true))
{
item["Field With Space"] = expected;
item["Image Field"] = imageValue;
}
var scContext = new SitecoreContext(db);
var glassHtml = new GlassHtml(scContext);
//Act
var instance = scContext.GetItem<FieldWithSpaceIssue>(path);
//Assert
Assert.AreEqual(expected, instance.FieldWithSpace);
Assert.IsNotNull(instance.ImageSpace);
}
示例2: ItemPropertySave_SavesItemOnProperty_SetsField
public void ItemPropertySave_SavesItemOnProperty_SetsField()
{
/*
* Tests that we can save to an item property.
*/
//Assign
var context = Context.Create(Utilities.CreateStandardResolver());
var db = Factory.GetDatabase("master");
var scContext = new SitecoreContext(db);
string path = "/sitecore/content/Tests/Misc/ItemPropertySave";
var expected = "some expected value";
var item = db.GetItem(path);
using (new ItemEditing(item, true))
{
item["Field1"] = string.Empty;
}
var instance = scContext.GetItem<ItemPropertySaveStub>(path);
//Act
instance.Field1 = expected;
using (new SecurityDisabler())
{
scContext.Save(instance);
}
//Assert
Assert.AreEqual(expected, instance.Item["Field1"]);
}
示例3: 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
}
}
}
示例4: GetSitecoreContext
public ISitecoreContext GetSitecoreContext(Context context)
{
if (context == null)
{
Context providerContext = GlassContextProvider.GetContext();
if (providerContext == null)
{
throw new NotSupportedException("Sitecore Context Requires a Glass Context");
}
context = providerContext;
}
string cacheKey = String.Format("GlassContext_{0}_{1}", context.Name, CachedContextsKey);
SitecoreContext sitecoreContext = Sitecore.Context.Items[cacheKey] as SitecoreContext;
if (sitecoreContext == null)
{
string contextName = context.Name;
sitecoreContext = new SitecoreContext(contextName);
Sitecore.Context.Items[cacheKey] = sitecoreContext;
}
return sitecoreContext;
}
示例5: InterfaceIssueInPageEditorWhenInterfaceInheritsFromAnInterfaceWithSimilarName
public void InterfaceIssueInPageEditorWhenInterfaceInheritsFromAnInterfaceWithSimilarName()
{
/*
* This test is in response to issue 53 raised on the Glass.Sitecore.Mapper
* project. When two interfaces have similar names are created as proxies
* the method GetTypeConfiguration returns the wrong config.
*/
//Assign
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));
var db = Sitecore.Configuration.Factory.GetDatabase("master");
var scContext = new SitecoreContext(db);
var glassHtml = new GlassHtml(scContext);
var instance = scContext.GetItem<IBasePage>("/sitecore");
//Act
glassHtml.Editable(instance, x => x.Title);
//This method should execute without error
}
示例6: RenderImage_MatchesSitecoreOutput_Issue133
public void RenderImage_MatchesSitecoreOutput_Issue133()
{
//Assign
string targetPath = "/sitecore/content/Tests/GlassHtml/RenderImage/Target";
var db = Sitecore.Configuration.Factory.GetDatabase("master");
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));
var service = new SitecoreContext(db);
var html = new GlassHtml(service);
string fieldValue= "<image mediaid=\"{D897833C-1F53-4FAE-B54B-BB5B11B8F851}\" mediapath=\"/Files/20121222_001405\" src=\"~/media/D897833C1F534FAEB54BBB5B11B8F851.ashx\" hspace=\"15\" vspace=\"20\" />";
var item = db.GetItem(targetPath);
var field = item.Fields["Image"];
using (new ItemEditing(item, true))
{
field.Value = fieldValue;
}
var model = service.GetItem<StubClassWithImage>(targetPath);
var scControl = new Sitecore.Web.UI.WebControls.Image();
scControl.Item = item;
scControl.Field = "Image";
scControl.Parameters = "mw=200";
var doc = new XmlDocument();
doc.LoadXml("<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />");
var siteContext = new SiteContextStub(
new SiteInfo(
doc.FirstChild
)
);
siteContext.SetDisplayMode(DisplayMode.Normal);
Sitecore.Context.Site = siteContext;
StringBuilder sb = new StringBuilder();
HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(sb));
//Act
scControl.RenderControl(writer);
var scResult = sb.ToString();
var result = html.RenderImage(model, x => x.Image, new {mw=200});
//Assert
Assert.AreEqual(result,scResult);
}
示例7: 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);
}
示例8: 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;
}
示例9: DropRead
public void DropRead()
{
ISitecoreContext context = new SitecoreContext();
DemoItem current = context.GetCurrentItem<DemoItem>();
if (current.Drop != null)
{
string otherName = current.Drop.Name;
}
}
示例10: 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");
}
示例11: 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();
}
}
示例12: 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");
}
}
示例13: Editable_InEditMode_StringFieldWithEditReturned
public void Editable_InEditMode_StringFieldWithEditReturned()
{
//Assign
string targetPath = "/sitecore/content/Tests/GlassHtml/MakeEditable/Target";
var db = Sitecore.Configuration.Factory.GetDatabase("master");
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));
var service = new SitecoreContext(db);
var html = new GlassHtml(service);
var model = service.GetItem<StubClass>(targetPath);
var fieldValue = "test content field";
model.StringField = fieldValue ;
using (new SecurityDisabler())
{
service.Save(model);
}
var doc = new XmlDocument();
doc.LoadXml("<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />");
var siteContext = new SiteContextStub(
new SiteInfo(
doc.FirstChild
)
);
siteContext.SetDisplayMode(DisplayMode.Edit);
Sitecore.Context.Site = siteContext;
//Act
string result;
using (new SecurityDisabler())
{
result = html.Editable(model, x => x.StringField);
}
//Assert
Assert.IsTrue(result.Contains(fieldValue));
//this is the webedit class
Assert.IsTrue(result.Contains("scWebEditInput"));
Console.WriteLine("result "+result);
}
示例14: 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;
}
}
示例15: RenderLink_LinkContainsAnchor_Issue155
public void RenderLink_LinkContainsAnchor_Issue155()
{
//Assign
string targetPath = "/sitecore/content/Tests/GlassHtml/MakeEditable/Target";
var db = Sitecore.Configuration.Factory.GetDatabase("master");
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));
var service = new SitecoreContext(db);
var html = new GlassHtml(service);
string fieldValue = "<link text='text' linktype='anchor' anchor='footer' title='' class='' />";
string expected = "<a href='#footer' >text</a>";
var item = db.GetItem(targetPath);
var field = item.Fields["StringField"];
using (new ItemEditing(item, true))
{
field.Value = fieldValue;
}
var model = service.GetItem<IStubLinkClass>(targetPath);
var doc = new XmlDocument();
doc.LoadXml("<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />");
var siteContext = new SiteContextStub(
new SiteInfo(
doc.FirstChild
)
);
siteContext.SetDisplayMode(DisplayMode.Normal);
Sitecore.Context.Site = siteContext;
StringBuilder sb = new StringBuilder();
//Act
var result = html.RenderLink(model, x => x.Link);
//Assert
Assert.AreEqual(expected, result);
}