Content Studio Linkvalidator is a new product in the Content Studio product family. The goal of Content Studio Linkvalidator is to crawl a specified Content Studio site looking for broken hyperlinks and report them to a specified administrator.
Requirements for Content Studio Linkvalidator
- Content Studio 5.2 or later
- SQL Server 2005 Express or later
- An account with access to the Content Studio site where reports should be generated
Installation steps
- Downloading Content Studio Linkvalidator setup
- Visit http://www.contentstudio.se/ and log in to the customer area to obtain the latest version of Content Studio Linkvalidator setup.
- Running Content Studio Linkvalidator setup
-
These are the steps for installing Content Studio Linkvalidator
Step 1 - WelcomeStep 2 - Selecting componentsThe available components are described below- Linkvalidator Service - Copies the service and settings applications to the specified folder. If the service is already installed it is stopped and uninstalled before the new version is copied.
- Create/update database - Executes the necessary scripts against the database to create the needed tables and routines.
- Copy .sql-files - Copies the .sql-files needed for manual database installation to a subfolder to the specified folder.
- Startmenu shortcuts - Creates startmenu shortcuts for the service settings application and for the uninstaller.
Step 3 - License agreementStep 4 - Service accountHere you can specify which account that the Linkvalidator service should run as. This account will need permission to save documents (broken link reports) to Content Studio.Step 5 - Database installationThe database installation page let you specify information for connecting to the sqlserver which will host the linkvalidator database. The account specified need permission to create a new database and tables/procedures under that one. If username and password is left out a connection will be tried using "Trusted Connection".Step 6 - Specifying installfolderStep 7 - Setup progressStep 8 - Finish page - Configuring Content Studio Linkvalidator
-
Service settingsThe service settings application allow you to configure and monitor the progress of the linkvalidator service. The individual fields are described below.
- Start Uri - The document that the linkvalidator should browse to first. It would typically be the sites startpage.
- Content Studio AdminUri - The uri to Content Studio admin (usually something like http://www.mysite.com/cs/). This is needed for the Linkvalidator to be able to save documents to Content Studio.
- Database Connectionstring - A connectionstring that the linkvalidator can use to communicate with the database that was created during installation.
- CS Query prefix - The Query prefix used by the current Content Studio site. In most cases this is simply "id".
- Time between checks - The time that should have passed before a link is checked again in the format hh:mm.
- Number of fails before reporting failed link - The number of times a link has to fail (without succeding in between) before it is reported as a failed link.
- CS Category ID - The category id of the category where the broken link reports should be stored.
- CS Connection ID - The connection id of the site where the broken link reports should be stored.
- Test connectionstring - Connects to the database using the specified connectionstring. If successfull it will return a string saying so which also contains the versionnumber from the database. Remember that if a Trusted_Connection is used it's the current users connection that will be tested and not the one of the service.
- Test saving to CS - Saves a document in the specified category in Content Studio to see that the configuration is correct. This will post it as the current user and not as the user the service will be running as.
- Save - Saves the current settings to the registry. Remember that the service will have to be restarted for it to notice any of the changes.
- Reset - Reads the settings from the registry again, reseting all current changes made since the last save.
- Start/Restart/Stop - Controls the linkvalidator service.
Creating a serverside eventhandler for notifying someone when a broken link is found
The easiest way to notify someone when a broken link is found is to create a serverside eventhandler for the OnDocumentApprove event. Below is an example of such a eventhandler written for Content Studio Linkvalidator. For more information about serverside eventhandlers see this article.
using System;
using System.Net.Mail;
using System.Xml;
using ContentStudio.Document.EPT;
using ContentStudio.Document;
using ContentStudio.EventActions;
namespace ExampleHandler
{
/// <summary>
/// Example handler that sends an email when a document is approved in a category.
/// This was built as an example for Content Studio Linkvalidator and won't work
/// with EPT-categories that doesn't have the specific fields that Content Studio
/// Linkvalidator creates.
/// </summary>
public class SendEmailOnApprove : ICSAsyncEventHandler
{
public void EventHandler(int csEvent,
int connectionId,
string eventXMLArguments,
string customData,
ICSCredentialsContainer credentials,
int timeOut,
out string statusText)
{
try
{
statusText = "Failure";
if (string.IsNullOrEmpty(eventXMLArguments))
{
statusText = "Failed to load eventXMLArguments";
return;
}
XmlDocument Xml = new XmlDocument();
Xml.LoadXml(eventXMLArguments);
Int32 SessionId;
if (!Int32.TryParse(Xml.DocumentElement.SelectSingleNode("sessionid").InnerText, out SessionId))
{
statusText = "Failed to read SessionId";
return;
}
Int32 DocumentId;
if (!Int32.TryParse(Xml.DocumentElement.SelectSingleNode("documentid").InnerText, out DocumentId))
{
statusText = "Failed to read DocumentId";
return;
}
SyncronizedEPTDocument Ept = new SyncronizedEPTDocument(connectionId, SessionId, DocumentId, false);
if (Ept == null)
{
statusText = "Failed to load SynchronizedEPTDocument";
return;
}
if (Ept.ExistsField("Document") == false || Ept.ExistsField("Query") == false || Ept.ExistsField("BrokenSublinks") == false)
{
statusText = "Failed to load EPT-fields from SynchronizedEPTDocument (Document, Query, BrokenSublinks)" + Environment.NewLine + "EptData for document #" + DocumentId.ToString() + ": " + Ept.ToString();
return;
}
string Body = string.Format(@"A broken link was discovered by Content Studio Linkvalidator!
The the page not responding is located at {0} and is linked from {1} pages.
These are the pages that link to the broken one:
", Ept["Document"] + Ept["Query"], Ept["BrokenSublinks"]);
CSSyncronizedDocument Doc = new CSSyncronizedDocument(connectionId, SessionId, DocumentId, CSDocumentInformation.ContentToLoad.DraftOrApproved);
if (Doc == null)
{
statusText = "Failed to load SynchronizedDocument";
return;
}
if (Doc.Content == null)
{
statusText = "Failed to load content from SynchronizedDocument";
return;
}
Xml.LoadXml(Doc.Content);
XmlNodeList nodeCol = Xml.DocumentElement.SelectNodes("CSRecord/LinkingPages/Page");
foreach (XmlNode Node in nodeCol)
{
Body += Node.InnerText + Environment.NewLine;
}
ContentStudio.SettingManager Mgr = new ContentStudio.SettingManager();
if (Mgr == null)
{
statusText = "Failed to load SettingManager";
return;
}
string SmtpHost = Mgr.SettingValue(connectionId, SessionId, "Default_SMTP_Server");
if (string.IsNullOrEmpty(SmtpHost))
{
statusText = "Failed to load Default_SMTP_Server, call failed or value is empty";
return;
}
SmtpClient Smtp = new SmtpClient();
Smtp.Host = SmtpHost;
MailMessage Message = new MailMessage();
Message.Subject = "A broken link was discovered by Content Studio Linkvalidator";
if (string.IsNullOrEmpty(customData))
{
statusText = "Failed to load customData (should be a valid email address)";
return;
}
Message.To.Add(customData);
Message.Body = Body;
Message.From = new MailAddress("linkvalidator@contentstudio.se");
Smtp.Send(Message);
statusText = "Success";
}
catch (NullReferenceException E)
{
statusText = E.Message + Environment.NewLine + E.StackTrace;
}
}
}
}