本文整理汇总了C#中SitecoreContext类的典型用法代码示例。如果您正苦于以下问题:C# SitecoreContext类的具体用法?C# SitecoreContext怎么用?C# SitecoreContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SitecoreContext类属于命名空间,在下文中一共展示了SitecoreContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:bplasmeijer,项目名称:Glass.Mapper,代码行数:41,代码来源:MiscFixture.cs
示例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"]);
}
开发者ID:seanmolam,项目名称:Glass.Mapper,代码行数:35,代码来源:MiscFixture.cs
示例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
}
}
}
开发者ID:RvanDalen,项目名称:Glass.Sitecore.Mapper,代码行数:25,代码来源:GetModel.cs
示例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;
}
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:26,代码来源:SitecoreContextFactory.cs
示例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
}
开发者ID:bplasmeijer,项目名称:Glass.Mapper,代码行数:26,代码来源:MiscFixture.cs
示例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);
}
开发者ID:seanmolam,项目名称:Glass.Mapper,代码行数:58,代码来源:GlassHtmlFixture.cs
示例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);
}
开发者ID:mujtahid,项目名称:Glass.Sitecore.Mapper.Tutorial,代码行数:11,代码来源:DemoLayout.ascx.cs
示例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;
}
开发者ID:mujtahid,项目名称:Glass.Sitecore.Mapper.Tutorial,代码行数:11,代码来源:GlassTutorial1.ascx.cs
示例9: DropRead
public void DropRead()
{
ISitecoreContext context = new SitecoreContext();
DemoItem current = context.GetCurrentItem<DemoItem>();
if (current.Drop != null)
{
string otherName = current.Drop.Name;
}
}
开发者ID:mujtahid,项目名称:Glass.Sitecore.Mapper.Tutorial,代码行数:11,代码来源:DemoLayout.ascx.cs
示例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");
}
开发者ID:JamesHay,项目名称:Glass.Sitecore.Mapper,代码行数:12,代码来源:MainLayout.aspx.cs
示例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();
}
}
开发者ID:bplasmeijer,项目名称:Glass.Mapper.Sc.Demo,代码行数:13,代码来源:SearchController.cs
示例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");
}
}
开发者ID:KayeeNL,项目名称:SUGNL-Website,代码行数:19,代码来源:Default.aspx.cs
示例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);
}
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:50,代码来源:GlassHtmlFixture.cs
示例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;
}
}
开发者ID:mujtahid,项目名称:Glass.Sitecore.Mapper.Tutorial,代码行数:16,代码来源:DemoLayout.ascx.cs
示例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);
}
开发者ID:rootix,项目名称:Glass.Mapper,代码行数:46,代码来源:GlassHtmlFixture.cs
示例16: 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);
}
开发者ID:jelleovermars,项目名称:Glass.Mapper,代码行数:19,代码来源:SitecoreContextFixture.cs
示例17: 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();
}
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:24,代码来源:ContextRazorView.cs
示例18: 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);
}
}
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:23,代码来源:SitecoreContextFixture.cs
示例19: 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);
}
开发者ID:james-melville,项目名称:Glass.Mapper,代码行数:65,代码来源:GetModel.cs
示例20: OrderOfIgnoreIssue2_ConfiguredShouldBeSet_TitleShouldBeIgnored
public void OrderOfIgnoreIssue2_ConfiguredShouldBeSet_TitleShouldBeIgnored()
{
//Assign
string path = "/sitecore/content/Tests/Misc/FieldConfigOrder";
string expected = "Hello space";
var fluentConfig = new SitecoreFluentConfigurationLoader();
var typeConfig = fluentConfig.Add<FieldOrderOnIgnore>();
typeConfig.AutoMap();
typeConfig.Field(x => x.ConfiguredTitle).FieldName("Title");
typeConfig.Ignore(x => x.Title);
var context = Context.Create(Utilities.CreateStandardResolver());
context.Load(fluentConfig);
var db = Sitecore.Configuration.Factory.GetDatabase("master");
var item = db.GetItem(path);
using (new ItemEditing(item, true))
{
item["Title"] = expected;
}
var scContext = new SitecoreContext(db);
//Act
var instance = scContext.GetItem<FieldOrderOnIgnore>(path);
//Assert
Assert.AreEqual(expected, instance.ConfiguredTitle);
Assert.IsNullOrEmpty(instance.Title);
}
开发者ID:bplasmeijer,项目名称:Glass.Mapper,代码行数:37,代码来源:MiscFixture.cs
注:本文中的SitecoreContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论