File, New Template

Going back in time, year 2000, Active Server Pages was all the rage, performing server-side magic and integrating with databases with ADO. Tridion had just released version 4.0 and adopted the MS Scripting Host, supporting VBScript and JScript as the de-facto standard scripting languages. We had DTD Schemas, XML, Blueprinting, and re-usable content. Content Delivery was 1 ISAPI filter to render the dynamic links. Life was good.

Today the landscape is very different and complex, with lots of the magic happening on the front-end Content Delivery tier, Context aware web applications serving mobile and desktop devices, running the latest SDL Content Delivery stack.

Today the standard supported template languages from the CMS is almost the same as it was in 2000 – we publish content – .aspx or .jsp files, from the CMS to the Content Delivery tier. We can still use the good old deprectated VBScript language, or the SDL-created DWT scripting tags, or the recent XSLT mediator, if XSLT is your thing. So, you want to stay within the ‘supported SDL technologies and products’ arena – this is it. Not cool.

But, look around and see what the SDL community has been up to, and hang on to your hat! It’s been a very busy last few years in the SDL community and today this is where all the cool kids hang out. .NET MVC – got it, with DD4T, created by Quirijn Slings – with great Forum support (185 questions answered) on StackExchange, classroom training from Trivident, and even a ‘Reference Implementation‘ built BY SDL on top of DD4T, called DXA (as of Feb 2015). Yes, the Reference Implementation is built on top of open-source SDL community software, by SDL, and yet DD4T is community software and not officially licensed or supported by SDL.

Maybe DD4T and a dynamic MVC runtime is not your thing. Your content or design is not changing too often, and your development team is happy with the static publishing model from years past.

If this is the case then the best option today is the Razor Mediator, created by Alexander Klock – again an open-source project, and again the most cool and often used technology on new SDL Tridion projects requiring static template programming, and again not officially supported by SDL. It also has good forum support (50 answers), great documentation with plenty of examples, and is widely used. With this mediator you might publish to a .NET Web Forms site or JSP files to a Web Application.

The good news is both of these solutions play well with the _really_ cool technology SDL has been creating and supporting in the Content Delivery tier. Yes, I’m referring to the pieces that make up SDL Mobile, including the Ambient Data Framework, Context Engine and Contextual Image Delivery. In addition, all of these open source frameworks also play well with other SDL supported software including SmartTarget, FredHopper, and Media Manager.

The community has grown by leaps and bounds in the past 15 years, and today this is where all the cool stuff is happening. It’s great to see so many active members in the community. If you have written your own framework, or built on top of the existing great frameworks out there, please share your solutions so we can together build the great frameworks of tomorrow.  If you’re thinking about using one of the frameworks above, go ahead and embrace these open source frameworks and be part of the community that created them.

These frameworks and solutions would not be where they are today without the time and support of developers at these organizations:  Trivident, Indivirtual, HintTech, Building Blocks, Cap Gemini, SDL and Yabolka.  Also, a big thanks to Nuno Linhares for his continued support of the SDL Community and organizing of the SDL Tridion MVP program.

Read More

Get List of Tridion Publish Targets with Core Service

Using the Core Service we can easily get a list of all the Publish Targets in the system. We might want to do this if we are creating an app to publish items to a target (like the publish window) or if we want to Decommission a Publication Target in an environment, such as when we restore a database from one environment to the next.

The following code will get a list of all PublishTargets available within the context of a Publication. If you want to get all targets in the system then using the Admin user is the best. However, if you want to use the logged on user, then see my previous article to use the Core Service as the authenticated user (for a web app).

The data returned from the GetSystemWideList call changed between 2011 and 2013, and with the code below you will get all the info from the 2013 method. Special thanks to Likhan for the tip on the Tridion StackExchange.

Read More

Using Core Service with Logged On User

The Tridion Core Service is a powerful API that gives us access to everything in the Tridion system. Sometimes we want to use an account with Admin permissions to get lists of items or delete items, for example. However, when creating or publishing items, we often want to do this in the context of the user logged into our Web Application built with the Core Service. This article is going to explain how to use the logged in user to perform Core Service actions and also give you a small debugging tip for Visual Studio.

Creating the Core Service Connection

I use a SessionAwareCoreService client which allows me to impersonate the user only with the username and not requiring a password. However, we do need port 2660 open between my local Visual Studio instance and the server if I debug against the server. Otherwise, if I work on my own local Virtual Machine with Tridion installed, I do not need to worry about this limitation. Then, after deploying to the server, it will work as expected.

Code

Making it work in Visual Studio

This user is normally empty when debugging in Visual Studio and this caused a small issue for me. Luckily, I found this great StackOverflow post explaining the solution. The one that worked for me is this:

“look at the properties of the web project, hit F4 to get the project properties when you have the top level of the project selected. Do not right click on the project and select properties, this is something entirely different.

