Friday, April 1, 2016

Back in the hotel after another eventful day. As tired as yesterday. I’m getting to old for this, I think.

Awesome news during the keynote today. As you’ve probably already have heard by now, Microsoft is going to be including Xamarin for free together with every version of Visual Studio. Yes, every version. That does include the Community Edition, which means that you will be able to develop iOS, Android and Windows Phone apps for free!

Well, you still have to have a mac with xcode installed for iOS. And you need to pay all three the developer fees. BUT! That you would’ve had to do either way.

And best of all - you will use C# for them all. Which is really nice. For obvious reasons.

You still won’t have free access to the Xamarin Test Cloud though. Which I can understand, there’s a lot of infrastructure behind that one! You will be able to buy it as a standalone service and it will be accessible through Visual Studio Teams Services. Nice having everything in the same place, and they showed some real impressive deploy and test functionality for it.

We actually tried out Xamarin for our last internal conference, NAPC15. Personally I really digged it. Awesome being able to share code in between different platforms, and using Xamarin Forms a lot of the UI could be shared as well, cutting down on development time for everyone. Really nice being able to preview the iOS from your windows machine as well with their remote viewer for the iOS simulator.

But, I digress. Back to Build!

Was a lot of talk about Azure today. And about how awesome it is. They now have 30 unique Azure regions and locations around the world, making sure everything is served as locally as possible. Quite impressive!

Another really impressive number is that over 85% of the Fortune 500 companies use Azure in some capacity!

Saw one really cool feature of Azure that I’ve totally missed until now… RemoteApp. You remotely connect straight to an app hosted in the cloud. This means you can access it from whatever device, pretty much. The example I saw was running Visual Studio on a Windows Lumia 950 phone, through Continuum. Super cool!

Angular have had quite a presence during this Build as well. With Angular 2 soon coming out, it’s been a lot of talk about it. Seems rather sweet, they have definitely gotten up the speed even more, and have nice solutions when it comes to precompiling templates on .Net, Java, Node.js and more. They wrote all of Angular 2 using Typescript, which definitely tells us how good Typescript is becoming as well.

I definitely look forward to my third and last day of Build 2016 tomorrow. I can’t wait to see what more goodies we will learn! Until then - Good night America… wherever you are.

Thursday, March 31, 2016

First day of Build 2016 is over, at least for my part. It’s been fun, a bit chaotic, and man… My feet hurt like crazy!

After registering I went straight up to get in line for the keynote. Good call, there were already at least 200 other that had the same great idea - 1.5 hours before it was to start! Pretty much everyone attends the keynote, which is the broader look at what Microsoft has in store for the near and far future.

After some fluff about how they are to empower every person and organization on the planet, and figures about how many Windows 10 installations that have been made (270+ million. whoah!) they dropped the first bit of good news - the Windows 10 Anniversary Update is coming this summer. Seem to have a lot of goodies in that one, for sure! And, it will be totally free. Awesome!

They went on with some news about Microsoft Edge. They will integrate the Windows Hello authentication so you can get to it by some simple javascript api’s. Great for logins to different sites etc - albeit, if people want to log in with their fingerprint there’s already good solutions for it with third party software - that works across browsers. My 2 cents: Good feature, sure, but just another Edge-exclusive api.

Big news for anyone looking into development for the Xbox One! From this summer (and out as a preview TONIGHT) any retail Xbox can become a developer edition by just flicking a checkbox in the settings. This removes the ability to start any games and apps you have installed, but instead you can connect to your Xbox from a Visual Studio 2015 installation and install any Universal Window Platform application to test. When finished with the app, just release it to the store as usual. If marked as Xbox compatible, it will automatically turn up in the Xbox store as well. Pretty darn sweet! You can of course turn it back into a regular non-dev console at any time.

I’m really starting to dig the whole UWP thing. Will have to mess around with that a bit more. You get a lot for free as well, they automatically hook up the controller instead of mouse events etc on the Xbox, and touch on phones/tablets/touchscreens. Of course you can also very easily override it all to tailor it for each device.

