Morten Bock

.Net developer

NAVIGATION - SEARCH

Shared Google calendars on the Nokia Lumia 1020

I just got my new Lumia 1020 which runs Windows Phone 8, and wanted to set up my Google stuff to sync with the phone. I use two factor auth, and after creating an application specific password, it synced up alle my email, and my own calendars.

But my wife's shared calendar did not show up, and given the history of issues between google and Windows Phone, I started searching for a solution. The Lumia 1020 is no longer using Active Sync, so all the old guides were no longer relevant. By pure luck, I stumbled on a post with this link:

https://www.google.com/calendar/syncselect

That will let you select which calendars should be synced when using CalDAV access, which is what the Lumia 1020 is now using.

You might need to remove/save/add the checkbox for syncing calendars for your google account on your phone before it shows up, but I now have the shared calendar in there as well.

I hope this might help out others struggling with this.

Profiling MVC views in Umbraco 6

As you might know, Umbraco 6 includes the MiniProfiler out of the box. This is great, as it gives everyone a chance to figure out what parts of your site might not be performing as well as they could. However, I discovered that sometimes the results that you get can be somewhat misleading, and I decided to dig into it a bit further.

My solution looks like this:

When I ran the profiler on my page, it looked like this:

So, for some reason, it is taking almost 85 milliseconds just to find a view? So I started looking into why it might take time to look for views, and made sure that my application was in debug="false" mode in order for the view engines caching to be enabled.

That didn't help. I was still spending 85 ms for each request. But hey, who needs "TopNav" anyway, right? So I removed the surface controller from my Home view. Now it was just the "DisplayTemplates/Product" view taking time to be found. This is starting to smell.

After looking into the Umbraco source, I could see that it was adding it's own viewengines to the mix, and they had some file IO code in there, so I thought, maybe that's the problem. Then I created my own profiling view engine wrapper, and added it to my project.

Since Umbraco already wraps it's view engines in the default profiler, I had to change it up a bit:

using System.Web.Mvc;
using Umbraco.Core;
using Umbraco.Web.Mvc;
 
namespace UmbMvcMiniProfiler
{
    public class Bootstrapper : ApplicationEventHandler
    {
        protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new MyProfilingEngine(new RenderViewEngine()));
            ViewEngines.Engines.Add(new MyProfilingEngine(new PluginViewEngine()));
        }
    }
}

Great. Let's see which one is the sinner!

WTF? So now it seems that almost no time is spent in the actual view engines? But there are some big jumps in the "from start" column, for each of the products. I'll update my profiler to also wrap the views, and put a profiler step in the .Render call.

Allright, now we're getting somewhere. What could be taking time in my Home view? Well, I'm iterating a list of products, maybe I should make sure that list is a Product[]?

And boom. Turns out that the view engines and the views aren't really that slow. The problem was in my Index action where I was mapping my products. It had (conveniently for this example) a Thread.Sleep() for each product.

So there you go. A way to profile what i actually going on in you views and view engines. Full Gist with the profiling code is here.

I still do not know what the heck is going on with the default profiler, and what it is actually trying to do, but it sure confused me more than it needed to. Looking at the source of it, I still don't know what it's supposed to do?? But I thought this might be handy for others wondering why it takes so long to find their views.

Slides from my UmbDkFest presentation

I had the pleasure of presenting a case about Trollbeadsuniverse.com at the Umbraco DK Festival last week. The talk focused on how we implemented a large site with many languages and editors in Umbraco.

If you would like to take a look at the slides, I've uploaded the PDF here.

Thanks to the Kraftvaerk guys for making a good event, and thanks to those of you who stopped by. Let me know if you have any questions.

The industry of heroes and dreamers

When I was younger, all I wanted was to be a musician. It was a magical thing where everyone seemed to have a common ground, and were creating something from their heart, which would mean something for a lot of people. Anyone can pick up an instrument, and start practicing, and start creating. Some are great, some are not. But anyone can do it.

Everyone who plays has at some point started by plucking at a guitar string, or playing on the piano in the living room. That is the connection between the beginner and the superstar. The very first notes. The only thing between them is effectively the number of notes played.