Change Anonymous Authentication to be Disabled and Windows Authentication to be Enabled.”

Happy Core Service hacking!

Read More

Tridion Event System Configuration Variables

The Tridion Event System is used to automatically perform actions for us when an event is ‘triggered’, such as saving a Component or Publishing a page. While programming our Event System solutions we sometimes need to specify the name of a Schema, WebDAV URL path of a Component, or (gasp) a Tridion URI. We don’t want this in our code and it’s better to have it in a config file. However, the Event System is a ‘Class’ project type, and we can’t simply put an app.config file in the folder and expect it to work. In this article I’ll show a small code sample that will allow you to read values from a config file.

Background

This original code comes from the Mihai’s Google Code solution here: https://code.google.com/p/yet-another-tridion-blog/source/browse/trunk/Yet+Another+Event+System/Com.Mitza.YAES/ConfigurationManager.cs

However, in Mihai’s article the code is fairly complex and has lots of functionality I didn’t need, and instead I prefer a more simple approach for getting the config file and getting a key. So, I’ve give the code a haircut and present to you just the bits you need to store the config values outside the Event System.

Setup:

1. Create a config file and add your appSettings:

2. Name the configuration file the same as the Event System DLL with ‘.config’ at the end. Put the config file in the same place as the DLL. This might be in the Debug folder on your Dev system or in the Bin folder on the Tridion server. For example, TridionEventSystem.dll.config

Code:

Use the GetAppSetting(keyName) method to get your app.config variables.

Caching

If in your Event System code you use static variables they will be “cached” and stay in Scope as long as the Event System is running. If you restart the TCM Service Host and TCM Publisher services then the static variables will be refreshed.

I also use the .Net ObjectCache in the code to cache the values and this would be helpful in case your variables are not static in the Event System class.

External Libraries

Finally, a small note, but the Tridion Event System likes to have 1 DLL, so if you reference any external libraries, or if you create many .Net projects with the solution (that produce their own DLLs) then you will need to put those DLLs in the GAC or use ILMerge to combine them. So, in that case, when possible, use 1 .Net project for the Event System and minimize the abstraction of the layers into their own .Net projects, as is often done with .Net solutions. For example, I created a ‘Model’ .Net project for the Models to share between the Event System and another project, but in the end this proved to be too much of a headache and instead I moved the Models into the Event System project.

Happy healthy hacking!

Read More

OrmLite SQL Server Example

ORMLite is a great example of a framework that does one thing and does it well. If we’re looking for a efficient and solid way to get and put data in a DB within .Net (or Mono) then the ServiceStack ORMLite micro-orm is a great choice. It was created by Demis Bellot. One of the great things about ServiceStack is the high level of support from Demis and you can find many of his answers on StackExchange. In this post I will explain how to quickly setup a connection to SQL Server and add / query 1 row. If you have used ORMLite before this article might not shed any new light into the ORMLite scenario for you. Note that the current version of OrmLite (v4) is paid software and uses a quota system for small projects and evaluations. The license allows a developer to use it for a DB of up to 10 tables for free.

Getting Started

1. Create a new .Net Console Application
2. Add a NuGet reference to OrmLite.SqlServer library

Prepare SQL Server

1. Create a new Database User (if needed) for your new DB.
2. Create a new Database (ORMLite does not do this for you)
3. Give the DB User permissions to the new DB
4. Create the connection string: “Server=Dev2011;Database=ItemInfoDb;User Id=MyNewDbUser;Password=S3cr3tPw;”

Write the code

The below code creates an instance of a POCO, and then saves it to the DB. Note the AutoIncrement data attribute. This creates our PK.

For more in-depth information I highly recommend the official ServiceStack documentation. and ORMLite example here.

Read More

Bookmarklet: Get Schema ID and Title

After my first entry to the Tridion Bookmarklet Challenge, to count items in the Dashboard, here is my second entry: View the Schema ID and Title for a selected Component. Drag the below box to your Bookmarks toolbar. Warning: The first time you use it the Schema Title will not load. However, from the 2nd time it will show. This has to do with the .load() argument and my lack of callbacks. It could probably be improved.

View Schema Info

Big thanks to Peter Kjaer’s StackExchange answer about getting the $models object.

Read More

Bookmarklet: Tridion Count Items in View

Have you ever wondered how many items are in this folder or Structure Group and wanted an easy way to count them? In the good bad old days of IE6 and Tridion 5.x we could see the amount of items selected in the status bar at the bottom of our browser. Today I don’t know if they removed that feature or it’s disabled, but in Chrome and Firefox I don’t have a way to see how many items are in a Folder or Structure Group. I often want to know because I am writing Core Service scripts to process all items in a folder and it is helpful knowing how big it is. Otherwise, it is sometimes interesting to see how many images, templates, schemas, etc are located in the system and having a simple ‘count’ of the items would be helpful.
Tridion Item Count
Install: Drag the box above to your Bookmarks Toolbar. When the Tridion GUI is open, select the bookmark to see the item count.

