#Sitecore’s Data Exchange Framework Reddit Style Part 4

In part 1 you saw what Sitecore items were created to for the data exchange process. In part 2 you saw how the backend was connected and the classes defined in the Converters section. In part 3 you saw how the item models are used. In this part I wanted to talk about the pipeline step processor. The method that brings it all together. You can find the source code here for reference.

This is a snapshot of each folder that was created and the corresponding class file. You can see there is a Processors\PipelineSteps folder that contains the process class.

RedditItemsProcessor.cs

In Sitecore under Pipelines\Reddit Pipeline\Reddit Pipeline Step you will see under Processor Type the RedditItemsProcessor defined.

Below is the code for the processor. You will see that the Required EndpointPlugin is defined for RedditSettings. Endpoint, PipelineStep and PipelineContext should all have values at this point. As you will notice the pipelineContext.PipelineBatchContext.Logger.Info is used to set up any custom logging. This will be outputted in the batch window when the processor runs. See example below.

If you look at the method RedditFeed. What that does is create a new Reddit class using RedditSharp. It then uses the blogpath setting from the endpoint to retrieve the blog feed. The redditfeedresults gets set to a collection of Reddit blogs. From there that collection is passed to the DXF which will use everything we setup to map and process each of the records. It will use fieldnames we defined earlier to match the Reddit feed fields to the fields defined for the new Reddit Sitecore item.

Outputted to the batch window:

Hopefully now you are getting the big picture on how all this stuff pieces together. In part 5 I will get into the part of running the DXF process and different options you can do. Let me know if you have any questions.

#Sitecore’s Data Exchange Framework Reddit Style Part 3

In part 1 you saw what Sitecore items were created to for the data exchange process. In part 2 you saw how the backend was connected and the classes defined in the Converters section. In this part I wanted to talk briefly about the item models that are defined for data exchange framework. You can find the source code here for reference.

This is a snapshot of each folder that was created and the corresponding class file. You can see there is a Models folder.

RedditFeedFieldValueValueAccessorItemModel.cs

As mentioned in the previous blog a ItemModel is used to defined the field name for the Value Accessor fields. Using this method is a good practice if you need to rename the field and makes the accessor code cleaner.

The name corresponds to the filed name of the template used for Value Accessor fields.

RedditReadStepItemModel.cs

As shown in the last blog in the RedditEndPointConverter class the RedditReadStepItemModel is used to correspond to the field name that holds the selection to the required EndPoint. As the previous item model mentioned this a good practice if you need to rename the field and makes the code cleaner.

Sitecore ItemModel class

The ItemModel Sitecore method that this item models inherit from is below.

So this blog was brief, but hopefully it gives a little glimpse of the value of having the item models defined. In part 4 I will get into the pipeline step processor. The most important piece that brings the functionality together. Let me know if you have any questions.

#Sitecore’s Data Exchange Framework Reddit Style Part 2

In part 1 you saw what items were created to for the data exchange process. Now I want to show you some of the backend so you can get a better picture on how they are connected. In this blog I will go over the Converters section. You can find the source code here for reference.

This is a snapshot of each folder that was created and the corresponding class file.

RedditFeedFieldValueAccessorConverter.cs

Let’s start with Value Access Converter. Below is the code.


The TemplateId ({68BD9AAD-635F-40F3-9ACD-711662C59EEC}) being set refers to the following template. This template inherits from the Value Accessor template installed by the DXF package.

So how this corresponds to Sitecore is simple. A Value Accessor Set item is created and the items underneath it use this template. In the RedditFeedFieldValueAccessorConverter class it is setup to get the value of that field using the combination of the template and the field name defined in the RedditFeedFieldValueValueAccesorItemModel. You will see how this is tied in to other parts of the DXF process as we go along.


In the code you will notice a ValueReader and a ValueWriter are defined. The ValueReader is used to read in the feed and match the fields for each Reddit blog item. That uses the RedditFeedValueReader class as you will see in another part of the blog. The ValueWriter DXFines a new PropertyValueWriter class. That class is part of the DXF and used to convert the field values.

RedditFeedValueReader.cs

This class will process the Reddit Post item and match field name with value. Title, AuthorName, SelfText etc… are field names in the Reddit feed. I believe you can name these differently, but I prefer to keep the same name as it is in the Reddit Post item.

RedditEndPoint.cs

The Reddit End Point will have the information for the Blog Path in Reddit. The TemplateId defined points to the RedditEndPoint template. Settings are returned and added to the plugin. The plugin is required to be implemented by the pipeline converter and processor.


This is the model plug in code:


This is values of the Reddit Endpoint. You can see that the Converter Type points to the RedditEndPoint class.

More about this later, but as you can see in the Reddit Pipeline Step the Reddit Endpoint is selected. Now you can see how this all ties together.

