Fork me on GitHub

Last June I was in Madrid for TechEd Conference. The main focus was The Cloud. Microsoft has actually done a really good job and the platform is very mature. I’m not going to lie by saying that I will prefer to host everything in the cloud than doing it on-premise. A few PowerShell scripts and voila you got yourself the desired environments. And with the instance slider, you got yourself the amount of instances that you could need for a specific period. Try to do something similar with your on-premises infrastructure. Another awesome feature is that from now on you will only pay for the environments if they are running. This means that DEV and TEST can be shut down while they are not being used:

All

Lucian Wischik gave three talks with regards to async arriving to C# 5.0 (no callbacks needed). Hmmmm, I wonder were we have seen this before, who said F#?

All

Another really interesting talk was David Starr regarding Brownfield Development. We all have seen this huge amount of spaghetti code right?

All

But how do we actually ensure that we don’t get to this point? And how do we avoid that methods grow to become huge? I think the main problem is because we use a toolbox that actually allows this to happen, mostly cos it’s part of it’s verbosity

All

… well the answer isn’t that difficult. Even though Dustin Campbell gave a good talk, Microsoft really needs to understand that they are not going to catch the businessmen attention by showing a how F# is really good to solve Project Euler problems. What Microsoft needs to do, is to show on one of their platforms how using F# provides a more clean and robust way to make quality software, and we might able to help out on this one, stay tuned:

All

Finally, not everything in Madrid had to be hard work, there were also time to some pleasure:

All

As it has been a while since I went to TechEd and because I have to give a small talk for the rest of Delegate A/S employees, I needed to get the PowerPoints and some videos. I was a bit bored and cos I love F# I decided to make a small file crawler. Things I noticed while creating the app is how simple it is to convert from a sequential to parallel app. Just convert the sequence to an array and then apply parallelism, as simple as that. The only issue I found while converting the app to run in parallel is that printfn is not thread-safe so a few changes to Console.WriteLine and sprintf and voila, it’s 100% parallel. This is one of the strong sides of F#, like any other .NET language, it has access to the whole Frameworks API.

namespace Stermon.Tools.TechEdFileCrawler

open System
open System.IO
open System.Net
open System.Text.RegularExpressions
open FSharp.Net