So this is my official entry into Dominic Cronin’s ‘Bookmarklet Challenge’. Although my Bookmarklet is simple, I believe it contains the essence of a Bookmarklet, something small and provide a useful value to those who use it.

Bookmarklet

Special thanks to Alexander Orlov, aka UI Beardcore, for the much needed help in getting access to the Dashboard in a nice, clean way without hardcoding the array position of it.

Before developing the Bookmarklet I had to consider what kind of feature to build with a Bookmarklet. The first thing to consider is the ‘context’ in which the Bookmarklet will be run. For example, when I have the Tridion GUI loaded, the context is what I can see in my view: Publications, dashboard items, and the ribbon menu bar. Another example could be the selected item, and this would then be our context and we could call WhereUsed, get Blueprint children, or access other private details of the selected item that are useful for our users. Finally, we can also perform actions with the Anguilla GUI, so if our context is a selected item, we could then do something to it.

A previous Bookmarklet created by Dominic Cronin, with code from Alex Klock, and inspired by my Stack Overflow question, allowed us to clear the MessageCenter warnings and notices in the Dashboard. Recently Roel van Rozendaal wrapped up this functionality into a pretty Chrome Extension, added it to the Chrome Webstore, and made a nice blog post of how he did it.

Only a few days left in Dom’s Bookmarklet Challenge. Good luck and may the browser be with you!

Read More

DD4T Training

Want to have a DD4T Application running within 1 hour? Not possible? Today I did that at the first Tridion DD4T training taught by Quirijn Slings and hosted at the Trivident office in Amsterdam. In this course we start at the very beginning and throughout 2 days go very deep inside DD4T and learn not only how to do many things, but why they were created that way in the first place!

The atmosphere of the course is similar to other SDL Tridion courses I have attended or taught, informal and focussed on the participant. Quirijn was kind enough to entertain all of our questions and comments, providing real-time coding examples or on several occassions diving deep into the DD4T Source code to show us how it was built and why it behaves in a certain way. This is priceless and the information is not found anyplace else.

On the first morning Quirijn gave us an overview of the DD4T concepts and why the framework was created. Shortly after this he led to us create a DD4T project from scratch, and it felt effortless. I’ve spent a lot of time previously creating DD4T projects from scratch, and nothing compares to how easy it was in the class. Small tips from Quirijn saved us many hours if we were to do this alone.

Later in the day we created Page views and Component views and the exercises were very easy to get into and the environment supported us very well. The exercise content of the course is really nice, with animals imported from a BBC website, making it feel like a nice training environment. Our new views looked great on the screen with the nice content. We used Visual Studio 2013 and MVC 5 to create our solutions.

Day 2 was more in depth than day 1 and we looked into the link level logic and were given some best practices and real-life examples of when to use what link level and the implications of it. We also went over publishing sitemaps, resource files (resx), and also hints about what is coming up in DD4T 2.0. We had a long discussion on caching with DD4T and the different approaches to be used for caching.  Finally we learned how easy it is to make Preview work in DD4T (it really is easy) and see this article from Quirijn on the Trivident blog.  He also showed us how to read a configuration file from a Compound Template and wrote another nice post here.

We were also given many tips that will save us hours of time during real projects. Below I will outline some of the tips he shared, but for the full experience I highly recommend to attend this training.

Minimize XML in DD4T

– Removes Publication, Folders (saves 30%)
– JSON publishing coming in DD4T 2.0, using compressed JSON

Template Builder Popup- to select Folder or Structure Group

– Using Template Builder, when creating Template Metadata fields, starting the XML fieldname with ‘sg_’ or ‘folder_’ allows us to select the items from the Template Builder!

RenderedContent in DD4T

– RenderedContent property contains the output if it is not DD4T XMl. The DD4T TBB examines the output of the Component Presentation, if not DD4T XML, puts in RenderedContent

Resources

– Resx is published to DB
– In web.config, tell it to use the DD4T Resources provider
– Resource page path defined in the web.config
– Need to create our own TBB to publish the resx file. Reason is that DD4T does not want to imply the structure of the Key/Value Schema you need to use in Tridion. There are many different aproaches to store key/value fields.

Index Pages with DD4T

Index pages with DD4T using custom controller and action method. This allows us to easily query the Broker directly or another external system and the Component on the page is a ‘placeholder’ that says directs the Page to output the results of the Query where the Author places it.

– On the CT Metadata, add 2 fields for the name of controller and name of action. XML Names are:
– controller
– action

Summary