RedditEndPointConverter.cs

The converter is one of the most crucial parts of the DXF. This is what ties together the pipeline step of the DXF. The TemplateId is the template id of the Reddit Pipeline step. As you can see the endpoint settings are passed in to the pipeline step.


Looking in Sitecore you can see where they Converter Type points to the Endpoint Converter and also the Processor Type which will get called and receive the end point information and do the Reddit Feed processing. More about that in another blog though.

Hopefully you are seeing how some of this stuff is tied together. In part 3 of the blog I will talk a little about the models which will be a short blog. Part 4 I will get into the processor. Let me know if you have any questions.

#Sitecore’s Data Exchange Framework Reddit Style Part 1

Now that I have been using #Sitecore’s Data Exchange Framework it was time share my knowledge with the rest of the world. For this blog post I will break it up in various parts. Hopefully it will give you a good overview of the DEF and how powerful it can be. I have used for a few different things, but for this example I decided to create something somewhat unique. I will try to keep each blog as short as possible, but there is a lot to cover. I will eventually update each blog with a link to the finished Sitecore module and source code.

First thing you want to do is download the Data Exchange Framework. You can find it here. I installed both the Date Exchange Framework and the Sitecore Provider for Data Exchange Framework.

After that it is a simple right click on the Data Exchange item under System and simple add a new tenant. Below are some of the settings I created and used. This should give you a rough outline on what you should create when doing your DEF feed.

I will go into more detail, but after I was done adding all the stuff for my Reddit feed this is what it looked like:

Value Accessor Sets

  • Used to map feed values from the source
  • Used to map source values to Sitecore

Each Accessor set has a field. I made these fields the same names I was getting from the feed. It made things a little easier to remember. For the list of fields check out the RedditSharp API here.

For the Sitecore field you will use the fields of a template you create. In this case it will be a Reddit item template.

The field value is going to point to the item template of the Reddit feed item. I kept the field naming consistent with the feed.

Value Mapping Sets

To bring those together we will use a value mapping set. This will make the connection from the feed field to the Sitecore field.

Example setting:

Endpoints

In this example created a template that contains settings needed for the field. Template inherits from the endpoint base template. For the Sitecore endpoint I created and used the default values.

Feed Endpoint example:

The converter type points to a created method in the code behind. The method is used to retrieve the blog path.

Sitecore Endpoint example (defaulted values):

After the batch process runs all of the pipeline steps the following will be created in Sitecore. I will go into how this is created in other parts of the blog, but this will give you a picture of what happens. Keep in mind the DXF can be used to do more than just create Sitecore items. Lots of things like external SQL tables, CRMs, MongoDB etc… could be updated.

RedditList

In the next blog post I will talk about how things get tied together. It should make things more clear on why things are setup this way in this blog post. You can find it at Sitecore’s Data Exchange Framework Reddit Style Part 2.

#Sitecore ‘s SaveUI Pipeline One Way it Can Save You from the Cache

Recently I had a bug fix that required fixing a custom tab page in the content editor. The custom page had a save button, but users were also clicking on the content editor save button. Well unfortunately that undid the previous change. The reason why was even though the changes were saved to the database the old values were still being cached.

So after doing some research on maybe refreshing, clearing cache etc… the best way to fix this issue turned out to be was adding a custom pipeline step on the SaveUI pipeline. It was a little a trial and error at first, but I was able to accomplish what I needed to.

First thing is you want to do is come up with a name for your new class and create a config file that will hook into the SaveUI pipeline. Now you have some options here. If you look below the SaveUI has a series of steps that happen in order for an item to save. You just need to find the one you want your step to go before or after.

<saveUI>
<processor mode=”on” type=”Sitecore.Pipelines.Save.BeforeSaveEvent, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.ParseXml, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.CheckItemLock, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.CheckRevision, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.Validators, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.ValidateFields, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.HasWritePermission, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.NewVersion, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.TightenRelativeImageLinks, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.ConvertToXHtml, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.CheckLock, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.Lock, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.CheckBaseTemplateFieldChange, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.CheckTemplateFieldChange, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.ConvertLayoutField, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.CheckLinks, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.Save, Sitecore.Kernel” />
<processor mode=”off” type=”Sitecore.Pipelines.Save.RenderingHack, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.Unlock, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.WorkflowSaveCommand, Sitecore.Kernel” />
<processor mode=”on” type=”Sitecore.Pipelines.Save.PostAction, Sitecore.Kernel” />
</saveUI>

I created a config file and placed it in the app_config\include folder of the website.