So you start by playing a note. Then trying to combine them, and as time goes by, you will get inspired by notes that others have combined and shared with the world. Some were played many years ago, and others have just flowed through the ether for the first time. But they are all there to be heard, and inspire those willing to hear them.

Music is a magical industry where some are raised to fame, for one reason or another. Not only among listeners, but also among fellow musicians all over the world. It is an ever evolving art between creators sitting in the wee hours of the morning, trying to bend the notes just right.

I did never become a musician. And at times I think of what it would have felt like to be one. But I've come to realize that being a developer actually has many similarities to what I think a musician experiences.

We are fortunate to be in an industry that is proud to share experience and knowledge between all levels of developers. We all have the opportunity to learn from our peers, be they colleagues, rising stars, heroes or dinosaurs.

It would not be far fetched to find the developer equivalents to The Beatles, Jimi Hendrix, Eminem or whatever floats your boat. Some have set the bar, and some are pushing the limits. And because of the culture that exists in software development, we all get to know about it. Be inspired by it.

I don't know if other industries have the same luck that we do. Will accountants read interviews with the godfathers of accounting? Are there ground breaking wizkids pushing the boundaries of public transport?

I do know, that I enjoy listening for inspiration no matter if it comes from Miles Davis, Bon Iver or Hanselminutes, and I am proud of our industry for creating that possibility.

 

Thanks to Scott Hanselman, for sparking this thought with his conversation with Paul Lutus.

Using inline macros in the Umbraco editor

I've seen the question asked a lot of times on the forum, and it's not always easy to give a good answer to it. "How do I create a macro that works inline in the editor". By default when inserting Macros in the editor, it will force a <p> or <div> tag to be created around it, which means that the macro will always be a block of content.

In some cases however, it is nice to be able to insert a macro that just creates a single word or phrase inside a sentence. It could be a price of a product, a user specific property, or whatever you might need.

So I came up with the below solution. Of course it has benefits and drawbacks. In short:
Benefit:
- Inline macros

Drawbacks:
- You do not get a nice way of entering data for macro parameters
- The preview snippet is static from the moment you insert it in the editor

At the bottom you will find a link to a complete zipped umbraco install that has been set up with this, so you can have a play with it. It's using SQL CE, so should be easy to get up and running.

If you can live with this, then read on :-). First let's take a look at what the result will look like. When you insert a snippet in the editor it will look like this:


In this case my snippet will write the name of the page, and when rendered in the frontend it will look like this:


So, how does this work? There a three parts that we need to set up
1. Create a previewable macro
2. Create an aspx page that renders the preview snippet for the editor
3. Configure the TinyMCE editor to use the snippets with the Templates module

Step 1: Previewable macro

Create a macro with a "preview" parameter. In this case I'm creating an xslt macro, but works just fine with razor or usercontrols as well.


Make the macro aware of a preview state


Step 2: Snippet page

Create an aspx page that will render the macro snippet as well as the macro in preview mode.


My snippet page looks like this. I added the snippet class to a span to make it appear green in the editor. Be aware that this is all in one line to avoid too many spaces in the output when rendered.


Now, for the TinyMCE to be able to reach the page, we need to exclude it from the urls that Umbraco handles. We do this is by adding the folder to the web.config:

Step 3: Enable the templates module in TinyMCE

First we add a few thing to the tinyMceConfig.config file.

The command


The plugin


Allow the umbraco:macro tag as valid html


And add configuration for the templates, so the editor knows which snippets it can get and from which urls.


Then we disable the tidy function in umbracoSettings.config, because that will throw an error when it sees the umbraco macro tag.


Now, go to the Richtext Editor datatype, and enable the newly added templates module.


I also added my own editorStyles stylesheet, but that is standard umbraco stuff :-)

And that is it. Now the macro can be inserted to your text without having to be in a <p> tag. Neato.

I hope this is useful for you. Let me know if you can see any other drawbacks than the ones that I mentioned at the beginning.

Get the demosite here: InlineMacroDemo.zip