This training will help those without DD4T knowledge get up and running very quickly. It also will provide information and tips for seasoned DD4T experts including in-depth caching explanations, using Broker queries with DD4T, link-level philosophy, and ideas where DD4T will improve in the future. Finally, SDL is showing increased support of the DD4T framework, with the inclusion of it in the Tridion Reference Implementation, using it on SDL.com, and also recommending it for current and future customers. It’s here to stay and now we have a great place to learn more about it in person.

Read More

Tridion Circular Reference Redux

What’s a Tridion Circular Reference and why worry about it? As it’s name suggests, it’s a link that results in a circle of endless self-referencing. This normally isn’t a problem…unless you have a template that does a loop through all the fields, and all the fields it contains, and the ones that the linked one contains, etc. You get the point…it’s possible to have a never-ending loop of links to ourselves. This happened recently on a project where we had a Multimedia Schema, with a Metadata field allowing the same Mutlimedia Schema (relatively sane, right?) for a mobile variant of the image. Then someone linked to itself (I guess they didn’t have a special Mobile version, and felt they must put something in the field) and then our looping template did its best to find all the linked items, and well, it died every time we published a page with this special scenario.

The error message we got was:
Faulting application name: TcmPublisher.exe, version: 7.1.0.1290, time stamp: 0x527d103f
Faulting module name: System.Xml.ni.dll, version: 4.0.30319.18033, time stamp: 0x50b5aabe
Exception code: 0xc00000fd
Fault offset: 0x0000000000178ab2
Faulting process id: 0x8d4
Faulting application start time: 0x01cfc009cc4fea09
Faulting application path: D:\Tridion\bin\TcmPublisher.exe
Faulting module path: C:\Windows\assembly\NativeImages_v4.0.30319_64\System.Xml\4334f45efbe62a6415f2cb7393c59f74\System.Xml.ni.dll
Report Id: d1521031-2c31-11e4-9507-0a7ec577d18d
Faulting package full name: 
Faulting package-relative application ID:

The fix I am using involves creating an Event System solution to detect OnComponentSave, in the initiated phase, if the Multimedia Component’s MobileImage field links to itself.

And if so, throws an exception, not allowing the content to be saved. And in the process, we save the Publishing Renderer from exhausting itself with endless links.

Code:

Read More

Tridion Publish Queue Monitor

Publishing is at the heart of every Tridion implementation – and when it breaks, I feel a bit sad inside.  Recently I had a strange content scenario breaking the Publisher service (and the TcmServiceHost.exe in Preview).  This happens about 1 time every 2 weeks or so, but when it does, it’s painful.  A seemingly normal Multimedia Component could cause this to happen, and we had no way to predict it.

Scenario:

1.  Publishing a Multimedia Component (linked to Page) gets stuck at the ‘Rendering’ phase and will not continue or fail.
2.  All other pages after this remain waiting in the Publish Queue.

To fix it:

1.  Remove item from Publish Queue
2.  Re-start Publisher

Troubleshooting the problem:
1.  Remove the Multimedia Components 1 by 1 until the problem one is found.
2.  Create a new Multimedia Component, using the same image, and replace the old broken Multimedia Component
3.  Re-Publish

We are still looking for the root cause.

In the meantime, we need a way to make sure the Publish Queue does not get stuck.

The Solution

Create a Windows Service that scans the Publish Queue at a regular interval (ie. 5 minutes) and if an item is in Queue for 2 intervals at the same phase, it’s stuck.  Remove the stuck item from the Queue, restart the Publisher service, and email an Admin.

Source Code

The Source Code is on GitHub at https://github.com/rcurlette/TridionPubQMonitor

Main class:  https://github.com/rcurlette/TridionPubQMonitor/blob/master/TridionPubQMonitoringService/TridionPubQService.cs

To Run:
1.  Download Source Code
2.  Add the Tridion Core Service DLL and Config to dependencies folder
3.  Update the app.config with your username / password for the Core Service
4.  Add mailtrap.io settings for sample email
5.  Compile
6.  Open Command Prompt (Run As Admin)
7.  Run ‘InstallUtil.exe TridionPubQMonitoringService.exe’
You can run this on the .exe file built from your Visual Studio in the bin/Debug folder
8.  Start the Service in the Services Control Panel.  Look at the Tridion Event Log for messages about starting, stopping, etc
9.  To recompile, stop the service, uninstall it ‘InstallUtil.exe /u TridionPubQMonitoringService.exe’ and then compile and install

Tips:

– Change the Phase to a phase that items stay in for more than 5 minutes while testing.  I had a lot of pages going to ‘Failed’ on my local Dev box, so I set it to that phase.  But if your Dev server is in better shape than mine, maybe you would want to change that to ‘Success’.

– You should see the items disappear from the Publish Queue at some moment (after 2 time intervals have passed) and also a message written to the Tridion Event Log.

 

Read More