They have talked a lot about bots and experts. Experts are essentially your app telling Cortana how she can use it, which keywords to trigger on etc. Seems easy enough to hook up to her. No pun intended. I really like this. Instead of going the route Apple is taking with Siri, as well as Google with Google Now, they let developers around the world extend Cortana as they see fit, and essentially make her smarter by helping out with the brain power. That also means she will become more tailored to you since it’s based on what applications you have installed giving her a boost through experts.

Integrations with Cortana seem to be huge within Microsoft as well. They showed some really cool (and kinda scary) demos of Cortana reading through your emails, looking for things you might have forgotten and automatically add as reminders and calendar events. Did you tell your mom you’ll call her tomorrow instead? Busted; this time Cortana will remind you of your white lie.

Bots are… Well, bots. Satya Nadella (Microsoft's CEO) was talking about a world powered by bots, where conversation is the platform, and voice is the UI. Good examples would be an automated bot taking your order at a drive-through restaurant, and other bots residing inside your favorite messaging app (which of course during Build everyone agrees is Skype no matter what we use otherwise). These bots could trigger on certain keywords, for instance if you talk about being hungry, instantly ask you if you want to order your favorite pizza. Like even easier access to pizza is a good thing for the world.

I can definitely see a lot of potential in this, and it really hit me when they showed a video of a blind man having helped design technology that, with a pair of smart glasses, let him take pictures, and have it described back to him through speech synthesis. Technology helping a blind person to see the world. Simply amazing.

And in other news;

Visual Studio Update 2 was released today.

Hololens is ready, and started to ship to preorder customers today.

Coincidence? I… Think… Not!

Hopefully I have the strength to stand in that humongous line tomorrow and let you guys know if it’s worth the hype or not. If, I manage to keep my sanity after standing in that line. That line. That line scares me.

Friday, February 19, 2016

We keep an internal base code platform at Nansen, which several of our sites are based. We like to think of this as our bread and butter. Meaning, those parts of every project you copy+paste to the next.
Sadly, we have been quite bad at documenting it, or we have been documenting it, but the problem is often that the code examples tend to get out-of-date as code naturally evolve with time.

To alleviate this I wanted to create a way to keep the documentation and examples to support it up-to-date, but also contain readable text. One could argue that an SDK is a way, but SDK's usually contain way too much fluff in the way of tables upon tables of method, property and event definitions. And they are also plagued by the out-of-date example code problem above, as examples are written in the <example>-section of the summary documentation. It is easy to get lazy and forget about an example if a method or class is updated.

Anyways, my colleague Andreas 'Honungsprinsen' Oldeskog used a clever way to document our front-end framework by pulling markdown from github, and generating documentation pages from those files. I wanted to find a similar way, but with c# source code instead. This gave me three problems to solve:

Having code examples that actually compile, and are relevant to the code I want to document.

The ability to easily attach human readable documentation and informational text to said code.

Some way of combining 1 and 2 in order to present it to the developers (hopefully) reading the documentation.

Now, for problem 1, part of the solution was so simple Andreas had to point it out to me: Use tests! I could just write unit tests, they run the actual code, and you can use assertions to verify the examples actually do what you show to the reader of the documentation.

The second part of the solution to problem 1 was finding a way to actually run the tests and present them to the reader. This was solved by using NUnit, and its test runner functionality somewhat hidden away in Nunit.core.dll, an assembly that is unfortunately not distributed along with nunit.framework.dll in the NUnit nuget package. I found it tucked away in a package named NUnit.Runners, and I had to manually reference the assemblies nunit.code.dll and nunit.core.interfaces.dll from my web project designated to run and present the results of my example tests.

The result is a neat list of all our tests and their results, this solved problem 1, neat!
A bonus of this approach is also, since we use Episerver in our project platform, and the documentation/demo site is a basic implementation of said platform, all the service loading for epsierver is already done and the site is running so I can use real data for any code interacting with the site without having to mock my heart out (seriously, unit testing episerver code is 98% service mocking).

For problem 2, I decided to just use markdown syntax in the summary documentation of each test. If a more generic description or informative text was needed, I used the summary documentation of the test class. I also made sure to comment as much as possible of the test method code.

Now, problem 3 was trickier, I needed to somehow parse both the code and summary documentation for my test cases, and present the result. Cue Roslyn! Using the new Roslyn code parser Microsoft came up with, I could easily read a source file, and extract whatever I wanted.

With it, I can call ExampleCodeHelper.Default.GetTestResults("MyTestAssembly.MyTestResultClass") to compile a simple data model (source not shown), with documentation, and test source code. The result looking something like below:

Friday, October 2, 2015

TL DR; On a page property in PageTypeBuilder (PTB) - If you have DefaultValueType =
DefaultValueType.Value, you must have DefaultValue set to something. Otherwise
your site might cause timeout on startup while PTB does it’s thing.

Background

The last months we've had problems with a clients test environment (EPiServer 6) regarding nasty timeouts while PageTypeBuilder does it's update on site startup. I spent some time cleaning the page types from missing/conflicting sort index on properties and removed tons of old page types that weren't in use anymore.

The issue

After the above mentinoed optimization, it felt like the startup ran smoother, but it was all an illusion. Every startup when PTB ran it's update, we got this exception:Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
At first I assumed it was network related since the hosting provider have had problems during this period with their firewall and other network issues.

The solution

After I configured EPiServerLog.config to log level ALL, I began to see the truth.
Just before every timeout error there was the same page property, over
and over again.

Took a while before I saw what was different from the other properties. This:
DefaultValueType = EPiServer.DataAbstraction.DefaultValueType.Value
But no DefaultValue was set.

I corrected this and then updated the test environment. Still got the same error, but now the log told me about the next property that had the same issue, and the next and the next etc.

So I had to go through all the page type properties in the code that used DefaultValueType and check to see if it had the matching DefaultValue or not.

When this was done, took a while, the site has about 100 page types and I found about 10-15 properties that had to be corrected, I updated the test site again and tried to trigged the timeout.

But alas, there was none.

Wisdom

It seems weird that this causes a timeout, there should be an ArgumentException or something further inside the EPiServer.DataAccess-assembly that actually does the page definition update. So when you set DefaultValueType to Value, you have to set DefaultValue to something

For us I think it was a combination of unstable network environment and time consuming PTB update that triggered this timeout. As a developer, at least you can give PTB the best possible conditions so it runs as smooth as possible.

Anywho… if you have weird timeouts on an Epi 6 site. Check the obvious PTB mistakes such as duplicate/missing sort index etc, but also check the DefaultValueType/DefaultValue pairings.

Thursday, September 17, 2015

I was trying to get the intellisense to work in my javascript files in my ASP.NET MVC project, for which i'm using RequireJS and here's how it all worked out.

Working with _references.js

Visual studio is using a file called _references.js to grant you the wisdom of intellisense in JavaScript files. First off, we need to make sure we have our _references.js file where Visual Studio can find it. By default Visual Studio will search for this file in the location "~/Scripts/_references.js" if your'e working with a web project. However if your scripts-folder resides in a different area of your project you can easily change where Visual Studio looks for this file.

The solution was to configure the basePath for RequireJS in the _references.js file, and after RequireJS will handle the dependencies you have in your modules and Visual Studio will grant you IntelliSense.

Code

Decorate your scripts with comments

In Visual Studio 2015, Microsoft has added support for JSDoc. Which is a documenting/comment syntax, and if you use it you get really sweet intellisense in correlation with _references.js. So instead of just getting what functions and properties an object might have you also get information of parameters and types if you choose to write it. Visual Studio also has support for xml based comments to complement your intllisense, but personally i prefer JSDoc.

"the required anti-forgery cookie __requestverificationtoken is not present"

It turns out that we had marked the cookies as secure (as we all should) with the configuration setting

<system.web><httpCookiesrequireSSL="true" /></system.web>

But we were accessing the site with http. So the real underlying error was that last one, “the required anti-forgery cookie __requestverificationtoken is not present”. The site was requesting secure anti-forgery cookies but was getting standard unsecure cookies, thus the tampering exception

The solution, query the site with https or change the setting to requireSSL=”false”