TopicCreating & TopicCreated |
Top Previous Next |
The TopicCreating and TopicCreated events are fired just before and after a topic is created that represents a page in EPiServer. During the event handler for the TopicCreating event you may make changes to the topic before it is passed to TMCore. The following programming example, taken from a global.asax.cs file adds a new occurrence to each topic as it is created using the TopicCreating event, then verifies it's existence on the TopicCreated event. protected void Application_Start(Object sender, EventArgs e) { // Other application startup code goes here ... // Register our event handlers TopicMapEventHandler.Instance.TopicCreating += new TopicMapEventHandler.TopicEventHandler(Instance_TopicCreating); TopicMapEventHandler.Instance.TopicCreated += new TopicMapEventHandler.TopicEventHandler(Instance_TopicCreated); }
void Instance_TopicCreating(object sender, TopicEventArgs tea) { // On TopicCreating, add an occurrence to the topic being constructed NetworkedPlanet.WebServiceClient.Tmws.Occurrence newOccurrence = new Occurrence(); // from serviceclient.dll newOccurrence.resourcedata = "A description of the topic " + tea.topic.names[0].namestring; newOccurrence.type = new TopicRef(); newOccurrence.type.psi = "http://www.networkedplanet.com/2005/01/episerver/description"; Occurrence[] newOccurrences = new Occurrence[tea.topic.occurrences.Length + 1]; Array.Copy(tea.topic.occurrences, 0, newOccurrences, 1, tea.topic.occurrences.Length); newOccurrences[0] = newOccurrence; tea.topic.occurrences = newOccurrences; }
void Instance_TopicCreated(object sender, TopicEventArgs tea) { // On topic created log the description occurrence ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); foreach (Occurrence occ in tea.topic.occurrences) { if (occ.type != null && occ.type.psi == "http://www.networkedplanet.com/2005/01/episerver/description") { log.Info("Found description after topic created: " + occ.resourcedata); } } }
|