Rash thoughts about .NET, C#, F# and Dynamics NAV.


"Every solution will only lead to new problems."

Friday, 4. January 2013


F# and Microsoft Dynamics NAV 2013 OData Services

Filed under: C#,Diverses,Dynamics NAV 2009,Dynamics NAV 2013,F#,Visual Studio — Steffen Forkmann at 13:52 Uhr

In my last post I described how we can access Dynamics NAV 2009 SOAP web services from F# and the benefits we get by using a type provder. Since version 2013 it’s also possible to expose NAV pages via OData. In this article I will show you how the OData type provider which is part of F# 3 can help you to easily access this data.

Exposing the data

First of all follow this walkthrough and expose the Customer Page from Microsoft Dynamics NAV 2013 as an OData feed.

Show the available companies

Let’s try to connect to the OData feed and list all available companies. Therefore we create a new F# console project (.NET 4.0) in Visual Studio 2012 and add references to FSharp.Data.TypeProviders and System.Data.Services.Client. With the following snippet we can access and print the company names:

As you can see we don’t need to use the “Add Service Reference” dialog. All service type are generated on the fly.

Access data within a company

Unfortunately Dynamics NAV 2013 seems to have a bug in the generated metadata. In order to access data within a company we need to apply a small trick. In the following sample we create a modified data context which points directly to a company:

Now we can start to access the data:

As you can see this approach is very easy and avoids the problem with the manual code generation. If you expose more pages then they are instantly available in your code.

As with the Wsdl type provider you can expose the generated types from this F# project for use in C# projects.

Further information:

https://frmedicamentsenligne.com
Tags: , , ,

Wednesday, 26. September 2012


FSharpx type providers are available as separate nuget packages

Filed under: F# — Steffen Forkmann at 20:20 Uhr

In order to simplify the access of the FSharpx type providers I separated them into their own nuget packages. From now on we have:

At the moment all type providers should work with .NET 4.0 and .NET 4.5 and F# 3.0.

Tags: , ,

Thursday, 13. September 2012


Graph type providers in FSharpx

Filed under: C#,F#,Informatik,Mathematik — Steffen Forkmann at 9:24 Uhr

After the official Visual Studio 2012 launch yesterday I think it’s a good idea to announce two new type providers which are based on the DGMLTypeProvider from the F# 3.0 Sample Pack.

Synchronous and asynchronous state machine

The first one is only a small extension to the DGMLTypeProvider by Tao. which allows to generate state machines from DGML files. The extension is simply that you can choose between the original async state machine and a synchronous version, which allows easier testing.

image

If you want the async version, which performs all state transitions asynchronously, you only have to write AsyncStateMachine instead of StateMachine.

State machine as a network of types

The generated state machine performs only valid state transitions, but we can go one step further and model the state transitions as compile time restrictions:

image

As you can see the compiler knows that we are in State2 and allows only the transitions to State3 and State4.

If you write labels on the edges of the graph the type provider will generate the method names based on the edge label. In the following sample I’ve created a small finite-state machine which allows to check a binary number if it has an even or odd number of zeros:

image

As you can see in this case the compiler has already calculated that 10100 has an odd number of zeros – no need to run the test Zwinkerndes Smiley.

This stuff is already part of the FSharpx.TypeProviders.Graph package on nuget so please check it out and give feedback.

Tags: , ,

Sunday, 25. March 2012


Statically typed access to JSON and XML by using schema inference

Filed under: F# — Steffen Forkmann at 18:11 Uhr

I’m happy to annouce a new nuget release of FSharpx.TypeProviders. The new version 1.5.3 allows to access JSON and XML in a strongly typed way. These new type providers are based on an XML type provider by Tomas Petricek. I added a write API and a JSON version.

Idea

Whereas XML allows different ways to define a schema, JSON has no schema. Nevertheless most documents have some kind of an implicitly defined schema. These new type providers try to infer the schema from a sample file and provide you types to access any file which is conform to this schema.

Let’s take a look at some of the new features.

JSON access

Consider this JSON sample from Wikipedia:

Let’s add this file to a new F# solution and reference the FSharpx.TypeProviders.dll via install-package FSharpx.TypeProviders. Enable the type provider in the following dialog:

enable

Now that we have a sample data and the type provider ready we get full Intellisense:

image

In most cases you want to use the initial document only as a sample, therefore it’s also possible to load a different document at runtime which the type provider will treat with the same schema:

It’s even possible to modify properties:

Accessing XML

After adding a reference to System.Xml.dll and System.Xml.Linq.dll it’s also very easy to access XML. Since both type providers have the same features we will use yet another way to provide a schema sample. In this case we give the schema inlined:

Schema invalidation

One important aspect of type providers is the schema invalidation. For instance try to remove the line with the age property of WikiSample.txt and save the file. The type provider will detect this schema change and your code will no longer compile:

image

Enjoy your statically typed JSON/XML documents.

Tags: , ,

Thursday, 22. March 2012


WPF Designer for F#

Filed under: C#,F#,WPF — Steffen Forkmann at 19:19 Uhr

F# 3.0 brings the new type providers feature which enables a lot of different applications. Today I’m happy to announce that the FSharpx project brings you a WPF designer for F# in the Visual Studio 11 beta.

image

A big kudos to Johann Deneux for writing the underlying XAML type provider.

  1. Create a new F# 3.0 Console application project
  2. Set the output type to “Windows Application” in the project settings
  3. Use nuget and install-package FSharpx.TypeProviders.Xaml
  4. Add references to WindowsBase.dll, PresentationFramework.dll, System.Xaml.dll and PresentationCore.dll
  5. Add a Xaml file to your project. Something like this:
  6. Now you can access the Xaml in a typed way:
  7. Start the project

Enjoy!

BTW: No code generation needed is for this. No more nasty *.xaml.cs files.
BTW2: Try to change the name of Button1 in the Xaml and press save. Zwinkerndes Smiley

Tags: , , , ,