Thursday, October 15, 2015

Azure Cloud Naming Conventions

The Last few years I have worked more heavily on creating cool stuff in the Azure cloud.

One problem when working in an enterprise company is that there is a lot of people (developers, devop's and operation engineers) is allowed to create their own services and solutions, and this can be very messy if you don't have any convention's.

So the main purpose of naming conventions in Azure is to get a better way to navigate and maintain system and services hosted on Azure. This will also get a more detailed and clear overview in regards to billing and usages of their services.

Me and my team have made the following naming conventions, that is used for services in all environments on Azure: 

{Environment}-{Purpose}-{component}-{geographic zone}-{datacentre}-{company}-{service} 

This gives the following abbreviation naming pattern: 

Note:It is not all azure services that is able to follow the naming pattern. There are services that do not accept “-“, for example the azure storage accounts. The last example shows how the pattern would looks like without “-“.


·         prd-dvc-eu-n-wdx-asp is a app hosting plan for the production environment for the dvc project (dvc is an abbreviation of devices) in Europe North data center.
·         stgdvcdcoeuwwdxst is a storage account for the staging environment on the dvc project and is specific for the component datacollector service.

 Geographic zones and datacentres

There should always be a default Datacentre to use. Example EMEA North, if there is a need to have failover or has a need to bring data closer to countries, you can split them of in for example three different geographical zones. Every geographical region has a primary datacentre and a corresponding failover datacentre. if you think of having you default datacentre in EMEA I will recommend EMEA West, it seems that new services is available sooner in west than in north. 

• Americas defined as [us-e] or [us-w]
• EMEA defined as [eu-w] or [eu-n]
• Asia-Pacific defined as [ap-s] or [ap-e] 

Geographical zone
Primary or failover
Americas East
Americas West
EMEA North
Asia-Pacific Southeast
Asia-Pacific East

 Azure services 

Short list of the Azure services can be identified by an abbreviation, here is a short list to get an idea.

Website (obsolete)
Web App
SQL Database
SQL Server
Resource Group
App Service Plan (old web hosting plan)
DocumentDB Account
Virtual Network
Cloud Service
Azure Service Bus
Virtual Machine
Virtual Images
Virtual Images

Azure environment setup

There are 4 different environment setups in our azure naming conventions. They all have their own abbreviation.

1.     Production This is “live” and is actively being used by customers. This is running on real data and exist on the azure production subscriptions.
2.     Staging this is a validation system that new features are evaluated in before final approval and roll-out to the production system. This is running on data as close to the reality as possible.
3.     Testing this is a system for trying out newly developed features that might not be fully completed. This is running on testing data.
4.     Development this is the playground for developing and explore new things on the Azure platform, and can be removed without further notice.


Hope you think this information was informative, and if you have any suggestions or other ways of doing this, please let me know.


Thursday, May 15, 2014

Why Enums? Example in TypeScript

it's been a while since my last post, this it not because I don't have anything to write about! I have just been busy. since my last post I have created a new site called this is a weekly compiled neews of whats going on in the TypeScript world, so if you have anything to share, please give me a note.

In this post I going through what an Enum is designed to solve, and then how to writing a simple Enum. I also going to show the difference between constant and computed member types.

Why Enums Sometimes as programmers we want to express the idea that a variable will be used for a specific purpose and should only be able to have a small number of values--for instance, a variable that stores the current direction of the wind might only need to store values corresponding to north, south, east, and west. One solution to this problem might be to use a number and some define'd values:

 var NORTH_WIND: number = 0;  
 var SOUTH_WIND: number = 1;  
 var EAST_WIND: number = 2;  
 var WEST_WIND: number = 3;  
 var NO_WIND: number = 4;  
 var wind_direction: number = NO_WIND;  

The problem with this approach is that it doesn't really prevent someone from assigning a nonsensical value to wind_direction; for instance, I could set wind_direction to -1 without any complaints from my compiler.
var NORTH_WIND: number = 0;
var SOUTH_WIND: number = 1;
var EAST_WIND: number = 2;
var WEST_WIND: number = 3;
var NO_WIND: number = 4;

var wind_direction: number = -1;

And if I looked at the type of wind_direction, i would see that it's just an integer, and this can be hard to see that something is wrong.

So the idea behind enumerated types is to create new data types that can take on only a restricted range of values. These values are all expressed as constants or computed types

Constant members declared with an integer value is assigned that value. A constant member declared without an integer value is assigned the value of the preceding constant member plus one, or the value zero if it is the first member in the enum body. The values of constant members are computed at compile-time and may be substituted for references to the members in the generated JavaScript code.
So here is an example of a enum with constant member types.
enum Windirections{
North = 0,
South = 1,
West = 2,
East = 3,
none = 4

Enums in TypeScript also support making computed members Expressions, specified for computed members must produce values of type Any, the Number primitive type, or an enum type. The values of computed members are not known at compile-time and no substitution is performed for references to computed members. heres is an example of a computed member called SoutEast where I assign it the values of South and East.

enum Windirections{
North = 0,
South = 1,
West = 2,
East = 3,
none = 4,
SoutEast = South + East
Conclusion We’ve seen how enums in the TypeScript language can be used to allow to constrain the values a variable takes on. I shown how to make constant and computed enum members. Enums can make your program more readable by eliminating magic numbers.

Thursday, March 6, 2014

AX 2012 X++ compilation from a .NET developers perspective

The last month or two I have been “forced” to look at X++ and AX2012, and getting started writing X++ is easy, if you have a background as a .NET developer.

When you start writing and compiling code in AX, you quickly get frustrated as a .NET developer. Why does it not work, - my “compilation” did not throw any errors! It works when I run the job manually, but automatically I does not!

So I realized that there was some fundamental AX2012 that I did not understand as a .NET developer, and much of the frustration was due not understand how the AX compiler works. For many (if not most!) developers this might not be a problem at all, or at least to at some point. In my case it was from the beginning.

I will try to explain how I understand as a .NET developer how the X++ compiler and runtime execution works.

At a high level, the process of compiling and X++ is illustrated in this diagram.

When you are compiling in AX, you don’t compile directly into .NET CIL, it only compiles to p-code. CIL is generated by actively choosing to generate it - either incrementally or full (full generation takes maybe 10-15 min). The Compilation results in P-code are stored in the model store (SQL database). 

Depending on the entry points your code will either be executed either directly in p-code or in CIL. From P-Code you can also easily switch to CIL execution – which is what the application does in most of the more complex proceses. However much code is still executed I P-Code.

Compilation is a three-phased process requiring all code fragments to be received from database (model store). “the three-phased process”, can be read in greater detail in this post:

Phase1: Limited compile only for metadata "class declarations and method signatures"
Phase2: Full compile for metadata and code bodies.
Phase3 to PhaseN: Recompile the error elements, until success or error stabilization.

I have tried for fun to create a detailed diagram, but sometime it’s just easier to tell by code, rather than a diagram :-) decide yourself. First you see the example

First I show a diagram and next a good C# pseudo code example.

C# pseudo code example, borrowed from the post

// Phase1: Limited compile only for metadata
// (of class declarations and method signatures).
foreach(Element in AOT)
// Phase2: Full compile for metadata and code bodies.
foreach(Element in AOT)
       compileSuceeded = Element.Compile();
       if (compileSuceeded == false)
// Phase3 to PhaseN: Recompile the errored elements
// until success or error stabilization.
if (ListOfBadElements.Count > 0)
              foreach(Element in ListOfBadElements)
                     compileSuceeded = Element.Compile();
                     if (compileSuceeded == false)
              if (ListOfBadElements.Count == NewListOfBadElements.Count)
                     break; // The list of elements with errors has been stabilized.
              ListOfBadElements = NewListOfBadElements.GetCopy();

So what is the different between p-code and CIL? In short: p-code is lazy regarding type-checking and CIL is strongly typed, the same way as when your C# code has been compiled to CIL.

p-code is the byte code, which been compiled from X++ by the AX compiler.
First when I started writing this post I was comparing p-code as JavaScript? Because of the less restrictive type checking at runtime than compiled CIL has, but this is not true! After some good discussions with Achim (Dynamics AX Technical Architect) and Stig (Consultant), I concluded that we are not playing around coding in byte code (P-Code) but you do in JavaScript. P-Code runs in interpreted mode on either the client or the server.

Batch jobs and the Business Connector always run in CIL code, and CIL can run on both the server, or the client. CIL runs on the CLR infrastructure, which is much faster than the interpreted p-code.

Be aware when using interpreted P-code
The last thing I want to mention in this post is to be aware when using interpreted P-code. It has less restrictive type-checking at runtime than compiled with CIL, and this can cause your problems. I have probably found an AX bug where a method requiring a sub-type argument but actually getting a super-type instead. This can work fine in p-code, if the code is not calling something that is sub-type specific, but would give you and error in CIL because it’s strictly typed. And this will raise an “unable to cast the super-type to a sub-type”.

Sunday, January 19, 2014

Preconf at the Warm Crocodile Developer Conference

The Warm Crocodile Developer Conference (WCDC) is normally 2 days, but this year Microsoft held a preconf the day before, so 3 days of geeking, speaking and drinking beers at nørrebro brewery, pretty nice!

Before I go into more detail of the 3 days I will give a special thanks to Thomas Jespersen from spiir to crash at his hotel room after a lot of beers sponsored by my awesome consultant Stig from copenhagensoftware.

There were 3 sessions at the preconf

Visual Studio 2013 by Luke Hoban, Microsoft
He came allround the Visual Studio, he talked about the new era of Visual Studio has changed from being single developer focus to be more team based, by adding more client + developer services running in azure.
Then he demoed a lot of "new" stuff in VS 2013.
  • Created simple web project and showed the new way of choosing project type
  • Showed async on the mvc controller
  • Browser link and web essentials how use the browser as our designer.
  • And deployed the website to azure and attach the debugger

F# Applications: From domain model to user interface by Tomas Petricek, PhD student, University of Cambridge
Tomas talked a lot of F#, and I was very curious about this because I never written a single line of F# code before.
He started by being really fundamental by showing a few sites ( to look at when you start out, he also mention that there is a local F# UserGroup starting up in copenhagen. Last he show how to make a Simple application checkout counter. I was pretty amazed by how few lines of code you needed to write in his demo.

ASP.NET MVC & WebAPI alongside AngularJS by Scott Allen, CTO at Medisolv
In the last session Scott showed us how to make a Single Page Application with WebAPI, Angular JS and the Entity Framework 6, and using the new standard MVC 5 template.

After the sessions there were free beers at nørrebro brewery. Henrik my boss, Stig from Copenhagen Software and I started enjoyed a few beers while talking about what presentations.

Stig to the left, Henrik to the right

After the free beer's ended, Henrik went home. Stig and I enjoyed the rest of the evening with a few other guy's with some more beer's, thanks for a great day everybody!

Sunday, January 12, 2014

What does being an MVP means to me.

My MVP lead asked, if I would answer a few questions about being an MVP, and thought of sharing the answers on my blog.

So here it is.

Tell us a little about yourself.

My name is Ronnie, I am a senior .Net developer/Technical Lead and been working at Widex for almost 3 years now. I have played around with .NET since the betas; think it was called “ webmatrix” 2000-2001. My passion for Microsoft technologies slowly grown since then.

What inspired you to be active in the community?

My “Microsoft” community activity started for about 8 years ago, thanks to the umbraco community. What inspired me was the feeling of being part of a family, and there always was a few people willing to help with your problems. The last few year’s motivation has been from TypeScript, Azure and ALM.
Being and MVP inspires me to be even more active spreading my passion of Microsoft Technologies.
It makes me proud to be a MVP, and acknowledge my work in different communities, it's an award I never thought was possible to achieve.

Brag! Tell us about something great you have been working on lately (either community-related or as a technical expert).

Since TypeScript was announced, I have had a lot of focus on that. Start writing a book, and in september I gave a talk “TypeScript kata: the TDD style” presented with Visual studio to Linux/php/opensource beer drinking geek user group (called brewww). We had some heavy discussions - they were not Microsoft fans! Nevertheless, in the end they actually began to see the potential of visual studio, and that it´s free J they will probably have an IDE bitch fight event later this year, I hope they will invite me, so I can convince them all to use visual studio!
The next cool thing that I want to do is making a visual studio extension like ncrunch, just for typescript.

What is, in your opinion, the greatest advantage of being a Microsoft MVP?

To know what the future of Microsoft brings to the table by being involved in the Microsoft product development process by attending the MVP PGI events and the MVP summit. Another great advantage is being part of a new community, and getting new friends that share some of your own passions.      

What would you recommend to people who aspire to be an MVP? 

To be an MVP the most important is to have passion for Microsoft technologies, and use a lot of time in the community by, answer questions, writing books, blogging, teaching, give talks at conferences/user groups or making some new cool products that make Microsoft technologies even better. In my opinion, a good blend of it all, but in the name of your passion to Microsoft Technologies.

Friday, December 13, 2013

Integration testing Azure Active Directory

This post is my history of how I got from not knowing how Azure Active Directory (AAD) to write some integrations tests with MSTest

Last week I had to investigate if Azure Active Directory was an option for my company’s next Web project and future applications. I started to play around inside the Azure Portal to see how that works, and must say that was very intuitive and easy to use- so I won’t cover that in this post.

Now that I had the fundamental understanding on how the AAD worked in the Azure Portal I needed to figure out how I could work with the data through code. I asked Magnus Mårtensson  aka @noopman on twitter (who is Windows Azure MVP) what frameworks to use, and he suggested that I should look at the Windows Azure AD Graph API. The API helps developers execute create, read, update, and delete (CRUD) operations on Windows Azure AD objects such as users and groups. Just the thing I need!

I thought that I could download the files via Nuget, but I wasn’t able to find it, and after some googling I found and MVC Sample App for Windows Azure Active Directory Graph the solution also included the WindowsAzure.AD.Graph project.

This was pretty cool, I could browse through all the code and understand how it all fits together. But why are example code often presented using a web or windows application? Why not just cut of all that web/windows crap and presented the code in small unit tests? This way you can easer understand what it takes to do a specific task with an API.

Prequisites you need to know how to setup an application in AAD if not got here

Enough talking let’s make the tests happens!


Create a unit test project, in this example I’m using MSTest. Make references to the following dll’s (the dll’s can be found in the WindowsAzure.AD.Graph project)
  • Microsoft.Data.Services.Client.dll
  • Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
  • Microsoft.WindowsAzure.ActiveDirectory.GraphHelper.2013_04_05.dll


Be sure that your application Azure Directory Access need to be SINGLE SING-ON, READ AND WRITE DIRECTORY DATA
First Create a GraphServiceHelper class, in this code you have need to specify the
tenantName: example

ClientId and Password
The clientID and password you can find in AAD under the applications “Enable your app to read or write directory data”
public static class GraphServiceHelper
        public static DirectoryDataService Create()
            var tenantName = "";
            // retrieve the clientId and password values
            string clientId = "XXXXXXXX-XXX-XXX-XXX-XXXXXXXXXXXX";
            string password = "v4J4p5gHnUeb437Mu4fzLP7e9Oo529ycpE3CNbA104g=";
            // get a token using the helper
            AADJWTToken token = DirectoryDataServiceAuthorizationHelper.GetAuthorizationToken(tenantName, clientId, password);
            // initialize a graphService instance using the token acquired from previous step
            var graphService = new DirectoryDataService(tenantName, token);
            return graphService;


Now were ready to write some tests, to get started and make sure that you have connection to your AAD write a simple test that get all the users that exist in you AAD. (In my case I have created a few users, so I know that I have more than 2 users in the AAD)


private DirectoryDataService DirectoryService{
      get { return GraphServiceHelper.Create(); }

public void ShouldHaveMoreThanTwoUsersInAAD()
            var users = DirectoryService.users;
            Assert.IsTrue((users.ToArray().Length >= 3));

When this test works, let’s try to create a new user.


public void CanCreateUser()
                             DirectoryDataService dataService = DirectoryService;
                             string alias = Guid.NewGuid().ToString();
                             User user = new User();
                             user.displayName = alias;
                             user.userPrincipalName = alias + "";
                             user.mailNickname = alias;
                             user.passwordProfile = new PasswordProfile{

                                                                                                       forceChangePasswordNextLogin = false, 
                                                                                                       password = "Myy%1982"
                             user.accountEnabled = true;
                             User newUser = DirectoryService.users
                                                          .Where(usr => usr.userPrincipalName == alias + "")

Run the test and got to see the success and go to you AAD to verify it.
Now that we have created a user let’s update the userprofile, by Finding the UserPrincipal of you newly created user in the AAD, and use that instead of the USERPRINCIPAL in the following code example.


public void CanUpdateUserDepartmentName()
                             DirectoryDataService dataService = DirectoryService;   
                             User user = dataService.users.Where(it => (it.userPrincipalName == USERPRINCIPAL)).SingleOrDefault();
                             string departmentName = "IT Department_" + DateTime.Now;
                             user.department = departmentName;
                             User newUser = DirectoryService.users
                                                          .Where(it => (it.userPrincipalName == USERPRINCIPAL))
                             Assert.AreEqual(newUser.department, departmentName);



In this post I just showed how easy it is to write integrations test against the AAD. And a more lightweight way to try working and debugging the API, than through a MVC application.

Friday, November 29, 2013

Do we need a TypeScript BCL

I have been thinking about starting a new TypeScript project TypeScript.BCL.

I'm not quite sure that I need it, but I also feeling dumb writing my own "standard types" for example the Guid. So I was thinking what would a TypeScript.BCL consist of.

Quick brainstorm:

  • Guid
  • Lists, queues, stacks, hashtables, dictionaries and readonly
  • StringBuilder

I know that I already can find most in JavaScript or TypeScript already, but I think i would be nice if there was only one place to get what you need, and a dedicated group to maintain the library. This would also be a good opportunity to meet others that would geek and talk about TypeScript.

So should we, or should we not have a TypeScript base library, that is the question, please post questions or comments that would be great.