Archive

Archive for the ‘.NET’ Category

Propagate infolog messages to the windows event log

November 4th, 2011 No comments

The windows event viewer can be a nice tool to check for messages dispatched by the system. You can save the logs in there, reopen them, different kinds of information is available so you can actually trace lots of things in there. But wouldn’t it be nice to also be able to log the messages thrown by Ax 2012 in the windows event log?

That way you do not lose user messages and they are nicely logged into the event viewer. It can also help to log messages received on a client that you cannot seem to reproduce, …

Well, it is possible and here is how to do it in a couple of steps:

  • Add a windows event log and source to put our specific infolog messages in
  • Edit the Ax32 config file to add an event log listener to the configuration

Create event log and source

So first things first, let’s create a windows event log by using the following powershell command

new-eventlog -logname "RealDolmen Ax Solutions" -source "Ax 2012 Infolog"

The result should be like in the figure below

Configure the listener

To add a listener, first open the ax32.exe.config file located in the clientbin directory. You should see a configuration similar to this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319" />
<requiredRuntime version="v4.0.30319" safemode="true"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="EditorComponents"/>
</assemblyBinding>
</runtime>
</configuration>

Modify the configuration so that it looks like this: (It is absolutely important to keep the source name !! The initializeData must be filled with the source you created in the event log)

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<trace autoflush="true"/>
<sources>
<source name="Microsoft.Dynamics.Kernel.Client.DiagnosticLog-Infolog" switchValue="Information">
<listeners>
<!-- The initializeData contains the source that was linked to the created event log -->
<add name="EventLog"
type="System.Diagnostics.EventLogTraceListener"
initializeData="Ax 2012 Infolog"/>
</listeners>
</source>
</sources>
</system.diagnostics>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319" />
<requiredRuntime version="v4.0.30319" safemode="true"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="EditorComponents"/>
</assemblyBinding>
</runtime>
</configuration>

Now we are all set up and when firing up the client, any messages to the infolog should be redirected to the event log. So let’s send some error lines to the infolog.

Now check if the same messages appear in the infolog. Normally this is what it should look like:

So there you have it. The messages are nicely logged in the event viewer. As a last remark, you can also adjust the logging level by modifying the switchvalue of the source. Off will not log anything at all, verbose will fill your event log with everything.

AX2012 Editor Extensions

November 3rd, 2011 No comments

Today I was reading a very interesting post about possible extensions to the editor in AX 2012 and I would very much like to share it.

Basically it explains that the editor is a hosted visual studio editor (that was already clear) and by knowing this, it is also possible to use the extensions that are available there to the editor inside Ax.
The post I read was dealing with the brace matching extension that is available to do automatic formatting of the braces.

You can read the full post here : http://dev.goshoom.net/en/2011/10/ax2012-editor-extensions/

Dynamics Ax 2012 Technical conference : Day 1 : Part 1

January 19th, 2011 6 comments

This articles will be brief, because I don’t have much time between the sessions J

Yesterdag was the first day of the Dynamics Technical conference and following sessions were attended by me:

  • Programming model improvements Part 1 of 2
  • Programming model improvements Part 2 of 2
  • Developing in .NET managed code and X++ Enhancements
  • Solving the element ID problem

Programming model improvements Part 1 of 2

From this session, I remember the following additional features:

  • Table inheritance is added. So now you can have abstract tables which are then inherited by child tables.
    The unit of work pattern also comes into play here as there will be issues to address to manage transactions and code dealing with one ‘virtual record’ which may consist of multiple child tables. (Vehicle table with child tables bycicle, car, truck, …)
  • Next to normal X++ temporary tables, there is now also support for temporary tables in SQL Server
  • Date effective tables have been added. This means you can actualy filter records based on an ‘effective as of date’
  • Eventing has been added so now you can actually subscribe methods to events on other classes. Also, this is implemented by drag and drop so it is actually user friendly to do this.
  • The normal batch framework has been ‘adjusted / replaced’ with the SysOperation framework
  • The tree of linked tables are then linked by RecId, but you can actually have a key with fields specified in a field group to be used in the design when showing on what the linked was based
  • Tables have full text indes support now : This means they can be optimized for searches on text fields to look for certain words in the body.

