3

We have a Windows service running on CD Server, which is scheduled to run daily. This service basically does some database interaction and send details in email to registered users.

An earlier mail template was created in Tridion and published on the file system, this service they were using that template to send emails. (The template path was configured in a service configuration file.)

Now, as we have moved to DD4T, the mail template will be published as JSON in the Broker; as we didn't change the Windows service logic, our Windows service still needs that template file available in CD Server. To make it work temporarily we deployed the email template file on CD Server. (So now the Email template is not coming from Tridion anymore; it's a file which is already deployed in the server.)

But, now as we have time, we decided to fetch the email template from the broker in my Windows service. So that it should come from Tridion only. I can see two ways to do this:

  1. Add the Tridion DLLs to the Windows Service, create a class for the mail template, make a broker query to retrieve the page data as JSON, then parse it to the newly created email class.

  2. Add the DD4T DLLs, create a class for the mail template, use the DD4T Framework to fetch JSON from the Broker, and parse it to the newly created email class.

My first question is in both approaches, somehow I have to create the view which will use this model, but I am not sure if this is really possible to use HTML with a model in a Windows service.

The second question is: can I use DD4T on a Windows service (I believe I need a controller to initialize DD4T objects like page factory and all), so is it possible to use the DD4T Framework on Windows service, or I should go with my first approach that is making a broker query?

If I can't make it a view in Windows service then I am thinking to publish an HTML template (with HTML using DWT as it was earlier) to the Broker, then I can use this HTML in my Windows service using the first or second approach above.

2 Answers 2

5

You can use DD4T for this, with two caveats:

  • Don't reference DD4T.MVC4 or 5 (this won't work in a Windows service)
  • Don't use Rich Text fields in your model (regular text and other types work)

This is because Rich Text fields must be modeled as MvcHtmlString, which brings in MVC.

3
  • Thanks @quirijn . we have Email template as a Page in Tridion. If i Use DD4T or CIL ,in both the cases my Html Should be in Broker ,so i still need to use DWT Template to generate html , because if i use dd4t templates in tridion, I cant pass my model to view in Window service , as there is no view concept in windows service. if my understandings are correct ?? Oct 31, 2018 at 11:04
  • Also, if i go with DD4T then i have to create controllers, and have to initialize DD4T Onject using dependency injection in windows service ? Oct 31, 2018 at 11:08
  • If this is just for generating an e-mail newsletter, I would agree with Velu. Creating a DD4T application just for that purpose would be over-engineering it.
    – Quirijn
    Oct 31, 2018 at 21:19
2

My recommended approach go to option 1, It's simple to use SDL Web CIL, It's simple to create broker query API to get your Email Template and do your business logic with your existing windows service.

Reference to Quick start CIL

I hope it helps.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.