Created
July 17, 2015 19:52
-
-
Save seankearney/1b6df5acf16b7f4cabe0 to your computer and use it in GitHub Desktop.
Sitecore-Bug-442839
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="C#" Debug="true" %> | |
<script runat="server"> | |
public void Page_Load() | |
{ | |
Response.ContentType = "text/plain"; | |
// wire up event handlers... Attach a debugger and look at the output window | |
EventHandlers.Init(); | |
Sitecore.Data.Database database = Sitecore.Configuration.Factory.GetDatabase("master"); | |
var name = "ItemName"; | |
var templateId = new Sitecore.Data.ID("{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"); | |
var id = new Sitecore.Data.ID(System.Guid.NewGuid()); | |
var language = Sitecore.Globalization.Language.Current; | |
var version = Sitecore.Data.Version.Latest; | |
var itemDefinition = new Sitecore.Data.ItemDefinition(id, name, templateId, Sitecore.Data.ID.Null); | |
var fieldList = new Sitecore.Data.FieldList(); | |
var itemData = new Sitecore.Data.ItemData(itemDefinition, language, version, fieldList); | |
var item = new Sitecore.Data.Items.Item(id, itemData, database); | |
// set a field value | |
item.Editing.BeginEdit(); | |
item["Title"] = "test"; | |
item.Editing.EndEdit(); | |
item.Delete(); //added for clean up | |
} | |
private static class EventHandlers | |
{ | |
static EventHandlers() | |
{ | |
// wire up the pre & post events | |
Sitecore.Data.Engines.DataEngine dataEngine = Sitecore.Configuration.Factory.GetDatabase("master").Engines.DataEngine; | |
dataEngine.AddingVersion += DataEngine_AddingVersion; | |
dataEngine.AddedVersion += DataEngine_AddedVersion; | |
dataEngine.SavingItem += DataEngine_SavingItem; | |
dataEngine.SavedItem += DataEngine_SavedItem; | |
dataEngine.CreatingItem += DataEngine_CreatingItem; | |
dataEngine.CreatedItem += DataEngine_CreatedItem; | |
} | |
public static void Init() | |
{ | |
} | |
private static void DataEngine_SavingItem(object sender, Sitecore.Data.Events.ExecutingEventArgs<Sitecore.Data.Engines.DataCommands.SaveItemCommand> e) | |
{ | |
Out("Saving item '{0}'", e.Command.Item.Name); | |
} | |
private static void DataEngine_SavedItem(object sender, Sitecore.Data.Events.ExecutedEventArgs<Sitecore.Data.Engines.DataCommands.SaveItemCommand> e) | |
{ | |
Out("Saved item '{0}'", e.Command.Item.Name); | |
} | |
private static void DataEngine_CreatingItem(object sender, Sitecore.Data.Events.ExecutingEventArgs<Sitecore.Data.Engines.DataCommands.CreateItemCommand> e) | |
{ | |
Out("Creating item '{0}'", e.Command.ItemName); | |
} | |
private static void DataEngine_CreatedItem(object sender, Sitecore.Data.Events.ExecutedEventArgs<Sitecore.Data.Engines.DataCommands.CreateItemCommand> e) | |
{ | |
Out("Created item '{0}'", e.Command.ItemName); | |
} | |
private static void DataEngine_AddingVersion(object sender, Sitecore.Data.Events.ExecutingEventArgs<Sitecore.Data.Engines.DataCommands.AddVersionCommand> e) | |
{ | |
Out("Adding Version of '{0}' ('{1}')", e.Command.Item.Name, e.Command.Item.Uri.ToString()); | |
} | |
private static void DataEngine_AddedVersion(object sender, Sitecore.Data.Events.ExecutedEventArgs<Sitecore.Data.Engines.DataCommands.AddVersionCommand> e) | |
{ | |
Out("Added Version of item '{0}' ('{1}')", e.Command.Item.Name, e.Command.Item.Uri.ToString()); | |
} | |
private static void Out(string message, params string[] args) | |
{ | |
System.Diagnostics.Debug.WriteLine(message, args); | |
System.Web.HttpContext.Current.Response.Write(string.Format(message, args)); | |
System.Web.HttpContext.Current.Response.Write(Environment.NewLine); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment