Blog posts by Oskar Zetterberg2012-09-19T14:03:55.0000000Z/blogs/Oskar-Zetterberg/Optimizely WorldPageTypeBuilder 2.0 with EPiServer CMS 7 Preview/blogs/Oskar-Zetterberg/Dates/2012/9/PageTypeBuilder-20-with-EPiServer-CMS-7-Preview/2012-09-19T14:03:55.0000000Z<p>This is a long overdue post about getting PageTypeBuilder 2.0 working with EPiServer 7 Preview.</p> <p>I´m not sure the changes I made is the best or even correct, but they work. Joel Abrahamsson, please comment on this.</p> <p> </p> <p>Lets begin.</p> <p>Get the source for <a href="http://pagetypebuilder.codeplex.com/">PageTypeBuilder 2.0</a></p> <p>Update the references from EPiServer CMS 6 to CMS 7.</p> <p>Changes have to be made in three files, TabDefinitionUpdater.cs, PageDefinitionUpdater.cs and PageTypeRepository.cs.</p> <p> </p> <p>First up, PageTypeRepository</p> <p>Add a new private member to the class and add a constructor</p><pre class="language-csharp"><code><span class="kwrd">private</span> EPiServer.DataAbstraction.IContentTypeRepository _contentTypeRepository;
<span class="kwrd">public</span> PageTypeRepository()
{
_contentTypeRepository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentTypeRepository>();
}</code></pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>In each of the Load methods (should be three of them) change PageType.Load(arg) to</p><pre class="language-csharp"><code>var pageType = (PageType)_contentTypeRepository.Load(arg).CreateWritableClone();</code></pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
where arg is string name, Guid guid or int id.
<p>Last change IEnumerable<IPageType> List() from</p><pre class="language-csharp"><code>PageType.List().Select(pageType => <span class="kwrd">new</span> WrappedPageType(pageType)).Cast<IPageType>();</code></pre>
<p>
<style type="text/css">.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
to</p><pre class="language-csharp"><code><span class="kwrd">return</span> _contentTypeRepository.List().Select(pageType => <span class="kwrd">new</span> WrappedPageType((PageType)pageType)).Cast<IPageType>();</code></pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>Now, compile and you will get four errors about ambiguous references due to referencing the new EPiServer dll. Clear them up by adding changing </p>
<p>ITabDefinitionRepository to PageTypeBuilder.Abstractions.ITabDefinitionRepository where the errors occurs.</p>
<p>Compile again and you will have a working PageTypeBuilder although there are 78 warnings all of them marking obsolete methods or calls.</p>
<p>That’s it.</p>
<p> </p>
<p> </p><pre class="language-csharp"><code> </code></pre>LinkItemCollection and the danger with StringDelayedLoadThreshold/blogs/Oskar-Zetterberg/Dates/2011/9/LinkItemCollection-and-the-danger-with-StringDelayedLoadThreshold/2011-09-26T17:50:00.0000000Z<p>I have done a company-office-contactperson solution on our website. On a company page you specify in what cities that company reside in the form of a LinkItemCollection. The problem started today after I made a small update to the website (= recycling of the application pool), all the contact options just disappeared. After republish of each of the company pages they reappeared and went away after the next application pool recycle.</p> Back to the development environment for debugging. Checked everything, the value in the database etc. Nothing was wrong. After more head scratching I remembered reading <a href="http://world.episerver.com/Blogs/Alexander-Haneng/Dates/2011/9/EPiServer-CMS-Checklist-Deployment-Checklist/">the deployment checklist by Alexander Haneng</a> (great read btw). I had changed the stringDelayedLoadThreshold from 0 to 50. When I changed this value back all worked like a charm again. <p>It all works fine with 50 as value on the actual page itself but when getting children with either FindPagesWithCriteria or GetChildren extension method I get null returned from the LinkItemCollection property. If anyone can shed some light on the differences I would appreciate it.</p> <p>So be careful setting the stringDelayedThreshold if you are working with LinkItemCollections.</p>Small bug in XFormStatisticsControl/blogs/Oskar-Zetterberg/Dates/2011/9/Small-bug-in-XFormStatisticsControl/2011-09-06T11:39:02.0000000ZHad a problem where the statistics control didn’t render properly when using StatisticsType N (number). After a bit of digging with reflector it all came down to the priavte method GenerateOutputForNumbers and adding the cssstyle attribute to the panel. The calculated number of em is of type float and when that type is converted to string and the value is decimal it will be rendering a “,” when it should render a “.” as css ain´t to keen on commas. <p>I had to build my own control inheriting from the original one with this small change to that private method:</p> <p>panel.Attributes.CssStyle.Add(HtmlTextWriterStyle.Width, num2.ToString().Replace(",", ".") + "em"); instead of panel.Attributes.CssStyle.Add(HtmlTextWriterStyle.Width, num2 + "em");</p>EPiServer CMS6 R2 and broken FriendlyUrlRewriteProvider/blogs/Oskar-Zetterberg/Dates/2011/4/EPiServer-CMS6-R2-and-broken-FriendlyUrlRewriteProvider/2011-04-13T17:00:53.0000000Z<p>Ran into alot of problems yesterday while upgrading our website to the latest EPiServer version, CMS6 R2. The problem: I have made a custom FriendlyUrlRewriteProvider that inherits from EPiServer.Web.FriendlyUrlRewriteProvider that partly stopped working. My custom querystrings was discarded and the link click rendered into a 404 visit.</p> <p>After alot of head scratching and dll and config checking I digged in to the EPiServer.dll of both the new and old version (CMS 6 and R2) and compared the two classes, method by method. Finally I realized that I needed to add an override for the method TryConvertToInternal with the same functionality as in ConvertToInternal (should have been obvious but I intend to always check the easiest solutions last).</p> <p>Now the pager and all the other rewrites works as expected. This might not be the correct way to handle this but from what I can tell it works as it should.</p> <p>Anyone with better solutions are more then welcome to comment on this.</p>