<configuration xmlns:patch=”http://www.sitecore.net/xmlconfig/”&gt;
<sitecore>
<processors>
<saveUI>
<processor patch:before=”processor[@type=’Sitecore.Pipelines.Save.CheckRevision, Sitecore.Kernel’]” type=”MySite.Feature.Website.Pipelines.ConfirmChanges,MySite.Feature.Website” />
</saveUI>
</processors>
</sitecore>
</configuration>

The code for the pipeline was simple. Basically I would check for what fields changed and made sure what was saved in the database fields would update the fields in the cache. That way when the save happens the SaveUI pipeline will process the changes and not overwrite anything.

public class ConfirmChanges
{
public void Process(SC.Pipelines.Save.SaveArgs args)
{
Assert.ArgumentNotNull(args, “args”);

if (!args.HasSheerUI)
{
return;
}

Assert.IsNotNull(SC.Context.ContentDatabase, “Sitecore.Context.ContentDatbabase”);
string message = string.Empty;

// for each of the items the user attempts to save
foreach (SC.Pipelines.Save.SaveArgs.SaveItem uiItem in args.Items)
{
// retrieve from the database the same item containing the old values
SC.Data.Items.Item dbItem = SC.Context.ContentDatabase.GetItem(uiItem.ID, uiItem.Language, uiItem.Version);
Assert.IsNotNull(dbItem, “dbItem”);

// for each of the fields in that item (not just updated fields)
if (UsesCustomTab(dbItem))
{
foreach (SC.Pipelines.Save.SaveArgs.SaveField uiField in uiItem.Fields)
{
if (uiField.Value == dbItem[uiField.ID])
{
continue;
}
string title = string.IsNullOrEmpty(dbItem.Fields[uiField.ID].Title)
? dbItem.Fields[uiField.ID].DisplayName
: dbItem.Fields[uiField.ID].Title;
if (title == “FieldName1” || title == “FieldName2”)
{
//if values are the same don’t do anything exit pipeline.
if (!string.IsNullOrEmpty(dbItem[uiField.ID]) && dbItem[uiField.ID] == uiField.Value)
{
continue;
}
else
{
if (title == “FieldName1”)
{
uiField.Value = dbItem.Fields[“FieldName1”].Value;
}
if (title == “FieldName2”)
{
uiField.Value = dbItem.Fields[“FieldName2”].Value;
}
}

}
}
}
}

}
}

That’s it. Let me know if you have any questions.

cache

#Sitecore 8+ #Workflow Comment Box a Much-Needed Upgrade

Back in Sitecore 7 I was tasked with creating a new workflow. I quickly discovered out of the box workflow may not have all the features the client was asking for. One of the main features they wanted was a more intuitive comment box. The current one was just a JavaScript message box. They wanted something that they could put longer worded changes in and images. At that time I had to come up with a custom way to do that. With Sitecore 8 and above they have added this feature out of the box.

When creating and selecting a workflow command now you will notice there are three new fields. Comment Template, Comment Dialog Height and Appearance Evaluator Type (more about this later in another blog).

I created a template to be used for the comments. I kept it simple, but you can do a lot of different fields custom to your site.

I set the command with the following values. Keep in mind that you could have different comment boxes for different commands.

When the command was clicked the following popped up. Simple and nice!

The workflow is such a great and important feature in Sitecore. I am so glad it has been updated in Sitecore 8+. It just goes to show you that Sitecore listens and is always improving their products.

#Sitecore Meetup Chicago Impressions

I finally attended my first Sitecore Chicago Meetup. This is my high level overview in a few words and pictures.

I got dressed for the occasion with my freshly made Sitecore Runner t-shirt. I took the train to Chicago. It is only 1.5 hour commute for me. 🙂 I am the first/last train stop to/from Chicago.

Shirt

I had some time to kill when I got to Chicago and Rightpoint invited me to check out their offices and have a beer. I got to tour their offices and talked a little about my Sitecore experiences and my current company I am at Paragon.

We got to the meeting a few minutes late. After banging on the door since it was locked we were let in. 🙂 The first thing I saw was the food. They served Lou Malnati’s pizza my favorite, along with refreshments and dessert. Regrettably I forgot to take a picture of the food.

The first presentation was “Experience Marketing Presentation: High Level Review of the latest from Sitecore. Lead by Tim Ahlenius (Sitecore Digital Strategist MVP from Americaneagle.com)”. It was great and very informative of a feature that I can see being very useful.

The second presentation was “Sitecore Publishing Service. Lead by Jim Noellsch (Senior Technical Architect from Rightpoint)”. So good to hear about how much the publishing has improved with Sitecore. I know this change will make Sitecore clients happy.

The meetup ended after the second presentation. I can’t wait for the next one. I hope I can eventually do a presentation at one. If you are interested in attending a future one check out the meetup website here. Listen to Yoda.

Yoda (2)

My First #Sitecore Module in the Marketplace

