28.07.2013 Views

Hent teknisk dokumentation - Go Basic

Hent teknisk dokumentation - Go Basic

Hent teknisk dokumentation - Go Basic

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

using System;<br />

using System.Collections.Generic;<br />

using System.Linq;<br />

using System.Text;<br />

using LinqIt.Cms;<br />

using <strong>Go</strong><strong>Basic</strong>.Interfaces.Enumerations;<br />

using <strong>Go</strong><strong>Basic</strong>.Logic.Exceptions;<br />

using <strong>Go</strong><strong>Basic</strong>.Logic.Utilities;<br />

using <strong>Go</strong><strong>Basic</strong>.Logic.Entities;<br />

namespace <strong>Go</strong><strong>Basic</strong>.Logic.Controllers.SiteManagement<br />

{<br />

public class NewsArchiveComponent : BaseSiteComponent<br />

{<br />

public override string Name<br />

{<br />

get { return "News Archive"; }<br />

}<br />

protected override void Initialize()<br />

{<br />

// Check if a page exists, which is linked to by a system link named "NewsArchivePage"<br />

var newsArchivePage = GetSiteLinkedEntity(SystemKey.NewsArchivePage);<br />

if (newsArchivePage == null)<br />

{<br />

// Notify that the component is disabled ( this is not a required component )<br />

// Provide a button click handler and text for the "Fix it" button.<br />

throw new SiteComponentException("The News archive is not yet enabled.", SiteComponentState.Disabled,<br />

OnSetupClicked, "Enable news archive");<br />

}<br />

}<br />

}<br />

}<br />

// If no exception was thrown, the page and systemlink is configured correctly.<br />

AddMessage("The News archive has been setup correctly.");<br />

// This code will execute when the "Fix It" button is clicked, and should setup the newsarchive<br />

protected void OnSetupClicked(object sender, EventArgs e)<br />

{<br />

using (CmsContext.Editing)<br />

{<br />

// Get a reference to the home page (This snippet assumes that the home page has been configured.)<br />

var homeItem = GetSiteLinkedEntity(SystemKey.HomePage);<br />

}<br />

// Create a newlistpage called "News Archive" under the home item<br />

var resultPage = CmsService.Instance.CreateEntity("News Archive", homeItem);<br />

EnsureSiteSystemLink(SystemKey.NewsArchivePage, resultPage);<br />

}<br />

ReloadEditor();<br />

En af de væsentlige ting som foretages af BaseSiteComponent klassen er at fange<br />

den SiteComponentException, som kastes under initialize fasen, og generere en label<br />

med fejlbeskeden, samt en knap som administratoren kan benytte til at løse<br />

problemerne. NewsArchiveComponent klassen behøver derfor kun at implementere<br />

”forretningslogikken”, og nedarver præsentationskoden.<br />

12

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!