Ektron CMS400.Net Reference

>>Plug-in Extension > Plug-in Samples

Plug-in Samples

Ektron provides the following sample code plug-in projects. These projects are located in the C:\Program Files\Ektron\CMS400SDK\Samples folder. Use the Samples.sln file to launch these samples in Visual Studio.

PublishSendAlert

PublishContentChange

InstantMessageOnPublish

The PublishSendAlert sample sends an email when new content is published. For example, you want to be notified if any content is publish on the Web site. See PublishSendAlert Code Sample

The PublishContentChange sample appends content when it is published. For example, you want to add a signature or copyright information to content when it is published. See PublishContentChange Sample

The InstantMessageOnPublish sample sends an instant message when new content is published. For example, you want to be notified if any content is publish on the Web site. See InstantMessageOnPublish Sample

The code for each sample appears below.

PublishSendAlert Code Sample

The following code sample sends an email when new content is publish.

using System;

using System.Collections.Generic;

using System.Text;

using System.Net.Mail;

using System.Net;

using Ektron.Cms.Extensibility;

namespace Ektron.Cms.Extensibility.Samples

{

public class PublishSendAlert : ExtensionEvent

{

public override bool OnAfterPublish()

{

// Declare variables.

bool bReturn = false;

SmtpClient sendClient = null;

MailMessage message = null;

MailAddress from = null;

try

{

// Create connection to mail server and create a new message.

sendClient = new SmtpClient("mail.sample.com", 25);

message = new MailMessage();

// Populate information in the new message.

// TODO: Add from address below

from = new MailAddress("sample_sender@sample.com");

message.From = from;

// TODO: Add all recipients below.

message.To.Add("email@sample.com");

message.To.Add("email2@sample.com");

message.Subject = "Content has been published";

message.Body = "Content published contained the following:\r\n" + Content.Html;

// Send the message.

sendClient.Send(message);

// Set return to success.

bReturn = true;

}

catch (Exception exThrown)

{

// If there was an error, catch it and record the last error message. This is displayed in the CMS to the end user based upon the method return value and the setup in the configuration utility. Typically SmtpClient throws an exception if the message could not be sent.

Content.ErrorMessage = exThrown.Message + exThrown.StackTrace;

bReturn = false;

}

finally

{

// Cleanup

if (message != null)

{

message.Dispose();

message = null;

}

if (sendClient != null)

{

sendClient = null;

}

}

return bReturn;

}

}

}

PublishContentChange Sample

The following code sample appends HTML content when it is published.

Warning! Only HTML content can be appended using the OnBeforePublish event. Assets can not appended and there is no error message.

using System;

using System.Collections.Generic;

using System.Collections;

using System.Text;

using Ektron.Cms.Extensibility;

namespace Ektron.Cms.Extensibility.Samples

{

public class PublishContentChange : ExtensionEvent

{

private const string S_APPEND = " ****added by PublishContentChange****";

public override bool OnBeforePublish()

{

// Declare variables

bool bReturn = false;

string sLastError = "";

string sTemp = Content.Html;

try

{

//Check content for the last closing paragraph tag. If one exists put additional text within it. Otherwise just append to end of content.

if (sTemp.Contains("</p>"))

sTemp = sTemp.Insert(Content.Html.LastIndexOf("</p>"), S_APPEND);

else

sTemp += S_APPEND;

// Set content html to our new updated string. This will set it on the CMS side.

Content.Html = sTemp;

// Set return to success.

bReturn = true;

}

catch (Exception exThrown)

{

// If there was an error, catch it and record the last error message. This is displayed in the CMS to the end user based upon the method return value and the setup in the configuration utility.

Content.ErrorMessage = exThrown.Message + exThrown.StackTrace;

bReturn = false;

}

            return bReturn;

}

}

}

InstantMessageOnPublish Sample

This sample plug-in sends an instant message (IM) to any designated AIM user. This sample is made up of various files. To view these files, navigate to the C:\Program Files\Ektron\CMS400SDK\Samples\InstantMessageOnPublish folder.

Use the following steps when working with this sample.

1. Open the config_info.reg file located in the C:\Program Files\Ektron\CMS400SDK\Samples\InstantMessageOnPublish folder and edit the following lines:

- change the SendToUserName

- change the SendFromUserName

- change the SendFromUserPassword

2. Save the file.

3. Double click the config_info.reg to add the information to the registry.

4. In Visual Studio, open the Sample.sln located at: C:\Program Files\Ektron\CMS400SDK\Samples

5. Save and build the project.

6. Navigate to the location of your InstantMessageOnPublish plug-in project.

7. From the Bin folder of the plug-in project, copy the newly created DLL to the following folder on your Ektron CMS400.NET server.

C:\Program Files\Ektron\Plugins\Extensions

Once you have created a plug-in, you can use the Extensibility Configuration Editor to configure how the plug-in will interact with See Also:

(continued in Manually_Creating_Plug_i)


Visit the Ektron Dev Center at http://dev.ektron.com 1-866 - 4 - EKTRON

Ektron CMS400.NET Reference Version 8.02 SP1 Rev 1

Ektron Documentation,© 2011 Ektron, Inc.