So now the dust has cleared after the Hackathon why not add what we did to the as #Sitecore #Module in the Market Place. I hope the following helps you if you are publishing your first Sitecore Module.

First thing I did was create a new Helix based project that would be used to generate the Sitecore Module. I also stripped off any thing that was not out of the box Sitecore. Such as Glass Mapper. The less dependencies the better.

To get to the Sitecore Marketplace click here. When you get to the page you will see the following.

When you click on Contribute Now the below screen appears.

After clicking on the CONTRIBUTE NOW button and entering in the module name the following message appeared.

Soon after the space was created and added the necessary information under the about and documentation tabs.

I then upload the installation package. The package was then in review.

After that I received an email message letting me know that my changes were submitted and will be reviewed by the marketplace coordinator.

 

So for a week or so I saw this when I checked my modules under my profile.

I was notified a little more than a week later my module was published.

 

Here it is:

https://marketplace.sitecore.net/Modules/R/RSS_Blog_Feed_Importer.aspx

Now I just need to add some more contributors.

#Sitecore and field labels. So many options to render them, but what is the best option?

Discussing programming techniques can be like discussing religion and politics. There might never really be a correct answer, but everyone thinks they know it. In the case of rendering labels (first name, last name, address for example) in #Sitecore we have more than a few options. In my example I have a label called Introduction. I have three different ways to render this field on the site.

The first line uses the Sitecore dictionary. The second is set in the controller from a settings page and the third line is coming  from the home page item.

 @Translate.Text("homeintrolabel")
 @Model.IntroText
 @Model.HomePage.Fields["Intro Text Label"].Value

They all render the same. As you can see below.However which way is the best way to do it?

labelrender2

I prefer using the dictionary to do it. It is quick and easy to render a field that way. I worked for one company that only used a settings item or the content item. Another company I worked for preferred the dictionary. So which way do you prefer?

My Sitecore Hackathon 2017 Adventure

I like things that challenge me. Don’t we all? I have done numerous races all different distances that were very challenging. I even had to give myself some Rocky speeches while doing them. Sure physically/mentally that stuff is hard, but how about doing something professionally/mentally challenging? Enter the #Sitecore Hackathon 2017 #SDHackathon. A 24 hour coding frenzy. Now I have done some all nighters for work at times, but doing something that was going to challenge me to show the world what I could do that is a different story.

sitecore-hackathon-logo

My team consisted of two other developers that happened to be coworkers.Our team name was the X-Men and we named our project WeaponX. Who doesn’t like comics right?

75964729

The contest started at 8 eastern time. We were giving instructions at that time and decided to do a Sitecore module. After brainstorming for a bit I came up with a blog importer. I have done something like it in the past, but never as a Sitecore module. My teammates agreed that is what we will do.

deadpool

So after having an idea in place next was figuring out our parts. One team member would be doing the documentation, presentation and Git Hub setup. The rest of us would do coding, analysis and researching.

One of the requirements of the contest is to make sure that we create the project in a Helix format. Well that was new to all of us. I was able to use a Helix generator though and we had a project started. Meanwhile one of my teammates started creating the Sitecore items we would need. Another teammate was getting the Git Hub stuff ready. I started adding all the stuff to the project that we would need to develop as a team. Such as TDS and Glass Mapper. When the project and Sitecore items were done I was ready to start coding. Before that I did my initial check in though. Always back up your code. 🙂

As it was getting late the team started dropping off. At this point there wasn’t much for them to do as I was full heads down coding. I stayed up until about 3:30 AM central time. I got the code to where I wanted it and made any Sitecore updates I needed to do. There was still a lot to be done though and I was having trouble getting Glass Mapper to cooperate. So I set the alarm for 6:30 AM and called it a night.

In the morning I woke up tired, but ready to go. I did shower and do all the usual morning stuff before logging back on. 🙂 I met with my teammates and gave them my status. Throughout the day we communicated, collaborated and stayed in contact as much as possible. We all have lives though so we had things to do people to see.

It was touch and go there for a while, but finally there was light at the end of the tunnel. We were finally code complete and we had our install package created/tested. There was not much time to spare though. Documentation and video presentation had to be done.

website-is-done-meme

As each minute ticked by we were approaching the final hour. Code, install package and documentation was handed in. However YouTube was taking it’s sweet time rendering the video. It finally finished and we had all the necessary stuff done and handed in. We could finally breath a sigh of relief. Check out our finished Sitecore module presentation here.

Things we learned:

  • Setting up a Helix project.
  • Keep things basic. GlassMapper is nice to have, but getting that going took us more time than if we used standard out of the box Sitecore functionality.
  • You only have so much time. Stick to getting the basics done first. Add the nice have stuff later.
  • The right people make things happen. We worked well together.

So next year will we do this again? I believe the answer is yes.

1kupdn