Historical data pattern

This one is actually cool. Let’s say you have a historical table to contain a history of sales. Then you can set properties on the SalesTable datasource and the kernel will keep the history for you. So when you change values on the sales order for example, the kernel will create / update records in the historical data table.

Query ranges vs Query filters

When using joins (outer joins) the query ranges can produce incorrect outcomes. But now query filters are used to fix that. Instead of using the QueryRange object on the query, you can now also use QueryFilter objects and they are more optimized for SQL Server.

The other sessions will be describes in following posts as there is new session beginning right now J

Dynamics Ax AIF Web Service reference credential problem

March 26th, 2010 2 comments
 

At a customer’s site, I was creating some extra AIF wcf services so that some extra tables would be externally available. For creating the WCF service, I was using the service wizard in Ax 2009 which is described here : http://msdn.microsoft.com/en-us/library/aa609947.aspx

The newly created service was deployed to the Internet Information Server but when the .Net application tried to reference the webservice, the following happened : The service was prompting for credentials and did not work properly.

WCF Service Reference Credential Prompt

After a certain amount of searching time and nearly giving up,  I was browsing the configuration file of the web services directory and discovered that the BindingMethod of the deployed services was configured to use basicHttpBinding.

Endpoint binding method basicHttpBinding

This was the actual problem because the wsdl looked like this : (negotiate authentication tags were added, …)

 

Wrong WSDL with negotiateAuthentication tag

Changing the binding method to wsHttpBinding creates the service without the negotiateAuthentication and takes care of our annoying credential problem.

Endpoint binding method wsHttpBinding

Using C# / XML / XSLT to create Excel Spreadsheet

August 21st, 2009 3 comments

This article will not go into the details of the SpreadSheetML format but is inteded to show a way of creating Excel spreadsheets programatically.
There are several ways to do this and this is only one of them so I am also not going to make comparisons between the different methods.

In this example we are going to do the following :

  • Create an XML file containing customers
  • Create a template from Excel
  • Adjust the template file and turn it into an XSL file
  • Transform the customer XML file to get the result we want

Creating the XML file

We are going to create a simple XML file using C# containing a list of Items. The following figure shows the fields available for an item.

tblinventTable

For this post, we are going to keep it simple and write three sample items in the XML file.
Normally this data would be fetched from a database but here we just export three sample items from the code.

CreateXml

The result is the following XML file :

RawXml

Creating the template

Now that we have the XML file (which is relatively simple to create from your application), we are going to create an excel file template that will be used to merge with the XML file to get the result we want.

So we fire up Excel and create a simple spreadsheet to contain the list of Items.

ExcelTemplate1

When we have our desired layout, we save the file as an XML spreadsheet.

FileType

Now it is getting interesting… We can open the XML file an there we see that it is saved in the OOXML format (SpreadsheetML in this case)

ExcelTemplate2

From here on we can change the template by adding XSLT code that will receive data from the Items.xml file and that way we can add a row for each item to our spreadsheet. (You many possibilities here. It is also possible for example to create a worksheet for each item, …)

First  we adjust the template to create an XSL file. So rename the ItemsTemplate.xml filename to ItemsTemplate.xsl.

Then adjust the xsl file by adding following code at the beginning of the document :

BeginDoc

Also add the closing tags at the end of the document.

To create a record for each item in the source XML file , we just need to do an xsl:for-each loop for each item and process the XML code generated by excel.

 ValueOfSelect

Before we continue, there is a little thing we still need to do because otherwise this will not be working. In the xml node “Table” we need to delete the attribute “ExpandedRowCount” otherwise excel will not be able to open the result document.

Now our template is ready to be used in a transformation with the source XML file.

Transform the XML

Following code shows how you can do XSLT transformation through C# code resulting in the final XML file.

TransformCode

The actual result looks like this in the XML file.

ResultXml

And this can be neatly opened in Excel and gives the following result.

ResultExcel