type TechEdFileCrawlerLib() =
    member private this.absoluteUrl url href =
        WebUtility.HtmlDecode(Uri(url).GetLeftPart(UriPartial.Authority) + href)

    member private this.ensureUrl url (match':string) (tags:string) =
        match'
        |> fun s -> s.Replace(@"href=""", String.Empty)
        |> fun s ->
            let rec cleanTags (s':string) tags' =
                match tags' with
                | x::xs -> cleanTags (s'.Replace(@""">" + x, String.Empty)) xs
                | [] -> s'
            cleanTags s (tags.Split('|') |> Array.toList)
        |> fun s ->
            match s.StartsWith("http") with
            | false -> this.absoluteUrl url s
            | true -> s        

    member this.Crawl url (tags:string) =
        let tags' =
            tags.Split('|')
            |> Array.map(fun x -> @"href.*" + x)
            |> Array.reduce(fun x y -> x + "|" + y)

        let html = Http.Request(url)

        let m = Regex.Match(html, tags')

        let rec hrefs (m:Match) = seq{
            match (m.Success) with
            | true ->
                yield! [for g in m.Groups -> this.ensureUrl url g.Value tags]
                yield! hrefs (m.NextMatch())
            | false -> ()
        }

        hrefs m

    member this.PagesRec url tag =
        let rec pages acc sq = seq{
                match (sq |> Seq.toList) with
                | x::xs -> yield! pages (Seq.append acc sq) (this.Crawl x tag)
                | [] -> yield url; yield! acc
            }

        pages Seq.empty (this.Crawl url tag)

    member this.Download href =
        try
            match Http.RequestDetailed(href).Body with
            | HttpResponseBody.Binary bytes ->
                let name (href':string) = 
                    href'
                    |> fun s -> s.Replace(@"http://", String.Empty)
                    |> fun s -> s.Replace(@"/", "_")

                match (Directory.Exists(@".\techEd")) with
                | false -> Directory.CreateDirectory(@".\techEd") |> ignore
                | true -> ()

                File.WriteAllBytes(@".\techEd\" + (name href), bytes)

                Console.WriteLine(sprintf "%O" (@"-Saved: " + href))
            | _ -> ()
        with
        | exn ->
            let en = Environment.NewLine
    
            Console.WriteLine(
                sprintf @"-An exception occurred:%s >>%s %s >>%s" 
                    en exn.Message en href)

Remark: There is no need to actually change the algorithm, so it is still as readable as it was before. Like stated before, change three lines and voila, the app runs in parallel …

open System
open Stermon.Tools.TechEdFileCrawler

let getArg argv key =
    let arg = Array.tryFind(fun (a:string) -> a.StartsWith(key)) argv
    match arg with
    | Some x -> x.Replace(key, String.Empty)
    | None -> failwith ("Missing argument: " + key)

[<EntryPoint>]
let main argv = 
    try
        let tec = TechEdFileCrawlerLib()
        tec.PagesRec (getArg argv "url=") (getArg argv "next=")
//        |> Seq.iter(fun x ->
//            tec.Crawl x (getArg argv "tags=")
//            |> Seq.iter(fun x -> tec.Download x))
        |> Seq.toArray
        |> Array.Parallel.iter(fun x ->
            tec.Crawl x (getArg argv "tags=")
            |> Seq.toArray
            |> Array.Parallel.iter(fun x -> tec.Download x))
    with
        | exn ->
            let iexn =
                match (exn.InnerException) with
                | null -> "No InnerException."
                | iexn' -> iexn'.Message
            printfn "An exception occurred:\n -%s\n -%s" exn.Message iexn
    0

The crawler is called from a terminal like this:

TechEdFileCrawler.exe ^
  "url=http://channel9.msdn.com/Events/TechEd/Europe/2013?sort=status" ^
  "next=next" ^
  "tags=Slides|Zip"

And will save the files and write the following output:

...
-Saved: http://video.ch9.ms/sessions/teched/eu/2013/ATC-B210.pptx
-Saved: http://video.ch9.ms/sessions/teched/eu/2013/OUC-B306.pptx
-Saved: http://video.ch9.ms/sessions/teched/eu/2013/DEV-IL201.zip
-Saved: http://video.ch9.ms/sessions/teched/eu/2013/OUC-B302.pptx
-Saved: http://video.ch9.ms/sessions/teched/eu/2013/WCA-B208.pptx
-Saved: http://video.ch9.ms/sessions/teched/eu/2013/ATC-B204.pptx
-An exception occurred: 
 >>The remote server returned an error: (404) Not Found.
 >>http://video.ch9.ms/sessions/teched/eu/2013/WPH-H201.zip
-An exception occurred:
 >>The remote server returned an error: (404) Not Found.
 >>http://video.ch9.ms/sessions/teched/eu/2013/WPH-H202.zip
-Saved: http://video.ch9.ms/sessions/teched/eu/2013/SES-H201.zip
-An exception occurred:
 >>The remote server returned an error: (404) Not Found.
 >>http://video.ch9.ms/sessions/teched/eu/2013/WPH-H203.zip
-Saved: http://video.ch9.ms/sessions/teched/eu/2013/DBI-H212.zip
-An exception occurred:
 >>The remote server returned an error: (404) Not Found.
 >>http://video.ch9.ms/sessions/teched/eu/2013/WPH-H206.zip
-Saved: http://video.ch9.ms/sessions/teched/eu/2013/ATC-B214.pptx
-Saved: http://video.ch9.ms/sessions/teched/eu/2013/WAD-B291.pptx
-Saved: http://video.ch9.ms/sessions/teched/eu/2013/SES-H204.zip
-Saved: http://video.ch9.ms/sessions/teched/eu/2013/DBI-H213.zip
-An exception occurred:
 >>The remote server returned an error: (404) Not Found.
 >>http://video.ch9.ms/sessions/teched/eu/2013/WPH-H204.zip
-Saved: http://video.ch9.ms/sessions/teched/eu/2013/SES-H202.zip
-Saved: http://video.ch9.ms/sessions/teched/eu/2013/OUC-B307.pptx
...

p.s.: It wouldn’t be that difficult to convert the code above to a generic website file crawler …

I recently participated at Microsoft’s Dynamics CRM Training Blitz Day, on the Technical Overview for Application consultants, Presales consultants and Developers Track. My first impression was …

All

… and it’s actually the way it should be. As we have it now, there a lot of code monkeys that really don’t understand the complexity of the systems they are developing, and I know cos I’ve been that monkey on several occasions. But it’s not always the monkeys fault, what you have to understand is that what people have been working on for several years, a developer has to learn and master in very short period in order to implement in code, normally the pre-analysis/design phase of a project. On other occasions it’s the experts in the subject that are not able to communicate what they want to the developers in an understandable language, like for example plain English.

Back in the days while I was studying at the Computer Science Department at Copenhagen University, myself and two fellow students, Joakim Ahnfelt-Rønne and Jørgen Thorlund Haahr, wrote a bachelor thesis on the subject: Klient/server-applikation til kvalitetskontrol af tandbehandlinger. We tried to create a generic application that would allow subject-matter experts to define some business processes from an administration interface without the use of any kind of code. This processes would be defined with a set of rules that would be enforced whenever his/hers peers/colleagues would execute the defined process on both the client side but as well on the server side. It’s been about 5 years since we made that initial prototype, a very limited piece of software but theoretical correct and usable in real-life, to what we have nowadays in form of CRM2013 and I can’t avoid to get a little smile on my face thinking that at least one of the big software companies are doing things the right way, or at least they are trying.

The agenda for the Training Blitz Day looked promising with buzzwords as: New UI, Process Agility, Mobile Client, Yammer Integration, Exchange Sync, Business Rules, Client Extensibility

All

… and it didn’t disappointed me, even though it was 4 hours with very short breaks combined with my previous 8 hours at work.

They started by given a simple introduction to the new UI. The left bar, which took about 20% of the screen is now placed on the top. This new bar is always visible and you can access all the different sections of the CRM system at any time.

All

Another major change in the Forms are that they now are a combination of several entities thanks to the Business Process flows. Given the many devices that now are able to connect to CRM, the Form visibility will adjust automatically based on the size of the screen. Also mention that Forms are now a single page, where the previous iFrames are replaced with div html tags that are loaded asynchronously.

All

Finally, as Microsoft already pointed out, the very heavy loading Ribbons are gone for good. They are replaced with the command bar, which is enabled for touch screens, which is always visible.

All

As mentioned in the beginning of this blog post, the Business Process Flows are pushed to a whole new level, where you are just not locked to a single process but while you are working on an opportunity for example, you can choose to run the cross-sale process if you already know the customer instead of having to go through the standard lead-to-opportunity process.

All

The processes are easily defined with the well known interface, there are some minor changes.

All

The best part is that these Business Processes will work for all your interfaces: CRM web interface, Mobile applications, Outlook, Custom apps

All

One of the awaited moments was the presentation of the Mobile Apps, only available for Microsoft and Apple phones and tablets at the moment. The application are build on HTML5 but with a native wrapper in order get access to the specific hardware features. By using HTML5 it’s easier to provide new functionality without having to deploy new applications to the different App Stores.

Note: There will be no offline client, what Microsoft tries to push is the always-online and when you aren’t, you will have cached previously downloaded data. As with the Xbox One, they would might have to rethink that one again, or at least we will need developers to do that part.

All

The XML used to save the visual representations for the Forms and Dashboard, will be reused on the Mobile Apps. This will make it easier to re-use already implemented functionality. There are introduced some limits in order to provide a fluent user experience.

All

There is also made a separate phone app that integrates with contacts in order to make phone-calls directly from the CRM app.

All

Another feature of the new CRM is that the old heavy-in-memory Outlook client

All

will be replaced by several processes that will operate separately avoiding the OS memory limit

All

Another awaited feature is the Server-side synchronization. No more E-mail routers and no more Outlook client must be running on the users PC in order to send a couple of messages.

All

From now on, these tasks will now be done between the Exchange and CRM servers.

All

A flow of the update of an item from a phone, is done without Outlook even been used.

All

So how difficult is it going to be to upgrade from CRM2011 to CRM2013? Well it’s going to be really easy, if your solution complies with the SDK. On the CRM online version, Microsoft will take care of everything. On-Premises there are to options:

  • Best-practice: Just take a backup of the current tenant and then import it into your new CRM2013 setup.

  • Alternatively: Upgrade the current CRM2011 with CRM2013 and choose to update all current tenants or wait to do it later from the Deploy Manager.

All

One of the performance improvements of the upgrade is that tables will be merged into a single table, it was separated into two tables because of previous SQL limitations for tables.

All

In order to implement Business Process Flows there will be almost no need to use code made by developers, that is usually difficult to maintain across different developers. Instead there will be used a declarative/visualized language/interface

All

Once a rule is defined, it will work everywhere.

All

The subject-matter experts will be able to define the processes from a very simple but powerful interface.

All

The process will be deployed with the solution packages and they now also support export/import of labels for use with several languages.

All

Only headache will be once again the unsupported solutions created by some “Partners”, even though Microsoft keeps saying time and time again, don’t do it.

All

What the final customer has to understand is that by allowing this to happen, it gets more difficult to upgrade smoothly and even install the latest roll-updates containing not only new functionality but also fixes to know bugs. Finally the amount of time/money used to correct these problems, that shouldn’t be there in the first place, are the final customer going to pay for and not the “Partner”. Just think about that for a moment …

All

Due to the new UI, the Client SDK is expanded to support the new functionality.

Remark: Some CRM2011 functionality will be @deprecated in the new release. You can see the differences between the two SDK visualizations here: Xrm.Page Object Model

All

Another must-have for any single business critical application out there is an built-in autosave functionality.

Remark: Plug-ins will trigger every time auto-saved is called, so please re-think the logic on how plug-ins are implemented. The best-practices recommended by Microsoft are always to limit the fields an update plug-in should be triggered on.

All

Sitemaps and customizations to that will still be done through the XML as we are used to.

All

Another AWESOME feature in combination with the Business Process flows are that now workflows can be run synchronously as plug-ins (both pre- and post). This will also limit the amount of code needed to implement plug-ins.

All

All

In order to support real-life scenarios where a set of events needs to be triggered and combine state between these events will now also be possible to be done without writing code. I wished they used a bit more time on this matter as it will be game changer compared to other CRM providers.

All

Also CRM2013 will provide OData access to Mobile/Custom Apps that uses the OData interface through the Windows Azure Active Authentication library.

There will also be support for phone/SMS mechanism to login for very high secured organizations.

All

As an CRM Architect is very easy to understand why so many, and more and more organizations are choosing the CRM Framework (xRM), as the backbone of their systems. Just look at the next picture. By adding a simple entity to your solution, you will automatically get all this. Just by doing a few mouse clicks and adding some text. Impressive right?

All

Finally I would like to say that I’m very exited and gratefully surprised with the outcome of the new CRM2013 release. I’m really looking forward to work with it and as I’m writing this blog post, we just received and e-mail from Microsoft noticing us that Delegate A/S CRM Online solution will be upgraded in December this year, without having to do anything from our side. The cloud is no longer the future, but the present.

I would see ideas in dreams. My mind was bursting with ideas. I would wake up in the middle of the night. In dreams, I would have visions of code.

Once you decide on your occupation, you must immerse yourself in your work. You have to fall in love with your work. Never complain about your job.

You must dedicate your life to mastering your skill. That’s the secret of success and is the key to being regarded honorably.

I’ve seen many software developers who are self-critical, but I’ve never seen another software developer who is so hard on himself.

  • He sets the standard for self-discipline.

  • He is always looking ahead.

  • He’s never satisfied with his work.

  • He’s always trying to find ways to make the code better or to improve his skills. Even now, that’s what he thinks about every day.

A great software developer has the following five attributes:

  • First, they take their work very seriously and consistently perform on the highest level.

  • Second, they aspire to improve their skills.

  • Third is cleanliness. If the code doesn’t feel clean, the program isn’t going to perform well.

  • Fourth attribute is impatience. They are not prone to collaboration. They’re stubborn and insist on having things their own way.

What ties these attributes together is passion. That’s what makes a great software developer.

A great software developer must have all of these attributes.

A great software developer must be a perfectionist.

How to print your inbox, including subfolders and mail items

open System.Runtime.InteropServices
open Microsoft.Office.Interop.Outlook
 
let printTreeStruture l =
    l |> List.map(fun n -> 
        printf "%O" (String.replicate n " ")
        printf "%O" "|") |> ignore
    printf "%O" "- "
    ()
 
let printItems l (mi:MailItem) =
    printTreeStruture l
    printfn "%O" (mi.Subject)
 
let printFolder l (mf:MAPIFolder) =
    printTreeStruture l
    printfn "%O" (mf.Name.ToUpper())
 
let items l (f:Items) =
    for i in f do
        match i with
        | :? MailItem as mi -> printItems l mi
        | _ -> ()
 
let rec folders l (f:Folders) =
    for mf in f do
        printFolder l mf
        items (l @ [1]) mf.Items
        match mf.Folders with
        | :? MAPIFolder -> ()
        | _ -> folders (l @ [1]) mf.Folders
 
[<EntryPoint>]
let main argv = 
    let o = new Microsoft.Office.Interop.Outlook.ApplicationClass()
    let mapi = o.GetNamespace("MAPI")
    let mv = System.Reflection.Missing.Value
    let f = mapi.GetDefaultFolder(OlDefaultFolders.olFolderInbox)
    let exp = f.GetExplorer(false) 
 
    mapi.Logon(mv,mv,mv,mv)
 
    printFolder [] f
 
    folders [0] f.Folders
 
    try
        Marshal.ReleaseComObject(o) |> ignore 
    with
        | exn ->
            let innerMessage =
                match (exn.InnerException) with
                | null -> ""
                | innerExn -> innerExn.Message
            printfn "An exception occurred:\n %s\n %s" exn.Message innerMessage
    0

The only dependency is the Microsoft.Office.Interop.Outlook assembly

Assembly

The output will be like:

-INBOX
|-FOLDER1_NAME
| |-SUBFOLDER1_NAME
| | |-Email1_Subject
| | |-SUBSUBFOLDER1_NAME
| | | |-Email1_Subject
| | | |-Email2_Subject
| | | |-…

If you have the issue that not all messages are retrieved, follow this kb article: Read more at Only a subset of your Exchange mailbox items are synchronized in Outlook 2013

But the trick is to set the Mails to keep offline slider to All: All

And remember to release the COM object.

JavaScript is the most used programing language on GitHub (21% of all the projects, https://github.com/languages/). All of us that have worked with this programing language, know that it’s very difficult to find errors while writing the code, as it is with all other dynamics typed languages. This is where FunScript enters the picture, by giving the possiblity to write in F#, a strongly typed programing language, and then by compiling it to JavaScript. But haven’t we heard this before? Write in a strongly-typed language and then compile to JavaScript (CoffeScript, Haxe, Cappuccino, Dart, TypeScript, …). Yes, but the main difference between FunScript and other frameworks, is that it doesn’t rely on a FFI (Foreign Function Interface) but on TypeProviders which makes the Framework very easy to extend.

FunScript supports REST + TypeScript, among others as TypeProviders. This way you can rely on other to write them (d3.d.ts, google.maps.d.ts, jquery.d.ts, jquerymobile.d.ts, jqueryui.d.ts, node.d.ts, …) and if you need a special library you can create your own TypeScript declaration file and contribute to expand the FunScript community.

Link to slides: Slides

And for more information (and video soon): Open Source Days 2013